View Single Post
Old 12-18-2010, 07:22 AM  
fris
Too lazy to set a custom title
 
fris's Avatar
 
Industry Role:
Join Date: Aug 2002
Posts: 55,426
Quote:
Originally Posted by Supz View Post
fris, is there a way to have plugins activate on theme activations in multisite. If you pick a certain theme, it auto activates certain plugins that the theme needs?
hopefully this will help you.

two ways, install automatically if it inst installed, or show a notice in the admin with an option to install the plugin.

Code:
<?php

// add to your theme functions.php
// two ways to do this, automatically, or give the user an option to install the required plugin

// 1. install plugin automatically

function run_activate_plugin( $plugin ) {
    $current = get_option( 'active_plugins' );
    $plugin = plugin_basename( trim( $plugin ) );
    if ( !in_array( $plugin, $current ) ) {
        $current[] = $plugin;
        sort( $current );
        do_action( 'activate_plugin', trim( $plugin ) );
        update_option( 'active_plugins', $current );
        do_action( 'activate_' . trim( $plugin ) );
        do_action( 'activated_plugin', trim( $plugin) );
    }

    return null;
}

run_activate_plugin( 'wp-postratings/wp-postratings.php' );


// 2. give user option to install

ratings_check();

function ratings_check()
{
	if ( !function_exists('the_ratings') )
	{
		add_thickbox(); 
		add_action('admin_notices', 'ratings_check_notice');
	}
}

function ratings_check_notice()
{
?>
	<div class='updated fade'>
		<p>The Post Ratings plugin is required for this theme to function properly. <a href="<?php echo admin_url('plugin-install.php?tab=plugin-information&plugin=wp-postratings&TB_iframe=true&width=640&height=517'); ?>" class="thickbox onclick">Install now</a>.</p>
	</div>
<?php
}
?>
__________________
Since 1999: 69 Adult Industry awards for Best Hosting Company and professional excellence.


WP Stuff
fris is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote