WordPress.org

Make WordPress Core

Changeset 44937


Ignore:
Timestamp:
03/20/2019 01:43:05 AM (9 months ago)
Author:
desrosj
Message:

Plugins: Block plugin updates if required PHP version is not supported.

When a plugin states it requires a specific minimum PHP version (as defined in the requires_php field included in the plugin update API response), a user should not be allowed to update that plugin when the server does not satisfy the minimum PHP version.

When this scenario is encountered, the update buttons and links are disabled and links to educational resources about PHP are displayed to the user with a notice.

Props afragen, schlessera, desrosj.
Fixes #43987.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-plugins-list-table.php

    r44717 r44937  
    747747        }
    748748
    749         $class       = $is_active ? 'active' : 'inactive';
    750         $checkbox_id = 'checkbox_' . md5( $plugin_data['Name'] );
    751         if ( $restrict_network_active || $restrict_network_only || in_array( $status, array( 'mustuse', 'dropins' ) ) ) {
     749        $compatible_php = ( empty( $plugin_data['requires_php'] ) || version_compare( phpversion(), $plugin_data['requires_php'], '>=' ) );
     750        $class          = $is_active ? 'active' : 'inactive';
     751        $checkbox_id    = 'checkbox_' . md5( $plugin_data['Name'] );
     752        if ( $restrict_network_active || $restrict_network_only || in_array( $status, array( 'mustuse', 'dropins' ) ) || ! $compatible_php ) {
    752753            $checkbox = '';
    753754        } else {
  • trunk/src/wp-admin/includes/plugin-install.php

    r44656 r44937  
    770770                esc_url( wp_get_update_php_url() )
    771771            );
    772             echo '</p>';
    773             wp_update_php_annotation();
     772
     773            wp_update_php_annotation( '</p><p><em>', '</em>' );
    774774        } else {
    775775            echo '</p>';
     
    828828            case 'update_available':
    829829                if ( $status['url'] ) {
    830                     echo '<a data-slug="' . esc_attr( $api->slug ) . '" data-plugin="' . esc_attr( $status['file'] ) . '" id="plugin_update_from_iframe" class="button button-primary right" href="' . $status['url'] . '" target="_parent">' . __( 'Install Update Now' ) . '</a>';
     830                    if ( $compatible_php ) {
     831                        echo '<a data-slug="' . esc_attr( $api->slug ) . '" data-plugin="' . esc_attr( $status['file'] ) . '" id="plugin_update_from_iframe" class="button button-primary right" href="' . $status['url'] . '" target="_parent">' . __( 'Install Update Now' ) . '</a>';
     832                    } else {
     833                        printf(
     834                            '<button type="button" class="button button-primary button-disabled right" disabled="disabled">%s</button>',
     835                            _x( 'Cannot Update', 'plugin' )
     836                        );
     837                    }
    831838                }
    832839                break;
  • trunk/src/wp-admin/includes/update.php

    r44451 r44937  
    401401        }
    402402
    403         echo '<tr class="plugin-update-tr' . $active_class . '" id="' . esc_attr( $response->slug . '-update' ) . '" data-slug="' . esc_attr( $response->slug ) . '" data-plugin="' . esc_attr( $file ) . '"><td colspan="' . esc_attr( $wp_list_table->get_column_count() ) . '" class="plugin-update colspanchange"><div class="update-message notice inline notice-warning notice-alt"><p>';
     403        $compatible_php = ( empty( $response->requires_php ) || version_compare( phpversion(), $response->requires_php, '>=' ) );
     404        $notice_type    = $compatible_php ? 'notice-warning' : 'notice-error';
     405
     406        echo '<tr class="plugin-update-tr' . $active_class . '" id="' . esc_attr( $response->slug . '-update' ) . '" data-slug="' . esc_attr( $response->slug ) . '" data-plugin="' . esc_attr( $file ) . '"><td colspan="' . esc_attr( $wp_list_table->get_column_count() ) . '" class="plugin-update colspanchange"><div class="update-message notice inline ' . $notice_type . ' notice-alt"><p>';
    404407
    405408        if ( ! current_user_can( 'update_plugins' ) ) {
     
    414417                    esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $plugin_name, $response->new_version ) )
    415418                ),
    416                 $response->new_version
     419                esc_attr( $response->new_version )
    417420            );
    418421        } elseif ( empty( $response->package ) ) {
     
    427430                    esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $plugin_name, $response->new_version ) )
    428431                ),
    429                 $response->new_version
     432                esc_attr( $response->new_version )
    430433            );
    431434        } else {
    432             /* translators: 1: plugin name, 2: details URL, 3: additional link attributes, 4: version number, 5: update URL, 6: additional link attributes */
    433             printf(
    434                 __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a> or <a href="%5$s" %6$s>update now</a>.' ),
    435                 $plugin_name,
    436                 esc_url( $details_url ),
    437                 sprintf(
    438                     'class="thickbox open-plugin-details-modal" aria-label="%s"',
    439                     /* translators: 1: plugin name, 2: version number */
    440                     esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $plugin_name, $response->new_version ) )
    441                 ),
    442                 $response->new_version,
    443                 wp_nonce_url( self_admin_url( 'update.php?action=upgrade-plugin&plugin=' ) . $file, 'upgrade-plugin_' . $file ),
    444                 sprintf(
    445                     'class="update-link" aria-label="%s"',
    446                     /* translators: %s: plugin name */
    447                     esc_attr( sprintf( __( 'Update %s now' ), $plugin_name ) )
    448                 )
    449             );
     435            if ( $compatible_php ) {
     436                /* translators: 1: plugin name, 2: details URL, 3: additional link attributes, 4: version number, 5: update URL, 6: additional link attributes */
     437                printf(
     438                    __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a> or <a href="%5$s" %6$s>update now</a>.' ),
     439                    $plugin_name,
     440                    esc_url( $details_url ),
     441                    sprintf(
     442                        'class="thickbox open-plugin-details-modal" aria-label="%s"',
     443                        /* translators: 1: plugin name, 2: version number */
     444                        esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $plugin_name, $response->new_version ) )
     445                    ),
     446                    esc_attr( $response->new_version ),
     447                    wp_nonce_url( self_admin_url( 'update.php?action=upgrade-plugin&plugin=' ) . $file, 'upgrade-plugin_' . $file ),
     448                    sprintf(
     449                        'class="update-link" aria-label="%s"',
     450                        /* translators: %s: plugin name */
     451                        esc_attr( sprintf( __( 'Update %s now' ), $plugin_name ) )
     452                    )
     453                );
     454            } else {
     455                /* translators: 1: plugin name, 2: details URL, 3: additional link attributes, 4: version number 5: Update PHP page URL */
     456                printf(
     457                    __( 'There is a new version of %1$s available, but it doesn&#8217;t work with your version of PHP. <a href="%2$s" %3$s>View version %4$s details</a> or <a href="%5$s">learn more about updating PHP</a>.' ),
     458                    $plugin_name,
     459                    esc_url( $details_url ),
     460                    sprintf(
     461                        'class="thickbox open-plugin-details-modal" aria-label="%s"',
     462                        /* translators: 1: plugin name, 2: version number */
     463                        esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $plugin_name, $response->new_version ) )
     464                    ),
     465                    esc_attr( $response->new_version ),
     466                    esc_url( wp_get_update_php_url() )
     467                );
     468                wp_update_php_annotation( '<br><span class="description">', '</span>' );
     469            }
    450470        }
    451471
Note: See TracChangeset for help on using the changeset viewer.