开发者

How to generate a WordPress plugin install link

开发者 https://www.devze.com 2023-02-17 09:40 出处:网络
I\'m created a plugin that replaces a previous plugin I wrote and adds some extra stuff too. I want to create an alert in the settings page of my old plugin with a link to download and install my new

I'm created a plugin that replaces a previous plugin I wrote and adds some extra stuff too. I want to create an alert in the settings page of my old plugin with a link to download and install my new plugin and inform them that the old plugin is no longer supported by its developer. Currently, from the plugin page of my admin panel, install links look like this:

http://www.example.com/wp-admin/network/update.php?action=install-plugin&plugin=wptouch&_wpnonce=a8d64aa295

It seems to me there are at least two things too keep in mind when creating the URI:

  1. Check whether or not this is a multi-site setup
  2. Make sure I generate the correct nonce.

Does anybody know how to properly do 开发者_C百科this? Is there anything else I need to consider when generating this URI?

Thanks in advance for your help.


I've found an answer. In wp-admin/import.php, there's a great example of how this work.

Here is my implementation:

$plugin_name = 'my_plugin_name';
$install_link = '<a href="' . esc_url( network_admin_url('plugin-install.php?tab=plugin-information&plugin=' . $plugin_name . '&TB_iframe=true&width=600&height=550' ) ) . '" class="thickbox" title="More info about ' . $plugin_name . '">Install ' . $plugin_name . '</a>';

Then just output that link tag anywhere in your admin pages.

If you want to get fancy and add the thickbox modal window effect, just use the function add_thickbox() and attach it to an action that's called in a typical admin request, such as:

add_action('admin_menu', 'my_plugin_add_thickbox');
function my_plugin_add_thickbox() {
    add_thickbox();
}

That should do it!


$action = 'install-plugin';
$slug = 'akismet';
wp_nonce_url(
    add_query_arg(
        array(
            'action' => $action,
            'plugin' => $slug
        ),
        admin_url( 'update.php' )
    ),
    $action.'_'.$slug
);

Use this. I found this and I am sure it will work.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号