BUG: Pro-Sites not enqueuing script properly causing issue for humming bird

In the file: pro-sites/pro-sites-files/gateways/gateway-stripe.php
This line:
add_action( 'wp_head', array( 'ProSites_Gateway_Stripe', 'checkout_js' ) );
Problemo for humming bird...checkout_js is jquery and if you load jquery below so that google page speed ranks you higher, ect then we get a problem...cause checkout_js is loading before and not making sure jquery has been loaded.

So..it needs to be re-written properly to wait for jquery and not be forced in the head of the file (why load it there? no comprende)

In addition...why inline this code.....there are no variables that the javascript needs to pull from PHP....right?

Anyways...this is broken...and unnecessarily bad word press coding standards.

But shoot...what do I know.

  • Ben

    replace that line mentioned with the following code:

    // ben ben start
                    //add_action( 'wp_head', array( 'ProSites_Gateway_Stripe', 'checkout_js' ) );
                    if ( ! wp_script_is( 'jquery', 'done' ) ) {
                                            wp_enqueue_script( 'jquery' );
                    }
                    $temp_message = "<script type='text/javascript'> jQuery( document ).ready( function () {
                                    jQuery( 'a#stripe_cancel' ).click( function () {
                                            if ( confirm( '";
                    $temp_message .=
                                     __( 'Please note that if you cancel your subscription you will not be immune to future price increases. The price of un-canceled subscriptions will never go up!\n\nAre you sure you really want to cancel your subscription? This action cannot be undone!', 'psts' );
                    $temp_message  .= "' ) ) {
                                                    return true;
                                            } else {
                                                    return false;
                                            }
                                    } );
                            } );</script>";
                    wp_add_inline_script( 'jquery-migrate', $temp_message );
                    // ben ben end
  • Mahlamusa

    Hello James.

    I hope you are having a great day so far.

    I would like to say thank you for taking your time to provide the solution to the problem. I have personally went through this and have applied your code to a fix for this.

    The final code is not exactly the same as the code above. This is due to the fact that the function wp_add_inline_script automatically adds the script opening <script type='text/javascript'> and closing </script> tags and so the code becomes like the following:

    if ( ! wp_script_is( 'jquery', 'done' ) ) {
    			wp_enqueue_script( 'jquery' );
    		}
    		$temp_message = "jQuery( document ).ready( function () {
    			jQuery( 'a#stripe_cancel' ).click( function () {
    				if ( confirm( '";
    $temp_message .= __( 'Please note that if you cancel your subscription you will not be immune to future price increases. The price of un-canceled subscriptions will never go up!\n\nAre you sure you really want to cancel your subscription? This action cannot be undone!', 'psts' );
    $temp_message .= "' ) ) {
    					return true;
    				} else {
    					return false;
    				}
    			} );
    		});";
    		wp_add_inline_script( 'jquery-migrate', $temp_message );

    Please note that this is without the <script type='text/javascript'> and </script> tags.

    Please note that this is still not in the current development of the plugin. It may be included in the next release and may possibly be modified or implemented in another way.

    You may use this or your version of the code and please let me know if you need help or you have more suggestions in this regard.

    We value your input and feedback.

    I hope you enjoy your day further.

    Cheers,
    Mahlamusa