The MU forums have moved to WordPress.org

Plugins vs blogs (8 posts)

  1. edir
    Member
    Posted 15 years ago #

    I'm trying to understand plugin section on MU.

    I noticed something, even if in the blogs the plugin is deactivated, when I activate it on main blog, it works on all other blogs instead of only in the main blog.

    I read the faq and stil don't understand the use of plugins on MU.

    How do I install a plugin and activate it on a single blog only?

    And in my installation, instead of create a new blog for the main site, I used the first blog "/", "wp_1", instead. Is that wrong?

  2. DeannaS
    Member
    Posted 15 years ago #

    I'm not sure what your last question means. But, activating a plugin on a single blog should work. You're not using the "activate sitewide" link, are you? Because that will do what you're describing - activate it for all blogs.

  3. edir
    Member
    Posted 15 years ago #

    No, i was activating for single use and it works like a sitewide. The activation is made on the main blog, the first blog that you have before installation.

  4. DeannaS
    Member
    Posted 15 years ago #

    It shouldn't do that. What plugin is this?

  5. edir
    Member
    Posted 15 years ago #

    I made my own, very simple. Lets see the code. Should I forgot to insert something in the code?

    function me_get_category_template($template) {
    	global $wp_query;
    	$post_obj = @$wp_query->get_queried_object();
    
    	if (is_single()) {
    		$file = 'single';
    		$categories = get_the_category($post_obj->ID);
    	} else if (is_category()) {
    		$file = 'category';
    		$categories[0] = &get_category($post_obj->cat_ID);
    	}
    
    	$categories = me_get_category_parents_hierarchical($categories[0]->cat_ID);
    
    	foreach((array)$categories as $category) {
    		$template = "/$file-{$category->slug}.php";
    		if (file_exists(TEMPLATEPATH.$template)) {
    			include(TEMPLATEPATH.$template);
    			exit;
    		}
    	}
    
    }
    
    function me_get_category_parents_hierarchical( $id) {
    	$chain = array();
    	$parent = &get_category($id);
    	$chain[] = $parent;
    	if($parent->parent) {
    		$chain = array_merge($chain, me_get_category_parents_hierarchical($parent->parent));
    	}
    	return $chain;
    }
    
    add_filter('template_redirect', 'me_get_category_template');
  6. SteveAtty
    Member
    Posted 15 years ago #

    and where did you put this "plugin". Code put into mu-plugins will automatically be applied across all blogs

  7. edir
    Member
    Posted 15 years ago #

    I know and I put it inside /plugins, like the others.
    I made a test, I just need to activate it on any of the blogs, just one, to let it work in all of them.

  8. DeannaS
    Member
    Posted 15 years ago #

    Here's what I did. I don't have any of the templates that you'd need to actually see what this plugin is doing. So, I added a dump of the $wp_filter['template_redirect'] global variable on the dashboard (via this code:)

    add_action( 'activity_box_end', 'cets_dashboard_message', 1);
    
    function cets_dashboard_message() {
    global $wp_filter;
    var_dump($wp_filter['template_redirect']);
    }

    Then, I put your code in a file with the appropriate plugin header information and activated it on the main blog. I correctly see these 2 variables:
    ["me_get_category_template"]=> array(2) { ["function"]=> string(24) "me_get_category_template" ["accepted_args"]=> int(1)

    I went to the dashboard of a subblog, and the plugin-defined template_redirect variables are not in the template_redirect structure. Seems to work exactly as it should.

    Are you using plugin commander or any of the other plugin manager things and somehow have it set to auto activate?

About this Topic