返回介绍

install_plugin_install_status()

发布于 2017-09-11 01:05:55 字数 4990 浏览 831 评论 0 收藏 0

install_plugin_install_status( array|object $api,  bool $loop = false )

Determine the status we can perform on a plugin.


description


参数

$api

(array|object) (Required) Data about the plugin retrieved from the API.

$loop

(bool) (Optional) Disable further loops.

Default value: false


返回值

(array) { Plugin installation status data. @type string $status Status of a plugin. Could be one of 'install', 'update_available', 'latest_installed' or 'newer_installed'. @type string $url Plugin installation URL. @type string $version The most recent version of the plugin. @type string $file Plugin filename relative to the plugins directory. }


源代码

File: wp-admin/includes/plugin-install.php

function install_plugin_install_status($api, $loop = false) {
	// This function is called recursively, $loop prevents further loops.
	if ( is_array($api) )
		$api = (object) $api;

	// Default to a "new" plugin
	$status = 'install';
	$url = false;
	$update_file = false;

	/*
	 * Check to see if this plugin is known to be installed,
	 * and has an update awaiting it.
	 */
	$update_plugins = get_site_transient('update_plugins');
	if ( isset( $update_plugins->response ) ) {
		foreach ( (array)$update_plugins->response as $file => $plugin ) {
			if ( $plugin->slug === $api->slug ) {
				$status = 'update_available';
				$update_file = $file;
				$version = $plugin->new_version;
				if ( current_user_can('update_plugins') )
					$url = wp_nonce_url(self_admin_url('update.php?action=upgrade-plugin&plugin=' . $update_file), 'upgrade-plugin_' . $update_file);
				break;
			}
		}
	}

	if ( 'install' == $status ) {
		if ( is_dir( WP_PLUGIN_DIR . '/' . $api->slug ) ) {
			$installed_plugin = get_plugins('/' . $api->slug);
			if ( empty($installed_plugin) ) {
				if ( current_user_can('install_plugins') )
					$url = wp_nonce_url(self_admin_url('update.php?action=install-plugin&plugin=' . $api->slug), 'install-plugin_' . $api->slug);
			} else {
				$key = array_keys( $installed_plugin );
				$key = reset( $key ); //Use the first plugin regardless of the name, Could have issues for multiple-plugins in one directory if they share different version numbers
				$update_file = $api->slug . '/' . $key;
				if ( version_compare($api->version, $installed_plugin[ $key ]['Version'], '=') ){
					$status = 'latest_installed';
				} elseif ( version_compare($api->version, $installed_plugin[ $key ]['Version'], '<') ) {
					$status = 'newer_installed';
					$version = $installed_plugin[ $key ]['Version'];
				} else {
					//If the above update check failed, Then that probably means that the update checker has out-of-date information, force a refresh
					if ( ! $loop ) {
delete_site_transient('update_plugins');
wp_update_plugins();
return install_plugin_install_status($api, true);
					}
				}
			}
		} else {
			// "install" & no directory with that slug
			if ( current_user_can('install_plugins') )
				$url = wp_nonce_url(self_admin_url('update.php?action=install-plugin&plugin=' . $api->slug), 'install-plugin_' . $api->slug);
		}
	}
	if ( isset($_GET['from']) )
		$url .= '&amp;from=' . urlencode( wp_unslash( $_GET['from'] ) );

	$file = $update_file;
	return compact( 'status', 'url', 'version', 'file' );
}

更新日志

Versiondescription
3.0.0Introduced.

相关函数

Uses

  • wp-admin/includes/plugin-install.php: install_plugin_install_status()
  • wp-admin/includes/plugin.php: get_plugins()
  • wp-includes/capabilities.php: current_user_can()
  • wp-includes/formatting.php: wp_unslash()
  • wp-includes/functions.php: wp_nonce_url()
  • wp-includes/link-template.php: self_admin_url()
  • wp-includes/update.php: wp_update_plugins()
  • wp-includes/option.php: get_site_transient()
  • wp-includes/option.php: delete_site_transient()
  • Show 4 more uses Hide more uses

Used By

  • wp-admin/includes/ajax-actions.php: wp_ajax_install_plugin()
  • wp-admin/includes/plugin-install.php: install_plugin_install_status()
  • wp-admin/includes/plugin-install.php: install_plugin_information()
  • wp-admin/includes/class-wp-plugin-install-list-table.php: WP_Plugin_Install_List_Table::display_rows()

User Contributed Notes

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

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

发布评论

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