You often need an action link to activate or deactivate a plugin. How do you do that? I have written a simple function that can help you achieve this.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<?php /** * Get activation or deactivation link of a plugin * * @author Nazmul Ahsan <mail@nazmulahsan.me> * @param string $plugin plugin file name * @param string $action action to perform. activate or deactivate * @return string $url action url */ function na_action_link( $plugin, $action = 'activate' ) { if ( strpos( $plugin, '/' ) ) { $plugin = str_replace( '\/', '%2F', $plugin ); } $url = sprintf( admin_url( 'plugins.php?action=' . $action . '&plugin=%s&plugin_status=all&paged=1&s' ), $plugin ); $_REQUEST['plugin'] = $plugin; $url = wp_nonce_url( $url, $action . '-plugin_' . $plugin ); return $url; } |
How to use? This function requires 2 parameters; first one is the plugin file name, and second one is action type. Plugin file name is…