Plugins: Disable "Install Now" button for plugins that require a higher version of PHP or WordPress.

Display a notice with an explanation and the steps required to resolve the issue.

Props afragen, schlessera, flixos90, nerrad, melchoyce, boemedia, hedgefield, joyously, johnalarcon, lakenh, afercia, acirujano, ibantxillo, SergeyBiryukov.
Fixes #43986.

git-svn-id: https://develop.svn.wordpress.org/trunk@43436 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov
2018-07-09 13:44:53 +00:00
parent 3d85e311ef
commit 7569772234
3 changed files with 105 additions and 19 deletions

View File

@@ -753,10 +753,35 @@ if ( ! empty( $api->contributors ) ) {
<?php
$wp_version = get_bloginfo( 'version' );
if ( ! empty( $api->tested ) && version_compare( substr( $wp_version, 0, strlen( $api->tested ) ), $api->tested, '>' ) ) {
echo '<div class="notice notice-warning notice-alt"><p>' . __( '<strong>Warning:</strong> This plugin has <strong>not been tested</strong> with your current version of WordPress.' ) . '</p></div>';
} elseif ( ! empty( $api->requires ) && version_compare( substr( $wp_version, 0, strlen( $api->requires ) ), $api->requires, '<' ) ) {
echo '<div class="notice notice-warning notice-alt"><p>' . __( '<strong>Warning:</strong> This plugin has <strong>not been marked as compatible</strong> with your version of WordPress.' ) . '</p></div>';
$compatible_php = ( empty( $api->requires_php ) || version_compare( substr( phpversion(), 0, strlen( $api->requires_php ) ), $api->requires_php, '>=' ) );
$tested_wp = ( empty( $api->tested ) || version_compare( substr( $wp_version, 0, strlen( $api->tested ) ), $api->tested, '<=' ) );
$compatible_wp = ( empty( $api->requires ) || version_compare( substr( $wp_version, 0, strlen( $api->requires ) ), $api->requires, '>=' ) );
if ( ! $compatible_php ) {
echo '<div class="notice notice-error notice-alt"><p>';
printf(
/* translators: "Updating PHP" page URL */
__( '<strong>Error:</strong> This plugin <strong>requires a newer version of PHP</strong>, so unfortunately you cannot install it. <a href="%s" target="_blank">Click here to learn more about updating PHP</a>.' ),
esc_url( __( 'https://wordpress.org/support/upgrade-php/' ) )
);
echo '</p></div>';
}
if ( ! $tested_wp ) {
echo '<div class="notice notice-warning notice-alt"><p>';
_e( '<strong>Warning:</strong> This plugin <strong>has not been tested</strong> with your current version of WordPress.' );
echo '</p></div>';
} elseif ( ! $compatible_wp ) {
echo '<div class="notice notice-error notice-alt"><p>';
_e( '<strong>Error:</strong> This plugin <strong>requires a newer version of WordPress</strong>.' );
if ( current_user_can( 'update_core' ) ) {
printf(
/* translators: %s: "Update WordPress" screen URL */
' ' . __( '<a href="%s" target="_parent">Click here to update WordPress</a>.' ),
self_admin_url( 'update-core.php' )
);
}
echo '</p></div>';
}
foreach ( (array) $api->sections as $section_name => $content ) {
@@ -780,7 +805,14 @@ if ( ! empty( $api->contributors ) ) {
switch ( $status['status'] ) {
case 'install':
if ( $status['url'] ) {
echo '<a data-slug="' . esc_attr( $api->slug ) . '" id="plugin_install_from_iframe" class="button button-primary right" href="' . $status['url'] . '" target="_parent">' . __( 'Install Now' ) . '</a>';
if ( $compatible_php && $compatible_wp ) {
echo '<a data-slug="' . esc_attr( $api->slug ) . '" id="plugin_install_from_iframe" class="button button-primary right" href="' . $status['url'] . '" target="_parent">' . __( 'Install Now' ) . '</a>';
} else {
printf(
'<button type="button" class="button button-primary button-disabled right" disabled="disabled">%s</button>',
_x( 'Cannot Install', 'plugin' )
);
}
}
break;
case 'update_available':