Plugin Directory

Changeset 2928769 for performance-lab


Ignore:
Timestamp:
06/20/2023 05:11:40 PM (3 years ago)
Author:
performanceteam
Message:

Update to version 2.4.0 from GitHub

Location:
performance-lab
Files:
2 added
26 edited
1 copied

Legend:

Unmodified
Added
Removed
  • performance-lab/tags/2.4.0/admin/load.php

    r2912645 r2928769  
    8080            $module_slug,
    8181            $module_data['name'],
    82             function() use ( $module_slug, $module_data, $module_settings ) {
     82            static function() use ( $module_slug, $module_data, $module_settings ) {
    8383                perflab_render_modules_page_field( $module_slug, $module_data, $module_settings );
    8484            },
     
    202202                <?php // Don't use the WP notice classes here, as that makes them move to the top of the page. ?>
    203203                <p class="notice notice-warning" style="padding:1em;max-width:50em;">
    204                     <?php esc_html_e( 'Enabling this module will switch to a separate database and install WordPress in it. You will need to reconfigure your site, and start with a fresh site. Disabling the module you will get back to your previous MySQL database, with all your previous data intact.', 'performance-lab' ); ?>
     204                    <?php esc_html_e( 'It is not advised to activate this module since it will be removed in the upcoming Performance Lab release.', 'performance-lab' ); ?>
     205                    <a href="https://wordpress.org/plugins/sqlite-database-integration">
     206                        <?php esc_html_e( 'Please use the standalone plugin instead.', 'performance-lab' ); ?>
     207                    </a>
    205208                </p>
    206209            <?php endif; ?>
     
    330333    uasort(
    331334        $modules,
    332         function( $a, $b ) {
     335        static function( $a, $b ) {
    333336            return strnatcasecmp( $a['name'], $b['name'] );
    334337        }
     
    418421    $dismissed    = explode( ',', (string) get_user_meta( $current_user, 'dismissed_wp_pointers', true ) );
    419422
     423    /*
     424     * Temporary: Show an admin pointer if SQLite module is active to prompt
     425     * for an action to use the standalone plugin instead.
     426     *
     427     * This code will be removed again when the SQLite module is removed from
     428     * the codebase.
     429     */
     430    if (
     431        defined( 'SQLITE_VERSION' )
     432        && str_starts_with( SQLITE_VERSION, 'Performance Lab ' )
     433        && ! in_array( 'perflab-sqlite-module-removal-pointer', $dismissed, true )
     434        && current_user_can( 'activate_plugins' )
     435    ) {
     436        /*
     437         * Enqueue the pointer logic and return early. A closure is used to
     438         * avoid introducing a new function as it should be removed again in
     439         * the following release.
     440         */
     441        wp_enqueue_style( 'wp-pointer' );
     442        wp_enqueue_script( 'wp-pointer' );
     443        add_action(
     444            'admin_print_footer_scripts',
     445            static function() {
     446                $content  = __( 'The SQLite module will be removed in the upcoming Performance Lab release in favor of a standalone plugin.', 'performance-lab' );
     447                $content .= ' ' . sprintf(
     448                    /* translators: %s: settings page link */
     449                    __( 'Open %s to learn more about next steps to keep the functionality available.', 'performance-lab' ),
     450                    '<a href="' . esc_url( add_query_arg( 'page', PERFLAB_MODULES_SCREEN, admin_url( 'options-general.php' ) ) ) . '">' . __( 'Settings > Performance', 'performance-lab' ) . '</a>'
     451                );
     452                perflab_render_pointer(
     453                    'perflab-sqlite-module-removal-pointer',
     454                    array(
     455                        'heading' => __( 'Action required', 'performance-lab' ),
     456                        'content' => $content,
     457                    )
     458                );
     459            }
     460        );
     461        return;
     462    }
     463
    420464    if ( in_array( 'perflab-admin-pointer', $dismissed, true ) ) {
    421465        return;
     
    425469    wp_enqueue_style( 'wp-pointer' );
    426470    wp_enqueue_script( 'wp-pointer' );
    427     add_action( 'admin_print_footer_scripts', 'perflab_render_pointer' );
     471    add_action( 'admin_print_footer_scripts', 'perflab_render_pointer', 10, 0 );
    428472}
    429473add_action( 'admin_enqueue_scripts', 'perflab_admin_pointer' );
     
    435479 *
    436480 * @since 1.0.0
    437  */
    438 function perflab_render_pointer() {
    439     $heading         = __( 'Performance Lab', 'performance-lab' );
     481 * @since 2.4.0 Optional arguments were added to make the function reusable for different pointers.
     482 *
     483 * @param string $pointer_id Optional. ID of the pointer. Default 'perflab-admin-pointer'.
     484 * @param array  $args       Optional. Pointer arguments. Supports 'heading' and 'content' entries.
     485 *                           Defaults are the heading and content for the 'perflab-admin-pointer'.
     486 */
     487function perflab_render_pointer( $pointer_id = 'perflab-admin-pointer', $args = array() ) {
     488    if ( ! isset( $args['heading'] ) ) {
     489        $args['heading'] = __( 'Performance Lab', 'performance-lab' );
     490    }
     491    if ( ! isset( $args['content'] ) ) {
     492        $args['content'] = sprintf(
     493            /* translators: %s: settings page link */
     494            __( 'You can now test upcoming WordPress performance features. Open %s to individually toggle the performance features included in the plugin.', 'performance-lab' ),
     495            '<a href="' . esc_url( add_query_arg( 'page', PERFLAB_MODULES_SCREEN, admin_url( 'options-general.php' ) ) ) . '">' . __( 'Settings > Performance', 'performance-lab' ) . '</a>'
     496        );
     497    }
     498
    440499    $wp_kses_options = array(
    441500        'a' => array(
     
    444503    );
    445504
    446     $content = sprintf(
    447         /* translators: %s: settings page link */
    448         __( 'You can now test upcoming WordPress performance features. Open %s to individually toggle the performance features included in the plugin.', 'performance-lab' ),
    449         '<a href="' . esc_url( add_query_arg( 'page', PERFLAB_MODULES_SCREEN, admin_url( 'options-general.php' ) ) ) . '">' . __( 'Settings > Performance', 'performance-lab' ) . '</a>'
    450     );
    451 
    452505    ?>
    453     <script id="perflab-admin-pointer" type="text/javascript">
     506    <script id="<?php echo esc_attr( $pointer_id ); ?>" type="text/javascript">
    454507        jQuery( function() {
    455508            // Pointer Options.
    456509            var options = {
    457                 content: '<h3><?php echo esc_js( $heading ); ?></h3><p><?php echo wp_kses( $content, $wp_kses_options ); ?></p>',
     510                content: '<h3><?php echo esc_js( $args['heading'] ); ?></h3><p><?php echo wp_kses( $args['content'], $wp_kses_options ); ?></p>',
    458511                position: {
    459512                    edge:  'left',
     
    466519                        window.ajaxurl,
    467520                        {
    468                             pointer: 'perflab-admin-pointer',
     521                            pointer: '<?php echo esc_js( $pointer_id ); ?>',
    469522                            action:  'dismiss-wp-pointer',
    470523                            _wpnonce: <?php echo wp_json_encode( wp_create_nonce( 'dismiss_pointer' ) ); ?>,
     
    513566 */
    514567function perflab_dismiss_wp_pointer_wrapper() {
    515     if ( isset( $_POST['pointer'] ) && 'perflab-admin-pointer' !== $_POST['pointer'] ) {
     568    if ( isset( $_POST['pointer'] ) && 'perflab-admin-pointer' !== $_POST['pointer'] && 'perflab-sqlite-module-removal-pointer' !== $_POST['pointer'] ) {
    516569        // Another plugin's pointer, do nothing.
    517570        return;
     
    520573}
    521574add_action( 'wp_ajax_dismiss-wp-pointer', 'perflab_dismiss_wp_pointer_wrapper', 0 );
     575
     576/*
     577 * Temporary code to inform about SQLite module removal. Since it will be
     578 * removed again when the module is removed from the plugin, it uses a closure
     579 * instead of a regular function.
     580 */
     581add_action(
     582    'admin_notices',
     583    static function() {
     584        global $hook_suffix;
     585
     586        // Only show in the WordPress dashboard and Performance Lab admin screen.
     587        if ( ! in_array( $hook_suffix, array( 'index.php', 'settings_page_' . PERFLAB_MODULES_SCREEN ), true ) ) {
     588            return;
     589        }
     590
     591        // Only show if the SQLite module is active.
     592        if ( ! defined( 'SQLITE_VERSION' ) || ! str_starts_with( SQLITE_VERSION, 'Performance Lab ' ) ) {
     593            return;
     594        }
     595
     596        // Only show if the user can manage plugins.
     597        if ( ! current_user_can( 'activate_plugins' ) ) {
     598            return;
     599        }
     600
     601        $wp_kses_options = array(
     602            'span'   => array(
     603                'style' => array(),
     604            ),
     605            'strong' => array(),
     606            'a'      => array(
     607                'href' => array(),
     608            ),
     609        );
     610
     611        $todo_before = '<span>';
     612        $todo_after  = '</span>';
     613        $done_before = '<span style="text-decoration: line-through;">';
     614        $done_after  = '</span> ✅';
     615
     616        if ( file_exists( WP_PLUGIN_DIR . '/sqlite-database-integration/load.php' ) ) {
     617            $step1_before      = $done_before;
     618            $step1_after       = $done_after;
     619            $step1_placeholder = 'SQLite Database Integration';
     620        } else {
     621            $step1_before      = $todo_before;
     622            $step1_after       = $todo_after;
     623            $step1_placeholder = '<a href="https://wordpress.org/plugins/sqlite-database-integration/">SQLite Database Integration</a></strong>';
     624        }
     625        if ( defined( 'SQLITE_MAIN_FILE' ) ) {
     626            $step2_before = $done_before;
     627            $step2_after  = $done_after;
     628        } else {
     629            $step2_before = $todo_before;
     630            $step2_after  = $todo_after;
     631            if ( file_exists( WP_PLUGIN_DIR . '/sqlite-database-integration/load.php' ) ) {
     632                $activate_url = wp_nonce_url(
     633                    add_query_arg(
     634                        array(
     635                            'action' => 'activate',
     636                            'plugin' => 'sqlite-database-integration/load.php',
     637                        ),
     638                        admin_url( 'plugins.php' )
     639                    ),
     640                    'activate-plugin_sqlite-database-integration/load.php'
     641                );
     642
     643                $step2_before .= '<a href="' . esc_url( $activate_url ) . '">';
     644                $step2_after   = '</a>' . $step2_after;
     645            }
     646        }
     647        $step3_before      = $todo_before;
     648        $step3_after       = $todo_after;
     649        $step3_placeholder = 'SQLite';
     650        if ( 'index.php' === $hook_suffix && defined( 'SQLITE_MAIN_FILE' ) ) {
     651            // Link to Performance Lab settings.
     652            $screen_url = add_query_arg(
     653                'page',
     654                PERFLAB_MODULES_SCREEN,
     655                admin_url( 'options-general.php' )
     656            );
     657
     658            $step3_before .= '<a href="' . esc_url( $screen_url ) . '">';
     659            $step3_after   = '</a>' . $step3_after;
     660        }
     661
     662        /*
     663         * The first two translation strings below are reused in the SQLite
     664         * module admin pointer to keep new temporary translation strings at a
     665         * small number.
     666         */
     667        ?>
     668        <div class="notice notice-warning">
     669            <h2><?php esc_html_e( 'Action required', 'performance-lab' ); ?></h2>
     670            <p>
     671                <?php esc_html_e( 'The SQLite module will be removed in the upcoming Performance Lab release in favor of a standalone plugin.', 'performance-lab' ); ?>
     672                <?php esc_html_e( 'In order to keep the functionality available, please go through the following steps:', 'performance-lab' ); ?>
     673            </p>
     674            <ol>
     675                <li>
     676                    <?php
     677                    echo wp_kses(
     678                        sprintf(
     679                            /* translators: %s: plugin name */
     680                            '%s' . __( 'Install the %s plugin', 'performance-lab' ) . '%s',
     681                            $step1_before,
     682                            $step1_placeholder,
     683                            $step1_after
     684                        ),
     685                        $wp_kses_options
     686                    );
     687                    ?>
     688                </li>
     689                <li>
     690                    <?php
     691                    echo wp_kses(
     692                        sprintf(
     693                            '%s' . __( 'Activate the plugin', 'performance-lab' ) . '%s',
     694                            $step2_before,
     695                            $step2_after
     696                        ),
     697                        $wp_kses_options
     698                    );
     699                    ?>
     700                </li>
     701                <li>
     702                    <?php
     703                    echo wp_kses(
     704                        sprintf(
     705                            /* translators: %s: module name */
     706                            '%s' . __( 'Deactivate the %s module', 'performance-lab' ) . '%s',
     707                            $step3_before,
     708                            $step3_placeholder,
     709                            $step3_after
     710                        ),
     711                        $wp_kses_options
     712                    );
     713                    ?>
     714                </li>
     715            </ol>
     716        </div>
     717        <?php
     718    }
     719);
  • performance-lab/tags/2.4.0/load.php

    r2912617 r2928769  
    66 * Requires at least: 6.1
    77 * Requires PHP: 5.6
    8  * Version: 2.3.0
     8 * Version: 2.4.0
    99 * Author: WordPress Performance Team
    1010 * Author URI: https://make.wordpress.org/performance/
     
    1616 */
    1717
    18 define( 'PERFLAB_VERSION', '2.2.0' );
     18define( 'PERFLAB_VERSION', '2.4.0' );
    1919define( 'PERFLAB_MAIN_FILE', __FILE__ );
    2020define( 'PERFLAB_PLUGIN_DIR_PATH', plugin_dir_path( PERFLAB_MAIN_FILE ) );
     
    6767        $default_option          = array_reduce(
    6868            $default_enabled_modules,
    69             function( $module_settings, $module_dir ) {
     69            static function( $module_settings, $module_dir ) {
    7070                $module_settings[ $module_dir ] = array( 'enabled' => true );
    7171                return $module_settings;
     
    9494    return array_filter(
    9595        array_map(
    96             function( $module_settings ) {
     96            static function( $module_settings ) {
    9797                if ( ! is_array( $module_settings ) ) {
    9898                    return array();
     
    149149        array_filter(
    150150            perflab_get_module_settings(),
    151             function( $module_settings ) {
     151            static function( $module_settings ) {
    152152                return isset( $module_settings['enabled'] ) && $module_settings['enabled'];
    153153            }
     
    288288        'images/fetchpriority'         => 'FETCHPRIORITY_VERSION',
    289289        'images/webp-uploads'          => 'WEBP_UPLOADS_VERSION',
     290        'database/sqlite'              => 'SQLITE_MAIN_FILE',
    290291    );
    291292}
     
    339340     * @since 2.0.0
    340341     *
    341      * @param bool Whether the server timing drop-in should be set.
     342     * @param bool $disabled Whether to disable the server timing drop-in. Default false.
    342343     */
    343344    if ( apply_filters( 'perflab_disable_object_cache_dropin', false ) ) {
     
    521522     * @param mixed  $value  Value of the option.
    522523     */
    523     function( $option, $value ) {
     524    static function( $option, $value ) {
    524525        perflab_run_module_activation_deactivation( perflab_get_modules_setting_default(), $value );
    525526    },
  • performance-lab/tags/2.4.0/modules/database/sqlite/activate.php

    r2836222 r2928769  
    1212 * @since 1.8.0
    1313 */
    14 return function() {
     14return static function() {
    1515    // Bail early if the SQLite3 class does not exist.
    1616    if ( ! class_exists( 'SQLite3' ) ) {
     
    5959    add_filter(
    6060        'wp_redirect',
    61         function( $redirect_location ) {
     61        static function( $redirect_location ) {
    6262            if ( ! defined( 'DATABASE_TYPE' ) ) {
    6363                define( 'DATABASE_TYPE', 'sqlite' );
     
    119119            // ensure it is inserted into the database like that, instead of
    120120            // being re-hashed.
    121             $unhash_user_pass = function( $data, $update, $user_id, $userdata ) use ( $admin_user, $current_user ) {
     121            $unhash_user_pass = static function( $data, $update, $user_id, $userdata ) use ( $admin_user, $current_user ) {
    122122                // Double check this is actually the already hashed password,
    123123                // to prevent any chance of accidentally putting another
  • performance-lab/tags/2.4.0/modules/database/sqlite/admin.php

    r2883717 r2928769  
    1717    // Bail early if the PERFLAB_SQLITE_DB_DROPIN_VERSION is defined.
    1818    if ( defined( 'PERFLAB_SQLITE_DB_DROPIN_VERSION' ) ) {
     19        return;
     20    }
     21
     22    // Bail early if the standalone plugin's equivalent constant is defined.
     23    if ( defined( 'SQLITE_DB_DROPIN_VERSION' ) ) {
    1924        return;
    2025    }
  • performance-lab/tags/2.4.0/modules/database/sqlite/can-load.php

    r2836222 r2928769  
    1212 * @since 1.8.0
    1313 */
    14 return function() {
     14return static function() {
    1515
    1616    // If the PERFLAB_SQLITE_DB_DROPIN_VERSION constant is defined, then the module is already active.
     
    2020
    2121    // If a db.php file already exists in the wp-content directory, then the module cannot be activated.
    22     if ( file_exists( WP_CONTENT_DIR . '/db.php' ) ) {
     22    // Except if it is the standalone plugin's drop-in.
     23    if ( file_exists( WP_CONTENT_DIR . '/db.php' ) && ! defined( 'SQLITE_DB_DROPIN_VERSION' ) ) {
    2324        return false;
    2425    }
  • performance-lab/tags/2.4.0/modules/database/sqlite/deactivate.php

    r2836222 r2928769  
    1212 * @since 1.8.0
    1313 */
    14 return function() {
    15     if ( ! defined( 'PERFLAB_SQLITE_DB_DROPIN_VERSION' ) || ! file_exists( WP_CONTENT_DIR . '/db.php' ) ) {
     14return static function() {
     15    // If neither of these constants are defined, the site is not operating in SQLite database.
     16    if ( ! defined( 'PERFLAB_SQLITE_DB_DROPIN_VERSION' ) && ! defined( 'SQLITE_DB_DROPIN_VERSION' ) ) {
    1617        return;
    1718    }
     
    1920    global $wp_filesystem;
    2021
    21     require_once ABSPATH . '/wp-admin/includes/file.php';
     22    // If the PL's own drop-in file is used, it should be removed.
     23    if ( defined( 'PERFLAB_SQLITE_DB_DROPIN_VERSION' ) && file_exists( WP_CONTENT_DIR . '/db.php' ) ) {
     24        require_once ABSPATH . '/wp-admin/includes/file.php';
    2225
    23     // Init the filesystem if needed, then delete custom drop-in.
    24     if ( $wp_filesystem || WP_Filesystem() ) {
    25         $wp_filesystem->delete( WP_CONTENT_DIR . '/db.php' );
     26        // Init the filesystem if needed, then delete custom drop-in.
     27        if ( $wp_filesystem || WP_Filesystem() ) {
     28            $wp_filesystem->delete( WP_CONTENT_DIR . '/db.php' );
     29        }
    2630    }
    2731
     
    2933    add_action(
    3034        'shutdown',
    31         function() {
     35        static function() {
    3236            global $table_prefix;
    3337
  • performance-lab/tags/2.4.0/modules/database/sqlite/load.php

    r2883717 r2928769  
    99 */
    1010
     11// Define the version constant.
     12if ( defined( 'SQLITE_VERSION' ) ) {
     13    return;
     14}
     15
     16define( 'SQLITE_VERSION', 'Performance Lab ' . PERFLAB_VERSION );
     17
    1118// Do not load the code if it is already loaded through another means.
    1219if ( function_exists( 'perflab_sqlite_plugin_admin_notice' ) ) {
  • performance-lab/tags/2.4.0/modules/database/sqlite/wp-includes/sqlite/class-perflab-sqlite-pdo-driver.php

    r2836222 r2928769  
    738738                usort(
    739739                    $results,
    740                     function ( $a, $b ) use ( $flipped ) {
     740                    static function ( $a, $b ) use ( $flipped ) {
    741741                        return $flipped[ $a->ID ] - $flipped[ $b->ID ];
    742742                    }
  • performance-lab/tags/2.4.0/modules/images/webp-uploads/can-load.php

    r2757901 r2928769  
    77 */
    88
    9 return function() {
     9return static function() {
    1010    return ! function_exists( 'wp_image_use_alternate_mime_types' );
    1111};
  • performance-lab/tags/2.4.0/modules/images/webp-uploads/image-edit.php

    r2900289 r2928769  
    104104    add_filter(
    105105        'wp_update_attachment_metadata',
    106         function ( $metadata, $post_meta_id ) use ( $post_id, $file_path, $mime_type, $editor, $mime_transforms, &$callback_executed ) {
     106        static function ( $metadata, $post_meta_id ) use ( $post_id, $file_path, $mime_type, $editor, $mime_transforms, &$callback_executed ) {
    107107            if ( $post_meta_id !== $post_id ) {
    108108                return $metadata;
     
    298298    $has_been_processed = false;
    299299
    300     $hook = function ( $meta_id, $post_id, $meta_name ) use ( $attachment_id, $sources, &$has_been_processed ) {
     300    $hook = static function ( $meta_id, $post_id, $meta_name ) use ( $attachment_id, $sources, &$has_been_processed ) {
    301301        // Make sure this hook is only executed in the same context for the provided $attachment_id.
    302302        if ( $post_id !== $attachment_id ) {
  • performance-lab/tags/2.4.0/modules/images/webp-uploads/load.php

    r2900289 r2928769  
    2525    add_action(
    2626        'admin_notices',
    27         function() {
     27        static function() {
    2828            printf(
    2929                '<div class="notice notice-error"><p>%s</p></div>',
  • performance-lab/tags/2.4.0/readme.txt

    r2912645 r2928769  
    55Tested up to:      6.2
    66Requires PHP:      5.6
    7 Stable tag:        2.3.0
     7Stable tag:        2.4.0
    88License:           GPLv2 or later
    99License URI:       https://www.gnu.org/licenses/gpl-2.0.html
     
    8181
    8282== Changelog ==
     83
     84= 2.4.0 =
     85
     86**Enhancements**
     87
     88* Database: Implement migration prompt to migrate from SQLite module to standalone plugin due to removal in the following release. ([739](https://github.com/WordPress/performance/pull/739))
     89* Infrastructure: Enhance code quality by adding PHPStan and fixing level 0 issues. ([730](https://github.com/WordPress/performance/pull/730))
     90* Infrastructure: Use static closures for minor performance improvement whenever instance access is not needed. ([729](https://github.com/WordPress/performance/pull/729))
     91
     92**Bug Fixes**
     93
     94* Database: Fix SQLite module deactivation routine to make standalone plugin migration work correctly. ([743](https://github.com/WordPress/performance/pull/743))
     95* Infrastructure: Make `Server-Timing` header output more robust. ([736](https://github.com/WordPress/performance/pull/736))
    8396
    8497= 2.3.0 =
  • performance-lab/tags/2.4.0/server-timing/class-perflab-server-timing.php

    r2836222 r2928769  
    228228        }
    229229
    230         ob_start();
    231         add_action(
    232             'shutdown',
    233             function() {
    234                 $output = ob_get_clean();
     230        ob_start(
     231            function( $output ) {
    235232                $this->send_header();
    236                 echo $output;
    237             },
    238             // phpcs:ignore PHPCompatibility.Constants.NewConstants
    239             defined( 'PHP_INT_MIN' ) ? PHP_INT_MIN : -1000
     233                return $output;
     234            }
    240235        );
    241236        return $passthrough;
  • performance-lab/trunk/admin/load.php

    r2912645 r2928769  
    8080            $module_slug,
    8181            $module_data['name'],
    82             function() use ( $module_slug, $module_data, $module_settings ) {
     82            static function() use ( $module_slug, $module_data, $module_settings ) {
    8383                perflab_render_modules_page_field( $module_slug, $module_data, $module_settings );
    8484            },
     
    202202                <?php // Don't use the WP notice classes here, as that makes them move to the top of the page. ?>
    203203                <p class="notice notice-warning" style="padding:1em;max-width:50em;">
    204                     <?php esc_html_e( 'Enabling this module will switch to a separate database and install WordPress in it. You will need to reconfigure your site, and start with a fresh site. Disabling the module you will get back to your previous MySQL database, with all your previous data intact.', 'performance-lab' ); ?>
     204                    <?php esc_html_e( 'It is not advised to activate this module since it will be removed in the upcoming Performance Lab release.', 'performance-lab' ); ?>
     205                    <a href="https://wordpress.org/plugins/sqlite-database-integration">
     206                        <?php esc_html_e( 'Please use the standalone plugin instead.', 'performance-lab' ); ?>
     207                    </a>
    205208                </p>
    206209            <?php endif; ?>
     
    330333    uasort(
    331334        $modules,
    332         function( $a, $b ) {
     335        static function( $a, $b ) {
    333336            return strnatcasecmp( $a['name'], $b['name'] );
    334337        }
     
    418421    $dismissed    = explode( ',', (string) get_user_meta( $current_user, 'dismissed_wp_pointers', true ) );
    419422
     423    /*
     424     * Temporary: Show an admin pointer if SQLite module is active to prompt
     425     * for an action to use the standalone plugin instead.
     426     *
     427     * This code will be removed again when the SQLite module is removed from
     428     * the codebase.
     429     */
     430    if (
     431        defined( 'SQLITE_VERSION' )
     432        && str_starts_with( SQLITE_VERSION, 'Performance Lab ' )
     433        && ! in_array( 'perflab-sqlite-module-removal-pointer', $dismissed, true )
     434        && current_user_can( 'activate_plugins' )
     435    ) {
     436        /*
     437         * Enqueue the pointer logic and return early. A closure is used to
     438         * avoid introducing a new function as it should be removed again in
     439         * the following release.
     440         */
     441        wp_enqueue_style( 'wp-pointer' );
     442        wp_enqueue_script( 'wp-pointer' );
     443        add_action(
     444            'admin_print_footer_scripts',
     445            static function() {
     446                $content  = __( 'The SQLite module will be removed in the upcoming Performance Lab release in favor of a standalone plugin.', 'performance-lab' );
     447                $content .= ' ' . sprintf(
     448                    /* translators: %s: settings page link */
     449                    __( 'Open %s to learn more about next steps to keep the functionality available.', 'performance-lab' ),
     450                    '<a href="' . esc_url( add_query_arg( 'page', PERFLAB_MODULES_SCREEN, admin_url( 'options-general.php' ) ) ) . '">' . __( 'Settings > Performance', 'performance-lab' ) . '</a>'
     451                );
     452                perflab_render_pointer(
     453                    'perflab-sqlite-module-removal-pointer',
     454                    array(
     455                        'heading' => __( 'Action required', 'performance-lab' ),
     456                        'content' => $content,
     457                    )
     458                );
     459            }
     460        );
     461        return;
     462    }
     463
    420464    if ( in_array( 'perflab-admin-pointer', $dismissed, true ) ) {
    421465        return;
     
    425469    wp_enqueue_style( 'wp-pointer' );
    426470    wp_enqueue_script( 'wp-pointer' );
    427     add_action( 'admin_print_footer_scripts', 'perflab_render_pointer' );
     471    add_action( 'admin_print_footer_scripts', 'perflab_render_pointer', 10, 0 );
    428472}
    429473add_action( 'admin_enqueue_scripts', 'perflab_admin_pointer' );
     
    435479 *
    436480 * @since 1.0.0
    437  */
    438 function perflab_render_pointer() {
    439     $heading         = __( 'Performance Lab', 'performance-lab' );
     481 * @since 2.4.0 Optional arguments were added to make the function reusable for different pointers.
     482 *
     483 * @param string $pointer_id Optional. ID of the pointer. Default 'perflab-admin-pointer'.
     484 * @param array  $args       Optional. Pointer arguments. Supports 'heading' and 'content' entries.
     485 *                           Defaults are the heading and content for the 'perflab-admin-pointer'.
     486 */
     487function perflab_render_pointer( $pointer_id = 'perflab-admin-pointer', $args = array() ) {
     488    if ( ! isset( $args['heading'] ) ) {
     489        $args['heading'] = __( 'Performance Lab', 'performance-lab' );
     490    }
     491    if ( ! isset( $args['content'] ) ) {
     492        $args['content'] = sprintf(
     493            /* translators: %s: settings page link */
     494            __( 'You can now test upcoming WordPress performance features. Open %s to individually toggle the performance features included in the plugin.', 'performance-lab' ),
     495            '<a href="' . esc_url( add_query_arg( 'page', PERFLAB_MODULES_SCREEN, admin_url( 'options-general.php' ) ) ) . '">' . __( 'Settings > Performance', 'performance-lab' ) . '</a>'
     496        );
     497    }
     498
    440499    $wp_kses_options = array(
    441500        'a' => array(
     
    444503    );
    445504
    446     $content = sprintf(
    447         /* translators: %s: settings page link */
    448         __( 'You can now test upcoming WordPress performance features. Open %s to individually toggle the performance features included in the plugin.', 'performance-lab' ),
    449         '<a href="' . esc_url( add_query_arg( 'page', PERFLAB_MODULES_SCREEN, admin_url( 'options-general.php' ) ) ) . '">' . __( 'Settings > Performance', 'performance-lab' ) . '</a>'
    450     );
    451 
    452505    ?>
    453     <script id="perflab-admin-pointer" type="text/javascript">
     506    <script id="<?php echo esc_attr( $pointer_id ); ?>" type="text/javascript">
    454507        jQuery( function() {
    455508            // Pointer Options.
    456509            var options = {
    457                 content: '<h3><?php echo esc_js( $heading ); ?></h3><p><?php echo wp_kses( $content, $wp_kses_options ); ?></p>',
     510                content: '<h3><?php echo esc_js( $args['heading'] ); ?></h3><p><?php echo wp_kses( $args['content'], $wp_kses_options ); ?></p>',
    458511                position: {
    459512                    edge:  'left',
     
    466519                        window.ajaxurl,
    467520                        {
    468                             pointer: 'perflab-admin-pointer',
     521                            pointer: '<?php echo esc_js( $pointer_id ); ?>',
    469522                            action:  'dismiss-wp-pointer',
    470523                            _wpnonce: <?php echo wp_json_encode( wp_create_nonce( 'dismiss_pointer' ) ); ?>,
     
    513566 */
    514567function perflab_dismiss_wp_pointer_wrapper() {
    515     if ( isset( $_POST['pointer'] ) && 'perflab-admin-pointer' !== $_POST['pointer'] ) {
     568    if ( isset( $_POST['pointer'] ) && 'perflab-admin-pointer' !== $_POST['pointer'] && 'perflab-sqlite-module-removal-pointer' !== $_POST['pointer'] ) {
    516569        // Another plugin's pointer, do nothing.
    517570        return;
     
    520573}
    521574add_action( 'wp_ajax_dismiss-wp-pointer', 'perflab_dismiss_wp_pointer_wrapper', 0 );
     575
     576/*
     577 * Temporary code to inform about SQLite module removal. Since it will be
     578 * removed again when the module is removed from the plugin, it uses a closure
     579 * instead of a regular function.
     580 */
     581add_action(
     582    'admin_notices',
     583    static function() {
     584        global $hook_suffix;
     585
     586        // Only show in the WordPress dashboard and Performance Lab admin screen.
     587        if ( ! in_array( $hook_suffix, array( 'index.php', 'settings_page_' . PERFLAB_MODULES_SCREEN ), true ) ) {
     588            return;
     589        }
     590
     591        // Only show if the SQLite module is active.
     592        if ( ! defined( 'SQLITE_VERSION' ) || ! str_starts_with( SQLITE_VERSION, 'Performance Lab ' ) ) {
     593            return;
     594        }
     595
     596        // Only show if the user can manage plugins.
     597        if ( ! current_user_can( 'activate_plugins' ) ) {
     598            return;
     599        }
     600
     601        $wp_kses_options = array(
     602            'span'   => array(
     603                'style' => array(),
     604            ),
     605            'strong' => array(),
     606            'a'      => array(
     607                'href' => array(),
     608            ),
     609        );
     610
     611        $todo_before = '<span>';
     612        $todo_after  = '</span>';
     613        $done_before = '<span style="text-decoration: line-through;">';
     614        $done_after  = '</span> ✅';
     615
     616        if ( file_exists( WP_PLUGIN_DIR . '/sqlite-database-integration/load.php' ) ) {
     617            $step1_before      = $done_before;
     618            $step1_after       = $done_after;
     619            $step1_placeholder = 'SQLite Database Integration';
     620        } else {
     621            $step1_before      = $todo_before;
     622            $step1_after       = $todo_after;
     623            $step1_placeholder = '<a href="https://wordpress.org/plugins/sqlite-database-integration/">SQLite Database Integration</a></strong>';
     624        }
     625        if ( defined( 'SQLITE_MAIN_FILE' ) ) {
     626            $step2_before = $done_before;
     627            $step2_after  = $done_after;
     628        } else {
     629            $step2_before = $todo_before;
     630            $step2_after  = $todo_after;
     631            if ( file_exists( WP_PLUGIN_DIR . '/sqlite-database-integration/load.php' ) ) {
     632                $activate_url = wp_nonce_url(
     633                    add_query_arg(
     634                        array(
     635                            'action' => 'activate',
     636                            'plugin' => 'sqlite-database-integration/load.php',
     637                        ),
     638                        admin_url( 'plugins.php' )
     639                    ),
     640                    'activate-plugin_sqlite-database-integration/load.php'
     641                );
     642
     643                $step2_before .= '<a href="' . esc_url( $activate_url ) . '">';
     644                $step2_after   = '</a>' . $step2_after;
     645            }
     646        }
     647        $step3_before      = $todo_before;
     648        $step3_after       = $todo_after;
     649        $step3_placeholder = 'SQLite';
     650        if ( 'index.php' === $hook_suffix && defined( 'SQLITE_MAIN_FILE' ) ) {
     651            // Link to Performance Lab settings.
     652            $screen_url = add_query_arg(
     653                'page',
     654                PERFLAB_MODULES_SCREEN,
     655                admin_url( 'options-general.php' )
     656            );
     657
     658            $step3_before .= '<a href="' . esc_url( $screen_url ) . '">';
     659            $step3_after   = '</a>' . $step3_after;
     660        }
     661
     662        /*
     663         * The first two translation strings below are reused in the SQLite
     664         * module admin pointer to keep new temporary translation strings at a
     665         * small number.
     666         */
     667        ?>
     668        <div class="notice notice-warning">
     669            <h2><?php esc_html_e( 'Action required', 'performance-lab' ); ?></h2>
     670            <p>
     671                <?php esc_html_e( 'The SQLite module will be removed in the upcoming Performance Lab release in favor of a standalone plugin.', 'performance-lab' ); ?>
     672                <?php esc_html_e( 'In order to keep the functionality available, please go through the following steps:', 'performance-lab' ); ?>
     673            </p>
     674            <ol>
     675                <li>
     676                    <?php
     677                    echo wp_kses(
     678                        sprintf(
     679                            /* translators: %s: plugin name */
     680                            '%s' . __( 'Install the %s plugin', 'performance-lab' ) . '%s',
     681                            $step1_before,
     682                            $step1_placeholder,
     683                            $step1_after
     684                        ),
     685                        $wp_kses_options
     686                    );
     687                    ?>
     688                </li>
     689                <li>
     690                    <?php
     691                    echo wp_kses(
     692                        sprintf(
     693                            '%s' . __( 'Activate the plugin', 'performance-lab' ) . '%s',
     694                            $step2_before,
     695                            $step2_after
     696                        ),
     697                        $wp_kses_options
     698                    );
     699                    ?>
     700                </li>
     701                <li>
     702                    <?php
     703                    echo wp_kses(
     704                        sprintf(
     705                            /* translators: %s: module name */
     706                            '%s' . __( 'Deactivate the %s module', 'performance-lab' ) . '%s',
     707                            $step3_before,
     708                            $step3_placeholder,
     709                            $step3_after
     710                        ),
     711                        $wp_kses_options
     712                    );
     713                    ?>
     714                </li>
     715            </ol>
     716        </div>
     717        <?php
     718    }
     719);
  • performance-lab/trunk/load.php

    r2912617 r2928769  
    66 * Requires at least: 6.1
    77 * Requires PHP: 5.6
    8  * Version: 2.3.0
     8 * Version: 2.4.0
    99 * Author: WordPress Performance Team
    1010 * Author URI: https://make.wordpress.org/performance/
     
    1616 */
    1717
    18 define( 'PERFLAB_VERSION', '2.2.0' );
     18define( 'PERFLAB_VERSION', '2.4.0' );
    1919define( 'PERFLAB_MAIN_FILE', __FILE__ );
    2020define( 'PERFLAB_PLUGIN_DIR_PATH', plugin_dir_path( PERFLAB_MAIN_FILE ) );
     
    6767        $default_option          = array_reduce(
    6868            $default_enabled_modules,
    69             function( $module_settings, $module_dir ) {
     69            static function( $module_settings, $module_dir ) {
    7070                $module_settings[ $module_dir ] = array( 'enabled' => true );
    7171                return $module_settings;
     
    9494    return array_filter(
    9595        array_map(
    96             function( $module_settings ) {
     96            static function( $module_settings ) {
    9797                if ( ! is_array( $module_settings ) ) {
    9898                    return array();
     
    149149        array_filter(
    150150            perflab_get_module_settings(),
    151             function( $module_settings ) {
     151            static function( $module_settings ) {
    152152                return isset( $module_settings['enabled'] ) && $module_settings['enabled'];
    153153            }
     
    288288        'images/fetchpriority'         => 'FETCHPRIORITY_VERSION',
    289289        'images/webp-uploads'          => 'WEBP_UPLOADS_VERSION',
     290        'database/sqlite'              => 'SQLITE_MAIN_FILE',
    290291    );
    291292}
     
    339340     * @since 2.0.0
    340341     *
    341      * @param bool Whether the server timing drop-in should be set.
     342     * @param bool $disabled Whether to disable the server timing drop-in. Default false.
    342343     */
    343344    if ( apply_filters( 'perflab_disable_object_cache_dropin', false ) ) {
     
    521522     * @param mixed  $value  Value of the option.
    522523     */
    523     function( $option, $value ) {
     524    static function( $option, $value ) {
    524525        perflab_run_module_activation_deactivation( perflab_get_modules_setting_default(), $value );
    525526    },
  • performance-lab/trunk/modules/database/sqlite/activate.php

    r2836222 r2928769  
    1212 * @since 1.8.0
    1313 */
    14 return function() {
     14return static function() {
    1515    // Bail early if the SQLite3 class does not exist.
    1616    if ( ! class_exists( 'SQLite3' ) ) {
     
    5959    add_filter(
    6060        'wp_redirect',
    61         function( $redirect_location ) {
     61        static function( $redirect_location ) {
    6262            if ( ! defined( 'DATABASE_TYPE' ) ) {
    6363                define( 'DATABASE_TYPE', 'sqlite' );
     
    119119            // ensure it is inserted into the database like that, instead of
    120120            // being re-hashed.
    121             $unhash_user_pass = function( $data, $update, $user_id, $userdata ) use ( $admin_user, $current_user ) {
     121            $unhash_user_pass = static function( $data, $update, $user_id, $userdata ) use ( $admin_user, $current_user ) {
    122122                // Double check this is actually the already hashed password,
    123123                // to prevent any chance of accidentally putting another
  • performance-lab/trunk/modules/database/sqlite/admin.php

    r2883717 r2928769  
    1717    // Bail early if the PERFLAB_SQLITE_DB_DROPIN_VERSION is defined.
    1818    if ( defined( 'PERFLAB_SQLITE_DB_DROPIN_VERSION' ) ) {
     19        return;
     20    }
     21
     22    // Bail early if the standalone plugin's equivalent constant is defined.
     23    if ( defined( 'SQLITE_DB_DROPIN_VERSION' ) ) {
    1924        return;
    2025    }
  • performance-lab/trunk/modules/database/sqlite/can-load.php

    r2836222 r2928769  
    1212 * @since 1.8.0
    1313 */
    14 return function() {
     14return static function() {
    1515
    1616    // If the PERFLAB_SQLITE_DB_DROPIN_VERSION constant is defined, then the module is already active.
     
    2020
    2121    // If a db.php file already exists in the wp-content directory, then the module cannot be activated.
    22     if ( file_exists( WP_CONTENT_DIR . '/db.php' ) ) {
     22    // Except if it is the standalone plugin's drop-in.
     23    if ( file_exists( WP_CONTENT_DIR . '/db.php' ) && ! defined( 'SQLITE_DB_DROPIN_VERSION' ) ) {
    2324        return false;
    2425    }
  • performance-lab/trunk/modules/database/sqlite/deactivate.php

    r2836222 r2928769  
    1212 * @since 1.8.0
    1313 */
    14 return function() {
    15     if ( ! defined( 'PERFLAB_SQLITE_DB_DROPIN_VERSION' ) || ! file_exists( WP_CONTENT_DIR . '/db.php' ) ) {
     14return static function() {
     15    // If neither of these constants are defined, the site is not operating in SQLite database.
     16    if ( ! defined( 'PERFLAB_SQLITE_DB_DROPIN_VERSION' ) && ! defined( 'SQLITE_DB_DROPIN_VERSION' ) ) {
    1617        return;
    1718    }
     
    1920    global $wp_filesystem;
    2021
    21     require_once ABSPATH . '/wp-admin/includes/file.php';
     22    // If the PL's own drop-in file is used, it should be removed.
     23    if ( defined( 'PERFLAB_SQLITE_DB_DROPIN_VERSION' ) && file_exists( WP_CONTENT_DIR . '/db.php' ) ) {
     24        require_once ABSPATH . '/wp-admin/includes/file.php';
    2225
    23     // Init the filesystem if needed, then delete custom drop-in.
    24     if ( $wp_filesystem || WP_Filesystem() ) {
    25         $wp_filesystem->delete( WP_CONTENT_DIR . '/db.php' );
     26        // Init the filesystem if needed, then delete custom drop-in.
     27        if ( $wp_filesystem || WP_Filesystem() ) {
     28            $wp_filesystem->delete( WP_CONTENT_DIR . '/db.php' );
     29        }
    2630    }
    2731
     
    2933    add_action(
    3034        'shutdown',
    31         function() {
     35        static function() {
    3236            global $table_prefix;
    3337
  • performance-lab/trunk/modules/database/sqlite/load.php

    r2883717 r2928769  
    99 */
    1010
     11// Define the version constant.
     12if ( defined( 'SQLITE_VERSION' ) ) {
     13    return;
     14}
     15
     16define( 'SQLITE_VERSION', 'Performance Lab ' . PERFLAB_VERSION );
     17
    1118// Do not load the code if it is already loaded through another means.
    1219if ( function_exists( 'perflab_sqlite_plugin_admin_notice' ) ) {
  • performance-lab/trunk/modules/database/sqlite/wp-includes/sqlite/class-perflab-sqlite-pdo-driver.php

    r2836222 r2928769  
    738738                usort(
    739739                    $results,
    740                     function ( $a, $b ) use ( $flipped ) {
     740                    static function ( $a, $b ) use ( $flipped ) {
    741741                        return $flipped[ $a->ID ] - $flipped[ $b->ID ];
    742742                    }
  • performance-lab/trunk/modules/images/webp-uploads/can-load.php

    r2757901 r2928769  
    77 */
    88
    9 return function() {
     9return static function() {
    1010    return ! function_exists( 'wp_image_use_alternate_mime_types' );
    1111};
  • performance-lab/trunk/modules/images/webp-uploads/image-edit.php

    r2900289 r2928769  
    104104    add_filter(
    105105        'wp_update_attachment_metadata',
    106         function ( $metadata, $post_meta_id ) use ( $post_id, $file_path, $mime_type, $editor, $mime_transforms, &$callback_executed ) {
     106        static function ( $metadata, $post_meta_id ) use ( $post_id, $file_path, $mime_type, $editor, $mime_transforms, &$callback_executed ) {
    107107            if ( $post_meta_id !== $post_id ) {
    108108                return $metadata;
     
    298298    $has_been_processed = false;
    299299
    300     $hook = function ( $meta_id, $post_id, $meta_name ) use ( $attachment_id, $sources, &$has_been_processed ) {
     300    $hook = static function ( $meta_id, $post_id, $meta_name ) use ( $attachment_id, $sources, &$has_been_processed ) {
    301301        // Make sure this hook is only executed in the same context for the provided $attachment_id.
    302302        if ( $post_id !== $attachment_id ) {
  • performance-lab/trunk/modules/images/webp-uploads/load.php

    r2900289 r2928769  
    2525    add_action(
    2626        'admin_notices',
    27         function() {
     27        static function() {
    2828            printf(
    2929                '<div class="notice notice-error"><p>%s</p></div>',
  • performance-lab/trunk/readme.txt

    r2912645 r2928769  
    55Tested up to:      6.2
    66Requires PHP:      5.6
    7 Stable tag:        2.3.0
     7Stable tag:        2.4.0
    88License:           GPLv2 or later
    99License URI:       https://www.gnu.org/licenses/gpl-2.0.html
     
    8181
    8282== Changelog ==
     83
     84= 2.4.0 =
     85
     86**Enhancements**
     87
     88* Database: Implement migration prompt to migrate from SQLite module to standalone plugin due to removal in the following release. ([739](https://github.com/WordPress/performance/pull/739))
     89* Infrastructure: Enhance code quality by adding PHPStan and fixing level 0 issues. ([730](https://github.com/WordPress/performance/pull/730))
     90* Infrastructure: Use static closures for minor performance improvement whenever instance access is not needed. ([729](https://github.com/WordPress/performance/pull/729))
     91
     92**Bug Fixes**
     93
     94* Database: Fix SQLite module deactivation routine to make standalone plugin migration work correctly. ([743](https://github.com/WordPress/performance/pull/743))
     95* Infrastructure: Make `Server-Timing` header output more robust. ([736](https://github.com/WordPress/performance/pull/736))
    8396
    8497= 2.3.0 =
  • performance-lab/trunk/server-timing/class-perflab-server-timing.php

    r2836222 r2928769  
    228228        }
    229229
    230         ob_start();
    231         add_action(
    232             'shutdown',
    233             function() {
    234                 $output = ob_get_clean();
     230        ob_start(
     231            function( $output ) {
    235232                $this->send_header();
    236                 echo $output;
    237             },
    238             // phpcs:ignore PHPCompatibility.Constants.NewConstants
    239             defined( 'PHP_INT_MIN' ) ? PHP_INT_MIN : -1000
     233                return $output;
     234            }
    240235        );
    241236        return $passthrough;
Note: See TracChangeset for help on using the changeset viewer.