Skip to content

Instantly share code, notes, and snippets.

@RalfAlbert
Created December 4, 2011 18:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RalfAlbert/1430842 to your computer and use it in GitHub Desktop.
Save RalfAlbert/1430842 to your computer and use it in GitHub Desktop.
automatic activate a plugin after install
add_filter( 'upgrader_post_install', 'autoactivate_plugin_after_install', 10, 3 );
function autoactivate_plugin_after_install( $value, $hook_extra, $result ){
$p_tmp = get_plugins('/' . $result['destination_name']);
$p_key = array_keys( $p_tmp );
$pre = ! empty( $result['destination_name'] ) ? $result['destination_name'] . '/' : '';
$plugin = $pre . $p_key[0];
$plugins = get_option('active_plugins');
if( ! in_array( $plugin, $plugins ) ){
array_push( $plugins, $plugin );
update_option( 'active_plugins', $plugins );
echo __('Plugin erfolgreich aktiviert');
} else {
echo __('Plugin konnte nicht aktiviert werden');
}
unset( $p_tmp, $p_key, $pre, $plugin, $plugins );
return $result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment