| 1612 | * Displays the PHP upgrade nag. |
| 1613 | * |
| 1614 | * @since 5.0.0 |
| 1615 | */ |
| 1616 | function wp_dashboard_php_nag() { |
| 1617 | $response = wp_check_php_version(); |
| 1618 | |
| 1619 | if ( ! $response ) { |
| 1620 | return; |
| 1621 | } |
| 1622 | |
| 1623 | $information_url = _x( 'https://wordpress.org/support/upgrade-php/', 'localized PHP upgrade information page' ); |
| 1624 | |
| 1625 | /** |
| 1626 | * Filters the URL to environment-specific instructions on how to upgrade the PHP version. |
| 1627 | * |
| 1628 | * By default, no such URL is provided. |
| 1629 | * |
| 1630 | * @since 5.0.0 |
| 1631 | * |
| 1632 | * @param string $update_url PHP version upgrade URL. Default empty string. |
| 1633 | */ |
| 1634 | $update_url = apply_filters( 'php_update_url', '' ); |
| 1635 | |
| 1636 | $msg = __( 'Hi, it's your friends at WordPress here.' ); |
| 1637 | if ( ! $response['is_secure'] ) { |
| 1638 | $msg .= ' ' . __( 'We noticed that your site is running on an insecure version of PHP, which is why we're showing you this notice.' ); |
| 1639 | } else { |
| 1640 | $msg .= ' ' . __( 'We noticed that your site is running on an outdated version of PHP, which is why we're showing you this notice.' ); |
| 1641 | } |
| 1642 | |
| 1643 | ?> |
| 1644 | <p><?php echo $msg; ?></p> |
| 1645 | |
| 1646 | <h3><?php _e( 'What is PHP and why should I care?' ); ?></h3> |
| 1647 | <p><?php _e( 'PHP is the programming language that WordPress is built on. Newer versions of PHP are both faster and more secure, so upgrading is better for your site, and better for the people who are building WordPress.' ); ?></p> |
| 1648 | <p><?php _e( 'If you want to know exactly how PHP works and why it is important, continue reading.' ); ?></p> |
| 1649 | |
| 1650 | <h3><?php _e( 'Okay, how do I update?' ); ?></h3> |
| 1651 | <p><?php _e( 'The button below will take you to a page with more details on what PHP is, how to upgrade your PHP version, and what to do if it turns out you can't.' ); ?></p> |
| 1652 | <p class="notice-upgrade-button-wrap"> |
| 1653 | <?php if ( ! empty( $update_url ) ) : ?> |
| 1654 | <a class="notice-upgrade-button button button-primary button-hero" href="<?php echo esc_url( $information_url ); ?>"><?php _e( 'Learn more about upgrading PHP' ); ?></a> |
| 1655 | <a href="<?php echo esc_url( $update_url ); ?>"><?php _e( 'or upgrade right away' ); ?></a> |
| 1656 | <?php else : ?> |
| 1657 | <a class="notice-upgrade-button button button-primary button-hero" href="<?php echo esc_url( $information_url ); ?>"><?php _e( 'Show me how to upgrade my PHP' ); ?></a> |
| 1658 | <?php endif; ?> |
| 1659 | </p> |
| 1660 | |
| 1661 | <h3><?php _e( 'Thank you for taking the time to read this!' ); ?></h3> |
| 1662 | <p><?php _e( 'If you follow the instructions we've provided to the letter, upgrading shouldn't take more than a few minutes, and it is generally very safe to do.' ); ?></p> |
| 1663 | <p><?php _e( 'Good luck and happy blogging!' ); ?></p> |
| 1664 | <?php |
| 1665 | } |
| 1666 | |
| 1667 | /** |
| 1668 | * Checks if the user needs to upgrade PHP. |
| 1669 | * |
| 1670 | * @since 5.0.0 |
| 1671 | * |
| 1672 | * @return array Array of PHP version data. |
| 1673 | */ |
| 1674 | function wp_check_php_version() { |
| 1675 | $version = phpversion(); |
| 1676 | $key = md5( $version ); |
| 1677 | |
| 1678 | $response = get_site_transient( 'php_check_' . $key ); |
| 1679 | if ( false === $response ) { |
| 1680 | $url = 'http://api.wordpress.org/core/serve-happy/1.0/'; |
| 1681 | if ( wp_http_supports( array( 'ssl' ) ) ) { |
| 1682 | $url = set_url_scheme( $url, 'https' ); |
| 1683 | } |
| 1684 | |
| 1685 | $url = add_query_arg( 'php_version', $version, $url ); |
| 1686 | |
| 1687 | $response = wp_remote_get( $url ); |
| 1688 | |
| 1689 | if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) ) { |
| 1690 | return false; |
| 1691 | } |
| 1692 | |
| 1693 | /** |
| 1694 | * Response should be an array with: |
| 1695 | * 'recommended_version' - string - The PHP version recommended by WordPress |
| 1696 | * 'is_supported' - boolean - Whether the PHP version is actively supported |
| 1697 | * 'is_secure' - boolean - Whether the PHP version receives security updates |
| 1698 | * 'is_acceptable' - boolean - Whether the PHP version is still acceptable for WordPress |
| 1699 | */ |
| 1700 | $response = json_decode( wp_remote_retrieve_body( $response ), true ); |
| 1701 | |
| 1702 | if ( ! is_array( $response ) ) { |
| 1703 | return false; |
| 1704 | } |
| 1705 | |
| 1706 | set_site_transient( 'php_check_' . $key, $response, WEEK_IN_SECONDS ); |
| 1707 | } |
| 1708 | |
| 1709 | return $response; |
| 1710 | } |
| 1711 | |
| 1712 | /** |