MarketPress prevent default script and stylesheet inclusion?

Hi all,

Would it be possible to prevent the default inclusion of icons.css, lumebox.css and ajax-cart.js that occurs on every site in a network where MarketPress is network-wide activated? These three files (plus some inline script) is being rendered on every site even if there are no Products configured or any options set.

This is kind of intrusive and redundant. The script is not needed if there is no cart added to the sidebar and these stylesheets can even have rules that conflict with certain themes. For example, I had a sites where the menu suddenly became unreadable. It turned out to be the rule

.clear {
...
font-size: 1px;
}

inside the icons.css in combination with a class "clear" attributed to the wrapping menu div...

Is there any way to make MarketPress start including these resources only when actually needed? So:
1. no shop style selected by default to prevent inclusion of any shop stylesheet;
2. The option Show Image Lightbox off by default;
3. Only include ajax-cart.js when the cart widget is active?

That would be great :slight_smile:

  • Vinod Dalvi

    Hi @RavanH,

    I hope you are well today and thank you for your question.

    Do you want not to include MarketPress scripts & stylesheets on the pages where marketpress products are not getting displayed and there isn't any use of these scripts & stylesheets?

    Do you want to only include ajax-cart.js when the MarketPress shopping cart widget is active?

    For example, I had a sites where the menu suddenly became unreadable.

    Could you please share me the site link or the the theme that you are using on that site so that i can troubleshoot the issue?

    NOTE: I just found that even when the Image Lightbox option if off, the lumebox stylesheet is still included.

    I have tested it on my test site and found this is not the case. If i set the option "Show Image Lightbox" to "No" in the MarketPress Presentation Settings then the lumebox.css stylesheet file is not included in the theme.

    This is handled by the following code in the MarketPress plugin.

    //loads the jquery lightbox plugin
    function enqueue_lightbox() {
     if ( !$this->get_setting('show_lightbox') )
    	return;
    
     wp_enqueue_script('jquery');
     wp_enqueue_style('mp-lightbox', $this->plugin_url . 'lightbox/style/lumebox.css', false, $this->version);	//we enqueue styles on every page just in case of shortcodes http://wp.mu/8ou
     wp_register_script('mp-lightbox', $this->plugin_url . 'lightbox/js/jquery.lumebox.min.js', array('jquery'), $this->version, true);	//we just register the script here - we can output selectively later
    
     // declare the variables we need to access in js
     $js_vars = array( 'graphicsDir' => $this->plugin_url . 'lightbox/style/' );
     wp_localize_script('mp-lightbox', 'lumeboxOptions', $js_vars);
    }

    Kind Regards,
    Vinod Dalvi

  • RavanH

    Do you want not to include MarketPress scripts & stylesheets on the pages where marketpress products are not getting displayed and there isn't any use of these scripts & stylesheets?

    No, even though that would be optimal, I'm talking about a slightly different case. I'll try to explain:
    I have a network where I have activated MarketPress network-wide. Currently, only one site in the network is actually selling products. Others are not using MarketPress (yet) but still, these three files (icons.css, lumebox.css and ajax-cart.js) are included on each site in the network.

    On one particular site, this made the menu disappear due to a font-size: 1px; inside icons.css that was inherited by the menu using that particular class too...

    Could you please share me the site link or the the theme that you are using on that site so that i can troubleshoot the issue?

    Thanks but no need, the conflict was resolved by changing the shop style to "None". I just gave this as an example of "weird" things happening on a network after activating MarketPress network wide.

    The site in question was http://phareo.fr/ where you can see in the source that the menu list uses a class 'clear': <ul id="menu-menu-fr" class="clear nav-menu">

    The site uses the Illustratr theme and Polylang (not sure where the class is coming from actually) and when the Icons shop theme is selected (it isn't now) then the menu becomes unreadably small.

    Do you want to only include ajax-cart.js when the MarketPress shopping cart widget is active?

    If ajax-cart.js is only used for the widget, then I suppose that is indeed what I'd prefer :slight_smile:

    If i set the option "Show Image Lightbox" to "No" in the MarketPress Presentation Settings then the lumebox.css stylesheet file is not included in the theme.

    Yes, you are right. I cannot reproduce that anymore... Think I was fooled by a caching issue. Thanks for checking!

  • Vinod Dalvi

    Hi @RavanH,

    Thank you for your reply.

    I have a network where I have activated MarketPress network-wide. Currently, only one site in the network is actually selling products. Others are not using MarketPress (yet) but still, these three files (icons.css, lumebox.css and ajax-cart.js) are included on each site in the network.

    This is because when you network activate the plugin then it gets activated in every sub site s of the network regardless whether you are using it or not.

    To disable the plugin on any particular sub site where you are not using it yet then you can create a PHP file like functions.php containing the following code and add it in the directory wp-content/mu-plugins( Create if not exist ).

    In the following code you have to change the blog ids 2, 3 to the blog ids on your multisite where you want to deactivate the MarketPress plugin.

    add_filter('site_option_active_sitewide_plugins', 'modify_sitewide_plugins');
    
    function modify_sitewide_plugins($value) {
        global $current_blog;
    
        if( $current_blog->blog_id == 2 || $current_blog->blog_id == 3 ) {
            unset($value['marketpress/marketpress.php']);
        }
    
        return $value;
    }

    The site in question was http://phareo.fr/ where you can see in the source that the menu list uses a class 'clear':
    <ul id="menu-menu-fr" class="clear nav-menu">

    The site uses the Illustratr theme and Polylang (not sure where the class is coming from actually) and when the Icons shop theme is selected (it isn't now) then the menu becomes unreadably small.

    I could confirm the issue which is causing by the following code in the below MarketPress plugin file therefore i have notified the plugin developer about it so that it can be fixed.

    marketpress/themes/icons.css

    .clear{
    clear:both;
    font-size:1px;
    }

    The above code issue can be fixed by declaring the CSS selector more specifically.

    If ajax-cart.js is only used for the widget, then I suppose that is indeed what I'd prefer :slight_smile:

    I will move this over to the features & feedback section. This way it can be considered for future development, and we can also see what other community members think about the feature request.

    Thanks,
    Vinod Dalvi

  • RavanH

    This is because when you network activate the plugin then it gets activated in every sub site s of the network regardless whether you are using it or not.

    Yes, sure, that's the whole point of activating it network wide... I'd like the Products post-type and checkout available to all site owners but not all will be using it.

    To disable the plugin on any particular sub site where you are not using it yet then you can create a PHP file like functions.php containing the following code and add it in the directory wp-content/mu-plugins( Create if not exist ).

    Thanks for the code suggestion. Hopefully it will be useful for others that want to do this. But I'd like the plugin to be active on all sites. Just not the inclusion of these scripts and stylesheets by default and on all pages. Only when there are actually any products added, cart widget set or visiting shop or product pages...

    Thanks for moving this to feature requests :slight_smile:

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.