Make WordPress Core

Changeset 44814


Ignore:
Timestamp:
03/07/2019 09:31:50 PM (6 years ago)
Author:
desrosj
Message:

General: Add a way to specify a direct link for a user to update PHP.

A direct URL to where a user can update PHP for their website can now be specified in one of two ways:

  • Defining the WP_DIRECT_UPDATE_PHP_URL environment variable.
  • Returning a URL to the wp_direct_php_update_url filter.

When a URL is specified, an additional “Update PHP” button will be displayed at the bottom of the Core dashboard widget informing administrators that their site is running an outdated version of PHP (see [42832]).

Fixes #46074.
Props afragen, desrosj, lukecarbis.

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/dashboard.php

    r44809 r44814  
    16481648
    16491649    wp_update_php_annotation();
     1650    wp_direct_php_update_button();
    16501651}
    16511652
  • trunk/src/wp-includes/functions.php

    r44791 r44814  
    68316831    echo'</p>';
    68326832}
     6833
     6834/**
     6835 * Gets the URL for directly updating the PHP version the site is running on.
     6836 *
     6837 * A URL will only be returned if the `WP_DIRECT_UPDATE_PHP_URL` environment variable is specified or
     6838 * by using the {@see 'wp_direct_php_update_url'} filter. This allows hosts to send users directly to
     6839 * the page where they can update PHP to a newer version.
     6840 *
     6841 * @return string URL for directly updating PHP or empty string.
     6842 */
     6843function wp_get_direct_php_update_url() {
     6844    $direct_update_url = '';
     6845
     6846    if ( false !== getenv( 'WP_DIRECT_UPDATE_PHP_URL' ) ) {
     6847        $direct_update_url = getenv( 'WP_DIRECT_UPDATE_PHP_URL' );
     6848    }
     6849
     6850    /**
     6851     * Filters the URL for directly updating the PHP version the site is running on from the host.
     6852     *
     6853     * @since 5.1.1
     6854     *
     6855     * @param string $direct_update_url URL for directly updating PHP.
     6856     */
     6857    $direct_update_url = apply_filters( 'wp_direct_php_update_url', $direct_update_url );
     6858
     6859    return $direct_update_url;
     6860}
     6861
     6862/**
     6863 * Display a button directly linking to a PHP update process.
     6864 *
     6865 * This provides hosts with a way for users to be sent directly to their PHP update process.
     6866 *
     6867 * The button is only displayed if a URL is returned by `wp_get_direct_php_update_url()`.
     6868 *
     6869 * @since 5.1.1
     6870 */
     6871function wp_direct_php_update_button() {
     6872    $direct_update_url = wp_get_direct_php_update_url();
     6873
     6874    if ( empty( $direct_update_url ) ) {
     6875        return;
     6876    }
     6877
     6878    echo '<p class="button-container">';
     6879    printf(
     6880        '<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>',
     6881        esc_url( $direct_update_url ),
     6882        __( 'Update PHP' ),
     6883        /* translators: accessibility text */
     6884        __( '(opens in a new tab)' )
     6885    );
     6886    echo '</p>';
     6887}
Note: See TracChangeset for help on using the changeset viewer.