116 pointsSerious WPMU DEV-sterI'm new here
btray77
Member
—
2nd October 2009 (2 years ago)
What is the main difference in how mu-plugins and plugins work. When I put my custom written plugin in the mu-folder it does not work, and I'm wondering what the difference is.
What is the main difference in how mu-plugins and plugins work. When I put my custom written plugin in the mu-folder it does not work, and I'm wondering what the difference is.
I just read on another website that the big difference was hooks and I was wondering if you have any ideas on how I can change from a hook to action or what is required.
Here's what the plugin is using now:
function runit_activate()
{
wp_schedule_event( time(), 'hourly', 'runit_hourly' );
update_option( "permalink_structure", '/%postname%/' );
update_option( "enable_xmlrpc", '1' );
update_option( "display_pnp", '0' );
update_option( "use_pagination", '1' );
update_option( "wpsc_products_per_page", '20' );
update_option( "wpsc_page_number_position", '3' );
}
// Turn off the hourly event if we deactivate the plugin.
function runit_deactivate()
{
wp_clear_scheduled_hook( 'runit_hourly' );
}
register_activation_hook(__FILE__, 'runit_activate');
register_deactivation_hook(__FILE__, 'runit_deactivate');
7430 pointsLike some sort of WPMU DEV GodMindblowingly helpful memberLifetime member
Erstwhile founder
—
2nd October 2009 (2 years ago)
#
Hiya,
Really the only difference between the two is how the plugins are loaded. Plugins placed in mu-plugins are automatically loaded and plugins placed in /plugins/ have to be activated.
The problem with your plugin is that it's firing function via the activation hooks which are not triggered for plugins in mu-plugins (because plugins are automatically loaded).
6593 pointsLike some sort of WPMU DEV GodExceptionally helpfulLifetime member
Keeper of the Dark Chocolate
—
2nd October 2009 (2 years ago)
#
Andrew, there's not a work around for thew activation hooks, is there? I know we're putting the database and option creation commands in the New Blog Default plugin that we use but it would be easier just to change the hook if we can get away with it.
Always seems like we mistype something when we add lines to NBD.
What would I look up or do to get around the activation bit... Just use an add_action(init,functionname) and check to see if some variables are already set?
There is code within wp that will check to see if a table has been created and, if not, go ahead and create those tables. Andrew's Blog Activity plugin is an example of this I believe but in other cases, the wp-shortstat plugin for example, it doesn't work. We go the New Blog Default method for those.
6593 pointsLike some sort of WPMU DEV GodExceptionally helpfulLifetime member
Keeper of the Dark Chocolate
—
6th October 2009 (2 years ago)
#
Sorry. As an aside and no offense to Andrew, make sure you're setting up the databases with the correct charset. That's been an issue with some autocreating database table codes.
6593 pointsLike some sort of WPMU DEV GodExceptionally helpfulLifetime member
Keeper of the Dark Chocolate
—
6th October 2009 (2 years ago)
#
It's really an educational issue that needs to come down from Matt. I think I've seen a total of like 3 plugins that use wp's charset setting when setting up database tables. I see this on other platforms but not many.
Of course I put all of our servers into UTF8 as a default ages ago. Makes for some damn huge databases and it's a bitch to export to outside servers if a client leaves but it solves many other problems.
Responses (11)
Member — 2nd October 2009 (2 years ago) #
I just read on another website that the big difference was hooks and I was wondering if you have any ideas on how I can change from a hook to action or what is required.
Here's what the plugin is using now:
Erstwhile founder — 2nd October 2009 (2 years ago) #
Hiya,
Really the only difference between the two is how the plugins are loaded. Plugins placed in mu-plugins are automatically loaded and plugins placed in /plugins/ have to be activated.
The problem with your plugin is that it's firing function via the activation hooks which are not triggered for plugins in mu-plugins (because plugins are automatically loaded).
Thanks,
Andrew
Keeper of the Dark Chocolate — 2nd October 2009 (2 years ago) #
Andrew, there's not a work around for thew activation hooks, is there? I know we're putting the database and option creation commands in the New Blog Default plugin that we use but it would be easier just to change the hook if we can get away with it.
Always seems like we mistype something when we add lines to NBD.
Erstwhile founder — 2nd October 2009 (2 years ago) #
Not to my knowledge. I've always just had to edit the plugins.
Thanks,
Andrew
Keeper of the Dark Chocolate — 2nd October 2009 (2 years ago) #
Thanks. Just trying to get rid of a few processor processes.
Member — 4th October 2009 (2 years ago) #
What would I look up or do to get around the activation bit... Just use an add_action(init,functionname) and check to see if some variables are already set?
Thanks
-Brad
Keeper of the Dark Chocolate — 4th October 2009 (2 years ago) #
Anything that needs to be activated, we just load into the New Blog Defaults plugin, get it done on blog creation and not worry about it:
http://mu.wordpress.org/forums/topic/10494
There is code within wp that will check to see if a table has been created and, if not, go ahead and create those tables. Andrew's Blog Activity plugin is an example of this I believe but in other cases, the wp-shortstat plugin for example, it doesn't work. We go the New Blog Default method for those.
Member — 6th October 2009 (2 years ago) #
That didn't really help... After looking at how you deal with it on the autoblog plugin I saw how you were doing it.
Keeper of the Dark Chocolate — 6th October 2009 (2 years ago) #
Sorry. As an aside and no offense to Andrew, make sure you're setting up the databases with the correct charset. That's been an issue with some autocreating database table codes.
Erstwhile founder — 6th October 2009 (2 years ago) #
That's still on my list for a rainy day when we're not floored with other work.
Thanks,
Andrew
Keeper of the Dark Chocolate — 6th October 2009 (2 years ago) #
It's really an educational issue that needs to come down from Matt. I think I've seen a total of like 3 plugins that use wp's charset setting when setting up database tables. I see this on other platforms but not many.
Of course I put all of our servers into UTF8 as a default ages ago. Makes for some damn huge databases and it's a bitch to export to outside servers if a client leaves but it solves many other problems.
Become a member