Make WordPress Core

Changeset 44627


Ignore:
Timestamp:
01/16/2019 05:05:37 PM (6 years ago)
Author:
flixos90
Message:

Plugins: Use centralized API to display information about updating PHP when a plugin requires a higher version.

This changeset uses the API functions introduced in [44476] to link to the resource about updating PHP when highlighting a plugin's required PHP version is not met. It furthermore expands them, introducing a new wp_update_php_annotation() function that prints the markup to indicate that the default URL has been altered by the web host, allowing it to be reused universally.

Furthermore, this changeset adds missing update_php capability checks before displaying the information about updating PHP.

Props afragen.
Fixes #45986. See #43986, #45686.

Location:
trunk/src
Files:
4 edited

Legend:

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

    r44574 r44627  
    636636                if ( ! $compatible_php && ! $compatible_wp ) {
    637637                    _e( 'This plugin doesn’t work with your versions of WordPress and PHP. ' );
    638                     if ( current_user_can( 'update_core' ) ) {
     638                    if ( current_user_can( 'update_core' ) && current_user_can( 'update_php' ) ) {
    639639                        printf(
    640                             /* translators: 1: "Update WordPress" screen URL, 2: "Updating PHP" page URL */
     640                            /* translators: 1: "Update WordPress" screen URL, 2: "Update PHP" page URL */
    641641                            __( '<a href="%1$s">Please update WordPress</a>, and then <a href="%2$s">learn more about updating PHP</a>.' ),
    642642                            self_admin_url( 'update-core.php' ),
    643                             esc_url( __( 'https://wordpress.org/support/update-php/' ) )
     643                            esc_url( wp_get_update_php_url() )
    644644                        );
    645                     } else {
     645                        wp_update_php_annotation();
     646                    } elseif ( current_user_can( 'update_core' ) ) {
    646647                        printf(
    647                             /* translators: %s: "Updating PHP" page URL */
     648                            /* translators: %s: "Update WordPress" screen URL */
     649                            __( '<a href="%s">Please update WordPress</a>.' ),
     650                            self_admin_url( 'update-core.php' )
     651                        );
     652                    } elseif ( current_user_can( 'update_php' ) ) {
     653                        printf(
     654                            /* translators: %s: "Update PHP" page URL */
    648655                            __( '<a href="%s">Learn more about updating PHP</a>.' ),
    649                             esc_url( __( 'https://wordpress.org/support/update-php/' ) )
     656                            esc_url( wp_get_update_php_url() )
    650657                        );
     658                        wp_update_php_annotation();
    651659                    }
    652660                } elseif ( ! $compatible_wp ) {
     
    661669                } elseif ( ! $compatible_php ) {
    662670                    _e( 'This plugin doesn&#8217;t work with your version of PHP. ' );
    663                     printf(
    664                         /* translators: %s: "Updating PHP" page URL */
    665                         __( '<a href="%s">Learn more about updating PHP</a>.' ),
    666                         esc_url( __( 'https://wordpress.org/support/update-php/' ) )
    667                     );
     671                    if ( current_user_can( 'update_php' ) ) {
     672                        printf(
     673                            /* translators: %s: "Update PHP" page URL */
     674                            __( '<a href="%s">Learn more about updating PHP</a>.' ),
     675                            esc_url( wp_get_update_php_url() )
     676                        );
     677                        wp_update_php_annotation();
     678                    }
    668679                }
    669680                echo '</p></div>';
  • trunk/src/wp-admin/includes/dashboard.php

    r44485 r44627  
    16271627    }
    16281628
    1629     $update_url  = wp_get_update_php_url();
    1630     $default_url = wp_get_default_update_php_url();
    1631 
    16321629    ?>
    16331630    <p><?php echo $msg; ?></p>
     
    16401637        printf(
    16411638            '<a class="button button-primary" href="%1$s" target="_blank" rel="noopener noreferrer">%2$s <span class="screen-reader-text">%3$s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a>',
    1642             esc_url( $update_url ),
     1639            esc_url( wp_get_update_php_url() ),
    16431640            __( 'Learn more about updating PHP' ),
    16441641            /* translators: accessibility text */
     
    16491646    <?php
    16501647
    1651     if ( $update_url !== $default_url ) {
    1652         ?>
    1653         <p class="description">
    1654             <?php
    1655             printf(
    1656                 /* translators: %s: default Update PHP page URL */
    1657                 __( 'This resource is provided by your web host, and is specific to your site. For more information, <a href="%s" target="_blank">see the official WordPress documentation</a>.' ),
    1658                 esc_url( $default_url )
    1659             );
    1660             ?>
    1661         </p>
    1662         <?php
    1663     }
     1648    wp_update_php_annotation();
    16641649}
    16651650
  • trunk/src/wp-admin/includes/plugin-install.php

    r44574 r44627  
    763763    if ( ! $compatible_php ) {
    764764        echo '<div class="notice notice-error notice-alt"><p>';
    765         printf(
    766             /* translators: "Updating PHP" page URL */
    767             __( '<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>.' ),
    768             esc_url( __( 'https://wordpress.org/support/update-php/' ) )
    769         );
    770         echo '</p></div>';
     765        _e( '<strong>Error:</strong> This plugin <strong>requires a newer version of PHP</strong>.' );
     766        if ( current_user_can( 'update_php' ) ) {
     767            printf(
     768                /* translators: %s: "Update PHP" page URL */
     769                ' ' . __( '<a href="%s" target="_blank">Click here to learn more about updating PHP</a>.' ),
     770                esc_url( wp_get_update_php_url() )
     771            );
     772            echo '</p>';
     773            wp_update_php_annotation();
     774        } else {
     775            echo '</p>';
     776        }
     777        echo '</div>';
    771778    }
    772779
  • trunk/src/wp-includes/functions.php

    r44625 r44627  
    67176717    return _x( 'https://wordpress.org/support/update-php/', 'localized PHP upgrade information page' );
    67186718}
     6719
     6720/**
     6721 * Prints the default annotation for the web host altering the "Update PHP" page URL.
     6722 *
     6723 * This function is to be used after {@see wp_get_update_php_url()} to display a consistent
     6724 * annotation if the web host has altered the default "Update PHP" page URL.
     6725 *
     6726 * @since 5.1.0
     6727 */
     6728function wp_update_php_annotation() {
     6729    $update_url  = wp_get_update_php_url();
     6730    $default_url = wp_get_default_update_php_url();
     6731
     6732    if ( $update_url === $default_url ) {
     6733        return;
     6734    }
     6735
     6736    echo '<p class="description">';
     6737    printf(
     6738        /* translators: %s: default Update PHP page URL */
     6739        __( 'This resource is provided by your web host, and is specific to your site. For more information, <a href="%s" target="_blank">see the official WordPress documentation</a>.' ),
     6740        esc_url( $default_url )
     6741    );
     6742    echo'</p>';
     6743}
Note: See TracChangeset for help on using the changeset viewer.