Skip to content

Instantly share code, notes, and snippets.

@maxyudin
Forked from ericclemmons/functions.php
Last active November 5, 2017 11:50
Show Gist options
  • Save maxyudin/d9172b75561c5ea48e4906ade2f5801f to your computer and use it in GitHub Desktop.
Save maxyudin/d9172b75561c5ea48e4906ade2f5801f to your computer and use it in GitHub Desktop.
not tested though
<?php
// Modified from https://gist.github.com/ericclemmons/6275346#gistcomment-2248160
// 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);
$result = activate_plugin( $path );
if ( !is_wp_error( $result ) ) {
add_action( 'admin_notices', function() use ($plugin) {
echo '<div class="notice notice-success"><p>' . sprintf('<strong>%s</strong> plugin is required & auto-enabled by the current theme.', $plugin) . '</p></div>';
} );
} else {
add_action( 'admin_notices', function() use ($plugin) {
echo '<div class="notice notice-error"><p>' . sprintf('<strong>%s</strong> plugin can\'t be auto-enabled by the current theme.', $plugin) . '</p></div>';
} );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment