WordPress.org

Ready to get started?Download WordPress

Forums

My Custom CSS
[resolved] Multisite compatibility (8 posts)

  1. Doug Yuen
    Member
    Posted 1 year ago #

    Great plugin! Can you make it multisite-compatible? Two ideas that come to mind are to either append the site ID to the name of the file created, so multiple CSS files can be created/used, or make the .css file disabled when it's on a multisite install. I am using an older version of your plugin on my multisite installs, and it works like a charm, but I can't upgrade because the file would make the same CSS apply to all sites. It would be great if you could add this fix.

    By the way, I just gave you a 5-star review, not that it should influence your priorities :)

    Thanks!

    http://wordpress.org/extend/plugins/my-custom-css/

  2. DarkWolf
    Member
    Plugin Author

    Posted 1 year ago #

    Sorry, i never tested on multisite... I can try to install a multisite installation in my localmachine and search a fix for it ;)
    -
    Thanks for report (and also for your rating) :)

  3. Doug Yuen
    Member
    Posted 1 year ago #

    Thanks for the quick response!

    After thinking about it again, the easiest thing would probably be to use a conditional so that if it's a multisite installation, ignore getting the CSS from the file and just get it from the options table. Messing around with files and site IDs is probably prone to error. I think the Prose theme by StudioPress used to be set up that way (with site IDs) but the latest version just stores the CSS in the database. There's probably a good reason why they switched.

    Just my thoughts.

  4. DarkWolf
    Member
    Plugin Author

    Posted 1 year ago #

    I've problem to setup multisite in my local machine... but my idea is this:

    function css_path()
    {
    	if (is_multisite())
    	{
    		$css_path = plugin_dir_path(__FILE__)."my_style_id-".get_current_site()->id.".css";
    	}
    	else
    	{
    		$css_path = plugin_dir_path(__FILE__)."my_style.css";
    	}
    	return $css_path;
    }
    
    function css_url()
    {
    	if (is_multisite())
    	{
    		$css_url = plugin_dir_url(__FILE__)."my_style_id-".get_current_site()->id.".css";
    	}
    	else
    	{
    		$css_url = plugin_dir_url(__FILE__)."my_style.css";
    	}
    	return $css_url;
    }
  5. DarkWolf
    Member
    Plugin Author

    Posted 1 year ago #

    Edit: i think is best like this (to maintain id 1 without id in url), but ATM i can't test:

    function css_path()
    {
    	if (is_multisite() && get_current_site()->id > "1")
    	{
    		$css_path = plugin_dir_path(__FILE__)."my_style_id-".get_current_site()->id.".css";
    	}
    	else
    	{
    		$css_path = plugin_dir_path(__FILE__)."my_style.css";
    	}
    	return $css_path;
    }
    
    function css_url()
    {
    	if (is_multisite() && get_current_site()->id > "1")
    	{
    		$css_url = plugin_dir_url(__FILE__)."my_style_id-".get_current_site()->id.".css";
    	}
    	else
    	{
    		$css_url = plugin_dir_url(__FILE__)."my_style.css";
    	}
    	return $css_url;
    }
  6. DarkWolf
    Member
    Plugin Author

    Posted 1 year ago #

    Edit... ok, i've fixed...
    This is a valid code (tested in my local machine):

    function css_path()
    {
    	global $blog_id;
    	if (is_multisite() && ($blog_id > "1"))
    	{
    		$css_path = plugin_dir_path(__FILE__)."my_style_id-".$blog_id.".css";
    	}
    	else
    	{
    		$css_path = plugin_dir_path(__FILE__)."my_style.css";
    	}
    	return $css_path;
    }
    
    function css_url()
    {
    	global $blog_id;
    	if (is_multisite() && ($blog_id > "1"))
    	{
    		$css_url = plugin_dir_url(__FILE__)."my_style_id-".$blog_id.".css";
    	}
    	else
    	{
    		$css_url = plugin_dir_url(__FILE__)."my_style.css";
    	}
    	return $css_url;
    }
  7. DarkWolf
    Member
    Plugin Author

    Posted 1 year ago #

    Fixed with a best control:

    function css_path()
    {
    	global $blog_id; $cssid = ( $blog_id > "1" ) ? $cssid = "_id-".$blog_id : $cssid = null;
    	$css_path = plugin_dir_path(__FILE__)."my_style".$cssid.".css";
    	return $css_path;
    }
    
    function css_url()
    {
    	global $blog_id; $cssid = ( $blog_id > "1" ) ? $cssid = "_id-".$blog_id : $cssid = null;
    	$css_url = plugin_dir_url(__FILE__)."my_style".$cssid.".css";
    	return $css_url;
    }

    I've tested more...
    Seems to work perfect ;)

  8. Doug Yuen
    Member
    Posted 1 year ago #

    Finally got around to testing the upgrade, and it works perfectly. Thanks for the compatibility fix, and for such a quick response!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic