diff --git a/README.md b/README.md deleted file mode 100644 index 7ff15e7..0000000 --- a/README.md +++ /dev/null @@ -1,7 +0,0 @@ -# CBX Plugin Restart (Deactivate and Activate) -Single click plugin restart - deactivate and activate - -**Todo** - -- Single Click Deactivate and Activate -- Single Click Deactivate and Delete diff --git a/README.txt b/README.txt new file mode 100644 index 0000000..4a9cc3e --- /dev/null +++ b/README.txt @@ -0,0 +1,46 @@ +=== CBX Plugin Restart, ReSleep and DD === +Contributors: codeboxr, manchumahara +Tags: plugin,dev,development +Requires at least: 3.0.1 +Tested up to: 5.2.3 +Stable tag: 1.0.1 +License: GPLv2 or later +License URI: http://www.gnu.org/licenses/gpl-2.0.html + +Single click plugin restart(Deactivate and Activate), resleep(Activate and Deactivate) and DD(Deactivate and Delete) + +== Description == + +This plugin adds new links to plugin action links in wordpress admin plugin listing. +Single click plugin restart(Deactivate and Activate), resleep(Activate and Deactivate) and DD(Deactivate and Delete) + +For any help/support please [contact us](https://codeboxr.com/contact-us/) + + +**Features** + +- Single Click plugin Restart (Deactivate and Activate) +- Single Click plugin Resleep (Activate and deactivate) +- Single Click plugin DD (Deactivate and Delete) +- Nonce security check +- WordPress core capability check for 'activate_plugins', 'deactivate_plugins' and 'delete_plugins' using 'current_user_can' + + +== Installation == + +- WordPress plugin dir has a very good article about how to install or manage plugin install which is best and we suggest to [follow that](https://codex.wordpress.org/Managing_Plugins#Installing_Plugins) + +- This plugin can be install like any other wordpress plugin. + + + +== Screenshots == + +== Changelog == += 1.0.1 = +* [New Features] Added 'Resleep' and 'DD' + + += 1.0.0 = +* Initial relesae + diff --git a/cbxplgrestart.php b/cbxplgrestart.php index 3e1a851..96acebc 100644 --- a/cbxplgrestart.php +++ b/cbxplgrestart.php @@ -1,124 +1,178 @@ ' . esc_html__( 'ReStart', 'cbxplgrestart' ) . ''; + } + + + if ( current_user_can( 'deactivate_plugins' ) && current_user_can( 'delete_plugins' ) ) { + //dd + $link_dd = sprintf( admin_url( 'index.php?cbxplgrestart=%s&cbxplgrestart_mode=%s' ), esc_attr( $plugin ), 'dd' ); + $link_dd_nonce = wp_nonce_url( $link_dd, 'cbxplgrestart', 'cbxplgrestart_nonce' ); + $links[] = '' . esc_html__( 'DD', 'cbxplgrestart' ) . ''; + } + } else { + //plugin is deactivated + if ( current_user_can( 'activate_plugins' ) && current_user_can( 'deactivate_plugins' ) ) { + //ad + $link_ad = sprintf( admin_url( 'index.php?cbxplgrestart=%s&cbxplgrestart_mode=%s' ), esc_attr( $plugin ), 'ad' ); + $link_ad_nonce = wp_nonce_url( $link_ad, 'cbxplgrestart', 'cbxplgrestart_nonce' ); + $links[] = '' . esc_html__( 'ReSleep', 'cbxplgrestart' ) . ''; + } + } - $link = sprintf(admin_url('index.php?cbxplgrestart=%s'), esc_attr($plugin)); - $link_nonce = wp_nonce_url($link, 'cbxplgrestart', 'cbxplgrestart_nonce'); - $links[] = ''.esc_html__('Restart','cbxplgrestart').''; + } + catch ( Exception $e ) { + // $links[] = esc_html( 'Debug: '.$e->getMessage() ); } } - catch( Exception $e ){ - // $links[] = esc_html( 'Debug: '.$e->getMessage() ); - } - } - return $links; - }//end method on_plugin_action_links + return $links; + }//end method on_plugin_action_links - /** - * Restart plugin - */ - public static function admin_init_restart(){ - if(isset($_REQUEST['cbxplgrestart']) && sanitize_text_field($_REQUEST['cbxplgrestart']) != ''){ - $plugin = esc_attr(sanitize_text_field($_REQUEST['cbxplgrestart'])); + /** + * Restart plugin + */ + public static function admin_init_restart() { + if ( isset( $_REQUEST['cbxplgrestart'] ) && sanitize_text_field( $_REQUEST['cbxplgrestart'] ) != '' ) { + $plugin = esc_attr( sanitize_text_field( $_REQUEST['cbxplgrestart'] ) ); + $cbxplgrestart_mode = esc_attr( sanitize_text_field( $_REQUEST['cbxplgrestart_mode'] ) ); + + check_admin_referer( 'cbxplgrestart', 'cbxplgrestart_nonce' ); + + if($plugin != '' && $cbxplgrestart_mode != ''){ + switch ($cbxplgrestart_mode){ + case 'da': + + if ( current_user_can( 'deactivate_plugins' ) && current_user_can( 'activate_plugins' ) && is_plugin_active( $plugin ) ) { + deactivate_plugins( $plugin ); + + if ( ! is_plugin_active( $plugin ) ) { + activate_plugins( $plugin ); + } + } + + break; + + case 'dd': + + if ( current_user_can( 'deactivate_plugins' ) && current_user_can( 'delete_plugins' ) && is_plugin_active( $plugin ) ) { + deactivate_plugins( $plugin ); + + if ( ! is_plugin_active( $plugin ) ) { + delete_plugins( array($plugin) ); + } + } + + break; - check_admin_referer( 'cbxplgrestart', 'cbxplgrestart_nonce' ); + case 'ad': - if(current_user_can( 'activate_plugins' ) && $plugin != '' && is_plugin_active($plugin)){ - deactivate_plugins($plugin); + if ( current_user_can( 'activate_plugins' ) && current_user_can( 'deactivate_plugins' ) && !is_plugin_active( $plugin ) ) { + activate_plugins( $plugin ); - if(!is_plugin_active($plugin)){ - activate_plugins($plugin); + if ( is_plugin_active( $plugin ) ) { + deactivate_plugins( $plugin ); + } + } + + break; + } } - } - wp_safe_redirect( admin_url( 'plugins.php?plugin_status=all' ) ); - exit(); - } - }//end method admin_init_restart + wp_safe_redirect( admin_url( 'plugins.php?plugin_status=all' ) ); + exit(); + } + }//end method admin_init_restart - }//end class CBXPluginRestart -} + }//end class CBXPluginRestart + } -/** - * Init the plugin - * - * @return void - */ -function cbxplgrestart_load_plugin() -{ - if(class_exists('CBXPluginRestart')){ - new CBXPluginRestart(); + /** + * Init the plugin + * + * @return void + */ + function cbxplgrestart_load_plugin() { + if ( class_exists( 'CBXPluginRestart' ) ) { + new CBXPluginRestart(); + } } -} -add_action('plugins_loaded', 'cbxplgrestart_load_plugin', 5); \ No newline at end of file + add_action( 'plugins_loaded', 'cbxplgrestart_load_plugin', 5 ); \ No newline at end of file diff --git a/languages/cbxplgrestart.pot b/languages/cbxplgrestart.pot index 4faa797..8bfd9c0 100644 --- a/languages/cbxplgrestart.pot +++ b/languages/cbxplgrestart.pot @@ -3,7 +3,7 @@ msgid "" msgstr "" "Project-Id-Version: CBX Plugin Restart(Deactivate and Activate)\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-09-25 18:23+0000\n" +"POT-Creation-Date: 2019-09-26 07:05+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: \n" @@ -15,16 +15,42 @@ msgstr "" "X-Generator: Loco https://localise.biz/\n" "X-Loco-Version: 2.3.0; wp-5.2.3" -#: cbxplgrestart.php:75 -msgid "Restart" +#: cbxplgrestart.php:78 +msgid "Deactivate & then Activate" +msgstr "" + +#: cbxplgrestart.php:78 +msgid "ReStart" +msgstr "" + +#: cbxplgrestart.php:86 +msgid "Are you absolutely sure you want to deactivate and delete this plugin?" +msgstr "" + +#: cbxplgrestart.php:86 +msgid "Deactivate & then Delete" +msgstr "" + +#: cbxplgrestart.php:86 +msgid "DD" +msgstr "" + +#: cbxplgrestart.php:94 +msgid "Activate & then Deactivate" +msgstr "" + +#: cbxplgrestart.php:94 +msgid "ReSleep" msgstr "" #. Name of the plugin -msgid "CBX Plugin Restart (Deactivate and Activate)" +msgid "CBX Plugin Restart, ReSleep and DD" msgstr "" #. Description of the plugin -msgid "Single click plugin restart - deactivate and activate" +msgid "" +"Single click plugin restart(Deactivate and Activate), resleep(Activate and " +"Deactivate) and DD(Deactivate and Delete)" msgstr "" #. URI of the plugin