Created
August 16, 2020 09:17
-
-
Save maheshwaghmare/5135fbb9488979902bf53ee2dce4dec8 to your computer and use it in GitHub Desktop.
WordPress get plugin deactivate link.
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( ! function_exists( 'prefix_get_plugin_deactivate_link' ) ) : | |
| /** | |
| * Generate and get the plugin deactivate link. | |
| * | |
| * E.g. | |
| * | |
| * $deactivate_url = prefix_get_plugin_deactivate_link( 'free-images/free-images.php', plugin_basename( __FILE__ ) ); | |
| * | |
| * @todo Change the `prefix_` and with your own unique prefix. | |
| * | |
| * @since 1.0.0 | |
| * @param string $init_file Pluin init file. E.g. free-images/free-images.php. | |
| * @param string $plugin_dir Pluin directory location. E.g. plugin_basename( __FILE__ ) | |
| * @return string | |
| */ | |
| function prefix_get_plugin_deactivate_link( $init_file = '', $plugin_dir = '' ) { | |
| $deactivate_url = admin_url( 'plugins.php' ); | |
| if ( is_plugin_active_for_network( $plugin_dir ) ) { | |
| $deactivate_url = network_admin_url( 'plugins.php' ); | |
| } | |
| return add_query_arg( | |
| array( | |
| 'action' => 'deactivate', | |
| 'plugin' => rawurlencode( $init_file ), | |
| 'plugin_status' => 'all', | |
| 'paged' => '1', | |
| '_wpnonce' => wp_create_nonce( 'deactivate-plugin_' . $init_file ), | |
| ), | |
| $deactivate_url | |
| ); | |
| } | |
| endif; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment