返回介绍

uninstall_plugin()

发布于 2017-09-11 10:57:59 字数 3198 浏览 908 评论 0 收藏 0

uninstall_plugin( string $plugin )

Uninstall a single plugin.


description

Calls the uninstall hook, if it is available.


参数

$plugin

(string) (Required) Path to the main plugin file from plugins directory.


返回值

(true) True if a plugin's uninstall.php file has been found and included.


源代码

File: wp-admin/includes/plugin.php

function uninstall_plugin($plugin) {
	$file = plugin_basename($plugin);

	$uninstallable_plugins = (array) get_option('uninstall_plugins');

	/**
	 * Fires in uninstall_plugin() immediately before the plugin is uninstalled.
	 *
	 * @since 4.5.0
	 *
	 * @param string $plugin                Path to the main plugin file from plugins directory.
	 * @param array  $uninstallable_plugins Uninstallable plugins.
	 */
	do_action( 'pre_uninstall_plugin', $plugin, $uninstallable_plugins );

	if ( file_exists( WP_PLUGIN_DIR . '/' . dirname($file) . '/uninstall.php' ) ) {
		if ( isset( $uninstallable_plugins[$file] ) ) {
			unset($uninstallable_plugins[$file]);
			update_option('uninstall_plugins', $uninstallable_plugins);
		}
		unset($uninstallable_plugins);

		define('WP_UNINSTALL_PLUGIN', $file);
		wp_register_plugin_realpath( WP_PLUGIN_DIR . '/' . $file );
		include( WP_PLUGIN_DIR . '/' . dirname($file) . '/uninstall.php' );

		return true;
	}

	if ( isset( $uninstallable_plugins[$file] ) ) {
		$callable = $uninstallable_plugins[$file];
		unset($uninstallable_plugins[$file]);
		update_option('uninstall_plugins', $uninstallable_plugins);
		unset($uninstallable_plugins);

		wp_register_plugin_realpath( WP_PLUGIN_DIR . '/' . $file );
		include( WP_PLUGIN_DIR . '/' . $file );

		add_action( "uninstall_{$file}", $callable );

		/**
		 * Fires in uninstall_plugin() once the plugin has been uninstalled.
		 *
		 * The action concatenates the 'uninstall_' prefix with the basename of the
		 * plugin passed to uninstall_plugin() to create a dynamically-named action.
		 *
		 * @since 2.7.0
		 */
		do_action( "uninstall_{$file}" );
	}
}

更新日志

Versiondescription
2.7.0Introduced.

相关函数

Uses

  • wp-admin/includes/plugin.php: pre_uninstall_plugin
  • wp-admin/includes/plugin.php: uninstall_{$file}
  • wp-includes/plugin.php: plugin_basename()
  • wp-includes/plugin.php: wp_register_plugin_realpath()
  • wp-includes/plugin.php: do_action()
  • wp-includes/plugin.php: add_action()
  • wp-includes/option.php: update_option()
  • wp-includes/option.php: get_option()
  • Show 3 more uses Hide more uses

Used By

  • wp-admin/includes/plugin.php: delete_plugins()

User Contributed Notes

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文