WordPress.org

Making WordPress.org

Ticket #4004: 4004.diff

File 4004.diff, 15.2 KB (added by flixos90, 2 years ago)
  • wordpress.org/public_html/wp-content/plugins/support-helphub/inc/helphub-update-php/helphub-update-php.php

     
     1<?php
     2/**
     3 * Injects the hard-coded page content for the Update PHP page, based on whether the page template is selected.
     4 *
     5 * @package HelpHub_Update_PHP
     6 */
     7
     8if ( ! defined( 'ABSPATH' ) ) {
     9        exit; // Exit if accessed directly.
     10}
     11
     12/**
     13 * Injects the title for the Update PHP page if the Update PHP page template is selected.
     14 *
     15 * @param string $title Post title.
     16 * @param int    $id    Post ID.
     17 * @return string Filtered post title.
     18 */
     19function hh_filter_update_php_title( $title, $id ) {
     20        if ( is_admin() ) {
     21                return $title;
     22        }
     23
     24        if ( 'page-update-php.php' !== get_page_template_slug( $id ) ) {
     25                return $title;
     26        }
     27
     28        return __( 'Get a faster, more secure website: update your PHP today', 'wporg-forums' );
     29}
     30add_filter( 'the_title', 'hh_filter_update_php_title', 5, 2 );
     31
     32/**
     33 * Injects the content for the Update PHP page if the Update PHP page template is selected.
     34 *
     35 * @param string $content Post content.
     36 * @return string Filtered post content.
     37 */
     38function hh_filter_update_php_content( $content ) {
     39        if ( is_admin() ) {
     40                return $title;
     41        }
     42
     43        if ( ! is_page_template( 'page-update-php.php' ) ) {
     44                return $content;
     45        }
     46
     47        if ( ! in_the_loop() || get_the_ID() !== get_queried_object_id() ) {
     48                return $content;
     49        }
     50
     51        $php_versions = hh_query_php_versions();
     52
     53        $minimum_php     = ! empty( $php_versions['minimum_version'] ) ? $php_versions['minimum_version'] : '5.2';
     54        $recommended_php = ! empty( $php_versions['recommended_version'] ) ? $php_versions['recommended_version'] : '7.2';
     55
     56        // Introduction.
     57        $content  = '<p><strong>' . __( 'Your WordPress site can be faster, and more secure, and you can make this happen!', 'wporg-forums' ) . '</strong></p>';
     58        $content .= '<p>' . __( 'This page will explain why this matters to you, and then how you can fix it.', 'wporg-forums' ) . '</p>';
     59
     60        // Section "Why PHP Matters To You".
     61        $content .= '<h3>' . __( 'Why PHP Matters To You', 'wporg-forums' ) . '</h3>';
     62        $content .= '<p>';
     63        $content .= sprintf(
     64                /* translators: %s: link URL about keeping WordPress up to date */
     65                __( 'PHP is the coding language WordPress is built on, and its version is set at the server-level by your hosting company. Whilst you may be familiar with the importance of <a href="%s">keeping WordPress, and your themes and plugins up-to-date</a>, keeping PHP up-to-date is just as important.', 'wporg-forums' ),
     66                esc_url( _x( 'https://wordpress.org/support/article/administration-screens/#updates', 'link URL about keeping WordPress up to date', 'wporg-forums' ) )
     67        );
     68        $content .= '</p>';
     69        $content .= '<p>' . __( 'There are two main benefits to keeping PHP up-to-date:', 'wporg-forums' ) . '</p>';
     70        $content .= '<ul>';
     71        $content .= '<li>';
     72        $content .= sprintf(
     73                /* translators: %s: recommended PHP version */
     74                __( '<strong>Your website will be faster</strong> as the latest version of PHP is more efficient. Updating to the latest supported version (currently %s) can deliver a huge performance increase; up to 3 or 4x faster for older versions.', 'wporg-forums' ),
     75                $recommended_php
     76        );
     77        $content .= '</li>';
     78        $content .= '<li>' . __( '<strong>Your website will be more secure.</strong> PHP, like WordPress, is maintained by its community. Because PHP is so popular, it is a target for hackers – but the latest version will have the latest security features. Older versions of PHP <em>do not have this</em>, so updating is essential to keep your WordPress site secure.', 'wporg-forums' ) . '</li>';
     79        $content .= '</ul>';
     80        $content .= '<p>' . __( 'And then there are a number of secondary benefits:', 'wporg-forums' ) . '</p>';
     81        $content .= '<ul>';
     82        $content .= '<li>' . __( '<strong>A faster WordPress website will be rewarded by search engines</strong>, so you&#8217;ll rank higher in search!', 'wporg-forums' ) . '</li>';
     83        $content .= '<li>' . __( '<strong>A faster website will retain visitors better</strong> (they&#8217;ll leave if it takes too long to load), making your website more effective.', 'wporg-forums' ) . '</li>';
     84        $content .= '<li>' . __( '<strong>A more secure website is better protected against hackers</strong>, and the cost and reputational damage associated with a hacked website.', 'wporg-forums' ) . '</li>';
     85        $content .= '</ul>';
     86        $content .= '<p>' . __( 'These benefits are good for you, and good for your website&#8217;s visitors. These are the reasons you should update PHP today. The next section will show you how to do this.', 'wporg-forums' ) . '</p>';
     87
     88        // Section "Before you update your PHP version".
     89        $content .= '<h3>' . __( 'Before you update your PHP version', 'wporg-forums' ) . '</h3>';
     90        $content .= '<p>' . __( 'This section starts off with some warnings, but don&#8217;t be afraid! As with most things technical, we just need to cover some background before we can get to the part where you update your PHP version.', 'wporg-forums' ) . '</p>';
     91        $content .= '<p>';
     92        $content .= sprintf(
     93                /* translators: 1: minimum required PHP version, 2: recommended PHP version */
     94                __( 'Updating your PHP version should not be a problem, but we can&#8217;t <em>guarantee</em> that it&#8217;s not. WordPress itself works with PHP versions as far back as %1$s (we&#8217;re currently recommending version %2$s, so this is <em>great</em> backward compatibility!), but we don&#8217;t know if your themes or plugins will work. They should, and popular or reputable ones almost certainly will be, but we can&#8217;t guarantee it.', 'wporg-forums' ),
     95                $minimum_php,
     96                $recommended_php
     97        );
     98        $content .= '</p>';
     99        $content .= '<p>' . __( 'There are a couple of steps you should take to mitigate any risk before proceeding:', 'wporg-forums' ) . '</p>';
     100        $content .= '<ul>';
     101        $content .= '<li>';
     102        $content .= sprintf(
     103                /* translators: %s: link URL for free backup plugins */
     104                __( '<strong>Make a backup of your website:</strong> a backup will let you revert your site to how it is right now in the event anything goes wrong. There are <a href="%s">plenty of free backup plugins available</a>, so if you don&#8217;t have a backup solution already – use one of these. In order to revert this backup, you&#8217;ll also need your web host to move your PHP version back to your current version (we&#8217;ll cover how to do this later).', 'wporg-forums' ),
     105                esc_url( _x( 'https://wordpress.org/plugins/search/backup/', 'link URL for free backup plugins', 'wporg-forums' ) )
     106        );
     107        $content .= '</li>';
     108        $content .= '<li>' . __( '<strong>Update WordPress, themes, and plugins:</strong> from your WordPress Dashboard, head to Updates, and then update all. You should do this regularly anyway. :) When done, check your site is working as expected.', 'wporg-forums' ) . '</li>';
     109        $content .= '<li>';
     110        $content .= sprintf(
     111                /* translators: %s: link URL to the PHP Compatibility Checker plugin */
     112                __( '<strong>Check PHP compatibility:</strong> install the <a href="%s">PHP Compatibility Checker plugin</a> to check your themes and plugins for possible issues. This plugin isn&#8217;t perfect and may miss items or flag false positives, but it does work in most cases.', 'wporg-forums' ),
     113                esc_url( _x( 'https://wordpress.org/plugins/php-compatibility-checker/', 'link URL to the PHP Compatibility Checker plugin', 'wporg-forums' ) )
     114        );
     115        $content .= '</li>';
     116        $content .= '<li>';
     117        $content .= sprintf(
     118                /* translators: %s: link URL to wordpress.org */
     119                __( '<strong>Fix any PHP compatibility issues:</strong> if the PHP Compatibility Checker plugin picks up any issues, get in touch with the theme or plugin developer and ask them to investigate. If they can&#8217;t or won&#8217;t get back to you, have a look for themes or plugins on <a href="%s">WordPress.org</a> with similar functionality and use one of these instead.', 'wporg-forums' ),
     120                esc_url( _x( 'https://wordpress.org/', 'link URL to wordpress.org', 'wporg-forums' ) )
     121        );
     122        $content .= '</li>';
     123        $content .= '</ul>';
     124        $content .= '<p>' . __( 'Run through these steps, and you&#8217;ll be ready to update the PHP version on your WordPress site – and enjoy all of the benefits that come with this!', 'wporg-forums' ) . '</p>';
     125        $content .= '<p>' . __( 'If you run into any issues whilst doing this or need help, you should contact a professional web developer, your hosting company, or your theme and plugins authors. All of these will be happy to help here.', 'wporg-forums' ) . '</p>';
     126        $content .= '<p>' . __( 'We can now get on to the final part: actually updating your website&#8217;s PHP version.', 'wporg-forums' ) . '</p>';
     127
     128        // Section "How to update your website's PHP version for a faster, more secure website".
     129        $content .= '<h3>' . __( 'How to update your website&#8217;s PHP version for a faster, more secure website', 'wporg-forums' ) . '</h3>';
     130        $content .= '<p>' . __( 'You&#8217;re now ready to update your website&#8217;s PHP version! You&#8217;ve done due diligence, got backups, and are in the best possible shape to do the update.', 'wporg-forums' ) . '</p>';
     131        $content .= '<p>' . __( 'As the PHP version is set at the server level by your hosting company, updating involves either interacting with your host&#8217;s settings or asking them to do it.', 'wporg-forums' ) . '</p>';
     132        $content .= '<p>';
     133        $content .= sprintf(
     134                /* translators: %s: link URL to hosting-specific update resources */
     135                __( 'Thus, exactly <em>how</em> to do the update depends on your hosting company. We&#8217;ve asked hosting companies to submit instructions on how to update your PHP version on their hosting, and <a href="%s">you&#8217;ll find a list of hosts who have instructions available here</a>.', 'wporg-forums' ),
     136                esc_url( _x( 'https://github.com/WordPress/servehappy-resources/blob/master/tutorials/hosting-specific/tutorials-en.md', 'link URL to hosting-specific update resources', 'wporg-forums' ) )
     137        );
     138        $content .= '</p>';
     139        $content .= '<p>' . __( 'If you can&#8217;t find your host on this list, then email your hosting company and ask them to help! Here&#8217;s some template text you can use:', 'wporg-forums' ) . '</p>';
     140        $content .= '<pre>' . __( 'Dear Hosting Provider,<br><br>I want my website to be as performant and secure as<br>possible with the latest version of PHP. For the server<br>my WordPress site is hosted on, I want to ensure that<br>is the case. If I am not already on the latest version<br>of PHP, please let me know what steps I need to take<br>to update.<br><br>Thanks!', 'wporg-forums' ) . '</pre>';
     141        $content .= '<p>' . __( 'If you run into any issues at this stage, either change the PHP version back yourself, contact your hosting company or a professional web developer. In the unlikely event something goes wrong and you need to restore your backup, contact your host and ask them to restore the previous version of PHP you had running. You can then restore your backup.', 'wporg-forums' ) . '</p>';
     142        $content .= '<p>' . __( 'You should now have all the information you need to update! Nice work! With an up-to-date version of PHP you&#8217;ll enjoy a faster, more secure website and happier visitors.', 'wporg-forums' ) . '</p>';
     143
     144        // Section "Faster, more secure WordPress websites for all".
     145        $content .= '<h3>' . __( 'Faster, more secure WordPress websites for all', 'wporg-forums' ) . '</h3>';
     146        $content .= '<p>' . __( 'Making sure you have the latest version of PHP ensures your website is as fast, and secure as possible.', 'wporg-forums' ) . '</p>';
     147        $content .= '<p>' . __( 'You now have all the information you need to update to the latest version of PHP, and you know how to update in the future as well. Look out for more PHP update messages on your WordPress Dashboard going forwards, or keep an eye on your hosting company&#8217;s news for more information.', 'wporg-forums' ) . '</p>';
     148        $content .= '<p>' . __( 'As a final reminder: contact your hosting company, a professional web developer, or your theme and/or plugin authors for any additional questions. They&#8217;ll all be able to help out with their areas of expertise.', 'wporg-forums' ) . '</p>';
     149        $content .= '<p><strong>' . __( 'Thanks for making the internet a better place!', 'wporg-forums' ) . '</strong></p>';
     150
     151        return $content;
     152}
     153add_filter( 'the_content', 'hh_filter_update_php_content', 5 );
     154
     155/**
     156 * Queries the Servehappy API on wordpress.org to retrieve general PHP version information.
     157 *
     158 * @return array Associative array with recommended PHP version and more.
     159 */
     160function hh_query_php_versions() {
     161        $response = get_site_transient( 'helphub_php_versions' );
     162        if ( false === $response ) {
     163                $url = 'http://api.wordpress.org/core/serve-happy/1.0/';
     164                if ( wp_http_supports( array( 'ssl' ) ) ) {
     165                        $url = set_url_scheme( $url, 'https' );
     166                }
     167
     168                // The API requires passing a PHP version, so we just pass something arbitrary.
     169                $url = add_query_arg( 'php_version', '5.2', $url );
     170
     171                $response = wp_remote_get( $url );
     172
     173                if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) {
     174                        return false;
     175                }
     176
     177                /**
     178                 * Response should be an array with:
     179                 *  'recommended_version' - string - The PHP version recommended by WordPress.
     180                 *  'is_supported' - boolean - Whether the PHP version is actively supported.
     181                 *  'is_secure' - boolean - Whether the PHP version receives security updates.
     182                 *  'is_acceptable' - boolean - Whether the PHP version is still acceptable for WordPress.
     183                 */
     184                $response = json_decode( wp_remote_retrieve_body( $response ), true );
     185
     186                if ( ! is_array( $response ) ) {
     187                        return false;
     188                }
     189
     190                set_site_transient( 'helphub_php_versions', $response, WEEK_IN_SECONDS );
     191        }
     192
     193        return $response;
     194}
  • wordpress.org/public_html/wp-content/plugins/support-helphub/support-helphub.php

     
    2323require_once( dirname( __FILE__ ) . '/inc/helphub-front-page-blocks/helphub-front-page-blocks.php' );
    2424require_once( dirname( __FILE__ ) . '/inc/helphub-customroles/class-helphub-custom-roles.php' );
    2525require_once( dirname( __FILE__ ) . '/inc/helphub-manager/class-helphub-manager.php' );
    26 
     26require_once( dirname( __FILE__ ) . '/inc/helphub-update-php/helphub-update-php.php' );
  • wordpress.org/public_html/wp-content/themes/pub/wporg-support/page-update-php.php

     
     1<?php
     2/**
     3 * Template Name: Update PHP
     4 *
     5 * @package WPOrg
     6 * @subpackage Theme
     7 */
     8
     9/*
     10Use the default template for pages. This specific template is only used to indicate that the content needs to be
     11manually injected, which happens in the HelpHub plugin.
     12 */
     13require get_stylesheet_directory() . '/page.php';