Example #1
0
/**
 * Load Scripts
 *
 * Enqueues the required scripts.
 *
 * @since 1.0
 * @global $post
 * @return void
 */
function edd_load_scripts()
{
    global $post;
    $js_dir = EDD_PLUGIN_URL . 'assets/js/';
    // Use minified libraries if SCRIPT_DEBUG is turned off
    $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
    // Get position in cart of current download
    if (isset($post->ID)) {
        $position = edd_get_item_position_in_cart($post->ID);
    }
    if (edd_is_checkout()) {
        if (edd_is_cc_verify_enabled()) {
            wp_register_script('creditCardValidator', $js_dir . 'jquery.creditCardValidator' . $suffix . '.js', array('jquery'), EDD_VERSION);
            wp_enqueue_script('creditCardValidator');
        }
        wp_register_script('edd-checkout-global', $js_dir . 'edd-checkout-global' . $suffix . '.js', array('jquery'), EDD_VERSION);
        wp_enqueue_script('edd-checkout-global');
        wp_localize_script('edd-checkout-global', 'edd_global_vars', apply_filters('edd_global_checkout_script_vars', array('ajaxurl' => edd_get_ajax_url(), 'checkout_nonce' => wp_create_nonce('edd_checkout_nonce'), 'currency_sign' => edd_currency_filter(''), 'currency_pos' => edd_get_option('currency_position', 'before'), 'no_gateway' => __('Please select a payment method', 'edd'), 'no_discount' => __('Please enter a discount code', 'edd'), 'enter_discount' => __('Enter discount', 'edd'), 'discount_applied' => __('Discount Applied', 'edd'), 'no_email' => __('Please enter an email address before applying a discount code', 'edd'), 'no_username' => __('Please enter a username before applying a discount code', 'edd'), 'purchase_loading' => __('Please Wait...', 'edd'), 'complete_purchase' => __('Purchase', 'edd'), 'taxes_enabled' => edd_use_taxes() ? '1' : '0', 'edd_version' => EDD_VERSION)));
    }
    // Load AJAX scripts, if enabled
    if (!edd_is_ajax_disabled()) {
        wp_register_script('edd-ajax', $js_dir . 'edd-ajax' . $suffix . '.js', array('jquery'), EDD_VERSION);
        wp_enqueue_script('edd-ajax');
        wp_localize_script('edd-ajax', 'edd_scripts', apply_filters('edd_ajax_script_vars', array('ajaxurl' => edd_get_ajax_url(), 'position_in_cart' => isset($position) ? $position : -1, 'already_in_cart_message' => __('You have already added this item to your cart', 'edd'), 'empty_cart_message' => __('Your cart is empty', 'edd'), 'loading' => __('Loading', 'edd'), 'select_option' => __('Please select an option', 'edd'), 'ajax_loader' => set_url_scheme(EDD_PLUGIN_URL . 'assets/images/loading.gif', 'relative'), 'is_checkout' => edd_is_checkout() ? '1' : '0', 'default_gateway' => edd_get_default_gateway(), 'redirect_to_checkout' => edd_straight_to_checkout() || edd_is_checkout() ? '1' : '0', 'checkout_page' => edd_get_checkout_uri(), 'permalinks' => get_option('permalink_structure') ? '1' : '0', 'quantities_enabled' => edd_item_quantities_enabled(), 'taxes_enabled' => edd_use_taxes() ? '1' : '0')));
    }
}
/**
 * Load Scripts
 *
 * Enqueues the required scripts.
 *
 * @access      private
 * @since       1.0
 * @return      void
*/
function edd_load_scripts()
{
    global $edd_options, $post;
    wp_enqueue_script('jquery');
    // Get position in cart of current download
    if (isset($post->ID)) {
        $position = edd_get_item_position_in_cart($post->ID);
    }
    // Load AJAX scripts, if enabled
    if (edd_is_ajax_enabled()) {
        wp_enqueue_script('edd-ajax', EDD_PLUGIN_URL . 'assets/js/edd-ajax.js', array('jquery'), EDD_VERSION);
        wp_localize_script('edd-ajax', 'edd_scripts', array('ajaxurl' => edd_get_ajax_url(), 'ajax_nonce' => wp_create_nonce('edd_ajax_nonce'), 'no_discount' => __('Please enter a discount code', 'edd'), 'discount_applied' => __('Discount Applied', 'edd'), 'no_email' => __('Please enter an email address before applying a discount code', 'edd'), 'no_username' => __('Please enter a username before applying a discount code', 'edd'), 'position_in_cart' => isset($position) ? $position : -1, 'already_in_cart_message' => __('You have already added this item to your cart', 'edd'), 'empty_cart_message' => __('Your cart is empty', 'edd'), 'loading' => __('Loading', 'edd'), 'ajax_loader' => EDD_PLUGIN_URL . 'assets/images/loading.gif', 'checkout_page' => edd_get_checkout_uri(), 'permalinks' => get_option('permalink_structure') ? '1' : '0'));
    }
    // Load jQuery validation
    if (isset($edd_options['jquery_validation']) && edd_is_checkout()) {
        wp_enqueue_script('jquery-validation', EDD_PLUGIN_URL . 'assets/js/jquery.validate.min.js');
        wp_enqueue_script('edd-validation', EDD_PLUGIN_URL . 'assets/js/form-validation.js', array('jquery', 'jquery-validation'), EDD_VERSION);
        $required = array('firstname' => true, 'lastname' => true);
        wp_localize_script('edd-validation', 'edd_scripts_validation', apply_filters('edd_scripts_validation', $required));
    }
    if (edd_is_checkout()) {
        if (edd_is_cc_verify_enabled()) {
            wp_enqueue_script('creditCardValidator', EDD_PLUGIN_URL . 'assets/js/jquery.creditCardValidator.js', array('jquery'), EDD_VERSION);
        }
        wp_enqueue_script('edd-checkout-global', EDD_PLUGIN_URL . 'assets/js/edd-checkout-global.js', array('jquery'), EDD_VERSION);
        wp_localize_script('edd-checkout-global', 'edd_global_vars', array('currency_sign' => edd_currency_filter(''), 'currency_pos' => isset($edd_options['currency_position']) ? $edd_options['currency_position'] : 'before', 'no_gateway' => __('Please select a payment method', 'edd')));
    }
}
Example #3
0
/**
 * Print scripts
 *
 * @since 1.0
*/
function edd_wl_print_scripts()
{
    global $edd_options;
    // Use minified libraries if SCRIPT_DEBUG is turned off
    $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
    // register scripts
    wp_register_script('edd-wl', EDD_WL_PLUGIN_URL . 'includes/js/edd-wl' . $suffix . '.js', array('jquery'), EDD_WL_VERSION, true);
    wp_register_script('edd-wl-validate', EDD_WL_PLUGIN_URL . 'includes/js/jquery.validate' . $suffix . '.js', array('jquery'), EDD_WL_VERSION, true);
    wp_register_script('edd-wl-modal', EDD_WL_PLUGIN_URL . 'includes/js/modal' . $suffix . '.js', array('jquery'), EDD_WL_VERSION, true);
    // load scripts on single post type pages
    $post_types = edd_wl_allowed_post_types();
    foreach ($post_types as $post_type) {
        if (is_singular($post_type)) {
            wp_enqueue_script('edd-wl');
            wp_enqueue_script('edd-wl-modal');
        }
    }
    // load validation if email sharing is present
    if (edd_wl_is_page('view') && edd_wl_sharing_is_enabled('email')) {
        wp_enqueue_script('edd-wl-validate');
    }
    wp_localize_script('edd-wl', 'edd_wl_scripts', array('ajaxurl' => edd_get_ajax_url(), 'wish_list_page' => edd_wl_get_wish_list_uri(), 'wish_list_add' => edd_wl_get_wish_list_create_uri(), 'ajax_nonce' => wp_create_nonce('edd_wl_ajax_nonce')));
    // CSS
    $file = 'edd-wl' . $suffix . '.css';
    $templates_dir = edd_get_theme_template_dir_name();
    $child_theme_style_sheet = trailingslashit(get_stylesheet_directory()) . $templates_dir . $file;
    $child_theme_style_sheet_2 = trailingslashit(get_stylesheet_directory()) . $templates_dir . 'edd-wl.css';
    $parent_theme_style_sheet = trailingslashit(get_template_directory()) . $templates_dir . $file;
    $parent_theme_style_sheet_2 = trailingslashit(get_template_directory()) . $templates_dir . 'edd-wl.css';
    $edd_plugin_style_sheet = trailingslashit(edd_wl_get_templates_dir()) . $file;
    // Look in the child theme directory first, followed by the parent theme, followed by the EDD core templates directory
    // Also look for the min version first, followed by non minified version, even if SCRIPT_DEBUG is not enabled.
    // This allows users to copy just edd-wl.css to their theme
    if (file_exists($child_theme_style_sheet) || !empty($suffix) && ($nonmin = file_exists($child_theme_style_sheet_2))) {
        if (!empty($nonmin)) {
            $url = trailingslashit(get_stylesheet_directory_uri()) . $templates_dir . 'edd-wl.css';
        } else {
            $url = trailingslashit(get_stylesheet_directory_uri()) . $templates_dir . $file;
        }
    } elseif (file_exists($parent_theme_style_sheet) || !empty($suffix) && ($nonmin = file_exists($parent_theme_style_sheet_2))) {
        if (!empty($nonmin)) {
            $url = trailingslashit(get_template_directory_uri()) . $templates_dir . 'edd-wl.css';
        } else {
            $url = trailingslashit(get_template_directory_uri()) . $templates_dir . $file;
        }
    } elseif (file_exists($edd_plugin_style_sheet) || file_exists($edd_plugin_style_sheet)) {
        $url = trailingslashit(edd_wl_get_templates_url()) . $file;
    }
    wp_enqueue_style('edd-wl-styles', $url, array(), EDD_WL_VERSION, 'screen');
}
/**
 * Check if AJAX works as expected
 *
 * @since 2.2
 * @return bool True if AJAX works, false otherwise
 */
