Easy Digital Downloads
  • Package
  • Function
  • Tree

Packages

  • EDD
    • Admin
      • Actions
      • Add-ons
      • Dashboard
      • Discounts
      • Downloads
      • Export
      • Notices
      • Pages
      • Payments
      • Reports
      • Settings
      • System
      • Upgrades
      • Upload
      • Welcome
    • Cart
    • Checkout
    • Classes
      • API
      • Fees
      • HTML
      • Roles
      • Session
    • Emails
    • Functions
      • AJAX
      • Compatibility
      • Errors
      • Formatting
      • Install
      • Login
      • Taxes
      • Templates
    • Gateways
    • Logging
    • Payments
    • Shortcodes
    • Widgets

Functions

  • edd_admin_footer_for_thickbox
  • edd_media_button
  1 <?php
  2 /**
  3  * Thickbox
  4  *
  5  * @package     EDD
  6  * @subpackage  Admin
  7  * @copyright   Copyright (c) 2013, Pippin Williamson
  8  * @license     http://opensource.org/licenses/gpl-2.0.php GNU Public License
  9  * @since       1.0
 10  */
 11 
 12 // Exit if accessed directly
 13 if ( ! defined( 'ABSPATH' ) ) exit;
 14 
 15 /**
 16  * Adds an "Insert Download" button above the TinyMCE Editor on add/edit screens.
 17  *
 18  * @since 1.0
 19  * @return string "Insert Download" Button
 20  */
 21 function edd_media_button( $context ) {
 22     global $pagenow, $typenow, $wp_version;
 23     $output = '';
 24 
 25     /** Only run in post/page creation and edit screens */
 26     if ( in_array( $pagenow, array( 'post.php', 'page.php', 'post-new.php', 'post-edit.php' ) ) && $typenow != 'download' ) {
 27         /* check current WP version */
 28         if ( version_compare( $wp_version, '3.5', '<' ) ) {
 29             $img = '<img src="' . EDD_PLUGIN_URL . 'assets/images/edd-media.png" alt="' . sprintf( __( 'Insert %s', 'edd' ), edd_get_label_singular() ) . '"/>';
 30             $output = '<a href="#TB_inline?width=640&inlineId=choose-download" class="thickbox" title="' . __( 'Insert Download', 'edd' ) . '">' . $img . '</a>';
 31         } else {
 32             $img = '<span class="wp-media-buttons-icon" id="edd-media-button"></span>';
 33             $output = '<a href="#TB_inline?width=640&inlineId=choose-download" class="thickbox button" title="' . sprintf( __( 'Insert %s', 'edd' ), strtolower ( edd_get_label_singular() ) ) . '" style="padding-left: .4em;">' . $img . sprintf( __( 'Insert %s', 'edd' ), strtolower( edd_get_label_singular() ) ) . '</a>';
 34         }
 35     }
 36     return $context . $output;
 37 }
 38 add_filter( 'media_buttons_context', 'edd_media_button' );
 39 
 40 /**
 41  * Admin Footer For Thickbox
 42  *
 43  * Prints the footer code needed for the Insert Download
 44  * TinyMCE button.
 45  *
 46  * @since 1.0
 47  * @global $pagenow
 48  * @global $typenow
 49  * @return void
 50  */
 51 function edd_admin_footer_for_thickbox() {
 52     global $pagenow, $typenow;
 53 
 54     // Only run in post/page creation and edit screens
 55     if ( in_array( $pagenow, array( 'post.php', 'page.php', 'post-new.php', 'post-edit.php' ) ) && $typenow != 'download' ) {
 56         $downloads = get_posts( array( 'post_type' => 'download', 'posts_per_page' => -1 ) );
 57         ?>
 58         <script type="text/javascript">
 59             function insertDownload() {
 60                 var id = jQuery('#select-edd-download').val(),
 61                     style = jQuery('#select-edd-style').val(),
 62                     color = jQuery('#select-edd-color').is(':visible') ? jQuery('#select-edd-color').val() : '',
 63                     text = jQuery('#edd-text').val() || '<?php _e( "Purchase", "edd" ); ?>';
 64 
 65                 // Return early if no download is selected
 66                 if ('' === id) {
 67                     alert('<?php _e( "You must choose a download", "edd" ); ?>');
 68                     return;
 69                 }
 70 
 71                 // Send the shortcode to the editor
 72                 window.send_to_editor('[purchase_link id="' + id + '" style="' + style + '" color="' + color + '" text="' + text + '"]');
 73             }
 74             jQuery(document).ready(function ($) {
 75                 $('#select-edd-style').change(function () {
 76                     if ($(this).val() === 'button') {
 77                         $('#edd-color-choice').slideDown();
 78                     } else {
 79                         $('#edd-color-choice').slideUp();
 80                     }
 81                 });
 82             });
 83         </script>
 84 
 85         <div id="choose-download" style="display: none;">
 86             <div class="wrap" style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;">
 87             <?php
 88             if ( $downloads ) { ?>
 89                 <p><?php echo sprintf( __( 'Use the form below to insert the short code for purchasing a %s', 'edd' ), edd_get_label_singular() ); ?></p>
 90                 <div>
 91                     <select id="select-edd-download" style="clear: both; display: block; margin-bottom: 1em;">
 92                         <option value=""><?php echo sprintf( __( 'Choose a %s', 'edd' ), edd_get_label_singular() ); ?></option>
 93                         <?php
 94                             foreach ( $downloads as $download )
 95                                 echo '<option value="' . absint( $download->ID ) . '">' . esc_attr( $download->post_title ) . '</option>';
 96                         ?>
 97                     </select>
 98                 </div>
 99                 <div>
100                     <select id="select-edd-style" style="clear: both; display: block; margin-bottom: 1em;">
101                         <option value=""><?php _e( 'Choose a style', 'edd' ); ?></option>
102                         <?php
103                             $styles = array( 'button', 'text link' );
104                             foreach ( $styles as $style ) {
105                                 echo '<option value="' . $style . '">' . $style . '</option>';
106                             }
107                         ?>
108                     </select>
109                 </div>
110                 <div id="edd-color-choice" style="display: none;">
111                     <select id="select-edd-color" style="clear: both; display: block; margin-bottom: 1em;">
112                         <option value=""><?php _e('Choose a button color', 'edd'); ?></option>
113                         <?php
114                             $colors = edd_get_button_colors();
115                             foreach ( $colors as $key => $color )
116                                 echo '<option value="' . str_replace( ' ', '_', $key ) . '">' . $color . '</option>';
117                         ?>
118                     </select>
119                 </div>
120                 <div>
121                     <input type="text" class="regular-text" id="edd-text" value="" placeholder="<?php _e( 'Link text . . .', 'edd' ); ?>"/>
122                 </div>
123                 <p class="submit">
124                     <input type="button" id="edd-insert-download" class="button-primary" value="<?php echo sprintf( __( 'Insert %s', 'edd' ), edd_get_label_singular() ); ?>" onclick="insertDownload();" />
125                     <a id="edd-cancel-download-insert" class="button-secondary" onclick="tb_remove();" title="<?php _e( 'Cancel', 'edd' ); ?>"><?php _e( 'Cancel', 'edd' ); ?></a>
126                 </p>
127             <?php } ?>
128         </div>
129     </div>
130     <?php
131     }
132 }
133 add_action( 'admin_footer', 'edd_admin_footer_for_thickbox' );
Easy Digital Downloads API documentation generated by ApiGen 2.8.0