Changeset 2928769 for performance-lab
- Timestamp:
- 06/20/2023 05:11:40 PM (3 years ago)
- Location:
- performance-lab
- Files:
-
- 2 added
- 26 edited
- 1 copied
-
tags/2.4.0 (copied) (copied from performance-lab/trunk)
-
tags/2.4.0/admin/load.php (modified) (10 diffs)
-
tags/2.4.0/load.php (modified) (8 diffs)
-
tags/2.4.0/modules/database/sqlite/activate.php (modified) (3 diffs)
-
tags/2.4.0/modules/database/sqlite/admin.php (modified) (1 diff)
-
tags/2.4.0/modules/database/sqlite/can-load.php (modified) (2 diffs)
-
tags/2.4.0/modules/database/sqlite/deactivate.php (modified) (3 diffs)
-
tags/2.4.0/modules/database/sqlite/load.php (modified) (1 diff)
-
tags/2.4.0/modules/database/sqlite/wp-includes/sqlite/class-perflab-sqlite-pdo-driver.php (modified) (1 diff)
-
tags/2.4.0/modules/images/webp-uploads/can-load.php (modified) (1 diff)
-
tags/2.4.0/modules/images/webp-uploads/image-edit.php (modified) (2 diffs)
-
tags/2.4.0/modules/images/webp-uploads/load.php (modified) (1 diff)
-
tags/2.4.0/phpstan.neon.dist (added)
-
tags/2.4.0/readme.txt (modified) (2 diffs)
-
tags/2.4.0/server-timing/class-perflab-server-timing.php (modified) (1 diff)
-
trunk/admin/load.php (modified) (10 diffs)
-
trunk/load.php (modified) (8 diffs)
-
trunk/modules/database/sqlite/activate.php (modified) (3 diffs)
-
trunk/modules/database/sqlite/admin.php (modified) (1 diff)
-
trunk/modules/database/sqlite/can-load.php (modified) (2 diffs)
-
trunk/modules/database/sqlite/deactivate.php (modified) (3 diffs)
-
trunk/modules/database/sqlite/load.php (modified) (1 diff)
-
trunk/modules/database/sqlite/wp-includes/sqlite/class-perflab-sqlite-pdo-driver.php (modified) (1 diff)
-
trunk/modules/images/webp-uploads/can-load.php (modified) (1 diff)
-
trunk/modules/images/webp-uploads/image-edit.php (modified) (2 diffs)
-
trunk/modules/images/webp-uploads/load.php (modified) (1 diff)
-
trunk/phpstan.neon.dist (added)
-
trunk/readme.txt (modified) (2 diffs)
-
trunk/server-timing/class-perflab-server-timing.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
performance-lab/tags/2.4.0/admin/load.php
r2912645 r2928769 80 80 $module_slug, 81 81 $module_data['name'], 82 function() use ( $module_slug, $module_data, $module_settings ) {82 static function() use ( $module_slug, $module_data, $module_settings ) { 83 83 perflab_render_modules_page_field( $module_slug, $module_data, $module_settings ); 84 84 }, … … 202 202 <?php // Don't use the WP notice classes here, as that makes them move to the top of the page. ?> 203 203 <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> 205 208 </p> 206 209 <?php endif; ?> … … 330 333 uasort( 331 334 $modules, 332 function( $a, $b ) {335 static function( $a, $b ) { 333 336 return strnatcasecmp( $a['name'], $b['name'] ); 334 337 } … … 418 421 $dismissed = explode( ',', (string) get_user_meta( $current_user, 'dismissed_wp_pointers', true ) ); 419 422 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 420 464 if ( in_array( 'perflab-admin-pointer', $dismissed, true ) ) { 421 465 return; … … 425 469 wp_enqueue_style( 'wp-pointer' ); 426 470 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 ); 428 472 } 429 473 add_action( 'admin_enqueue_scripts', 'perflab_admin_pointer' ); … … 435 479 * 436 480 * @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 */ 487 function 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 440 499 $wp_kses_options = array( 441 500 'a' => array( … … 444 503 ); 445 504 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 452 505 ?> 453 <script id=" perflab-admin-pointer" type="text/javascript">506 <script id="<?php echo esc_attr( $pointer_id ); ?>" type="text/javascript"> 454 507 jQuery( function() { 455 508 // Pointer Options. 456 509 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>', 458 511 position: { 459 512 edge: 'left', … … 466 519 window.ajaxurl, 467 520 { 468 pointer: ' perflab-admin-pointer',521 pointer: '<?php echo esc_js( $pointer_id ); ?>', 469 522 action: 'dismiss-wp-pointer', 470 523 _wpnonce: <?php echo wp_json_encode( wp_create_nonce( 'dismiss_pointer' ) ); ?>, … … 513 566 */ 514 567 function 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'] ) { 516 569 // Another plugin's pointer, do nothing. 517 570 return; … … 520 573 } 521 574 add_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 */ 581 add_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 6 6 * Requires at least: 6.1 7 7 * Requires PHP: 5.6 8 * Version: 2. 3.08 * Version: 2.4.0 9 9 * Author: WordPress Performance Team 10 10 * Author URI: https://make.wordpress.org/performance/ … … 16 16 */ 17 17 18 define( 'PERFLAB_VERSION', '2. 2.0' );18 define( 'PERFLAB_VERSION', '2.4.0' ); 19 19 define( 'PERFLAB_MAIN_FILE', __FILE__ ); 20 20 define( 'PERFLAB_PLUGIN_DIR_PATH', plugin_dir_path( PERFLAB_MAIN_FILE ) ); … … 67 67 $default_option = array_reduce( 68 68 $default_enabled_modules, 69 function( $module_settings, $module_dir ) {69 static function( $module_settings, $module_dir ) { 70 70 $module_settings[ $module_dir ] = array( 'enabled' => true ); 71 71 return $module_settings; … … 94 94 return array_filter( 95 95 array_map( 96 function( $module_settings ) {96 static function( $module_settings ) { 97 97 if ( ! is_array( $module_settings ) ) { 98 98 return array(); … … 149 149 array_filter( 150 150 perflab_get_module_settings(), 151 function( $module_settings ) {151 static function( $module_settings ) { 152 152 return isset( $module_settings['enabled'] ) && $module_settings['enabled']; 153 153 } … … 288 288 'images/fetchpriority' => 'FETCHPRIORITY_VERSION', 289 289 'images/webp-uploads' => 'WEBP_UPLOADS_VERSION', 290 'database/sqlite' => 'SQLITE_MAIN_FILE', 290 291 ); 291 292 } … … 339 340 * @since 2.0.0 340 341 * 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. 342 343 */ 343 344 if ( apply_filters( 'perflab_disable_object_cache_dropin', false ) ) { … … 521 522 * @param mixed $value Value of the option. 522 523 */ 523 function( $option, $value ) {524 static function( $option, $value ) { 524 525 perflab_run_module_activation_deactivation( perflab_get_modules_setting_default(), $value ); 525 526 }, -
performance-lab/tags/2.4.0/modules/database/sqlite/activate.php
r2836222 r2928769 12 12 * @since 1.8.0 13 13 */ 14 return function() {14 return static function() { 15 15 // Bail early if the SQLite3 class does not exist. 16 16 if ( ! class_exists( 'SQLite3' ) ) { … … 59 59 add_filter( 60 60 'wp_redirect', 61 function( $redirect_location ) {61 static function( $redirect_location ) { 62 62 if ( ! defined( 'DATABASE_TYPE' ) ) { 63 63 define( 'DATABASE_TYPE', 'sqlite' ); … … 119 119 // ensure it is inserted into the database like that, instead of 120 120 // 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 ) { 122 122 // Double check this is actually the already hashed password, 123 123 // to prevent any chance of accidentally putting another -
performance-lab/tags/2.4.0/modules/database/sqlite/admin.php
r2883717 r2928769 17 17 // Bail early if the PERFLAB_SQLITE_DB_DROPIN_VERSION is defined. 18 18 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' ) ) { 19 24 return; 20 25 } -
performance-lab/tags/2.4.0/modules/database/sqlite/can-load.php
r2836222 r2928769 12 12 * @since 1.8.0 13 13 */ 14 return function() {14 return static function() { 15 15 16 16 // If the PERFLAB_SQLITE_DB_DROPIN_VERSION constant is defined, then the module is already active. … … 20 20 21 21 // 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' ) ) { 23 24 return false; 24 25 } -
performance-lab/tags/2.4.0/modules/database/sqlite/deactivate.php
r2836222 r2928769 12 12 * @since 1.8.0 13 13 */ 14 return function() { 15 if ( ! defined( 'PERFLAB_SQLITE_DB_DROPIN_VERSION' ) || ! file_exists( WP_CONTENT_DIR . '/db.php' ) ) { 14 return 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' ) ) { 16 17 return; 17 18 } … … 19 20 global $wp_filesystem; 20 21 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'; 22 25 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 } 26 30 } 27 31 … … 29 33 add_action( 30 34 'shutdown', 31 function() {35 static function() { 32 36 global $table_prefix; 33 37 -
performance-lab/tags/2.4.0/modules/database/sqlite/load.php
r2883717 r2928769 9 9 */ 10 10 11 // Define the version constant. 12 if ( defined( 'SQLITE_VERSION' ) ) { 13 return; 14 } 15 16 define( 'SQLITE_VERSION', 'Performance Lab ' . PERFLAB_VERSION ); 17 11 18 // Do not load the code if it is already loaded through another means. 12 19 if ( 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 738 738 usort( 739 739 $results, 740 function ( $a, $b ) use ( $flipped ) {740 static function ( $a, $b ) use ( $flipped ) { 741 741 return $flipped[ $a->ID ] - $flipped[ $b->ID ]; 742 742 } -
performance-lab/tags/2.4.0/modules/images/webp-uploads/can-load.php
r2757901 r2928769 7 7 */ 8 8 9 return function() {9 return static function() { 10 10 return ! function_exists( 'wp_image_use_alternate_mime_types' ); 11 11 }; -
performance-lab/tags/2.4.0/modules/images/webp-uploads/image-edit.php
r2900289 r2928769 104 104 add_filter( 105 105 '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 ) { 107 107 if ( $post_meta_id !== $post_id ) { 108 108 return $metadata; … … 298 298 $has_been_processed = false; 299 299 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 ) { 301 301 // Make sure this hook is only executed in the same context for the provided $attachment_id. 302 302 if ( $post_id !== $attachment_id ) { -
performance-lab/tags/2.4.0/modules/images/webp-uploads/load.php
r2900289 r2928769 25 25 add_action( 26 26 'admin_notices', 27 function() {27 static function() { 28 28 printf( 29 29 '<div class="notice notice-error"><p>%s</p></div>', -
performance-lab/tags/2.4.0/readme.txt
r2912645 r2928769 5 5 Tested up to: 6.2 6 6 Requires PHP: 5.6 7 Stable tag: 2. 3.07 Stable tag: 2.4.0 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 81 81 82 82 == 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)) 83 96 84 97 = 2.3.0 = -
performance-lab/tags/2.4.0/server-timing/class-perflab-server-timing.php
r2836222 r2928769 228 228 } 229 229 230 ob_start(); 231 add_action( 232 'shutdown', 233 function() { 234 $output = ob_get_clean(); 230 ob_start( 231 function( $output ) { 235 232 $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 } 240 235 ); 241 236 return $passthrough; -
performance-lab/trunk/admin/load.php
r2912645 r2928769 80 80 $module_slug, 81 81 $module_data['name'], 82 function() use ( $module_slug, $module_data, $module_settings ) {82 static function() use ( $module_slug, $module_data, $module_settings ) { 83 83 perflab_render_modules_page_field( $module_slug, $module_data, $module_settings ); 84 84 }, … … 202 202 <?php // Don't use the WP notice classes here, as that makes them move to the top of the page. ?> 203 203 <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> 205 208 </p> 206 209 <?php endif; ?> … … 330 333 uasort( 331 334 $modules, 332 function( $a, $b ) {335 static function( $a, $b ) { 333 336 return strnatcasecmp( $a['name'], $b['name'] ); 334 337 } … … 418 421 $dismissed = explode( ',', (string) get_user_meta( $current_user, 'dismissed_wp_pointers', true ) ); 419 422 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 420 464 if ( in_array( 'perflab-admin-pointer', $dismissed, true ) ) { 421 465 return; … … 425 469 wp_enqueue_style( 'wp-pointer' ); 426 470 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 ); 428 472 } 429 473 add_action( 'admin_enqueue_scripts', 'perflab_admin_pointer' ); … … 435 479 * 436 480 * @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 */ 487 function 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 440 499 $wp_kses_options = array( 441 500 'a' => array( … … 444 503 ); 445 504 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 452 505 ?> 453 <script id=" perflab-admin-pointer" type="text/javascript">506 <script id="<?php echo esc_attr( $pointer_id ); ?>" type="text/javascript"> 454 507 jQuery( function() { 455 508 // Pointer Options. 456 509 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>', 458 511 position: { 459 512 edge: 'left', … … 466 519 window.ajaxurl, 467 520 { 468 pointer: ' perflab-admin-pointer',521 pointer: '<?php echo esc_js( $pointer_id ); ?>', 469 522 action: 'dismiss-wp-pointer', 470 523 _wpnonce: <?php echo wp_json_encode( wp_create_nonce( 'dismiss_pointer' ) ); ?>, … … 513 566 */ 514 567 function 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'] ) { 516 569 // Another plugin's pointer, do nothing. 517 570 return; … … 520 573 } 521 574 add_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 */ 581 add_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 6 6 * Requires at least: 6.1 7 7 * Requires PHP: 5.6 8 * Version: 2. 3.08 * Version: 2.4.0 9 9 * Author: WordPress Performance Team 10 10 * Author URI: https://make.wordpress.org/performance/ … … 16 16 */ 17 17 18 define( 'PERFLAB_VERSION', '2. 2.0' );18 define( 'PERFLAB_VERSION', '2.4.0' ); 19 19 define( 'PERFLAB_MAIN_FILE', __FILE__ ); 20 20 define( 'PERFLAB_PLUGIN_DIR_PATH', plugin_dir_path( PERFLAB_MAIN_FILE ) ); … … 67 67 $default_option = array_reduce( 68 68 $default_enabled_modules, 69 function( $module_settings, $module_dir ) {69 static function( $module_settings, $module_dir ) { 70 70 $module_settings[ $module_dir ] = array( 'enabled' => true ); 71 71 return $module_settings; … … 94 94 return array_filter( 95 95 array_map( 96 function( $module_settings ) {96 static function( $module_settings ) { 97 97 if ( ! is_array( $module_settings ) ) { 98 98 return array(); … … 149 149 array_filter( 150 150 perflab_get_module_settings(), 151 function( $module_settings ) {151 static function( $module_settings ) { 152 152 return isset( $module_settings['enabled'] ) && $module_settings['enabled']; 153 153 } … … 288 288 'images/fetchpriority' => 'FETCHPRIORITY_VERSION', 289 289 'images/webp-uploads' => 'WEBP_UPLOADS_VERSION', 290 'database/sqlite' => 'SQLITE_MAIN_FILE', 290 291 ); 291 292 } … … 339 340 * @since 2.0.0 340 341 * 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. 342 343 */ 343 344 if ( apply_filters( 'perflab_disable_object_cache_dropin', false ) ) { … … 521 522 * @param mixed $value Value of the option. 522 523 */ 523 function( $option, $value ) {524 static function( $option, $value ) { 524 525 perflab_run_module_activation_deactivation( perflab_get_modules_setting_default(), $value ); 525 526 }, -
performance-lab/trunk/modules/database/sqlite/activate.php
r2836222 r2928769 12 12 * @since 1.8.0 13 13 */ 14 return function() {14 return static function() { 15 15 // Bail early if the SQLite3 class does not exist. 16 16 if ( ! class_exists( 'SQLite3' ) ) { … … 59 59 add_filter( 60 60 'wp_redirect', 61 function( $redirect_location ) {61 static function( $redirect_location ) { 62 62 if ( ! defined( 'DATABASE_TYPE' ) ) { 63 63 define( 'DATABASE_TYPE', 'sqlite' ); … … 119 119 // ensure it is inserted into the database like that, instead of 120 120 // 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 ) { 122 122 // Double check this is actually the already hashed password, 123 123 // to prevent any chance of accidentally putting another -
performance-lab/trunk/modules/database/sqlite/admin.php
r2883717 r2928769 17 17 // Bail early if the PERFLAB_SQLITE_DB_DROPIN_VERSION is defined. 18 18 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' ) ) { 19 24 return; 20 25 } -
performance-lab/trunk/modules/database/sqlite/can-load.php
r2836222 r2928769 12 12 * @since 1.8.0 13 13 */ 14 return function() {14 return static function() { 15 15 16 16 // If the PERFLAB_SQLITE_DB_DROPIN_VERSION constant is defined, then the module is already active. … … 20 20 21 21 // 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' ) ) { 23 24 return false; 24 25 } -
performance-lab/trunk/modules/database/sqlite/deactivate.php
r2836222 r2928769 12 12 * @since 1.8.0 13 13 */ 14 return function() { 15 if ( ! defined( 'PERFLAB_SQLITE_DB_DROPIN_VERSION' ) || ! file_exists( WP_CONTENT_DIR . '/db.php' ) ) { 14 return 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' ) ) { 16 17 return; 17 18 } … … 19 20 global $wp_filesystem; 20 21 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'; 22 25 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 } 26 30 } 27 31 … … 29 33 add_action( 30 34 'shutdown', 31 function() {35 static function() { 32 36 global $table_prefix; 33 37 -
performance-lab/trunk/modules/database/sqlite/load.php
r2883717 r2928769 9 9 */ 10 10 11 // Define the version constant. 12 if ( defined( 'SQLITE_VERSION' ) ) { 13 return; 14 } 15 16 define( 'SQLITE_VERSION', 'Performance Lab ' . PERFLAB_VERSION ); 17 11 18 // Do not load the code if it is already loaded through another means. 12 19 if ( function_exists( 'perflab_sqlite_plugin_admin_notice' ) ) { -
performance-lab/trunk/modules/database/sqlite/wp-includes/sqlite/class-perflab-sqlite-pdo-driver.php
r2836222 r2928769 738 738 usort( 739 739 $results, 740 function ( $a, $b ) use ( $flipped ) {740 static function ( $a, $b ) use ( $flipped ) { 741 741 return $flipped[ $a->ID ] - $flipped[ $b->ID ]; 742 742 } -
performance-lab/trunk/modules/images/webp-uploads/can-load.php
r2757901 r2928769 7 7 */ 8 8 9 return function() {9 return static function() { 10 10 return ! function_exists( 'wp_image_use_alternate_mime_types' ); 11 11 }; -
performance-lab/trunk/modules/images/webp-uploads/image-edit.php
r2900289 r2928769 104 104 add_filter( 105 105 '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 ) { 107 107 if ( $post_meta_id !== $post_id ) { 108 108 return $metadata; … … 298 298 $has_been_processed = false; 299 299 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 ) { 301 301 // Make sure this hook is only executed in the same context for the provided $attachment_id. 302 302 if ( $post_id !== $attachment_id ) { -
performance-lab/trunk/modules/images/webp-uploads/load.php
r2900289 r2928769 25 25 add_action( 26 26 'admin_notices', 27 function() {27 static function() { 28 28 printf( 29 29 '<div class="notice notice-error"><p>%s</p></div>', -
performance-lab/trunk/readme.txt
r2912645 r2928769 5 5 Tested up to: 6.2 6 6 Requires PHP: 5.6 7 Stable tag: 2. 3.07 Stable tag: 2.4.0 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 81 81 82 82 == 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)) 83 96 84 97 = 2.3.0 = -
performance-lab/trunk/server-timing/class-perflab-server-timing.php
r2836222 r2928769 228 228 } 229 229 230 ob_start(); 231 add_action( 232 'shutdown', 233 function() { 234 $output = ob_get_clean(); 230 ob_start( 231 function( $output ) { 235 232 $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 } 240 235 ); 241 236 return $passthrough;
Note: See TracChangeset
for help on using the changeset viewer.