From 1b48135f82e42dac4e777f0ea7b716624c415dbc Mon Sep 17 00:00:00 2001 From: lucha <lucha@paranoici.org> Date: Wed, 19 Apr 2017 18:28:22 +0200 Subject: [PATCH] rename-blogs: deactivate old plugin name, and activates the new one --- bin/noblogs.in | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/bin/noblogs.in b/bin/noblogs.in index 91cb710..980e618 100755 --- a/bin/noblogs.in +++ b/bin/noblogs.in @@ -78,6 +78,9 @@ Known commands: fix-cdn BLOG Sets the correct CDN config. + rename-plugins BLOG + Disables old plugins and enables new ones, when there has been a change in names. + <?php exit(1); } @@ -505,6 +508,37 @@ function do_fix_cdn($args){ } } +// handles renaming of plugin: disables the old one, enables the new one +function do_rename_plugins($args){ + include_once(NOBLOGS_ROOT . '/wp-admin/includes/plugin.php'); + $rename = array( + 'wordpress-popular-post/wordpress-popular-posts.php' => 'wordpress-popular-posts/wordpress-popular-posts.php', + 'french-creative-commons-license-widget/ccLicense.php' => 'creative-commons-license-widget/ccLicense.php' + ); + foreach ($args as $arg) { + $blog = noblogs_get_blog($arg); + if (!$blog) { + echo "{$arg}: blog not found.\n"; + continue; + } + switch_to_blog($blog->blog_id); + + $plugin_dir = NOBLOGS_ROOT . '/wp-content/plugins/'; + foreach ($rename as $old => $new){ + if (is_plugin_active( $plugin_dir . $old )){ + deactivate_plugins($plugin_dir . $old, false, false); + $result = activate_plugin($plugin_dir . $new); + if (is_wp_error($result)){ + echo "{$arg}: " . $result->get_error_message(); + } else { + echo "{$arg}: $old \n"; + } + } + } + restore_currnt_blog(): + } +} + // Command-line parsing. $cmd = $argv[1]; if (!$cmd) { -- GitLab