1 <?php
2 3 4 5 6 7 8 9 10
11
12
13 if ( ! defined( 'ABSPATH' ) ) exit;
14
15 16 17 18 19 20
21 function edd_media_button( $context ) {
22 global $pagenow, $typenow, $wp_version;
23 $output = '';
24
25
26 if ( in_array( $pagenow, array( 'post.php', 'page.php', 'post-new.php', 'post-edit.php' ) ) && $typenow != 'download' ) {
27
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 42 43 44 45 46 47 48 49 50
51 function () {
52 global $pagenow, $typenow;
53
54
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
66 if ('' === id) {
67 alert('<?php _e( "You must choose a download", "edd" ); ?>');
68 return;
69 }
70
71
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' );