germanny
8/19/2013 - 11:19 PM

Auto-activate WordPress Plugins

Auto-activate WordPress Plugins

<?php

// Add to: path/to/wp-content/wp-themes/your-theme/functions.php

/**
 * Activate required plugins
 */

include_once ( ABSPATH . 'wp-admin/includes/plugin.php' );

foreach (array(
    'plugin-name',
) as $plugin) {
    $path = sprintf('%s/%s.php', $plugin, $plugin);

    if (!is_plugin_active( $path )) {
        activate_plugin( $path );

        add_action( 'admin_notices', function() use ($plugin) {
            echo '<div class="updated"><p>' . sprintf('<strong>%s</strong> plugin is required & auto-enabled by the current theme.', $plugin) . '</p></div>';
        } );
    }
}