Skip to content

Commit

Permalink
QM: Update to 3.17.1 (#6124)
Browse files Browse the repository at this point in the history
  • Loading branch information
rebeccahum authored Feb 4, 2025
1 parent df73362 commit 91a9c0f
Show file tree
Hide file tree
Showing 35 changed files with 401 additions and 397 deletions.
6 changes: 4 additions & 2 deletions 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 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 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 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
15 changes: 15 additions & 0 deletions query-monitor/classes/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,21 @@ public function __construct( QM_Plugin $qm ) {
*/
abstract public function is_active();

/**
* @param string $message
* @param mixed[] $e
* @phpstan-param array{
* message: string,
* file: string,
* line: int,
* type?: int,
* trace?: mixed|null,
* } $e
*/
public function output_fatal( $message, array $e ): void {
print_r( $e );
}

/**
* @return bool
*/
Expand Down
2 changes: 1 addition & 1 deletion 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 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 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
67 changes: 10 additions & 57 deletions query-monitor/collectors/block_editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,22 +130,26 @@ public function filter_render_block( $block_content, array $block ) {
public function process() {
global $_wp_current_template_content;

$this->data->block_editor_enabled = self::wp_block_editor_enabled();

if ( ! empty( $_wp_current_template_content ) ) {
// Full site editor:
$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;
}

$this->data->post_has_blocks = self::wp_has_blocks( $content );
$this->data->post_blocks = self::wp_parse_blocks( $content );
$this->data->all_dynamic_blocks = self::wp_get_dynamic_block_names();
$this->data->post_has_blocks = has_blocks( $content );
$this->data->post_blocks = array_values( parse_blocks( $content ) );
$this->data->all_dynamic_blocks = get_dynamic_block_names();
$this->data->total_blocks = 0;
$this->data->has_block_context = false;
$this->data->has_block_timing = false;
Expand Down Expand Up @@ -204,57 +208,6 @@ protected function process_block( array $block ) {

return $block;
}

/**
* @return bool
*/
protected static function wp_block_editor_enabled() {
// WP 5.0
return ( function_exists( 'parse_blocks' ) || function_exists( 'gutenberg_parse_blocks' ) );
}

/**
* @param string $content
* @return bool
*/
protected static function wp_has_blocks( $content ) {
// WP 5.0
if ( function_exists( 'has_blocks' ) ) {
return has_blocks( $content );
} elseif ( function_exists( 'gutenberg_has_blocks' ) ) {
return gutenberg_has_blocks( $content );
}

return false;
}

/**
* @param string $content
* @return array<int, mixed>|null
*/
protected static function wp_parse_blocks( $content ) {
// WP 5.0
if ( function_exists( 'parse_blocks' ) ) {
return parse_blocks( $content );
} elseif ( function_exists( 'gutenberg_parse_blocks' ) ) {
return gutenberg_parse_blocks( $content );
}

return null;
}

/**
* @return array<int, string>|null
*/
protected static function wp_get_dynamic_block_names() {
// WP 5.0
if ( function_exists( 'get_dynamic_block_names' ) ) {
return get_dynamic_block_names();
}

return array();
}

}

/**
Expand Down
1 change: 1 addition & 0 deletions query-monitor/collectors/conditionals.php
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
39 changes: 37 additions & 2 deletions query-monitor/collectors/doing_it_wrong.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function set_up() {
add_filter( 'deprecated_file_trigger_error', array( $this, 'maybe_prevent_error' ), 999 );
add_filter( 'deprecated_argument_trigger_error', array( $this, 'maybe_prevent_error' ), 999 );
add_filter( 'deprecated_hook_trigger_error', array( $this, 'maybe_prevent_error' ), 999 );
add_filter( 'doing_it_wrong_trigger_error', array( $this, 'maybe_prevent_error' ), 999 );
add_filter( 'doing_it_wrong_trigger_error', array( $this, 'maybe_prevent_doing_it_wrong_error' ), 999, 4 );
}

/**
Expand All @@ -64,7 +64,7 @@ public function tear_down() {
remove_filter( 'deprecated_file_trigger_error', array( $this, 'maybe_prevent_error' ) );
remove_filter( 'deprecated_argument_trigger_error', array( $this, 'maybe_prevent_error' ) );
remove_filter( 'deprecated_hook_trigger_error', array( $this, 'maybe_prevent_error' ) );
remove_filter( 'doing_it_wrong_trigger_error', array( $this, 'maybe_prevent_error' ) );
remove_filter( 'doing_it_wrong_trigger_error', array( $this, 'maybe_prevent_doing_it_wrong_error' ), 999 );
}

/**
Expand All @@ -82,6 +82,25 @@ public function maybe_prevent_error( $trigger ) {
return $trigger;
}

/**
* Prevents the doing_it_wrong error from being triggered for doing it wrong calls when the
* current user can view Query Monitor output.
*
* @param bool|mixed $trigger Whether to trigger the error for _doing_it_wrong() calls. Default true.
* @param string $function_name The function that was called.
* @param string $message A message explaining what has been done incorrectly.
* @param string $version The version of WordPress where the message was added.
*
* @return bool
*/
public function maybe_prevent_doing_it_wrong_error( $trigger, $function_name, $message, $version ) {
if ( function_exists( 'wp_get_current_user' ) && current_user_can( 'view_query_monitor' ) ) {
return false;
}

return $this->is_just_in_time_for_qm_domain( $function_name, $message ) ? false : $trigger;
}

/**
* @return array<int, string>
*/
Expand Down Expand Up @@ -121,6 +140,10 @@ public function action_doing_it_wrong_run( $function_name, $message, $version )
return;
}

if ( $this->is_just_in_time_for_qm_domain( $function_name, $message ) ) {
return;
}

$this->collecting = true;

$trace = new QM_Backtrace( array(
Expand Down Expand Up @@ -388,6 +411,18 @@ public function action_deprecated_hook_run( $hook, $replacement, $version, $mess
$this->collecting = false;
}

/**
* Whether it is the just_in_time_error for the QM domains.
*
* @param string $function_name Function name.
* @param string $message Message.
*
* @return bool
*/
protected function is_just_in_time_for_qm_domain( string $function_name, string $message ): bool {
return $function_name === '_load_textdomain_just_in_time' && strpos( $message, '<code>query-monitor' ) !== false;
}

}

# Load early to catch early actions
Expand Down
44 changes: 22 additions & 22 deletions query-monitor/collectors/environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,28 +40,30 @@ public function get_storage(): QM_Data {
* @return array<string, bool>
*/
protected static function get_error_levels( $error_reporting ) {
$levels = array(
'E_ERROR' => false,
'E_WARNING' => false,
'E_PARSE' => false,
'E_NOTICE' => false,
'E_CORE_ERROR' => false,
'E_CORE_WARNING' => false,
'E_COMPILE_ERROR' => false,
'E_COMPILE_WARNING' => false,
'E_USER_ERROR' => false,
'E_USER_WARNING' => false,
'E_USER_NOTICE' => false,
'E_STRICT' => false,
'E_RECOVERABLE_ERROR' => false,
'E_DEPRECATED' => false,
'E_USER_DEPRECATED' => false,
'E_ALL' => false,
$constants = array(
'E_ERROR' => 1,
'E_WARNING' => 2,
'E_PARSE' => 4,
'E_NOTICE' => 8,
'E_CORE_ERROR' => 16,
'E_CORE_WARNING' => 32,
'E_COMPILE_ERROR' => 64,
'E_COMPILE_WARNING' => 128,
'E_USER_ERROR' => 256,
'E_USER_WARNING' => 512,
'E_USER_NOTICE' => 1024,
'E_STRICT' => 2048,
'E_RECOVERABLE_ERROR' => 4096,
'E_DEPRECATED' => 8192,
'E_USER_DEPRECATED' => 16384,
'E_ALL' => 30719,
);

$levels = array_fill_keys( array_keys( $constants ), false );

foreach ( $levels as $level => $reported ) {
if ( defined( $level ) ) {
$c = constant( $level );
$c = $constants[ $level ];
if ( $error_reporting & $c ) {
$levels[ $level ] = true;
}
Expand Down Expand Up @@ -187,10 +189,7 @@ public function process() {
'WP_DEVELOPMENT_MODE' => self::format_bool_constant( 'WP_DEVELOPMENT_MODE' ),
);

// WP 5.5
if ( function_exists( 'wp_get_environment_type' ) ) {
$this->data->wp['environment_type'] = wp_get_environment_type();
}
$this->data->wp['environment_type'] = wp_get_environment_type();

// WP 6.3
if ( function_exists( 'wp_get_development_mode' ) ) {
Expand Down Expand Up @@ -227,6 +226,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
Loading

0 comments on commit 91a9c0f

Please sign in to comment.