Make WordPress Core

Opened 3 years ago

Last modified 3 years ago

#55330 new enhancement

Set global_styles_svg_filters transient to return true causing symbol `1` to be appeared on the screen in a production mode

Reported by: aliakseyenkaihar's profile aliakseyenkaihar Owned by:
Milestone: Awaiting Review Priority: normal
Severity: trivial Version: 5.9.1
Component: General Keywords:
Focuses: Cc:

Description

WordPress 5.9.1
PHP 8.0.15

When I set global_styles_svg_filters to return true (to prevent from being set - I don't use theme.json but request is sending so I want to disable it) it renders 1 at the top of the website

Steps to reproduce on TwentyTwentyTwo theme:

  1. Paste these lines in functions.php
<?php
// @see https://github.com/WordPress/WordPress/blob/master/wp-includes/option.php#L131
$theme = get_stylesheet();
add_filter( "pre_transient_global_styles_svg_filters_{$theme}", '__return_true' );

You will see 1 at the top of any screen on site's front

If you define WP_DEBUG as true or WP_ENVIRONMENT_TYPE as development it will dissapear

It happens [here](https://github.com/WordPress/WordPress/blob/master/wp-includes/script-loader.php#L2361) - wp_get_global_styles_svg_filters() function will return true (as I manually set transient) so $cached [will](https://github.com/WordPress/WordPress/blob/2399966d8ce0f89e3989360929fa01edf86e15c0/wp-includes/global-styles-and-settings.php#L172) be true as well. Therefore it echoing as 1

It is so minor and specific but it happened to me :) So because I may set any return type for this transient my guess there is no need for extra check but for a filter. For example

<?php
// script-loader.php
$svg_filters = wp_get_global_styles_svg_filters();
$filters = apply_filters( 'wp_get_global_styles_svg_filters', $svg_filters );

This way I will control svg filters output myself

Change History (2)

#1 @vijayhardaha
3 years ago

Hey @aliakseyenkaihar, May I ask why __return_true instead of setting __return_false ? as you mentioned to prevent from being set that can be done by setting false, since you're setting it true that's validated the if condition and you returned content is being printed as 1.

#2 @aliakseyenkaihar
3 years ago

Hey @vijayhardaha

I'm actually need anything but false to satisfy false !== $pre condition. See [here](https://github.com/WordPress/WordPress/blob/master/wp-includes/option.php#L847). I tested with null - 1 is NOT appearing but the call to update transient is present - and my personal goal is to prevent it

Note: See TracTickets for help on using tickets.