Make WordPress Core

Changeset 43436


Ignore:
Timestamp:
07/09/2018 01:44:53 PM (8 years ago)
Author:
SergeyBiryukov
Message:

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.

Location:
trunk/src/wp-admin
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/css/list-tables.css

    r43309 r43436  
    15151515}
    15161516
     1517.plugin-card .notice {
     1518        margin: 20px 20px 0 20px;
     1519}
     1520
    15171521.plugin-icon {
    15181522        position: absolute;
  • trunk/src/wp-admin/includes/class-wp-plugin-install-list-table.php

    r43178 r43436  
    497497                        }
    498498
     499                        $wp_version = get_bloginfo( 'version' );
     500
     501                        $compatible_php = ( empty( $plugin['requires_php'] ) || version_compare( substr( phpversion(), 0, strlen( $plugin['requires_php'] ) ), $plugin['requires_php'], '>=' ) );
     502                        $tested_wp      = ( empty( $plugin['tested'] ) || version_compare( substr( $wp_version, 0, strlen( $plugin['tested'] ) ), $plugin['tested'], '<=' ) );
     503                        $compatible_wp  = ( empty( $plugin['requires'] ) || version_compare( substr( $wp_version, 0, strlen( $plugin['requires'] ) ), $plugin['requires'], '>=' ) );
     504
    499505                        $action_links = array();
    500506
    … …  
    505511                                        case 'install':
    506512                                                if ( $status['url'] ) {
    507                                                         $action_links[] = sprintf(
    508                                                                 '<a class="install-now button" data-slug="%s" href="%s" aria-label="%s" data-name="%s">%s</a>',
    509                                                                 esc_attr( $plugin['slug'] ),
    510                                                                 esc_url( $status['url'] ),
    511                                                                 /* translators: %s: plugin name and version */
    512                                                                 esc_attr( sprintf( __( 'Install %s now' ), $name ) ),
    513                                                                 esc_attr( $name ),
    514                                                                 __( 'Install Now' )
    515                                                         );
     513                                                        if ( $compatible_php && $compatible_wp ) {
     514                                                                $action_links[] = sprintf(
     515                                                                        '<a class="install-now button" data-slug="%s" href="%s" aria-label="%s" data-name="%s">%s</a>',
     516                                                                        esc_attr( $plugin['slug'] ),
     517                                                                        esc_url( $status['url'] ),
     518                                                                        /* translators: %s: plugin name and version */
     519                                                                        esc_attr( sprintf( __( 'Install %s now' ), $name ) ),
     520                                                                        esc_attr( $name ),
     521                                                                        __( 'Install Now' )
     522                                                                );
     523                                                        } else {
     524                                                                $action_links[] = sprintf(
     525                                                                        '<button type="button" class="button button-disabled" disabled="disabled">%s</button>',
     526                                                                        _x( 'Cannot Install', 'plugin' )
     527                                                                );
     528                                                        }
    516529                                                }
    517530                                                break;
    … …  
    611624                ?>
    612625                <div class="plugin-card plugin-card-<?php echo sanitize_html_class( $plugin['slug'] ); ?>">
     626                        <?php
     627                        if ( ! $compatible_php || ! $compatible_wp ) {
     628                                echo '<div class="notice inline notice-error notice-alt"><p>';
     629                                if ( ! $compatible_php && ! $compatible_wp ) {
     630                                        _e( 'This plugin doesn&#8217;t work with your versions of WordPress and PHP. ' );
     631                                        if ( current_user_can( 'update_core' ) ) {
     632                                                printf(
     633                                                        /* translators: 1: "Update WordPress" screen URL, 2: "Updating PHP" page URL */
     634                                                        __( '<a href="%1$s">Please update WordPress</a>, and then <a href="%2$s">learn more about updating PHP</a>.' ),
     635                                                        self_admin_url( 'update-core.php' ),
     636                                                        esc_url( __( 'https://wordpress.org/support/upgrade-php/' ) )
     637                                                );
     638                                        } else {
     639                                                printf(
     640                                                        /* translators: %s: "Updating PHP" page URL */
     641                                                        __( '<a href="%s">Learn more about updating PHP</a>.' ),
     642                                                        esc_url( __( 'https://wordpress.org/support/upgrade-php/' ) )
     643                                                );
     644                                        }
     645                                } elseif ( ! $compatible_wp ) {
     646                                        _e( 'This plugin doesn&#8217;t work with your version of WordPress. ' );
     647                                        if ( current_user_can( 'update_core' ) ) {
     648                                                printf(
     649                                                        /* translators: %s: "Update WordPress" screen URL */
     650                                                        __( '<a href="%s">Please update WordPress</a>.' ),
     651                                                        self_admin_url( 'update-core.php' )
     652                                                );
     653                                        }
     654                                } elseif ( ! $compatible_php  ) {
     655                                        _e( 'This plugin doesn&#8217;t work with your version of PHP. ' );
     656                                        printf(
     657                                                /* translators: %s: "Updating PHP" page URL */
     658                                                __( '<a href="%s">Learn more about updating PHP</a>.' ),
     659                                                esc_url( __( 'https://wordpress.org/support/upgrade-php/' ) )
     660                                        );
     661                                }
     662                                echo '</p></div>';
     663                        }
     664                        ?>
    613665                        <div class="plugin-card-top">
    614666                                <div class="name column-name">
    … …  
    642694                                                )
    643695                                        );
    644 ?>
     696                                        ?>
    645697                                        <span class="num-ratings" aria-hidden="true">(<?php echo number_format_i18n( $plugin['num_ratings'] ); ?>)</span>
    646698                                </div>
    … …  
    666718                                <div class="column-compatibility">
    667719                                        <?php
    668                                         $wp_version = get_bloginfo( 'version' );
    669 
    670                                         if ( ! empty( $plugin['tested'] ) && version_compare( substr( $wp_version, 0, strlen( $plugin['tested'] ) ), $plugin['tested'], '>' ) ) {
     720                                        if ( ! $tested_wp ) {
    671721                                                echo '<span class="compatibility-untested">' . __( 'Untested with your version of WordPress' ) . '</span>';
    672                                         } elseif ( ! empty( $plugin['requires'] ) && version_compare( substr( $wp_version, 0, strlen( $plugin['requires'] ) ), $plugin['requires'], '<' ) ) {
     722                                        } elseif ( ! $compatible_wp ) {
    673723                                                echo '<span class="compatibility-incompatible">' . __( '<strong>Incompatible</strong> with your version of WordPress' ) . '</span>';
    674724                                        } else {
  • trunk/src/wp-admin/includes/plugin-install.php

    r43179 r43436  
    754754        $wp_version = get_bloginfo( 'version' );
    755755
    756         if ( ! empty( $api->tested ) && version_compare( substr( $wp_version, 0, strlen( $api->tested ) ), $api->tested, '>' ) ) {
    757                 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>';
    758         } elseif ( ! empty( $api->requires ) && version_compare( substr( $wp_version, 0, strlen( $api->requires ) ), $api->requires, '<' ) ) {
    759                 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>';
     756        $compatible_php = ( empty( $api->requires_php ) || version_compare( substr( phpversion(), 0, strlen( $api->requires_php ) ), $api->requires_php, '>=' ) );
     757        $tested_wp      = ( empty( $api->tested ) || version_compare( substr( $wp_version, 0, strlen( $api->tested ) ), $api->tested, '<=' ) );
     758        $compatible_wp  = ( empty( $api->requires ) || version_compare( substr( $wp_version, 0, strlen( $api->requires ) ), $api->requires, '>=' ) );
     759
     760        if ( ! $compatible_php ) {
     761                echo '<div class="notice notice-error notice-alt"><p>';
     762                printf(
     763                        /* translators: "Updating PHP" page URL */
     764                        __( '<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>.' ),
     765                        esc_url( __( 'https://wordpress.org/support/upgrade-php/' ) )
     766                );
     767                echo '</p></div>';
     768        }
     769
     770        if ( ! $tested_wp ) {
     771                echo '<div class="notice notice-warning notice-alt"><p>';
     772                _e( '<strong>Warning:</strong> This plugin <strong>has not been tested</strong> with your current version of WordPress.' );
     773                echo '</p></div>';
     774        } elseif ( ! $compatible_wp ) {
     775                echo '<div class="notice notice-error notice-alt"><p>';
     776                _e( '<strong>Error:</strong> This plugin <strong>requires a newer version of WordPress</strong>.' );
     777                if ( current_user_can( 'update_core' ) ) {
     778                        printf(
     779                                /* translators: %s: "Update WordPress" screen URL */
     780                                ' ' . __( '<a href="%s" target="_parent">Click here to update WordPress</a>.' ),
     781                                self_admin_url( 'update-core.php' )
     782                        );
     783                }
     784                echo '</p></div>';
    760785        }
    761786
    … …  
    781806                        case 'install':
    782807                                if ( $status['url'] ) {
    783                                         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>';
     808                                        if ( $compatible_php && $compatible_wp ) {
     809                                                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>';
     810                                        } else {
     811                                                printf(
     812                                                        '<button type="button" class="button button-primary button-disabled right" disabled="disabled">%s</button>',
     813                                                        _x( 'Cannot Install', 'plugin' )
     814                                                );
     815                                        }
    784816                                }
    785817                                break;
Note: See TracChangeset for help on using the changeset viewer.