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 22 23 24
25 function edd_load_scripts() {
26 global $edd_options, $post;
27
28 wp_enqueue_script( 'jquery' );
29
30
31 if ( isset( $post->ID ) ) {
32 $position = edd_get_item_position_in_cart( $post->ID );
33 }
34
35 if ( edd_is_checkout() ) {
36 if ( edd_is_cc_verify_enabled() ) {
37 wp_enqueue_script( 'creditCardValidator', EDD_PLUGIN_URL . 'assets/js/jquery.creditCardValidator.js', array( 'jquery' ), EDD_VERSION );
38 }
39 wp_enqueue_script( 'edd-checkout-global', EDD_PLUGIN_URL . 'assets/js/edd-checkout-global.js', array( 'jquery' ), EDD_VERSION );
40 wp_localize_script( 'edd-checkout-global', 'edd_global_vars', array(
41 'ajaxurl' => edd_get_ajax_url(),
42 'checkout_nonce' => wp_create_nonce( 'edd_checkout_nonce' ),
43 'currency_sign' => edd_currency_filter(''),
44 'currency_pos' => isset( $edd_options['currency_position'] ) ? $edd_options['currency_position'] : 'before',
45 'no_gateway' => __( 'Please select a payment method', 'edd' ),
46 'no_discount' => __('Please enter a discount code', 'edd'),
47 'discount_applied' => __('Discount Applied', 'edd'),
48 'no_email' => __('Please enter an email address before applying a discount code', 'edd'),
49 'no_username' => __('Please enter a username before applying a discount code', 'edd'),
50 'purchase_loading' => __('Please Wait...', 'edd'),
51 'complete_purchasse' => __('Purchase', 'edd')
52 ));
53 }
54
55
56 if ( edd_is_ajax_enabled() ) {
57 wp_enqueue_script( 'edd-ajax', EDD_PLUGIN_URL . 'assets/js/edd-ajax.js', array( 'jquery' ), EDD_VERSION );
58 wp_localize_script( 'edd-ajax', 'edd_scripts', array(
59 'ajaxurl' => edd_get_ajax_url(),
60 'ajax_nonce' => wp_create_nonce( 'edd_ajax_nonce' ),
61 'position_in_cart' => isset( $position ) ? $position : -1,
62 'already_in_cart_message' => __('You have already added this item to your cart', 'edd'),
63 'empty_cart_message' => __('Your cart is empty', 'edd'),
64 'loading' => __('Loading', 'edd') ,
65 'ajax_loader' => EDD_PLUGIN_URL . 'assets/images/loading.gif',
66 'is_checkout' => edd_is_checkout() ? '1' : '0',
67 'default_gateway' => edd_get_default_gateway(),
68 'redirect_to_checkout' => edd_straight_to_checkout() ? '1' : '0',
69 'checkout_page' => edd_get_checkout_uri(),
70 'permalinks' => get_option( 'permalink_structure' ) ? '1' : '0',
71 )
72 );
73 }
74 }
75 add_action( 'wp_enqueue_scripts', 'edd_load_scripts' );
76
77 78 79 80 81 82 83 84 85
86 function edd_register_styles() {
87 global $edd_options;
88
89 if ( isset( $edd_options['disable_styles'] ) )
90 return;
91
92 $file = 'edd.css';
93
94 if ( file_exists( trailingslashit( get_stylesheet_directory() ) . 'edd_templates/' . $file ) ) {
95 $url = trailingslashit( get_stylesheet_directory_uri() ) . 'edd_templates/' . $file;
96 } elseif ( file_exists( trailingslashit( get_template_directory() ) . 'edd_templates/' . $file ) ) {
97 $url = trailingslashit( get_template_directory_uri() ) . 'edd_templates/' . $file;
98 } elseif ( file_exists( trailingslashit( edd_get_templates_dir() ) . $file ) ) {
99 $url = trailingslashit( edd_get_templates_url() ) . $file;
100 }
101
102 wp_enqueue_style( 'edd-styles', $url, EDD_VERSION );
103 }
104 add_action( 'wp_enqueue_scripts', 'edd_register_styles' );
105
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
125 function edd_load_admin_scripts( $hook ) {
126 global $post, $pagenow, $edd_discounts_page, $edd_payments_page, $edd_settings_page, $edd_reports_page, $edd_system_info_page, $edd_add_ons_page, $edd_options, $edd_upgrades_screen;
127
128 $edd_pages = array( $edd_discounts_page, $edd_payments_page, $edd_settings_page, $edd_reports_page, $edd_system_info_page, $edd_add_ons_page, $edd_upgrades_screen, 'index.php' );
129 $edd_cpt = apply_filters( 'edd_load_scripts_for_these_types', array( 'download', 'edd_payment' ) );
130
131 if ( ! in_array( $hook, $edd_pages ) && ! is_object( $post ) )
132 return;
133
134 if ( is_object( $post ) && ! in_array( $post->post_type, $edd_cpt ) )
135 return;
136
137 if ( $hook == 'download_page_edd-reports' ) {
138 wp_enqueue_script( 'jquery-flot', EDD_PLUGIN_URL . 'assets/js/jquery.flot.js' );
139 }
140 if ( $hook == 'download_page_edd-discounts' ) {
141 wp_enqueue_script( 'jquery-ui-datepicker' );
142 $ui_style = ( 'classic' == get_user_option( 'admin_color' ) ) ? 'classic' : 'fresh';
143 wp_enqueue_style( 'jquery-ui-css', EDD_PLUGIN_URL . 'assets/css/jquery-ui-' . $ui_style . '.css' );
144 }
145 if ( $hook == $edd_settings_page ) {
146 wp_enqueue_style( 'colorbox', EDD_PLUGIN_URL . 'assets/css/colorbox.css', array( ), '1.3.20' );
147 wp_enqueue_script( 'colorbox', EDD_PLUGIN_URL . 'assets/js/jquery.colorbox-min.js', array( 'jquery' ), '1.3.20' );
148 }
149 wp_enqueue_style( 'jquery-chosen', EDD_PLUGIN_URL . 'assets/css/chosen.css', array( ), EDD_VERSION );
150 wp_enqueue_script( 'jquery-chosen', EDD_PLUGIN_URL . 'assets/js/chosen.jquery.min.js', array( 'jquery' ), EDD_VERSION );
151 wp_enqueue_script( 'media-upload' );
152 wp_enqueue_script( 'thickbox' );
153 wp_enqueue_script( 'edd-admin-scripts', EDD_PLUGIN_URL . 'assets/js/admin-scripts.js', array( 'jquery' ), EDD_VERSION, false );
154 wp_localize_script( 'edd-admin-scripts', 'edd_vars', array(
155 'post_id' => isset( $post->ID ) ? $post->ID : null,
156 'edd_version' => EDD_VERSION,
157 'add_new_download' => __( 'Add New Download', 'edd' ),
158 'use_this_file' => __( 'Use This File','edd' ),
159 'quick_edit_warning'=> __( 'Sorry, not available for variable priced products.', 'edd' ),
160 'delete_payment' => __( 'Are you sure you wish to delete this payment?', 'edd' ),
161 'one_price_min' => __( 'You must have at least one price', 'edd' ),
162 'one_file_min' => __( 'You must have at least one file', 'edd' ),
163 'one_field_min' => __( 'You must have at least one field', 'edd' ),
164 'currency_sign' => edd_currency_filter(''),
165 'currency_pos' => isset( $edd_options['currency_position'] ) ? $edd_options['currency_position'] : 'before',
166 'new_media_ui' => apply_filters( 'edd_use_35_media_ui', 1 ),
167 'remove_text' => __( 'Remove', 'edd' )
168 ));
169 wp_enqueue_style( 'thickbox' );
170
171 wp_enqueue_style( 'edd-admin', EDD_PLUGIN_URL . 'assets/css/edd-admin.css', EDD_VERSION );
172 }
173 add_action( 'admin_enqueue_scripts', 'edd_load_admin_scripts', 100 );
174
175 176 177 178 179 180 181 182 183
184 function edd_admin_downloads_icon() {
185 global $post_type;
186 $icon_url = EDD_PLUGIN_URL . 'assets/images/edd-icon.png';
187 ?>
188 <style type="text/css" media="screen">
189 body " ) no-repeat 7px -32px; }
190 body #adminmenu #menu-posts-download:hover div.wp-menu-image,
191 body #adminmenu #menu-posts-download.wp-has-current-submenu div.wp-menu-image { background:transparent url( "<?php echo $icon_url; ?>" ) no-repeat 7px 0; }
192 <?php if ( ( isset( $_GET['post_type'] ) ) && ( $_GET['post_type'] == 'download' ) || ( $post_type == 'download' ) ) : ?>
193 #icon-edit { background:transparent url("<?php echo EDD_PLUGIN_URL .'assets/images/edd-cpt.png'; ?>") no-repeat; }
194 <?php endif; ?>
195 @media
196 only screen and (-webkit-min-device-pixel-ratio: 1.5),
197 only screen and ( min--moz-device-pixel-ratio: 1.5),
198 only screen and ( -o-min-device-pixel-ratio: 3/2),
199 only screen and ( min-device-pixel-ratio: 1.5),
200 only screen and ( min-resolution: 1.5dppx) {
201 /* Admin Menu - 16px @2x */
202 body #adminmenu #menu-posts-download div.wp-menu-image {
203 background: transparent url('<?php echo EDD_PLUGIN_URL; ?>assets/images/edd-icon-2x.png') no-repeat 7px -20px !important;
204 background-size: 16px 48px !important;
205 }
206
207 body #adminmenu #menu-posts-download:hover div.wp-menu-image,
208 body #adminmenu #menu-posts-download.wp-menu-open div.wp-menu-image {
209 background-position: 7px 4px !important;
210 }
211
212 /* Post Screen - 32px @2x */
213 .icon32-posts-download {
214 background: url('<?php echo EDD_PLUGIN_URL; ?>assets/images/edd-cpt-2x.png') no-repeat 0 0 !important;
215 background-size: 32px 32px !important;
216 }
217 }
218 #edd-media-button { -webkit-background-size: 16px; -moz-background-size: 16px; background-size: 16px; background-image: url(<?php echo EDD_PLUGIN_URL; ?>assets/images/edd-cpt-2x.png); margin-top: -1px; }
219 </style>
220 <?php
221 }
222 add_action( 'admin_head','edd_admin_downloads_icon' );
223
224 /**
225 * Adds EDD Version to the <head> tag
226 *
227 * @since 1.4.2
228 * @return void
229 */
230 function edd_version_in_header(){
231 // Newline on both sides to avoid being in a blob
232 echo '<meta name="generator" content="Easy Digital Downloads v'.EDD_VERSION.'" />'."\n";
233 }
234 add_action( 'wp_head', 'edd_version_in_header' );