Created
August 4, 2014 07:33
-
-
Save viktorbezdek/a9e64baf603fce642d04 to your computer and use it in GitHub Desktop.
Bundling plugins to Wordpress Theme
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if (is_admin() && isset($_GET['activated'] ) && $pagenow == "themes.php" ) { | |
$theme_url = get_bloginfo('template_url'); | |
$theme_url_split = explode("/", $theme_url); | |
$theme_url_split_length = count($theme_url_split); | |
$theme_name = $theme_url_split[$theme_url_split_length-1]; | |
$plugin_source = "../wp-content/themes/".$theme_name."/bundled_plugins/plugin_name"; | |
$plugin_target = "../wp-content/plugins/plugin_name"; | |
function full_copy( $source, $target ) { | |
if ( is_dir( $source ) ) { | |
@mkdir( $target ); | |
$d = dir( $source ); | |
while ( FALSE !== ( $entry = $d->read() ) ) { | |
if ( $entry == '.' || $entry == '..' ) { | |
continue; | |
} | |
$Entry = $source . '/' . $entry; | |
if ( is_dir( $Entry ) ) { | |
full_copy( $Entry, $target . '/' . $entry ); | |
continue; | |
} | |
copy( $Entry, $target . '/' . $entry ); | |
} | |
$d->close(); | |
$plugin_path = 'plugin_name/index.php'; | |
$active_plugins = get_option('active_plugins'); | |
if (!isset($active_plugins[$plugin_path])) run_activate_plugin( 'plugin_name/index.php' ); | |
} | |
} | |
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; | |
} | |
full_copy($plugin_source, $plugin_target); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment