Edit File by line
/home/zeestwma/ceyloniy.../wp-admin/includes
File: plugin-install.php
}
[500] Fix | Delete
}
[501] Fix | Delete
}
[502] Fix | Delete
if ( isset( $_GET['from'] ) ) {
[503] Fix | Delete
$url .= '&from=' . urlencode( wp_unslash( $_GET['from'] ) );
[504] Fix | Delete
}
[505] Fix | Delete
[506] Fix | Delete
$file = $update_file;
[507] Fix | Delete
return compact( 'status', 'url', 'version', 'file' );
[508] Fix | Delete
}
[509] Fix | Delete
[510] Fix | Delete
/**
[511] Fix | Delete
* Displays plugin information in dialog box form.
[512] Fix | Delete
*
[513] Fix | Delete
* @since 2.7.0
[514] Fix | Delete
*
[515] Fix | Delete
* @global string $tab
[516] Fix | Delete
*/
[517] Fix | Delete
function install_plugin_information() {
[518] Fix | Delete
global $tab;
[519] Fix | Delete
[520] Fix | Delete
if ( empty( $_REQUEST['plugin'] ) ) {
[521] Fix | Delete
return;
[522] Fix | Delete
}
[523] Fix | Delete
[524] Fix | Delete
$api = plugins_api(
[525] Fix | Delete
'plugin_information',
[526] Fix | Delete
array(
[527] Fix | Delete
'slug' => wp_unslash( $_REQUEST['plugin'] ),
[528] Fix | Delete
)
[529] Fix | Delete
);
[530] Fix | Delete
[531] Fix | Delete
if ( is_wp_error( $api ) ) {
[532] Fix | Delete
wp_die( $api );
[533] Fix | Delete
}
[534] Fix | Delete
[535] Fix | Delete
$plugins_allowedtags = array(
[536] Fix | Delete
'a' => array(
[537] Fix | Delete
'href' => array(),
[538] Fix | Delete
'title' => array(),
[539] Fix | Delete
'target' => array(),
[540] Fix | Delete
),
[541] Fix | Delete
'abbr' => array( 'title' => array() ),
[542] Fix | Delete
'acronym' => array( 'title' => array() ),
[543] Fix | Delete
'code' => array(),
[544] Fix | Delete
'pre' => array(),
[545] Fix | Delete
'em' => array(),
[546] Fix | Delete
'strong' => array(),
[547] Fix | Delete
'div' => array( 'class' => array() ),
[548] Fix | Delete
'span' => array( 'class' => array() ),
[549] Fix | Delete
'p' => array(),
[550] Fix | Delete
'br' => array(),
[551] Fix | Delete
'ul' => array(),
[552] Fix | Delete
'ol' => array(),
[553] Fix | Delete
'li' => array(),
[554] Fix | Delete
'h1' => array(),
[555] Fix | Delete
'h2' => array(),
[556] Fix | Delete
'h3' => array(),
[557] Fix | Delete
'h4' => array(),
[558] Fix | Delete
'h5' => array(),
[559] Fix | Delete
'h6' => array(),
[560] Fix | Delete
'img' => array(
[561] Fix | Delete
'src' => array(),
[562] Fix | Delete
'class' => array(),
[563] Fix | Delete
'alt' => array(),
[564] Fix | Delete
),
[565] Fix | Delete
'blockquote' => array( 'cite' => true ),
[566] Fix | Delete
);
[567] Fix | Delete
[568] Fix | Delete
$plugins_section_titles = array(
[569] Fix | Delete
'description' => _x( 'Description', 'Plugin installer section title' ),
[570] Fix | Delete
'installation' => _x( 'Installation', 'Plugin installer section title' ),
[571] Fix | Delete
'faq' => _x( 'FAQ', 'Plugin installer section title' ),
[572] Fix | Delete
'screenshots' => _x( 'Screenshots', 'Plugin installer section title' ),
[573] Fix | Delete
'changelog' => _x( 'Changelog', 'Plugin installer section title' ),
[574] Fix | Delete
'reviews' => _x( 'Reviews', 'Plugin installer section title' ),
[575] Fix | Delete
'other_notes' => _x( 'Other Notes', 'Plugin installer section title' ),
[576] Fix | Delete
);
[577] Fix | Delete
[578] Fix | Delete
// Sanitize HTML.
[579] Fix | Delete
foreach ( (array) $api->sections as $section_name => $content ) {
[580] Fix | Delete
$api->sections[ $section_name ] = wp_kses( $content, $plugins_allowedtags );
[581] Fix | Delete
}
[582] Fix | Delete
[583] Fix | Delete
foreach ( array( 'version', 'author', 'requires', 'tested', 'homepage', 'downloaded', 'slug' ) as $key ) {
[584] Fix | Delete
if ( isset( $api->$key ) ) {
[585] Fix | Delete
$api->$key = wp_kses( $api->$key, $plugins_allowedtags );
[586] Fix | Delete
}
[587] Fix | Delete
}
[588] Fix | Delete
[589] Fix | Delete
$_tab = esc_attr( $tab );
[590] Fix | Delete
[591] Fix | Delete
// Default to the Description tab, Do not translate, API returns English.
[592] Fix | Delete
$section = isset( $_REQUEST['section'] ) ? wp_unslash( $_REQUEST['section'] ) : 'description';
[593] Fix | Delete
if ( empty( $section ) || ! isset( $api->sections[ $section ] ) ) {
[594] Fix | Delete
$section_titles = array_keys( (array) $api->sections );
[595] Fix | Delete
$section = reset( $section_titles );
[596] Fix | Delete
}
[597] Fix | Delete
[598] Fix | Delete
iframe_header( __( 'Plugin Installation' ) );
[599] Fix | Delete
[600] Fix | Delete
$_with_banner = '';
[601] Fix | Delete
[602] Fix | Delete
if ( ! empty( $api->banners ) && ( ! empty( $api->banners['low'] ) || ! empty( $api->banners['high'] ) ) ) {
[603] Fix | Delete
$_with_banner = 'with-banner';
[604] Fix | Delete
$low = empty( $api->banners['low'] ) ? $api->banners['high'] : $api->banners['low'];
[605] Fix | Delete
$high = empty( $api->banners['high'] ) ? $api->banners['low'] : $api->banners['high'];
[606] Fix | Delete
?>
[607] Fix | Delete
<style type="text/css">
[608] Fix | Delete
#plugin-information-title.with-banner {
[609] Fix | Delete
background-image: url( <?php echo esc_url( $low ); ?> );
[610] Fix | Delete
}
[611] Fix | Delete
@media only screen and ( -webkit-min-device-pixel-ratio: 1.5 ) {
[612] Fix | Delete
#plugin-information-title.with-banner {
[613] Fix | Delete
background-image: url( <?php echo esc_url( $high ); ?> );
[614] Fix | Delete
}
[615] Fix | Delete
}
[616] Fix | Delete
</style>
[617] Fix | Delete
<?php
[618] Fix | Delete
}
[619] Fix | Delete
[620] Fix | Delete
echo '<div id="plugin-information-scrollable">';
[621] Fix | Delete
echo "<div id='{$_tab}-title' class='{$_with_banner}'><div class='vignette'></div><h2>{$api->name}</h2></div>";
[622] Fix | Delete
echo "<div id='{$_tab}-tabs' class='{$_with_banner}'>\n";
[623] Fix | Delete
[624] Fix | Delete
foreach ( (array) $api->sections as $section_name => $content ) {
[625] Fix | Delete
if ( 'reviews' === $section_name && ( empty( $api->ratings ) || 0 === array_sum( (array) $api->ratings ) ) ) {
[626] Fix | Delete
continue;
[627] Fix | Delete
}
[628] Fix | Delete
[629] Fix | Delete
if ( isset( $plugins_section_titles[ $section_name ] ) ) {
[630] Fix | Delete
$title = $plugins_section_titles[ $section_name ];
[631] Fix | Delete
} else {
[632] Fix | Delete
$title = ucwords( str_replace( '_', ' ', $section_name ) );
[633] Fix | Delete
}
[634] Fix | Delete
[635] Fix | Delete
$class = ( $section_name === $section ) ? ' class="current"' : '';
[636] Fix | Delete
$href = add_query_arg(
[637] Fix | Delete
array(
[638] Fix | Delete
'tab' => $tab,
[639] Fix | Delete
'section' => $section_name,
[640] Fix | Delete
)
[641] Fix | Delete
);
[642] Fix | Delete
$href = esc_url( $href );
[643] Fix | Delete
$san_section = esc_attr( $section_name );
[644] Fix | Delete
echo "\t<a name='$san_section' href='$href' $class>$title</a>\n";
[645] Fix | Delete
}
[646] Fix | Delete
[647] Fix | Delete
echo "</div>\n";
[648] Fix | Delete
[649] Fix | Delete
?>
[650] Fix | Delete
<div id="<?php echo $_tab; ?>-content" class='<?php echo $_with_banner; ?>'>
[651] Fix | Delete
<div class="fyi">
[652] Fix | Delete
<ul>
[653] Fix | Delete
<?php if ( ! empty( $api->version ) ) { ?>
[654] Fix | Delete
<li><strong><?php _e( 'Version:' ); ?></strong> <?php echo $api->version; ?></li>
[655] Fix | Delete
<?php } if ( ! empty( $api->author ) ) { ?>
[656] Fix | Delete
<li><strong><?php _e( 'Author:' ); ?></strong> <?php echo links_add_target( $api->author, '_blank' ); ?></li>
[657] Fix | Delete
<?php } if ( ! empty( $api->last_updated ) ) { ?>
[658] Fix | Delete
<li><strong><?php _e( 'Last Updated:' ); ?></strong>
[659] Fix | Delete
<?php
[660] Fix | Delete
/* translators: %s: Human-readable time difference. */
[661] Fix | Delete
printf( __( '%s ago' ), human_time_diff( strtotime( $api->last_updated ) ) );
[662] Fix | Delete
?>
[663] Fix | Delete
</li>
[664] Fix | Delete
<?php } if ( ! empty( $api->requires ) ) { ?>
[665] Fix | Delete
<li>
[666] Fix | Delete
<strong><?php _e( 'Requires WordPress Version:' ); ?></strong>
[667] Fix | Delete
<?php
[668] Fix | Delete
/* translators: %s: Version number. */
[669] Fix | Delete
printf( __( '%s or higher' ), $api->requires );
[670] Fix | Delete
?>
[671] Fix | Delete
</li>
[672] Fix | Delete
<?php } if ( ! empty( $api->tested ) ) { ?>
[673] Fix | Delete
<li><strong><?php _e( 'Compatible up to:' ); ?></strong> <?php echo $api->tested; ?></li>
[674] Fix | Delete
<?php } if ( ! empty( $api->requires_php ) ) { ?>
[675] Fix | Delete
<li>
[676] Fix | Delete
<strong><?php _e( 'Requires PHP Version:' ); ?></strong>
[677] Fix | Delete
<?php
[678] Fix | Delete
/* translators: %s: Version number. */
[679] Fix | Delete
printf( __( '%s or higher' ), $api->requires_php );
[680] Fix | Delete
?>
[681] Fix | Delete
</li>
[682] Fix | Delete
<?php } if ( isset( $api->active_installs ) ) { ?>
[683] Fix | Delete
<li><strong><?php _e( 'Active Installations:' ); ?></strong>
[684] Fix | Delete
<?php
[685] Fix | Delete
if ( $api->active_installs >= 1000000 ) {
[686] Fix | Delete
$active_installs_millions = floor( $api->active_installs / 1000000 );
[687] Fix | Delete
printf(
[688] Fix | Delete
/* translators: %s: Number of millions. */
[689] Fix | Delete
_nx( '%s+ Million', '%s+ Million', $active_installs_millions, 'Active plugin installations' ),
[690] Fix | Delete
number_format_i18n( $active_installs_millions )
[691] Fix | Delete
);
[692] Fix | Delete
} elseif ( $api->active_installs < 10 ) {
[693] Fix | Delete
_ex( 'Less Than 10', 'Active plugin installations' );
[694] Fix | Delete
} else {
[695] Fix | Delete
echo number_format_i18n( $api->active_installs ) . '+';
[696] Fix | Delete
}
[697] Fix | Delete
?>
[698] Fix | Delete
</li>
[699] Fix | Delete
<?php } if ( ! empty( $api->slug ) && empty( $api->external ) ) { ?>
[700] Fix | Delete
<li><a target="_blank" href="<?php echo esc_url( __( 'https://wordpress.org/plugins/' ) . $api->slug ); ?>/"><?php _e( 'WordPress.org Plugin Page &#187;' ); ?></a></li>
[701] Fix | Delete
<?php } if ( ! empty( $api->homepage ) ) { ?>
[702] Fix | Delete
<li><a target="_blank" href="<?php echo esc_url( $api->homepage ); ?>"><?php _e( 'Plugin Homepage &#187;' ); ?></a></li>
[703] Fix | Delete
<?php } if ( ! empty( $api->donate_link ) && empty( $api->contributors ) ) { ?>
[704] Fix | Delete
<li><a target="_blank" href="<?php echo esc_url( $api->donate_link ); ?>"><?php _e( 'Donate to this plugin &#187;' ); ?></a></li>
[705] Fix | Delete
<?php } ?>
[706] Fix | Delete
</ul>
[707] Fix | Delete
<?php if ( ! empty( $api->rating ) ) { ?>
[708] Fix | Delete
<h3><?php _e( 'Average Rating' ); ?></h3>
[709] Fix | Delete
<?php
[710] Fix | Delete
wp_star_rating(
[711] Fix | Delete
array(
[712] Fix | Delete
'rating' => $api->rating,
[713] Fix | Delete
'type' => 'percent',
[714] Fix | Delete
'number' => $api->num_ratings,
[715] Fix | Delete
)
[716] Fix | Delete
);
[717] Fix | Delete
?>
[718] Fix | Delete
<p aria-hidden="true" class="fyi-description">
[719] Fix | Delete
<?php
[720] Fix | Delete
printf(
[721] Fix | Delete
/* translators: %s: Number of ratings. */
[722] Fix | Delete
_n( '(based on %s rating)', '(based on %s ratings)', $api->num_ratings ),
[723] Fix | Delete
number_format_i18n( $api->num_ratings )
[724] Fix | Delete
);
[725] Fix | Delete
?>
[726] Fix | Delete
</p>
[727] Fix | Delete
<?php
[728] Fix | Delete
}
[729] Fix | Delete
[730] Fix | Delete
if ( ! empty( $api->ratings ) && array_sum( (array) $api->ratings ) > 0 ) {
[731] Fix | Delete
?>
[732] Fix | Delete
<h3><?php _e( 'Reviews' ); ?></h3>
[733] Fix | Delete
<p class="fyi-description"><?php _e( 'Read all reviews on WordPress.org or write your own!' ); ?></p>
[734] Fix | Delete
<?php
[735] Fix | Delete
foreach ( $api->ratings as $key => $ratecount ) {
[736] Fix | Delete
// Avoid div-by-zero.
[737] Fix | Delete
$_rating = $api->num_ratings ? ( $ratecount / $api->num_ratings ) : 0;
[738] Fix | Delete
$aria_label = esc_attr(
[739] Fix | Delete
sprintf(
[740] Fix | Delete
/* translators: 1: Number of stars (used to determine singular/plural), 2: Number of reviews. */
[741] Fix | Delete
_n(
[742] Fix | Delete
'Reviews with %1$d star: %2$s. Opens in a new tab.',
[743] Fix | Delete
'Reviews with %1$d stars: %2$s. Opens in a new tab.',
[744] Fix | Delete
$key
[745] Fix | Delete
),
[746] Fix | Delete
$key,
[747] Fix | Delete
number_format_i18n( $ratecount )
[748] Fix | Delete
)
[749] Fix | Delete
);
[750] Fix | Delete
?>
[751] Fix | Delete
<div class="counter-container">
[752] Fix | Delete
<span class="counter-label">
[753] Fix | Delete
<?php
[754] Fix | Delete
printf(
[755] Fix | Delete
'<a href="%s" target="_blank" aria-label="%s">%s</a>',
[756] Fix | Delete
"https://wordpress.org/support/plugin/{$api->slug}/reviews/?filter={$key}",
[757] Fix | Delete
$aria_label,
[758] Fix | Delete
/* translators: %s: Number of stars. */
[759] Fix | Delete
sprintf( _n( '%d star', '%d stars', $key ), $key )
[760] Fix | Delete
);
[761] Fix | Delete
?>
[762] Fix | Delete
</span>
[763] Fix | Delete
<span class="counter-back">
[764] Fix | Delete
<span class="counter-bar" style="width: <?php echo 92 * $_rating; ?>px;"></span>
[765] Fix | Delete
</span>
[766] Fix | Delete
<span class="counter-count" aria-hidden="true"><?php echo number_format_i18n( $ratecount ); ?></span>
[767] Fix | Delete
</div>
[768] Fix | Delete
<?php
[769] Fix | Delete
}
[770] Fix | Delete
}
[771] Fix | Delete
if ( ! empty( $api->contributors ) ) {
[772] Fix | Delete
?>
[773] Fix | Delete
<h3><?php _e( 'Contributors' ); ?></h3>
[774] Fix | Delete
<ul class="contributors">
[775] Fix | Delete
<?php
[776] Fix | Delete
foreach ( (array) $api->contributors as $contrib_username => $contrib_details ) {
[777] Fix | Delete
$contrib_name = $contrib_details['display_name'];
[778] Fix | Delete
if ( ! $contrib_name ) {
[779] Fix | Delete
$contrib_name = $contrib_username;
[780] Fix | Delete
}
[781] Fix | Delete
$contrib_name = esc_html( $contrib_name );
[782] Fix | Delete
[783] Fix | Delete
$contrib_profile = esc_url( $contrib_details['profile'] );
[784] Fix | Delete
$contrib_avatar = esc_url( add_query_arg( 's', '36', $contrib_details['avatar'] ) );
[785] Fix | Delete
[786] Fix | Delete
echo "<li><a href='{$contrib_profile}' target='_blank'><img src='{$contrib_avatar}' width='18' height='18' alt='' />{$contrib_name}</a></li>";
[787] Fix | Delete
}
[788] Fix | Delete
?>
[789] Fix | Delete
</ul>
[790] Fix | Delete
<?php if ( ! empty( $api->donate_link ) ) { ?>
[791] Fix | Delete
<a target="_blank" href="<?php echo esc_url( $api->donate_link ); ?>"><?php _e( 'Donate to this plugin &#187;' ); ?></a>
[792] Fix | Delete
<?php } ?>
[793] Fix | Delete
<?php } ?>
[794] Fix | Delete
</div>
[795] Fix | Delete
<div id="section-holder">
[796] Fix | Delete
<?php
[797] Fix | Delete
$requires_php = isset( $api->requires_php ) ? $api->requires_php : null;
[798] Fix | Delete
$requires_wp = isset( $api->requires ) ? $api->requires : null;
[799] Fix | Delete
[800] Fix | Delete
$compatible_php = is_php_version_compatible( $requires_php );
[801] Fix | Delete
$compatible_wp = is_wp_version_compatible( $requires_wp );
[802] Fix | Delete
$tested_wp = ( empty( $api->tested ) || version_compare( get_bloginfo( 'version' ), $api->tested, '<=' ) );
[803] Fix | Delete
[804] Fix | Delete
if ( ! $compatible_php ) {
[805] Fix | Delete
$compatible_php_notice_message = '<p>';
[806] Fix | Delete
$compatible_php_notice_message .= __( '<strong>Error:</strong> This plugin <strong>requires a newer version of PHP</strong>.' );
[807] Fix | Delete
[808] Fix | Delete
if ( current_user_can( 'update_php' ) ) {
[809] Fix | Delete
$compatible_php_notice_message .= sprintf(
[810] Fix | Delete
/* translators: %s: URL to Update PHP page. */
[811] Fix | Delete
' ' . __( '<a href="%s" target="_blank">Click here to learn more about updating PHP</a>.' ),
[812] Fix | Delete
esc_url( wp_get_update_php_url() )
[813] Fix | Delete
) . wp_update_php_annotation( '</p><p><em>', '</em>', false );
[814] Fix | Delete
} else {
[815] Fix | Delete
$compatible_php_notice_message .= '</p>';
[816] Fix | Delete
}
[817] Fix | Delete
[818] Fix | Delete
wp_admin_notice(
[819] Fix | Delete
$compatible_php_notice_message,
[820] Fix | Delete
array(
[821] Fix | Delete
'type' => 'error',
[822] Fix | Delete
'additional_classes' => array( 'notice-alt' ),
[823] Fix | Delete
'paragraph_wrap' => false,
[824] Fix | Delete
)
[825] Fix | Delete
);
[826] Fix | Delete
}
[827] Fix | Delete
[828] Fix | Delete
if ( ! $tested_wp ) {
[829] Fix | Delete
wp_admin_notice(
[830] Fix | Delete
__( '<strong>Warning:</strong> This plugin <strong>has not been tested</strong> with your current version of WordPress.' ),
[831] Fix | Delete
array(
[832] Fix | Delete
'type' => 'warning',
[833] Fix | Delete
'additional_classes' => array( 'notice-alt' ),
[834] Fix | Delete
)
[835] Fix | Delete
);
[836] Fix | Delete
} elseif ( ! $compatible_wp ) {
[837] Fix | Delete
$compatible_wp_notice_message = __( '<strong>Error:</strong> This plugin <strong>requires a newer version of WordPress</strong>.' );
[838] Fix | Delete
if ( current_user_can( 'update_core' ) ) {
[839] Fix | Delete
$compatible_wp_notice_message .= sprintf(
[840] Fix | Delete
/* translators: %s: URL to WordPress Updates screen. */
[841] Fix | Delete
' ' . __( '<a href="%s" target="_parent">Click here to update WordPress</a>.' ),
[842] Fix | Delete
esc_url( self_admin_url( 'update-core.php' ) )
[843] Fix | Delete
);
[844] Fix | Delete
}
[845] Fix | Delete
[846] Fix | Delete
wp_admin_notice(
[847] Fix | Delete
$compatible_wp_notice_message,
[848] Fix | Delete
array(
[849] Fix | Delete
'type' => 'error',
[850] Fix | Delete
'additional_classes' => array( 'notice-alt' ),
[851] Fix | Delete
)
[852] Fix | Delete
);
[853] Fix | Delete
}
[854] Fix | Delete
[855] Fix | Delete
foreach ( (array) $api->sections as $section_name => $content ) {
[856] Fix | Delete
$content = links_add_base_url( $content, 'https://wordpress.org/plugins/' . $api->slug . '/' );
[857] Fix | Delete
$content = links_add_target( $content, '_blank' );
[858] Fix | Delete
[859] Fix | Delete
$san_section = esc_attr( $section_name );
[860] Fix | Delete
[861] Fix | Delete
$display = ( $section_name === $section ) ? 'block' : 'none';
[862] Fix | Delete
[863] Fix | Delete
echo "\t<div id='section-{$san_section}' class='section' style='display: {$display};'>\n";
[864] Fix | Delete
echo $content;
[865] Fix | Delete
echo "\t</div>\n";
[866] Fix | Delete
}
[867] Fix | Delete
echo "</div>\n";
[868] Fix | Delete
echo "</div>\n";
[869] Fix | Delete
echo "</div>\n"; // #plugin-information-scrollable
[870] Fix | Delete
echo "<div id='$tab-footer'>\n";
[871] Fix | Delete
if ( ! empty( $api->download_link ) && ( current_user_can( 'install_plugins' ) || current_user_can( 'update_plugins' ) ) ) {
[872] Fix | Delete
$button = wp_get_plugin_action_button( $api->name, $api, $compatible_php, $compatible_wp );
[873] Fix | Delete
$button = str_replace( 'class="', 'class="right ', $button );
[874] Fix | Delete
[875] Fix | Delete
if ( ! str_contains( $button, _x( 'Activate', 'plugin' ) ) ) {
[876] Fix | Delete
$button = str_replace( 'class="', 'id="plugin_install_from_iframe" class="', $button );
[877] Fix | Delete
}
[878] Fix | Delete
[879] Fix | Delete
echo wp_kses_post( $button );
[880] Fix | Delete
}
[881] Fix | Delete
echo "</div>\n";
[882] Fix | Delete
[883] Fix | Delete
wp_print_request_filesystem_credentials_modal();
[884] Fix | Delete
wp_print_admin_notice_templates();
[885] Fix | Delete
[886] Fix | Delete
iframe_footer();
[887] Fix | Delete
exit;
[888] Fix | Delete
}
[889] Fix | Delete
[890] Fix | Delete
/**
[891] Fix | Delete
* Gets the markup for the plugin install action button.
[892] Fix | Delete
*
[893] Fix | Delete
* @since 6.5.0
[894] Fix | Delete
*
[895] Fix | Delete
* @param string $name Plugin name.
[896] Fix | Delete
* @param array|object $data {
[897] Fix | Delete
* An array or object of plugin data. Can be retrieved from the API.
[898] Fix | Delete
*
[899] Fix | Delete
* @type string $slug The plugin slug.
[900] Fix | Delete
* @type string[] $requires_plugins An array of plugin dependency slugs.
[901] Fix | Delete
* @type string $version The plugin's version string. Used when getting the install status.
[902] Fix | Delete
* }
[903] Fix | Delete
* @param bool $compatible_php The result of a PHP compatibility check.
[904] Fix | Delete
* @param bool $compatible_wp The result of a WP compatibility check.
[905] Fix | Delete
* @return string The markup for the dependency row button. An empty string if the user does not have capabilities.
[906] Fix | Delete
*/
[907] Fix | Delete
function wp_get_plugin_action_button( $name, $data, $compatible_php, $compatible_wp ) {
[908] Fix | Delete
$button = '';
[909] Fix | Delete
$data = (object) $data;
[910] Fix | Delete
$status = install_plugin_install_status( $data );
[911] Fix | Delete
$requires_plugins = $data->requires_plugins ?? array();
[912] Fix | Delete
[913] Fix | Delete
// Determine the status of plugin dependencies.
[914] Fix | Delete
$installed_plugins = get_plugins();
[915] Fix | Delete
$active_plugins = get_option( 'active_plugins', array() );
[916] Fix | Delete
$plugin_dependencies_count = count( $requires_plugins );
[917] Fix | Delete
$installed_plugin_dependencies_count = 0;
[918] Fix | Delete
$active_plugin_dependencies_count = 0;
[919] Fix | Delete
foreach ( $requires_plugins as $dependency ) {
[920] Fix | Delete
foreach ( array_keys( $installed_plugins ) as $installed_plugin_file ) {
[921] Fix | Delete
if ( str_contains( $installed_plugin_file, '/' ) && explode( '/', $installed_plugin_file )[0] === $dependency ) {
[922] Fix | Delete
++$installed_plugin_dependencies_count;
[923] Fix | Delete
}
[924] Fix | Delete
}
[925] Fix | Delete
[926] Fix | Delete
foreach ( $active_plugins as $active_plugin_file ) {
[927] Fix | Delete
if ( str_contains( $active_plugin_file, '/' ) && explode( '/', $active_plugin_file )[0] === $dependency ) {
[928] Fix | Delete
++$active_plugin_dependencies_count;
[929] Fix | Delete
}
[930] Fix | Delete
}
[931] Fix | Delete
}
[932] Fix | Delete
$all_plugin_dependencies_installed = $installed_plugin_dependencies_count === $plugin_dependencies_count;
[933] Fix | Delete
$all_plugin_dependencies_active = $active_plugin_dependencies_count === $plugin_dependencies_count;
[934] Fix | Delete
[935] Fix | Delete
if ( current_user_can( 'install_plugins' ) || current_user_can( 'update_plugins' ) ) {
[936] Fix | Delete
switch ( $status['status'] ) {
[937] Fix | Delete
case 'install':
[938] Fix | Delete
if ( $status['url'] ) {
[939] Fix | Delete
if ( $compatible_php && $compatible_wp && $all_plugin_dependencies_installed && ! empty( $data->download_link ) ) {
[940] Fix | Delete
$button = sprintf(
[941] Fix | Delete
'<a class="install-now button" data-slug="%s" href="%s" aria-label="%s" data-name="%s" role="button">%s</a>',
[942] Fix | Delete
esc_attr( $data->slug ),
[943] Fix | Delete
esc_url( $status['url'] ),
[944] Fix | Delete
/* translators: %s: Plugin name and version. */
[945] Fix | Delete
esc_attr( sprintf( _x( 'Install %s now', 'plugin' ), $name ) ),
[946] Fix | Delete
esc_attr( $name ),
[947] Fix | Delete
_x( 'Install Now', 'plugin' )
[948] Fix | Delete
);
[949] Fix | Delete
} else {
[950] Fix | Delete
$button = sprintf(
[951] Fix | Delete
'<button type="button" class="install-now button button-disabled" disabled="disabled">%s</button>',
[952] Fix | Delete
_x( 'Install Now', 'plugin' )
[953] Fix | Delete
);
[954] Fix | Delete
}
[955] Fix | Delete
}
[956] Fix | Delete
break;
[957] Fix | Delete
[958] Fix | Delete
case 'update_available':
[959] Fix | Delete
if ( $status['url'] ) {
[960] Fix | Delete
if ( $compatible_php && $compatible_wp ) {
[961] Fix | Delete
$button = sprintf(
[962] Fix | Delete
'<a class="update-now button aria-button-if-js" data-plugin="%s" data-slug="%s" href="%s" aria-label="%s" data-name="%s" role="button">%s</a>',
[963] Fix | Delete
esc_attr( $status['file'] ),
[964] Fix | Delete
esc_attr( $data->slug ),
[965] Fix | Delete
esc_url( $status['url'] ),
[966] Fix | Delete
/* translators: %s: Plugin name and version. */
[967] Fix | Delete
esc_attr( sprintf( _x( 'Update %s now', 'plugin' ), $name ) ),
[968] Fix | Delete
esc_attr( $name ),
[969] Fix | Delete
_x( 'Update Now', 'plugin' )
[970] Fix | Delete
);
[971] Fix | Delete
} else {
[972] Fix | Delete
$button = sprintf(
[973] Fix | Delete
'<button type="button" class="button button-disabled" disabled="disabled">%s</button>',
[974] Fix | Delete
_x( 'Update Now', 'plugin' )
[975] Fix | Delete
);
[976] Fix | Delete
}
[977] Fix | Delete
}
[978] Fix | Delete
break;
[979] Fix | Delete
[980] Fix | Delete
case 'latest_installed':
[981] Fix | Delete
case 'newer_installed':
[982] Fix | Delete
if ( is_plugin_active( $status['file'] ) ) {
[983] Fix | Delete
$button = sprintf(
[984] Fix | Delete
'<button type="button" class="button button-disabled" disabled="disabled">%s</button>',
[985] Fix | Delete
_x( 'Active', 'plugin' )
[986] Fix | Delete
);
[987] Fix | Delete
} elseif ( current_user_can( 'activate_plugin', $status['file'] ) ) {
[988] Fix | Delete
if ( $compatible_php && $compatible_wp && $all_plugin_dependencies_active ) {
[989] Fix | Delete
$button_text = _x( 'Activate', 'plugin' );
[990] Fix | Delete
/* translators: %s: Plugin name. */
[991] Fix | Delete
$button_label = _x( 'Activate %s', 'plugin' );
[992] Fix | Delete
$activate_url = add_query_arg(
[993] Fix | Delete
array(
[994] Fix | Delete
'_wpnonce' => wp_create_nonce( 'activate-plugin_' . $status['file'] ),
[995] Fix | Delete
'action' => 'activate',
[996] Fix | Delete
'plugin' => $status['file'],
[997] Fix | Delete
),
[998] Fix | Delete
network_admin_url( 'plugins.php' )
[999] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function