function edd_test_ajax_works()
{
    // Check if the Airplane Mode plugin is installed
    if (class_exists('Airplane_Mode_Core')) {
        $airplane = Airplane_Mode_Core::getInstance();
        if (method_exists($airplane, 'enabled')) {
            if ($airplane->enabled()) {
                return true;
            }
        } else {
            if ($airplane->check_status() == 'on') {
                return true;
            }
        }
    }
    add_filter('block_local_requests', '__return_false');
    if (get_transient('_edd_ajax_works')) {
        return true;
    }
    $params = array('sslverify' => false, 'timeout' => 30, 'body' => array('action' => 'edd_test_ajax'));
    $ajax = wp_remote_post(edd_get_ajax_url(), $params);
    $works = true;
    if (is_wp_error($ajax)) {
        $works = false;
    } else {
        if (empty($ajax['response'])) {
            $works = false;
        }
        if (empty($ajax['response']['code']) || 200 !== (int) $ajax['response']['code']) {
            $works = false;
        }
        if (empty($ajax['response']['message']) || 'OK' !== $ajax['response']['message']) {
            $works = false;
        }
        if (!isset($ajax['body']) || 0 !== (int) $ajax['body']) {
            $works = false;
        }
    }
    if ($works) {
        set_transient('_edd_ajax_works', '1', DAY_IN_SECONDS);
    }
    return $works;
}
 /**
  * Load custom ajax
  */
 public function load_custom_ajax()
 {
     wp_enqueue_script('wpmenucart', plugins_url('/javascript/wpmenucart.js', __FILE__), array('jquery'), '2.5.6', true);
     // get URL to WordPress ajax handling page
     if ($this->options['shop_plugin'] == 'easy-digital-downloads' && function_exists('edd_get_ajax_url')) {
         // use EDD function to prevent SSL issues http://git.io/V7w76A
         $ajax_url = edd_get_ajax_url();
     } else {
         $ajax_url = admin_url('admin-ajax.php');
     }
     wp_localize_script('wpmenucart', 'wpmenucart_ajax', array('ajaxurl' => $ajax_url, 'nonce' => wp_create_nonce('wpmenucart')));
 }
 /**
  * Enqueues all theme assets
  */
 public function enqueue_assets()
 {
     wp_enqueue_style('yoast-com');
     wp_enqueue_script('yoast-com');
     wp_localize_script('yoast-com', 'YoastAjax', array('ajaxurl' => admin_url('admin-ajax.php')));
     if (function_exists('edd_is_checkout') && edd_is_checkout()) {
         wp_enqueue_style('chosen');
         wp_enqueue_script('yoast-com-checkout');
         wp_localize_script('yoast-com-checkout', 'yoast_com_checkout_vars', array('ajaxurl' => edd_get_ajax_url(), 'checkout_nonce' => wp_create_nonce('edd_checkout_nonce'), 'taxes_enabled' => edd_use_taxes() ? '1' : '0', 'tax_rates' => $this->get_tax_rates()));
     }
     // Remove the cross selling CSS because we overwrite it completely.
     wp_deregister_style('edd-csau-css');
     if (is_singular('post') && !Hide_Comments::hide_comments() && comments_open()) {
         wp_enqueue_script('comment-reply');
     }
     if (is_singular(array('course', 'lesson', 'llms_quiz'))) {
         wp_enqueue_script('yoast-com-academy');
     }
 }
