On using inspect element to check the 'href' attribute of 'Deactivate' links for the plugins listed on plugins.php page, I found that the url contains a wpnonce field with a certain value. I need to get this value. For eg,
<a href="plugins.php?action=deactivate&plugin=my-custom-css%2Fmy-custom-css.php&plugin_status=all&paged=1&s&_wpnonce=08a2b0d940" title="Deactivate this plugin">Deactivate</a>
How do I get this value '08a2b0d940' as in the above link ?
On using inspect element to check the 'href' attribute of 'Deactivate' links for the plugins listed on plugins.php page, I found that the url contains a wpnonce field with a certain value. I need to get this value. For eg,
<a href="plugins.php?action=deactivate&plugin=my-custom-css%2Fmy-custom-css.php&plugin_status=all&paged=1&s&_wpnonce=08a2b0d940" title="Deactivate this plugin">Deactivate</a>
How do I get this value '08a2b0d940' as in the above link ?
Share Improve this question asked Sep 25, 2013 at 13:48 Navin NagpalNavin Nagpal 1871 gold badge2 silver badges9 bronze badges2 Answers
Reset to default 0That value is a random-ish string generated for one-time use with a lifespan of, if I remember correctly, 12 hours. I am not sure what you mean by "get" the value. Assuming you mean "generate the nonce" then...
You want wp_nonce_url
or one of the related functions.
wp_nonce_url( $actionurl, $action, $name );
For example:
wp_nonce_url( 'http://www.google');
You can't regenerate the value if that is what you want but you could regex it out of the URL with PHP, circumstances permitting, or use Javascript to search the generated markup. Since I don't know why you are trying to do this, a solid answer is difficult.
I know this is old, but someone else might find this a useful function:
<?php
function elab_disable_plugin_link( $plugin, $action = 'deactivate' ) {
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;
}
Then add your plugin name and filename to it.
ex.
<a href="<?php echo elab_disable_plugin_link('my-custom-css-plugin/my-custom-css.php'); ?>">Disable Plugin</a>