| 1610 | * Displays the PHP upgrade nag. |
| 1611 | * |
| 1612 | * @since 5.0.0 |
| 1613 | */ |
| 1614 | function wp_dashboard_php_nag() { |
| 1615 | $response = wp_check_php_version(); |
| 1616 | |
| 1617 | if ( ! $response ) { |
| 1618 | return; |
| 1619 | } |
| 1620 | |
| 1621 | $information_url = __( 'https://wordpress.org/support/upgrade-php/' ); |
| 1622 | |
| 1623 | $msg = __( 'Hi, it's your friends at WordPress here.' ); |
| 1624 | if ( $response['insecure'] ) { |
| 1625 | $msg .= ' ' . __( 'We noticed that your site is running on an insecure version of PHP, which is why we're showing you this notice.' ); |
| 1626 | } else { |
| 1627 | $msg .= ' ' . __( 'We noticed that your site is running on an outdated version of PHP, which is why we're showing you this notice.' ); |
| 1628 | } |
| 1629 | |
| 1630 | ?> |
| 1631 | <p><?php echo $msg; ?></p> |
| 1632 | |
| 1633 | <h3><?php _e( 'What is PHP and why should I care?' ); ?></h3> |
| 1634 | <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> |
| 1635 | <p><?php _e( 'If you want to know exactly how PHP works and why it is important, continue reading.' ); ?></p> |
| 1636 | |
| 1637 | <h3><?php _e( 'Okay, how do I update?' ); ?></h3> |
| 1638 | <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> |
| 1639 | <p class="notice-upgrade-button-wrap"> |
| 1640 | <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> |
| 1641 | <?php if ( ! empty( $response['update_url'] ) ) : ?> |
| 1642 | <a href="<?php echo esc_url( $response['update_url'] ); ?>"><?php _e( 'or upgrade right away' ); ?></a> |
| 1643 | <?php endif; ?> |
| 1644 | </p> |
| 1645 | |
| 1646 | <h3><?php _e( 'Thank you for taking the time to read this!' ); ?></h3> |
| 1647 | <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> |
| 1648 | <p><?php _e( 'Good luck and happy blogging!' ); ?></p> |
| 1649 | <?php |
| 1650 | } |
| 1651 | |
| 1652 | /** |
| 1653 | * Checks if the user needs to upgrade PHP. |
| 1654 | * |
| 1655 | * @since 5.0.0 |
| 1656 | * |
| 1657 | * @return array Array of PHP version data. |
| 1658 | */ |
| 1659 | function wp_check_php_version() { |
| 1660 | $version = phpversion(); |
| 1661 | $key = md5( $version ); |
| 1662 | |
| 1663 | $response = get_site_transient( 'php_check_' . $key ); |
| 1664 | if ( false === $response ) { |
| 1665 | // Instead of hard-coding information here, this could be an API request to http://api.wordpress.org/core/serve-happy/. |
| 1666 | $response = array( |
| 1667 | 'name' => 'PHP', |
| 1668 | 'version' => $version, |
| 1669 | 'current_version' => '7.2.1', |
| 1670 | 'upgrade' => false, |
| 1671 | 'insecure' => false, |
| 1672 | 'update_url' => '', // This could contain a host-specific upgrade link. |
| 1673 | ); |
| 1674 | |
| 1675 | // This version would actually be 7.0, but we start slowly for now. |
| 1676 | if ( version_compare( $version, '5.3.0', '<' ) ) { |
| 1677 | $response['upgrade'] = true; |
| 1678 | } |
| 1679 | |
| 1680 | // PHP 5.6 is the oldest version that still receives security updates. |
| 1681 | if ( version_compare( $version, '5.6.0', '<' ) ) { |
| 1682 | $response['insecure'] = true; |
| 1683 | } |
| 1684 | |
| 1685 | set_site_transient( 'php_check_' . $key, $response, WEEK_IN_SECONDS ); |
| 1686 | } |
| 1687 | |
| 1688 | return $response; |
| 1689 | } |
| 1690 | |
| 1691 | /** |