Edit File by line
/home/barbar84/public_h.../wp-admin/includes
File: plugin-install.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* WordPress Plugin Install Administration API
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
* @subpackage Administration
[5] Fix | Delete
*/
[6] Fix | Delete
[7] Fix | Delete
/**
[8] Fix | Delete
* Retrieves plugin installer pages from the WordPress.org Plugins API.
[9] Fix | Delete
*
[10] Fix | Delete
* It is possible for a plugin to override the Plugin API result with three
[11] Fix | Delete
* filters. Assume this is for plugins, which can extend on the Plugin Info to
[12] Fix | Delete
* offer more choices. This is very powerful and must be used with care when
[13] Fix | Delete
* overriding the filters.
[14] Fix | Delete
*
[15] Fix | Delete
* The first filter, {@see 'plugins_api_args'}, is for the args and gives the action
[16] Fix | Delete
* as the second parameter. The hook for {@see 'plugins_api_args'} must ensure that
[17] Fix | Delete
* an object is returned.
[18] Fix | Delete
*
[19] Fix | Delete
* The second filter, {@see 'plugins_api'}, allows a plugin to override the WordPress.org
[20] Fix | Delete
* Plugin Installation API entirely. If `$action` is 'query_plugins' or 'plugin_information',
[21] Fix | Delete
* an object MUST be passed. If `$action` is 'hot_tags' or 'hot_categories', an array MUST
[22] Fix | Delete
* be passed.
[23] Fix | Delete
*
[24] Fix | Delete
* Finally, the third filter, {@see 'plugins_api_result'}, makes it possible to filter the
[25] Fix | Delete
* response object or array, depending on the `$action` type.
[26] Fix | Delete
*
[27] Fix | Delete
* Supported arguments per action:
[28] Fix | Delete
*
[29] Fix | Delete
* | Argument Name | query_plugins | plugin_information | hot_tags | hot_categories |
[30] Fix | Delete
* | -------------------- | :-----------: | :----------------: | :------: | :------------: |
[31] Fix | Delete
* | `$slug` | No | Yes | No | No |
[32] Fix | Delete
* | `$per_page` | Yes | No | No | No |
[33] Fix | Delete
* | `$page` | Yes | No | No | No |
[34] Fix | Delete
* | `$number` | No | No | Yes | Yes |
[35] Fix | Delete
* | `$search` | Yes | No | No | No |
[36] Fix | Delete
* | `$tag` | Yes | No | No | No |
[37] Fix | Delete
* | `$author` | Yes | No | No | No |
[38] Fix | Delete
* | `$user` | Yes | No | No | No |
[39] Fix | Delete
* | `$browse` | Yes | No | No | No |
[40] Fix | Delete
* | `$locale` | Yes | Yes | No | No |
[41] Fix | Delete
* | `$installed_plugins` | Yes | No | No | No |
[42] Fix | Delete
* | `$is_ssl` | Yes | Yes | No | No |
[43] Fix | Delete
* | `$fields` | Yes | Yes | No | No |
[44] Fix | Delete
*
[45] Fix | Delete
* @since 2.7.0
[46] Fix | Delete
*
[47] Fix | Delete
* @param string $action API action to perform: 'query_plugins', 'plugin_information',
[48] Fix | Delete
* 'hot_tags' or 'hot_categories'.
[49] Fix | Delete
* @param array|object $args {
[50] Fix | Delete
* Optional. Array or object of arguments to serialize for the Plugin Info API.
[51] Fix | Delete
*
[52] Fix | Delete
* @type string $slug The plugin slug. Default empty.
[53] Fix | Delete
* @type int $per_page Number of plugins per page. Default 24.
[54] Fix | Delete
* @type int $page Number of current page. Default 1.
[55] Fix | Delete
* @type int $number Number of tags or categories to be queried.
[56] Fix | Delete
* @type string $search A search term. Default empty.
[57] Fix | Delete
* @type string $tag Tag to filter plugins. Default empty.
[58] Fix | Delete
* @type string $author Username of an plugin author to filter plugins. Default empty.
[59] Fix | Delete
* @type string $user Username to query for their favorites. Default empty.
[60] Fix | Delete
* @type string $browse Browse view: 'popular', 'new', 'beta', 'recommended'.
[61] Fix | Delete
* @type string $locale Locale to provide context-sensitive results. Default is the value
[62] Fix | Delete
* of get_locale().
[63] Fix | Delete
* @type string $installed_plugins Installed plugins to provide context-sensitive results.
[64] Fix | Delete
* @type bool $is_ssl Whether links should be returned with https or not. Default false.
[65] Fix | Delete
* @type array $fields {
[66] Fix | Delete
* Array of fields which should or should not be returned.
[67] Fix | Delete
*
[68] Fix | Delete
* @type bool $short_description Whether to return the plugin short description. Default true.
[69] Fix | Delete
* @type bool $description Whether to return the plugin full description. Default false.
[70] Fix | Delete
* @type bool $sections Whether to return the plugin readme sections: description, installation,
[71] Fix | Delete
* FAQ, screenshots, other notes, and changelog. Default false.
[72] Fix | Delete
* @type bool $tested Whether to return the 'Compatible up to' value. Default true.
[73] Fix | Delete
* @type bool $requires Whether to return the required WordPress version. Default true.
[74] Fix | Delete
* @type bool $requires_php Whether to return the required PHP version. Default true.
[75] Fix | Delete
* @type bool $rating Whether to return the rating in percent and total number of ratings.
[76] Fix | Delete
* Default true.
[77] Fix | Delete
* @type bool $ratings Whether to return the number of rating for each star (1-5). Default true.
[78] Fix | Delete
* @type bool $downloaded Whether to return the download count. Default true.
[79] Fix | Delete
* @type bool $downloadlink Whether to return the download link for the package. Default true.
[80] Fix | Delete
* @type bool $last_updated Whether to return the date of the last update. Default true.
[81] Fix | Delete
* @type bool $added Whether to return the date when the plugin was added to the wordpress.org
[82] Fix | Delete
* repository. Default true.
[83] Fix | Delete
* @type bool $tags Whether to return the assigned tags. Default true.
[84] Fix | Delete
* @type bool $compatibility Whether to return the WordPress compatibility list. Default true.
[85] Fix | Delete
* @type bool $homepage Whether to return the plugin homepage link. Default true.
[86] Fix | Delete
* @type bool $versions Whether to return the list of all available versions. Default false.
[87] Fix | Delete
* @type bool $donate_link Whether to return the donation link. Default true.
[88] Fix | Delete
* @type bool $reviews Whether to return the plugin reviews. Default false.
[89] Fix | Delete
* @type bool $banners Whether to return the banner images links. Default false.
[90] Fix | Delete
* @type bool $icons Whether to return the icon links. Default false.
[91] Fix | Delete
* @type bool $active_installs Whether to return the number of active installations. Default false.
[92] Fix | Delete
* @type bool $group Whether to return the assigned group. Default false.
[93] Fix | Delete
* @type bool $contributors Whether to return the list of contributors. Default false.
[94] Fix | Delete
* }
[95] Fix | Delete
* }
[96] Fix | Delete
* @return object|array|WP_Error Response object or array on success, WP_Error on failure. See the
[97] Fix | Delete
* {@link https://developer.wordpress.org/reference/functions/plugins_api/ function reference article}
[98] Fix | Delete
* for more information on the make-up of possible return values depending on the value of `$action`.
[99] Fix | Delete
*/
[100] Fix | Delete
function plugins_api( $action, $args = array() ) {
[101] Fix | Delete
// Include an unmodified $wp_version.
[102] Fix | Delete
require ABSPATH . WPINC . '/version.php';
[103] Fix | Delete
[104] Fix | Delete
if ( is_array( $args ) ) {
[105] Fix | Delete
$args = (object) $args;
[106] Fix | Delete
}
[107] Fix | Delete
[108] Fix | Delete
if ( 'query_plugins' === $action ) {
[109] Fix | Delete
if ( ! isset( $args->per_page ) ) {
[110] Fix | Delete
$args->per_page = 24;
[111] Fix | Delete
}
[112] Fix | Delete
}
[113] Fix | Delete
[114] Fix | Delete
if ( ! isset( $args->locale ) ) {
[115] Fix | Delete
$args->locale = get_user_locale();
[116] Fix | Delete
}
[117] Fix | Delete
[118] Fix | Delete
if ( ! isset( $args->wp_version ) ) {
[119] Fix | Delete
$args->wp_version = substr( $wp_version, 0, 3 ); // x.y
[120] Fix | Delete
}
[121] Fix | Delete
[122] Fix | Delete
/**
[123] Fix | Delete
* Filters the WordPress.org Plugin Installation API arguments.
[124] Fix | Delete
*
[125] Fix | Delete
* Important: An object MUST be returned to this filter.
[126] Fix | Delete
*
[127] Fix | Delete
* @since 2.7.0
[128] Fix | Delete
*
[129] Fix | Delete
* @param object $args Plugin API arguments.
[130] Fix | Delete
* @param string $action The type of information being requested from the Plugin Installation API.
[131] Fix | Delete
*/
[132] Fix | Delete
$args = apply_filters( 'plugins_api_args', $args, $action );
[133] Fix | Delete
[134] Fix | Delete
/**
[135] Fix | Delete
* Filters the response for the current WordPress.org Plugin Installation API request.
[136] Fix | Delete
*
[137] Fix | Delete
* Passing a non-false value will effectively short-circuit the WordPress.org API request.
[138] Fix | Delete
*
[139] Fix | Delete
* If `$action` is 'query_plugins' or 'plugin_information', an object MUST be passed.
[140] Fix | Delete
* If `$action` is 'hot_tags' or 'hot_categories', an array should be passed.
[141] Fix | Delete
*
[142] Fix | Delete
* @since 2.7.0
[143] Fix | Delete
*
[144] Fix | Delete
* @param false|object|array $result The result object or array. Default false.
[145] Fix | Delete
* @param string $action The type of information being requested from the Plugin Installation API.
[146] Fix | Delete
* @param object $args Plugin API arguments.
[147] Fix | Delete
*/
[148] Fix | Delete
$res = apply_filters( 'plugins_api', false, $action, $args );
[149] Fix | Delete
[150] Fix | Delete
if ( false === $res ) {
[151] Fix | Delete
[152] Fix | Delete
$url = 'http://api.wordpress.org/plugins/info/1.2/';
[153] Fix | Delete
$url = add_query_arg(
[154] Fix | Delete
array(
[155] Fix | Delete
'action' => $action,
[156] Fix | Delete
'request' => $args,
[157] Fix | Delete
),
[158] Fix | Delete
$url
[159] Fix | Delete
);
[160] Fix | Delete
[161] Fix | Delete
$http_url = $url;
[162] Fix | Delete
$ssl = wp_http_supports( array( 'ssl' ) );
[163] Fix | Delete
if ( $ssl ) {
[164] Fix | Delete
$url = set_url_scheme( $url, 'https' );
[165] Fix | Delete
}
[166] Fix | Delete
[167] Fix | Delete
$http_args = array(
[168] Fix | Delete
'timeout' => 15,
[169] Fix | Delete
'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' ),
[170] Fix | Delete
);
[171] Fix | Delete
$request = wp_remote_get( $url, $http_args );
[172] Fix | Delete
[173] Fix | Delete
if ( $ssl && is_wp_error( $request ) ) {
[174] Fix | Delete
if ( ! wp_is_json_request() ) {
[175] Fix | Delete
trigger_error(
[176] Fix | Delete
sprintf(
[177] Fix | Delete
/* translators: %s: Support forums URL. */
[178] Fix | Delete
__( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ),
[179] Fix | Delete
__( 'https://wordpress.org/support/forums/' )
[180] Fix | Delete
) . ' ' . __( '(WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.)' ),
[181] Fix | Delete
headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE
[182] Fix | Delete
);
[183] Fix | Delete
}
[184] Fix | Delete
[185] Fix | Delete
$request = wp_remote_get( $http_url, $http_args );
[186] Fix | Delete
}
[187] Fix | Delete
[188] Fix | Delete
if ( is_wp_error( $request ) ) {
[189] Fix | Delete
$res = new WP_Error(
[190] Fix | Delete
'plugins_api_failed',
[191] Fix | Delete
sprintf(
[192] Fix | Delete
/* translators: %s: Support forums URL. */
[193] Fix | Delete
__( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ),
[194] Fix | Delete
__( 'https://wordpress.org/support/forums/' )
[195] Fix | Delete
),
[196] Fix | Delete
$request->get_error_message()
[197] Fix | Delete
);
[198] Fix | Delete
} else {
[199] Fix | Delete
$res = json_decode( wp_remote_retrieve_body( $request ), true );
[200] Fix | Delete
if ( is_array( $res ) ) {
[201] Fix | Delete
// Object casting is required in order to match the info/1.0 format.
[202] Fix | Delete
$res = (object) $res;
[203] Fix | Delete
} elseif ( null === $res ) {
[204] Fix | Delete
$res = new WP_Error(
[205] Fix | Delete
'plugins_api_failed',
[206] Fix | Delete
sprintf(
[207] Fix | Delete
/* translators: %s: Support forums URL. */
[208] Fix | Delete
__( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ),
[209] Fix | Delete
__( 'https://wordpress.org/support/forums/' )
[210] Fix | Delete
),
[211] Fix | Delete
wp_remote_retrieve_body( $request )
[212] Fix | Delete
);
[213] Fix | Delete
}
[214] Fix | Delete
[215] Fix | Delete
if ( isset( $res->error ) ) {
[216] Fix | Delete
$res = new WP_Error( 'plugins_api_failed', $res->error );
[217] Fix | Delete
}
[218] Fix | Delete
}
[219] Fix | Delete
} elseif ( ! is_wp_error( $res ) ) {
[220] Fix | Delete
$res->external = true;
[221] Fix | Delete
}
[222] Fix | Delete
[223] Fix | Delete
/**
[224] Fix | Delete
* Filters the Plugin Installation API response results.
[225] Fix | Delete
*
[226] Fix | Delete
* @since 2.7.0
[227] Fix | Delete
*
[228] Fix | Delete
* @param object|WP_Error $res Response object or WP_Error.
[229] Fix | Delete
* @param string $action The type of information being requested from the Plugin Installation API.
[230] Fix | Delete
* @param object $args Plugin API arguments.
[231] Fix | Delete
*/
[232] Fix | Delete
return apply_filters( 'plugins_api_result', $res, $action, $args );
[233] Fix | Delete
}
[234] Fix | Delete
[235] Fix | Delete
/**
[236] Fix | Delete
* Retrieve popular WordPress plugin tags.
[237] Fix | Delete
*
[238] Fix | Delete
* @since 2.7.0
[239] Fix | Delete
*
[240] Fix | Delete
* @param array $args
[241] Fix | Delete
* @return array|WP_Error
[242] Fix | Delete
*/
[243] Fix | Delete
function install_popular_tags( $args = array() ) {
[244] Fix | Delete
$key = md5( serialize( $args ) );
[245] Fix | Delete
$tags = get_site_transient( 'poptags_' . $key );
[246] Fix | Delete
if ( false !== $tags ) {
[247] Fix | Delete
return $tags;
[248] Fix | Delete
}
[249] Fix | Delete
[250] Fix | Delete
$tags = plugins_api( 'hot_tags', $args );
[251] Fix | Delete
[252] Fix | Delete
if ( is_wp_error( $tags ) ) {
[253] Fix | Delete
return $tags;
[254] Fix | Delete
}
[255] Fix | Delete
[256] Fix | Delete
set_site_transient( 'poptags_' . $key, $tags, 3 * HOUR_IN_SECONDS );
[257] Fix | Delete
[258] Fix | Delete
return $tags;
[259] Fix | Delete
}
[260] Fix | Delete
[261] Fix | Delete
/**
[262] Fix | Delete
* @since 2.7.0
[263] Fix | Delete
*/
[264] Fix | Delete
function install_dashboard() {
[265] Fix | Delete
?>
[266] Fix | Delete
<p>
[267] Fix | Delete
<?php
[268] Fix | Delete
printf(
[269] Fix | Delete
/* translators: %s: https://wordpress.org/plugins/ */
[270] Fix | Delete
__( 'Plugins extend and expand the functionality of WordPress. You may automatically install plugins from the <a href="%s">WordPress Plugin Directory</a> or upload a plugin in .zip format by clicking the button at the top of this page.' ),
[271] Fix | Delete
__( 'https://wordpress.org/plugins/' )
[272] Fix | Delete
);
[273] Fix | Delete
?>
[274] Fix | Delete
</p>
[275] Fix | Delete
[276] Fix | Delete
<?php display_plugins_table(); ?>
[277] Fix | Delete
[278] Fix | Delete
<div class="plugins-popular-tags-wrapper">
[279] Fix | Delete
<h2><?php _e( 'Popular tags' ); ?></h2>
[280] Fix | Delete
<p><?php _e( 'You may also browse based on the most popular tags in the Plugin Directory:' ); ?></p>
[281] Fix | Delete
<?php
[282] Fix | Delete
[283] Fix | Delete
$api_tags = install_popular_tags();
[284] Fix | Delete
[285] Fix | Delete
echo '<p class="popular-tags">';
[286] Fix | Delete
if ( is_wp_error( $api_tags ) ) {
[287] Fix | Delete
echo $api_tags->get_error_message();
[288] Fix | Delete
} else {
[289] Fix | Delete
// Set up the tags in a way which can be interpreted by wp_generate_tag_cloud().
[290] Fix | Delete
$tags = array();
[291] Fix | Delete
foreach ( (array) $api_tags as $tag ) {
[292] Fix | Delete
$url = self_admin_url( 'plugin-install.php?tab=search&type=tag&s=' . urlencode( $tag['name'] ) );
[293] Fix | Delete
$data = array(
[294] Fix | Delete
'link' => esc_url( $url ),
[295] Fix | Delete
'name' => $tag['name'],
[296] Fix | Delete
'slug' => $tag['slug'],
[297] Fix | Delete
'id' => sanitize_title_with_dashes( $tag['name'] ),
[298] Fix | Delete
'count' => $tag['count'],
[299] Fix | Delete
);
[300] Fix | Delete
$tags[ $tag['name'] ] = (object) $data;
[301] Fix | Delete
}
[302] Fix | Delete
echo wp_generate_tag_cloud(
[303] Fix | Delete
$tags,
[304] Fix | Delete
array(
[305] Fix | Delete
/* translators: %s: Number of plugins. */
[306] Fix | Delete
'single_text' => __( '%s plugin' ),
[307] Fix | Delete
/* translators: %s: Number of plugins. */
[308] Fix | Delete
'multiple_text' => __( '%s plugins' ),
[309] Fix | Delete
)
[310] Fix | Delete
);
[311] Fix | Delete
}
[312] Fix | Delete
echo '</p><br class="clear" /></div>';
[313] Fix | Delete
}
[314] Fix | Delete
[315] Fix | Delete
/**
[316] Fix | Delete
* Displays a search form for searching plugins.
[317] Fix | Delete
*
[318] Fix | Delete
* @since 2.7.0
[319] Fix | Delete
* @since 4.6.0 The `$type_selector` parameter was deprecated.
[320] Fix | Delete
*
[321] Fix | Delete
* @param bool $deprecated Not used.
[322] Fix | Delete
*/
[323] Fix | Delete
function install_search_form( $deprecated = true ) {
[324] Fix | Delete
$type = isset( $_REQUEST['type'] ) ? wp_unslash( $_REQUEST['type'] ) : 'term';
[325] Fix | Delete
$term = isset( $_REQUEST['s'] ) ? wp_unslash( $_REQUEST['s'] ) : '';
[326] Fix | Delete
?>
[327] Fix | Delete
<form class="search-form search-plugins" method="get">
[328] Fix | Delete
<input type="hidden" name="tab" value="search" />
[329] Fix | Delete
<label class="screen-reader-text" for="typeselector"><?php _e( 'Search plugins by:' ); ?></label>
[330] Fix | Delete
<select name="type" id="typeselector">
[331] Fix | Delete
<option value="term"<?php selected( 'term', $type ); ?>><?php _e( 'Keyword' ); ?></option>
[332] Fix | Delete
<option value="author"<?php selected( 'author', $type ); ?>><?php _e( 'Author' ); ?></option>
[333] Fix | Delete
<option value="tag"<?php selected( 'tag', $type ); ?>><?php _ex( 'Tag', 'Plugin Installer' ); ?></option>
[334] Fix | Delete
</select>
[335] Fix | Delete
<label class="screen-reader-text" for="search-plugins"><?php _e( 'Search Plugins' ); ?></label>
[336] Fix | Delete
<input type="search" name="s" id="search-plugins" value="<?php echo esc_attr( $term ); ?>" class="wp-filter-search" placeholder="<?php esc_attr_e( 'Search plugins...' ); ?>" />
[337] Fix | Delete
<?php submit_button( __( 'Search Plugins' ), 'hide-if-js', false, false, array( 'id' => 'search-submit' ) ); ?>
[338] Fix | Delete
</form>
[339] Fix | Delete
<?php
[340] Fix | Delete
}
[341] Fix | Delete
[342] Fix | Delete
/**
[343] Fix | Delete
* Upload from zip
[344] Fix | Delete
*
[345] Fix | Delete
* @since 2.8.0
[346] Fix | Delete
*/
[347] Fix | Delete
function install_plugins_upload() {
[348] Fix | Delete
?>
[349] Fix | Delete
<div class="upload-plugin">
[350] Fix | Delete
<p class="install-help"><?php _e( 'If you have a plugin in a .zip format, you may install or update it by uploading it here.' ); ?></p>
[351] Fix | Delete
<form method="post" enctype="multipart/form-data" class="wp-upload-form" action="<?php echo self_admin_url( 'update.php?action=upload-plugin' ); ?>">
[352] Fix | Delete
<?php wp_nonce_field( 'plugin-upload' ); ?>
[353] Fix | Delete
<label class="screen-reader-text" for="pluginzip"><?php _e( 'Plugin zip file' ); ?></label>
[354] Fix | Delete
<input type="file" id="pluginzip" name="pluginzip" accept=".zip" />
[355] Fix | Delete
<?php submit_button( __( 'Install Now' ), '', 'install-plugin-submit', false ); ?>
[356] Fix | Delete
</form>
[357] Fix | Delete
</div>
[358] Fix | Delete
<?php
[359] Fix | Delete
}
[360] Fix | Delete
[361] Fix | Delete
/**
[362] Fix | Delete
* Show a username form for the favorites page
[363] Fix | Delete
*
[364] Fix | Delete
* @since 3.5.0
[365] Fix | Delete
*/
[366] Fix | Delete
function install_plugins_favorites_form() {
[367] Fix | Delete
$user = get_user_option( 'wporg_favorites' );
[368] Fix | Delete
$action = 'save_wporg_username_' . get_current_user_id();
[369] Fix | Delete
?>
[370] Fix | Delete
<p><?php _e( 'If you have marked plugins as favorites on WordPress.org, you can browse them here.' ); ?></p>
[371] Fix | Delete
<form method="get">
[372] Fix | Delete
<input type="hidden" name="tab" value="favorites" />
[373] Fix | Delete
<p>
[374] Fix | Delete
<label for="user"><?php _e( 'Your WordPress.org username:' ); ?></label>
[375] Fix | Delete
<input type="search" id="user" name="user" value="<?php echo esc_attr( $user ); ?>" />
[376] Fix | Delete
<input type="submit" class="button" value="<?php esc_attr_e( 'Get Favorites' ); ?>" />
[377] Fix | Delete
<input type="hidden" id="wporg-username-nonce" name="_wpnonce" value="<?php echo esc_attr( wp_create_nonce( $action ) ); ?>" />
[378] Fix | Delete
</p>
[379] Fix | Delete
</form>
[380] Fix | Delete
<?php
[381] Fix | Delete
}
[382] Fix | Delete
[383] Fix | Delete
/**
[384] Fix | Delete
* Display plugin content based on plugin list.
[385] Fix | Delete
*
[386] Fix | Delete
* @since 2.7.0
[387] Fix | Delete
*
[388] Fix | Delete
* @global WP_List_Table $wp_list_table
[389] Fix | Delete
*/
[390] Fix | Delete
function display_plugins_table() {
[391] Fix | Delete
global $wp_list_table;
[392] Fix | Delete
[393] Fix | Delete
switch ( current_filter() ) {
[394] Fix | Delete
case 'install_plugins_favorites':
[395] Fix | Delete
if ( empty( $_GET['user'] ) && ! get_user_option( 'wporg_favorites' ) ) {
[396] Fix | Delete
return;
[397] Fix | Delete
}
[398] Fix | Delete
break;
[399] Fix | Delete
case 'install_plugins_recommended':
[400] Fix | Delete
echo '<p>' . __( 'These suggestions are based on the plugins you and other users have installed.' ) . '</p>';
[401] Fix | Delete
break;
[402] Fix | Delete
case 'install_plugins_beta':
[403] Fix | Delete
printf(
[404] Fix | Delete
/* translators: %s: URL to "Features as Plugins" page. */
[405] Fix | Delete
'<p>' . __( 'You are using a development version of WordPress. These feature plugins are also under development. <a href="%s">Learn more</a>.' ) . '</p>',
[406] Fix | Delete
'https://make.wordpress.org/core/handbook/about/release-cycle/features-as-plugins/'
[407] Fix | Delete
);
[408] Fix | Delete
break;
[409] Fix | Delete
}
[410] Fix | Delete
[411] Fix | Delete
?>
[412] Fix | Delete
<form id="plugin-filter" method="post">
[413] Fix | Delete
<?php $wp_list_table->display(); ?>
[414] Fix | Delete
</form>
[415] Fix | Delete
<?php
[416] Fix | Delete
}
[417] Fix | Delete
[418] Fix | Delete
/**
[419] Fix | Delete
* Determine the status we can perform on a plugin.
[420] Fix | Delete
*
[421] Fix | Delete
* @since 3.0.0
[422] Fix | Delete
*
[423] Fix | Delete
* @param array|object $api Data about the plugin retrieved from the API.
[424] Fix | Delete
* @param bool $loop Optional. Disable further loops. Default false.
[425] Fix | Delete
* @return array {
[426] Fix | Delete
* Plugin installation status data.
[427] Fix | Delete
*
[428] Fix | Delete
* @type string $status Status of a plugin. Could be one of 'install', 'update_available', 'latest_installed' or 'newer_installed'.
[429] Fix | Delete
* @type string $url Plugin installation URL.
[430] Fix | Delete
* @type string $version The most recent version of the plugin.
[431] Fix | Delete
* @type string $file Plugin filename relative to the plugins directory.
[432] Fix | Delete
* }
[433] Fix | Delete
*/
[434] Fix | Delete
function install_plugin_install_status( $api, $loop = false ) {
[435] Fix | Delete
// This function is called recursively, $loop prevents further loops.
[436] Fix | Delete
if ( is_array( $api ) ) {
[437] Fix | Delete
$api = (object) $api;
[438] Fix | Delete
}
[439] Fix | Delete
[440] Fix | Delete
// Default to a "new" plugin.
[441] Fix | Delete
$status = 'install';
[442] Fix | Delete
$url = false;
[443] Fix | Delete
$update_file = false;
[444] Fix | Delete
$version = '';
[445] Fix | Delete
[446] Fix | Delete
/*
[447] Fix | Delete
* Check to see if this plugin is known to be installed,
[448] Fix | Delete
* and has an update awaiting it.
[449] Fix | Delete
*/
[450] Fix | Delete
$update_plugins = get_site_transient( 'update_plugins' );
[451] Fix | Delete
if ( isset( $update_plugins->response ) ) {
[452] Fix | Delete
foreach ( (array) $update_plugins->response as $file => $plugin ) {
[453] Fix | Delete
if ( $plugin->slug === $api->slug ) {
[454] Fix | Delete
$status = 'update_available';
[455] Fix | Delete
$update_file = $file;
[456] Fix | Delete
$version = $plugin->new_version;
[457] Fix | Delete
if ( current_user_can( 'update_plugins' ) ) {
[458] Fix | Delete
$url = wp_nonce_url( self_admin_url( 'update.php?action=upgrade-plugin&plugin=' . $update_file ), 'upgrade-plugin_' . $update_file );
[459] Fix | Delete
}
[460] Fix | Delete
break;
[461] Fix | Delete
}
[462] Fix | Delete
}
[463] Fix | Delete
}
[464] Fix | Delete
[465] Fix | Delete
if ( 'install' === $status ) {
[466] Fix | Delete
if ( is_dir( WP_PLUGIN_DIR . '/' . $api->slug ) ) {
[467] Fix | Delete
$installed_plugin = get_plugins( '/' . $api->slug );
[468] Fix | Delete
if ( empty( $installed_plugin ) ) {
[469] Fix | Delete
if ( current_user_can( 'install_plugins' ) ) {
[470] Fix | Delete
$url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=' . $api->slug ), 'install-plugin_' . $api->slug );
[471] Fix | Delete
}
[472] Fix | Delete
} else {
[473] Fix | Delete
$key = array_keys( $installed_plugin );
[474] Fix | Delete
// Use the first plugin regardless of the name.
[475] Fix | Delete
// Could have issues for multiple plugins in one directory if they share different version numbers.
[476] Fix | Delete
$key = reset( $key );
[477] Fix | Delete
[478] Fix | Delete
$update_file = $api->slug . '/' . $key;
[479] Fix | Delete
if ( version_compare( $api->version, $installed_plugin[ $key ]['Version'], '=' ) ) {
[480] Fix | Delete
$status = 'latest_installed';
[481] Fix | Delete
} elseif ( version_compare( $api->version, $installed_plugin[ $key ]['Version'], '<' ) ) {
[482] Fix | Delete
$status = 'newer_installed';
[483] Fix | Delete
$version = $installed_plugin[ $key ]['Version'];
[484] Fix | Delete
} else {
[485] Fix | Delete
// If the above update check failed, then that probably means that the update checker has out-of-date information, force a refresh.
[486] Fix | Delete
if ( ! $loop ) {
[487] Fix | Delete
delete_site_transient( 'update_plugins' );
[488] Fix | Delete
wp_update_plugins();
[489] Fix | Delete
return install_plugin_install_status( $api, true );
[490] Fix | Delete
}
[491] Fix | Delete
}
[492] Fix | Delete
}
[493] Fix | Delete
} else {
[494] Fix | Delete
// "install" & no directory with that slug.
[495] Fix | Delete
if ( current_user_can( 'install_plugins' ) ) {
[496] Fix | Delete
$url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=' . $api->slug ), 'install-plugin_' . $api->slug );
[497] Fix | Delete
}
[498] Fix | Delete
}
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function