最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

plugins - How to get the wpnonce value?

programmeradmin4浏览0评论

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&amp;plugin=my-custom-css%2Fmy-custom-css.php&amp;plugin_status=all&amp;paged=1&amp;s&amp;_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&amp;plugin=my-custom-css%2Fmy-custom-css.php&amp;plugin_status=all&amp;paged=1&amp;s&amp;_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 badges
Add a comment  | 

2 Answers 2

Reset to default 0

That 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>

发布评论

评论列表(0)

  1. 暂无评论