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.
Built from https://develop.svn.wordpress.org/trunk@43436


git-svn-id: http://core.svn.wordpress.org/trunk@43263 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2018-07-09 13:45:25 +00:00
parent 9768bde3c4
commit 632d61cead
7 changed files with 112 additions and 22 deletions

View File

@ -1514,6 +1514,10 @@ div.action-links,
content: "\f147";
}
.plugin-card .notice {
margin: 20px 20px 0 20px;
}
.plugin-icon {
position: absolute;
top: 20px;

File diff suppressed because one or more lines are too long

View File

@ -1514,6 +1514,10 @@ div.action-links,
content: "\f147";
}
.plugin-card .notice {
margin: 20px 20px 0 20px;
}
.plugin-icon {
position: absolute;
top: 20px;

File diff suppressed because one or more lines are too long

View File

@ -496,6 +496,12 @@ class WP_Plugin_Install_List_Table extends WP_List_Table {
$author = ' <cite>' . sprintf( __( 'By %s' ), $author ) . '</cite>';
}
$wp_version = get_bloginfo( 'version' );
$compatible_php = ( empty( $plugin['requires_php'] ) || version_compare( substr( phpversion(), 0, strlen( $plugin['requires_php'] ) ), $plugin['requires_php'], '>=' ) );
$tested_wp = ( empty( $plugin['tested'] ) || version_compare( substr( $wp_version, 0, strlen( $plugin['tested'] ) ), $plugin['tested'], '<=' ) );
$compatible_wp = ( empty( $plugin['requires'] ) || version_compare( substr( $wp_version, 0, strlen( $plugin['requires'] ) ), $plugin['requires'], '>=' ) );
$action_links = array();
if ( current_user_can( 'install_plugins' ) || current_user_can( 'update_plugins' ) ) {
@ -504,15 +510,22 @@ class WP_Plugin_Install_List_Table extends WP_List_Table {
switch ( $status['status'] ) {
case 'install':
if ( $status['url'] ) {
$action_links[] = sprintf(
'<a class="install-now button" data-slug="%s" href="%s" aria-label="%s" data-name="%s">%s</a>',
esc_attr( $plugin['slug'] ),
esc_url( $status['url'] ),
/* translators: %s: plugin name and version */
esc_attr( sprintf( __( 'Install %s now' ), $name ) ),
esc_attr( $name ),
__( 'Install Now' )
);
if ( $compatible_php && $compatible_wp ) {
$action_links[] = sprintf(
'<a class="install-now button" data-slug="%s" href="%s" aria-label="%s" data-name="%s">%s</a>',
esc_attr( $plugin['slug'] ),
esc_url( $status['url'] ),
/* translators: %s: plugin name and version */
esc_attr( sprintf( __( 'Install %s now' ), $name ) ),
esc_attr( $name ),
__( 'Install Now' )
);
} else {
$action_links[] = sprintf(
'<button type="button" class="button button-disabled" disabled="disabled">%s</button>',
_x( 'Cannot Install', 'plugin' )
);
}
}
break;
@ -610,6 +623,45 @@ class WP_Plugin_Install_List_Table extends WP_List_Table {
$last_updated_timestamp = strtotime( $plugin['last_updated'] );
?>
<div class="plugin-card plugin-card-<?php echo sanitize_html_class( $plugin['slug'] ); ?>">
<?php
if ( ! $compatible_php || ! $compatible_wp ) {
echo '<div class="notice inline notice-error notice-alt"><p>';
if ( ! $compatible_php && ! $compatible_wp ) {
_e( 'This plugin doesn&#8217;t work with your versions of WordPress and PHP. ' );
if ( current_user_can( 'update_core' ) ) {
printf(
/* translators: 1: "Update WordPress" screen URL, 2: "Updating PHP" page URL */
__( '<a href="%1$s">Please update WordPress</a>, and then <a href="%2$s">learn more about updating PHP</a>.' ),
self_admin_url( 'update-core.php' ),
esc_url( __( 'https://wordpress.org/support/upgrade-php/' ) )
);
} else {
printf(
/* translators: %s: "Updating PHP" page URL */
__( '<a href="%s">Learn more about updating PHP</a>.' ),
esc_url( __( 'https://wordpress.org/support/upgrade-php/' ) )
);
}
} elseif ( ! $compatible_wp ) {
_e( 'This plugin doesn&#8217;t work with your version of WordPress. ' );
if ( current_user_can( 'update_core' ) ) {
printf(
/* translators: %s: "Update WordPress" screen URL */
__( '<a href="%s">Please update WordPress</a>.' ),
self_admin_url( 'update-core.php' )
);
}
} elseif ( ! $compatible_php ) {
_e( 'This plugin doesn&#8217;t work with your version of PHP. ' );
printf(
/* translators: %s: "Updating PHP" page URL */
__( '<a href="%s">Learn more about updating PHP</a>.' ),
esc_url( __( 'https://wordpress.org/support/upgrade-php/' ) )
);
}
echo '</p></div>';
}
?>
<div class="plugin-card-top">
<div class="name column-name">
<h3>
@ -641,7 +693,7 @@ class WP_Plugin_Install_List_Table extends WP_List_Table {
'number' => $plugin['num_ratings'],
)
);
?>
?>
<span class="num-ratings" aria-hidden="true">(<?php echo number_format_i18n( $plugin['num_ratings'] ); ?>)</span>
</div>
<div class="column-updated">
@ -665,11 +717,9 @@ class WP_Plugin_Install_List_Table extends WP_List_Table {
</div>
<div class="column-compatibility">
<?php
$wp_version = get_bloginfo( 'version' );
if ( ! empty( $plugin['tested'] ) && version_compare( substr( $wp_version, 0, strlen( $plugin['tested'] ) ), $plugin['tested'], '>' ) ) {
if ( ! $tested_wp ) {
echo '<span class="compatibility-untested">' . __( 'Untested with your version of WordPress' ) . '</span>';
} elseif ( ! empty( $plugin['requires'] ) && version_compare( substr( $wp_version, 0, strlen( $plugin['requires'] ) ), $plugin['requires'], '<' ) ) {
} elseif ( ! $compatible_wp ) {
echo '<span class="compatibility-incompatible">' . __( '<strong>Incompatible</strong> with your version of WordPress' ) . '</span>';
} else {
echo '<span class="compatibility-compatible">' . __( '<strong>Compatible</strong> with your version of WordPress' ) . '</span>';

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':

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.0-alpha-43435';
$wp_version = '5.0-alpha-43436';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.