Example #7
0
/**
 * Print scripts
 *
 * @since 1.0
*/
function edd_wl_sharing_print_scripts()
{
    global $edd_options;
    if (!edd_wl_is_view_page()) {
        return;
    }
    ?>
	<script type="text/javascript">

	<?php 
    /**
     * Twitter
     *
     * @since 1.0
     */
    if (edd_wl_sharing_is_enabled('twitter')) {
        ?>
	  	window.twttr = (function (d,s,id) {
		  var t, js, fjs = d.getElementsByTagName(s)[0];
		  if (d.getElementById(id)) return; js=d.createElement(s); js.id=id;
		  js.src="https://platform.twitter.com/widgets.js"; fjs.parentNode.insertBefore(js, fjs);
		  return window.twttr || (t = { _e: [], ready: function(f){ t._e.push(f) } });
		}(document, "script", "twitter-wjs"));

		twttr.ready(function (twttr) {
		    twttr.events.bind('tweet', function (event) {
		        jQuery.event.trigger({
		            type: "listShared",
		            url: event.target.baseURI
		        });
		    });
		});

		<?php 
    }
    ?>

		<?php 
    /**
     * Google +
     *
     * @since 1.0
     */
    if (edd_wl_sharing_is_enabled('googleplus')) {
        $locale = apply_filters('edd_wl_googleplus_locale', 'en-US');
        ?>
			window.___gcfg = {
			  lang: '<?php 
        echo $locale;
        ?>
',
			  parsetags: 'onload'
			};

			(function() {
			    var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
			    po.src = 'https://apis.google.com/js/plusone.js';
			    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
			  })();

			function plusOned(obj) {
				console.log(obj);
				jQuery.event.trigger({
				    type: "listShared",
				    url: obj.href
				});
			}
		<?php 
    }
    ?>

		<?php 
    /**
     * LinkedIn
     *
     * @since 1.0
     */
    if (edd_wl_sharing_is_enabled('linkedin')) {
        ?>
			function share(url) {
				console.log(url);
			 	jQuery.event.trigger({
		            type: "listShared",
		            url: url
		        });
			}
		
		<?php 
    }
    ?>

		<?php 
    /**
     * Facebook
     *
     * @since 1.0
     */
    if (edd_wl_sharing_is_enabled('facebook')) {
        // defaults to en_US if left blank
        $locale = apply_filters('edd_wl_facebook_locale', 'en_US');
        ?>

			(function(d, s, id) {
			     var js, fjs = d.getElementsByTagName(s)[0];
			     if (d.getElementById(id)) {return;}
			     js = d.createElement(s); js.id = id;
			     js.src = "//connect.facebook.net/<?php 
        echo $locale;
        ?>
/all.js";
			     fjs.parentNode.insertBefore(js, fjs);
			 }(document, 'script', 'facebook-jssdk'));

			window.fbAsyncInit = function() {
			    // init the FB JS SDK
			    FB.init({
			      status	: true,
			      cookie	: true,                               
			      xfbml		: true                              
			    });

			    FB.Event.subscribe('edge.create', function(href, widget) {
			        jQuery.event.trigger({
			            type: "listShared",
			            url: href
			        });     
			    });
			};
		<?php 
    }
    ?>

		<?php 
    /**
     * Listen for the productShared event
     *
     * @since 1.0
     */
    if (edd_wl_sharing_is_enabled()) {
        ?>

		/* <![CDATA[ */
		var edd_wl_vars = {
			"ajaxurl": 		"<?php 
        echo edd_get_ajax_url();
        ?>
",
			"edd_wl_nonce": "<?php 
        echo wp_create_nonce('edd_wl_nonce');
        ?>
"
		};
		/* ]]> */

		jQuery(document).ready(function ($) {

			jQuery(document).on( 'listShared', function(e) {

				if( e.url == window.location.href ) {

			    	var postData = {
			            action: 'share_list',
			            list_id: <?php 
        echo get_the_ID();
        ?>
, 
			            nonce: edd_scripts.ajax_nonce
			        };

			    	$.ajax({
			            type: "POST",
			            data: postData,
			            dataType: "json",
			            url: edd_wl_vars.ajaxurl,
			            success: function ( share_response ) {

		            	}
				        }).fail(function (data) {
				            console.log( data );
				        });
				}
			});
		});
	<?php 
    }
    ?>
	</script>
	<?php 
}
        /**
         * Print scripts
         *
         * @since 2.0
         */
        public function print_script()
        {
            global $edd_options;
            if (!self::$add_script) {
                return;
            }
            ?>
			<script type="text/javascript">

			<?php 
            /**
             * Twitter
             *
             * @since 2.0
             */
            if ($this->is_enabled('twitter')) {
                ?>
			  	window.twttr = (function (d,s,id) {
				  var t, js, fjs = d.getElementsByTagName(s)[0];
				  if (d.getElementById(id)) return; js=d.createElement(s); js.id=id;
				  js.src="https://platform.twitter.com/widgets.js"; fjs.parentNode.insertBefore(js, fjs);
				  return window.twttr || (t = { _e: [], ready: function(f){ t._e.push(f) } });
				}(document, "script", "twitter-wjs"));

				twttr.ready(function (twttr) {
				    twttr.events.bind('tweet', function (event) {
				        jQuery.event.trigger({
				            type: "productShared",
				            url: event.target.baseURI
				        });
				    });
				});

				<?php 
            }
            ?>

				<?php 
            /**
             * Google +
             *
             * @since 2.0
             */
            if ($this->is_enabled('googleplus')) {
                // defaults to en_US if left blank
                $locale = isset($edd_options['edd_sd_googleplus_locale']) && !empty($edd_options['edd_sd_googleplus_locale']) ? $edd_options['edd_sd_googleplus_locale'] : 'en-US';
                ?>
					window.___gcfg = {
					  lang: '<?php 
                echo $locale;
                ?>
',
					  parsetags: 'onload'
					};

					(function() {
					    var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
					    po.src = 'https://apis.google.com/js/plusone.js';
					    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
					  })();

					function plusOned(obj) {
						console.log(obj);
						jQuery.event.trigger({
						    type: "productShared",
						    url: obj.href
						});
					}
				<?php 
            }
            ?>

				<?php 
            /**
             * LinkedIn
             *
             * @since 2.0
             */
            if ($this->is_enabled('linkedin')) {
                ?>
					function share(url) {
						console.log(url);
					 	jQuery.event.trigger({
				            type: "productShared",
				            url: url
				        });
					}
				
				<?php 
            }
            ?>

				<?php 
            /**
             * Facebook
             *
             * @since 2.0
             */
            if ($this->is_enabled('facebook')) {
                // defaults to en_US if left blank
                $locale = isset($edd_options['edd_sd_facebook_locale']) && !empty($edd_options['edd_sd_facebook_locale']) ? $edd_options['edd_sd_facebook_locale'] : 'en_US';
                ?>

					(function(d, s, id) {
					     var js, fjs = d.getElementsByTagName(s)[0];
					     if (d.getElementById(id)) {return;}
					     js = d.createElement(s); js.id = id;
					     js.src = "//connect.facebook.net/<?php 
                echo $locale;
                ?>
/all.js";
					     fjs.parentNode.insertBefore(js, fjs);
					 }(document, 'script', 'facebook-jssdk'));

					window.fbAsyncInit = function() {
					    // init the FB JS SDK
					    FB.init({
					      status	: true,
					      cookie	: true,                               
					      xfbml		: true                              
					    });

					    FB.Event.subscribe('edge.create', function(href, widget) {
					        jQuery.event.trigger({
					            type: "productShared",
					            url: href
					        });     
					    });
					};
				<?php 
            }
            ?>

				<?php 
            /**
             * Listen for the productShared event
             *
             * @since 2.0
             */
            if ($this->is_enabled()) {
                ?>

				/* <![CDATA[ */
				var edd_social_discount_vars = {
					"ajaxurl": "<?php 
                echo edd_get_ajax_url();
                ?>
",
					"edd_sd_nonce": "<?php 
                echo wp_create_nonce('edd_sd_nonce');
                ?>
"
				};
				/* ]]> */

				jQuery(document).ready(function ($) {

					jQuery(document).on( 'productShared', function(e) {

					    	var postData = {
					            action: 'share_product',
					            product_id: <?php 
                echo get_the_ID();
                ?>
, // post the download's ID
					            nonce: edd_social_discount_vars.edd_sd_nonce
					        };

					    	$.ajax({
				            type: "POST",
				            data: postData,
				            dataType: "json",
				            url: edd_social_discount_vars.ajaxurl,
				            success: function ( share_response ) {

				                if( share_response ) {

				                    if ( share_response.msg == 'valid' ) {
										console.log('successfully shared');
										console.log( share_response );

										$('.edd_cart_discount').html( share_response.html );
                        				$('.edd_cart_discount_row').show();

                        				// update cart amounts with new total
										$('.edd_cart_amount').each(function() {
											$(this).text(share_response.total);
										});

				                       jQuery('.edd-sd-share .edd-sd-title').html( share_response.success_title );
				                       jQuery('.edd-sd-share .edd-sd-message').html( share_response.success_message );

				                       // add CSS class so the box can be styled
				                       jQuery('.edd-sd-share').addClass('shared');
				                    } 
				                    else {
				                        console.log('failed to share');
				                        console.log( share_response );
				                    }
				                } 
				                else {
				                    console.log( share_response );
				                }
				            }
				        }).fail(function (data) {
				            console.log( data );
				        });

					});
				});
			<?php 
            }
            ?>
			</script>
			<?php 
        }