Skip to content

Commit

Permalink
Update Query Monitor plugin from 3.16.4 to 3.17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
bitpoke-bot committed Nov 28, 2024
1 parent b1d056b commit 86d1077
Show file tree
Hide file tree
Showing 25 changed files with 139 additions and 156 deletions.
6 changes: 4 additions & 2 deletions wp-content/plugins/query-monitor/assets/query-monitor.css
Original file line number Diff line number Diff line change
Expand Up @@ -1472,13 +1472,15 @@ body.admin-color-light #wp-admin-bar-query-monitor:not(.qm-all-clear):not(:hover
padding: 0 0 1em 1em !important;
}
#qm-fatal li {
margin: 0 0 0.7em !important;
list-style: none !important;
margin: 0 0 0.7em 1em !important;
}
#qm-fatal .qm-info {
/* @TODO */
color: #666 !important;
}
#qm-fatal a.qm-edit-link svg {
display: none;
}

body#error-page #qm-fatal {
margin: 0 !important;
Expand Down
2 changes: 1 addition & 1 deletion wp-content/plugins/query-monitor/classes/Backtrace.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class QM_Backtrace {
* @param array<string, mixed[]> $args
* @param mixed[] $trace
*/
public function __construct( array $args = array(), array $trace = null ) {
public function __construct( array $args = array(), ?array $trace = null ) {
$this->trace = $trace ?? debug_backtrace( 0 );

$this->args = array_merge( array(
Expand Down
2 changes: 1 addition & 1 deletion wp-content/plugins/query-monitor/classes/CLI.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function enable() {
* @param string $file
* @return self
*/
public static function init( $file = null ) {
public static function init( ?string $file = null ) {

static $instance = null;

Expand Down
5 changes: 0 additions & 5 deletions wp-content/plugins/query-monitor/classes/Collector_Assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,6 @@ protected static function get_script_modules(): ?array {
return null;
}

// https://core.trac.wordpress.org/ticket/60596
if ( ! did_action( 'wp_head' ) ) {
return null;
}

$reflector = new ReflectionClass( $modules );

$get_marked_for_enqueue = $reflector->getMethod( 'get_marked_for_enqueue' );
Expand Down
2 changes: 1 addition & 1 deletion wp-content/plugins/query-monitor/classes/QueryMonitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ public function action_cease() {
* @param string $file
* @return self
*/
public static function init( $file = null ) {
public static function init( ?string $file = null ) {

static $instance = null;

Expand Down
8 changes: 4 additions & 4 deletions wp-content/plugins/query-monitor/classes/Timer.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class QM_Timer {
* @param mixed[] $data
* @return self
*/
public function start( array $data = null ) {
public function start( ?array $data = null ) {
$this->trace = new QM_Backtrace();
$this->start = array(
'time' => microtime( true ),
Expand All @@ -60,7 +60,7 @@ public function start( array $data = null ) {
* @param mixed[] $data
* @return self
*/
public function stop( array $data = null ) {
public function stop( ?array $data = null ) {

$this->end = array(
'time' => microtime( true ),
Expand All @@ -77,7 +77,7 @@ public function stop( array $data = null ) {
* @param string $name
* @return self
*/
public function lap( array $data = null, $name = null ) {
public function lap( ?array $data = null, ?string $name = null ) {

$lap = array(
'time' => microtime( true ),
Expand Down Expand Up @@ -176,7 +176,7 @@ public function get_trace() {
* @param mixed[] $data
* @return self
*/
public function end( array $data = null ) {
public function end( ?array $data = null ) {
return $this->stop( $data );
}

Expand Down
14 changes: 9 additions & 5 deletions wp-content/plugins/query-monitor/classes/debug_bar.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,15 @@ public function ensure_ajaxurl() {
$dispatcher = QM_Dispatchers::get( 'html' );

if ( $this->panels && $dispatcher && $dispatcher::user_can_view() ) {
?>
<script type="text/javascript">
var ajaxurl = '<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>';
</script>
<?php
wp_print_inline_script_tag(
sprintf(
"var ajaxurl = '%s';",
esc_url_raw( admin_url( 'admin-ajax.php' ) )
),
array(
'id' => 'query-monitor-inline-debug-bar',
)
);
}
}

Expand Down
8 changes: 7 additions & 1 deletion wp-content/plugins/query-monitor/collectors/block_editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,13 @@ public function process() {
$content = $_wp_current_template_content;
} elseif ( is_singular() ) {
// Post editor:
$content = get_post( get_queried_object_id() )->post_content;
$post = get_post( get_queried_object_id() );

if ( ! $post ) {
return;
}

$content = $post->post_content;
} else {
// Nada:
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public function process() {
'is_feed',
'is_front_page',
'is_home',
'is_login',
'is_main_network',
'is_main_site',
'is_month',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ public function process() {
'host' => null,
'OS' => null,
'arch' => null,
'basicauth' => wp_is_site_protected_by_basic_auth() ? 'true' : 'false',
);

if ( function_exists( 'php_uname' ) ) {
Expand Down
9 changes: 5 additions & 4 deletions wp-content/plugins/query-monitor/collectors/http.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ public function action_http_api_debug( $response, $action, $class, $args, $url )
* @param mixed[] $info
* @return void
*/
public function action_curl_after_request( $headers, array $info = null ) {
public function action_curl_after_request( $headers, ?array $info = null ) {
$this->info = $info;
}

Expand All @@ -268,7 +268,7 @@ public function action_curl_after_request( $headers, array $info = null ) {
* @param mixed[] $info
* @return void
*/
public function action_fsockopen_after_request( $headers, array $info = null ) {
public function action_fsockopen_after_request( $headers, ?array $info = null ) {
$this->info = $info;
}

Expand Down Expand Up @@ -360,8 +360,9 @@ public function process() {

if ( isset( $response['info'] ) && ! empty( $response['info']['url'] ) && is_string( $response['info']['url'] ) ) {
// Ignore query variables when detecting a redirect.
$from = untrailingslashit( preg_replace( '#\?[^$]+$#', '', $request['url'] ) );
$to = untrailingslashit( preg_replace( '#\?[^$]+$#', '', $response['info']['url'] ) );
$from = untrailingslashit( preg_replace( '#\?[^$]*$#', '', $request['url'] ) );
$to = untrailingslashit( preg_replace( '#\?[^$]*$#', '', $response['info']['url'] ) );

if ( $from !== $to ) {
$redirected_to = $response['info']['url'];
}
Expand Down
12 changes: 7 additions & 5 deletions wp-content/plugins/query-monitor/collectors/languages.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function set_up() {
parent::set_up();

add_filter( 'load_textdomain_mofile', array( $this, 'log_mo_file_load' ), 9999, 2 );
add_filter( 'load_translation_file', array( $this, 'log_translation_file_load' ), 9999, 2 );
add_filter( 'load_translation_file', array( $this, 'log_translation_file_load' ), 9999, 3 );
add_filter( 'load_script_translation_file', array( $this, 'log_script_file_load' ), 9999, 3 );
add_action( 'init', array( $this, 'collect_locale_data' ), 9999 );

Expand Down Expand Up @@ -169,17 +169,19 @@ public function log_mo_file_load( $file, $domain ) {
*
* @phpstan-template T
*
* @param mixed $file Should be a string path to the MO or PHP file, could be anything.
* @param mixed $file Should be a string path to the MO or PHP file, could be anything.
* @param string $domain Text domain.
* @param string $locale Locale. Only present in 6.6 and later.
* @return string The original file path.
* @phpstan-param T $file
* @phpstan-return T
*/
public function log_translation_file_load( $file, $domain ) {
public function log_translation_file_load( $file, $domain, ?string $locale = null ) {
// @phpstan-ignore WPCompat.methodNotAvailable
$i18n_controller = \WP_Translation_Controller::get_instance();

$locale = determine_locale();
$found = $i18n_controller->load_file( $file, $domain, $locale );
// @phpstan-ignore WPCompat.methodNotAvailable
$found = $i18n_controller->load_file( $file, $domain, $locale ?? determine_locale() );

return $this->log_file_load( $file, $domain, $found );
}
Expand Down
4 changes: 2 additions & 2 deletions wp-content/plugins/query-monitor/collectors/logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public function log( $level, $message, array $context = array() ) {
* @phpstan-param LogMessage $message
* @return void
*/
protected function store( $level, $message, array $context = array(), string $prefix = null ) {
protected function store( $level, $message, array $context = array(), ?string $prefix = null ) {
$trace = new QM_Backtrace( array(
'ignore_hook' => array(
current_filter() => true,
Expand Down Expand Up @@ -259,7 +259,7 @@ protected function store( $level, $message, array $context = array(), string $pr
* @param ?string $prefix
* @return string
*/
protected static function interpolate( $message, array $context = array(), string $prefix = null ) {
protected static function interpolate( $message, array $context = array(), ?string $prefix = null ) {
// build a replacement array with braces around the context keys
$replace = array();

Expand Down
34 changes: 29 additions & 5 deletions wp-content/plugins/query-monitor/collectors/php_errors.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,17 +203,18 @@ public function error_handler( $errno, $message, $file = null, $line = null, $co
$type = 'notice';
break;

case E_STRICT:
$type = 'strict';
break;

case E_DEPRECATED:
case E_USER_DEPRECATED:
$type = 'deprecated';
break;

}

// E_STRICT is deprecated in PHP 8.4 so it needs to be behind a version check.
if ( null === $type && version_compare( PHP_VERSION, '8.4', '<' ) && E_STRICT === $errno ) {
$type = 'strict';
}

if ( null === $type ) {
return false;
}
Expand Down Expand Up @@ -359,9 +360,32 @@ protected function output_fatal( $error, array $e ) {
continue;
}

$args = array_map( function( $value ) {
$type = gettype( $value );

switch ( $type ) {
case 'object':
return get_class( $value );
case 'boolean':
return $value ? 'true' : 'false';
case 'integer':
case 'double':
return $value;
case 'string':
if ( strlen( $value ) > 50 ) {
return "'" . substr( $value, 0, 20 ) . '...' . substr( $value, -20 ) . "'";
}
return "'" . $value . "'";
}

return $type;
}, $frame['args'] ?? array() );

$name = str_replace( '()', '(' . implode( ', ', $args ) . ')', $callback['name'] );

printf(
'<li>%s</li>',
QM_Output_Html::output_filename( $callback['name'], $frame['file'], $frame['line'] )
QM_Output_Html::output_filename( $name, $frame['file'], $frame['line'] )
); // WPCS: XSS ok.
}
echo '</ol>';
Expand Down
38 changes: 4 additions & 34 deletions wp-content/plugins/query-monitor/collectors/theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,8 @@ public function filter_template_hierarchy( array $templates ) {
}
}

if ( self::wp_is_block_theme() ) {
$block_theme_folders = self::wp_get_block_theme_folders();
if ( wp_is_block_theme() ) {
$block_theme_folders = get_block_theme_folders();
foreach ( $templates as $template ) {
if ( str_ends_with( $template, '.php' ) ) {
// Standard PHP template, inject the HTML version:
Expand Down Expand Up @@ -471,7 +471,7 @@ public function process() {
$all = array_merge( $posts, $files, $nopes );

foreach ( $all as $part ) {
$file = $part['path'] ?? $part['post'];
$file = isset( $part['path'] ) ? QM_Util::standard_dir( $part['path'] ) : $part['post'];

if ( isset( $this->data->count_template_parts[ $file ] ) ) {
$this->data->count_template_parts[ $file ]++;
Expand All @@ -484,8 +484,6 @@ public function process() {
$display = $part['id'];
$theme_display = $display;
} else {
$file = QM_Util::standard_dir( $file );

$filename = str_replace( array(
$stylesheet_directory,
$template_directory,
Expand Down Expand Up @@ -520,7 +518,7 @@ public function process() {
$this->data->template => $template_directory,
);

$this->data->theme_folders = self::wp_get_block_theme_folders();
$this->data->theme_folders = get_block_theme_folders();

$stylesheet_theme_json = $stylesheet_directory . '/theme.json';
$template_theme_json = $template_directory . '/theme.json';
Expand All @@ -539,41 +537,13 @@ public function process() {

}

/**
* @return bool
*/
protected static function wp_is_block_theme() {
// WP 5.9
return function_exists( 'wp_is_block_theme' ) && wp_is_block_theme();
}

/**
* @return array<string, string>
*/
protected static function wp_get_block_theme_folders() {
// WP 5.9
if ( ! function_exists( 'get_block_theme_folders' ) ) {
return array(
'wp_template' => 'templates',
'wp_template_part' => 'parts',
);
}

return get_block_theme_folders();
}

/**
* @param string $template_type The current template type.
* @param array<int, string> $template_hierarchy The current template hierarchy, ordered by priority.
* @param string $fallback_template A PHP fallback template to use if no matching block template is found.
* @return WP_Block_Template|null template A template object, or null if none could be found.
*/
protected static function wp_resolve_block_template( $template_type, $template_hierarchy, $fallback_template ) {
// WP 5.8
if ( ! function_exists( 'resolve_block_template' ) ) {
return null;
}

if ( ! current_theme_supports( 'block-templates' ) ) {
return null;
}
Expand Down
Loading

0 comments on commit 86d1077

Please sign in to comment.