Making WordPress.org

Changeset 8963


Ignore:
Timestamp:
06/19/2019 06:55:06 PM (5 years ago)
Author:
iandunn
Message:

Service Worker Caching: Initial commit.

Props avillegasn, Iceable, westonruter, iandunn.

See https://make.wordpress.org/community/2019/04/30/wordcamp-pwa-an-update/
See https://github.com/wceu/wordcamp-pwa-page/

Location:
sites/trunk/wordcamp.org/public_html/wp-content/mu-plugins
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordcamp.org/public_html/wp-content/mu-plugins/load-other-mu-plugins.php

    r8936 r8963  
    55wcorg_include_individual_mu_plugins();
    66wcorg_include_mu_plugin_folders();
     7enable_pwa_alpha_test();    // Do _not_ comment out this line to disable this, see instructions in docblock instead.
    78
    89/**
     
    5051    }
    5152}
     53
     54/*
     55 * Enable the day-of-event and PWA features on alpha test sites.
     56 *
     57 * If something goes seriously wrong during WCEU2019, the following should disable the features and restore
     58 * stability:
     59 *
     60 * 1) Comment out the `2019.europe` ID inside `$pwa_test_sites`.
     61 * 2) Uncomment the `2019.europe` ID in the `rest_pre_dispatch` callback below.
     62 * 3) Deploy the above changes.
     63 * 4) Deactivate the `pwa` plugin on `2019.europe`.
     64 * 5) Visit https://2019.europe.wordcamp.org/wp-admin/options-reading.php and set the homepage to "Your latest posts".
     65 *
     66 * If that doesn't work, ask Systems for details about what's causing problems, and work with them to resolve it.
     67 * They may need to block REST API requests to `2019.europe` at the network level. Also, call Ian's cell phone until
     68 * he picks up :)
     69 *
     70 * todo When enabling this for all sites, most of this function can be removed, and the `require_once()` statements
     71 * can be integrated into `wcorg_include_individual_mu_plugins()`, and then this function can be removed.
     72 */
     73function enable_pwa_alpha_test() {
     74    /*
     75     * These are experimental features that were rushed to activate before the WCEU 2019 deadline, and are _not_
     76     * ready for production beyond this limited alpha test. There are many UX and code issues that need to be
     77     * resolved before any other sites are added to this list, including WCEU 2020.
     78     *
     79     * See https://github.com/wceu/wordcamp-pwa-page/issues/6, the other open issues in that repository, and the
     80     * `todo` notes in all of these files.
     81     *
     82     * When adding more sites here, you'll need to activate the `pwa` plugin for that site first.
     83     *
     84     * WARNING: Do _not_ add more sites, or network-enable this, until the issues mentioned above are resolved.
     85     */
     86    $pwa_test_sites = array(
     87        928,  // 2017.testing
     88        // todo enable after testing on 2017.testing production -- 1026, // 2019.europe
     89    );
     90
     91    if ( 'development' === WORDCAMP_ENVIRONMENT || in_array( get_current_blog_id(), $pwa_test_sites, true ) ) {
     92        require_once( __DIR__ . '/service-worker-caching.php' );
     93        // require_once( __DIR__ . '/theme-templates/bootstrap.php' );
     94    }
     95
     96    /**
     97     * Disable the REST API if the server is overloaded.
     98     *
     99     * This is a kill switch for the REST API, because even after disabling the `require()` calls above and the
     100     * `pwa` plugin, browsers will still be making requests to the API. This will short-circuit those, so that
     101     * the server isn't overloaded.
     102     */
     103    add_action( 'rest_pre_dispatch', function( $result, $server, $request ) {
     104        $overloaded_sites = array(
     105            //1026, // 2019.europe
     106        );
     107
     108        if ( in_array( get_current_blog_id(), $overloaded_sites, true ) ) {
     109            $result = new WP_Error(
     110                'api_temporarily_disabled',
     111                'The REST API has been temporarily disabled on this site because of unexpected stability problems',
     112                array( 'status' => 503 )
     113            );
     114        }
     115
     116        return $result;
     117    }, 10, 3 );
     118}
Note: See TracChangeset for help on using the changeset viewer.