Support » Plugin: eShop » BUG: The javascript for eShop is not defined properly.

  • Resolved trusktr


    There is some javascript that eShop adds to the page that looks like this:

    <script type="text/javascript">
    		var Id =$(this).attr("id");
    		var data = {action: 'eshop_special_action',post:$('#'+Id).serialize() };
    		$.post("", data,
    			$('#'+Id +" .eshopajax").insertAfter(this).fadeIn(100).html(response).fadeOut(3000);
    			setTimeout (cleareshopCart,1000);
    			setTimeout (doeshopRequest,750);
    			setTimeout (cleareshopRequest,3000);
    		function doeshopRequest(){
    			var tdata = {action: 'eshop_cart'};
    			$.post("", tdata,
    		function cleareshopRequest(){
    		function cleareshopCart(){
    		return false;

    This code is improperly defined. It doesn’t follow WordPress standards. How do I know? I installed a plugin called “JavaScript to Footer” which moves all properly defined scripts to the “footer” hook location. All the scripts on my page get moved except for that eShop code.

    Can you please fix?

Viewing 13 replies - 1 through 13 (of 13 total)
  • For example, you need to do something like this:

    // activate modified Shutter reloaded if not use the Shutter plugin
    	if ( ($this->options['thumbEffect'] == "shutter") && !function_exists('srel_makeshutter') ) {
    		wp_register_script('shutter', NGGALLERY_URLPATH .'shutter/shutter-reloaded.js', false ,'1.3.3');
    		wp_localize_script('shutter', 'shutterSettings', array(
    					'msgLoading' => __('L O A D I N Ghello', 'nggallery'),
    					'msgClose' => __('Click to Close', 'nggallery'),
    					'imageCount' => '1'
    		) );
    		wp_enqueue_script( 'shutter' );

    You must use the wp_enqueue_script() function.

    Why not do something like

    <script src="eshop_action_javascript.php?addfadein=100&addfadeout=3000&etc"></script>

    then include it with wp_enqueue_script()?



    Forum Moderator

    The script you reference should not be placed in the page’s footer. It simply will not work there. Secondly, please bear in mind that eShop is a pretty mature plugin (it’s almost 5 years old). I agree that some of the early coding may need to be updated but with over 200 separate files and only a limited amount of available time, it’s a task that has to be undertaken over a few versions. I’ve flagged the enqueue issue up for next version but it won’t solve your issue as the script in question will still be added to the header. Move it and eShop will stop working properly.

    Finally, this is not a “bug”. The plugin works just fine. It’s just that WordPress itself has matured considerably since eShop was first created. Given that the plugin is currently on version 6.2.12, I think we’re doing pretty well. 🙂

    Hello esmi, I moved the script to the footer and it works just fine. After moving all other scripts to the footer, I changed ‘wp_head’ to ‘wp_footer’ on line 134 in eshop.php as a temporary fix. It works perfect.

    I’ll make a working solution and post it in a little while.



    Forum Moderator

    The issue that we’re looking at if we enqueue it is how to add variables (such as the site/page url) dynamically to the script.

    Alright, I fixed it. The variables are added dynamically while still using wp_enqueue_script().

    So basically, I swapped line 134 with 135 in eshop.php, then on line 135 I changed ‘wp_head’ to ‘wp_print_scripts’ so in eshop.php we have this:

    Then I removed the script from the eshop_action_javascript() function and put it in a seperate file called ‘eshop-cart.js’. Now the eshop_action_javascript() function in public-functions.php looks like this:

    The wp_localize_script() function writes the parameters to the HTML before the script is included on the page. So inside eshop-cart.js we use ‘eshopCartParams.addfadein’ (etc) to use the php-generated variables.

    The generated HTML looks like this:

    and eshop-cart.js looks like this:

    Now the script is properly registered and so it follows wordpress standards. It works now with plugins like “JavaScript to Footer”.

    Below is a zip file containing the modified plugin. Can you checkout the differences and apply a patch to the plugin here on



    Forum Moderator

    We can certainly have a look at it and maybe add it to the next release but that’s not due until the end of June, I’m afraid.

    That’s alright, I can use my modified version until then. 😉 If my fix makes it into the source it’d be cool to know that I contributed. 😀



    Forum Moderator

    I’ve flagged this topic up again for Rich, so hopefully he’ll get a chance to have a look at the patch over the next few days and get back to you. In the meantime, thanks for taking the time out to create and submit a patch.

    By the way, thanks to Otto for the article on passing PHP variables to Javascript:

    Passing parameters from PHP to Javascripts in plugins

    Sure, no prob. It benefits myself and the WordPress community at the same time.

    Plugin Author elfin


    won’t have time to test atm, but thanks for the work on this. It is on my list of todo things for the next release now.

    Sweet. No prob. Should I post the patch somewhere? In the bug tracker?

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘BUG: The javascript for eShop is not defined properly.’ is closed to new replies.