Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public static function delete_transient() {
* @since Twenty Fourteen 1.0
*
* @param WP_Query $query WP_Query object.
* @return WP_Query Possibly-modified WP_Query.
* @return void

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems right. For history, this was already in r25808, when the Featured_Content class was added.

*/
public static function pre_get_posts( $query ) {

Expand Down
6 changes: 3 additions & 3 deletions src/wp-content/themes/twentytwenty/inc/template-tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
*
* @param array $args Arguments for displaying the site logo either as an image or text.
* @param bool $display Display or return the HTML.
* @return string Compiled HTML based on our arguments.
* @return string|void Compiled HTML based on our arguments.
*/
function twentytwenty_site_logo( $args = array(), $display = true ) {
$logo = get_custom_logo();
Expand Down Expand Up @@ -107,7 +107,7 @@ function twentytwenty_site_logo( $args = array(), $display = true ) {
* @since Twenty Twenty 1.0
*
* @param bool $display Display or return the HTML.
* @return string The HTML to display.
* @return string|void The HTML to display.
*/
function twentytwenty_site_description( $display = true ) {
$description = get_bloginfo( 'description' );
Expand Down Expand Up @@ -249,7 +249,7 @@ function twentytwenty_edit_post_link( $link, $post_id, $text ) {
*
* @param int $post_id The ID of the post.
* @param string $location The location where the meta is shown.
* @return string Post meta HTML.
* @return string|void Post meta HTML.
Copy link

@sabernhardt sabernhardt Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function can return void in two situations, but I think returning an empty string could be better when there is no HTML to return. Maybe it's unwise to change that now, though.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, for this it seems best to document the existing behavior.

*/
function twentytwenty_get_post_meta( $post_id = null, $location = 'single-top' ) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,12 @@ public function __construct() {
public function register( $wp_customize ) {

// Change site-title & description to postMessage.
$wp_customize->get_setting( 'blogname' )->transport = 'postMessage'; // @phpstan-ignore-line. Assume that this setting exists.
$wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage'; // @phpstan-ignore-line. Assume that this setting exists.
foreach ( array( 'blogname', 'blogdescription' ) as $setting_id ) {
$setting = $wp_customize->get_setting( $setting_id );
if ( $setting ) {
$setting->transport = 'postMessage';
}
}

// Add partial for blogname.
$wp_customize->selective_refresh->add_partial(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function enqueue_scripts() {
if ( is_rtl() ) {
$url = get_template_directory_uri() . '/assets/css/style-dark-mode-rtl.css';
}
wp_enqueue_style( 'tt1-dark-mode', $url, array( 'twenty-twenty-one-style' ), wp_get_theme()->get( 'Version' ) ); // @phpstan-ignore-line. Version is always a string.
wp_enqueue_style( 'tt1-dark-mode', $url, array( 'twenty-twenty-one-style' ), wp_get_theme()->get( 'Version' ) );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,18 +181,17 @@ public static function get_svg( $group, $icon, $size ) {
*
* @since Twenty Twenty-One 1.0
*
* @param array $arr Array of icons.
* @param array<string, string> $arr Array of icons.
*/
$arr = apply_filters( "twenty_twenty_one_svg_icons_{$group}", $arr );

$svg = '';
if ( array_key_exists( $icon, $arr ) ) {
if ( isset( $arr[ $icon ] ) && is_string( $arr[ $icon ] ) ) {
$repl = sprintf( '<svg class="svg-icon" width="%d" height="%d" aria-hidden="true" role="img" focusable="false" ', $size, $size );

$svg = preg_replace( '/^<svg /', $repl, trim( $arr[ $icon ] ) ); // Add extra attributes to SVG code.
$svg = (string) preg_replace( '/^<svg /', $repl, trim( $arr[ $icon ] ) ); // Add extra attributes to SVG code.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pattern and $repl are both strings. If $arr[ $icon ] is somehow not a string, then it will have errors with the trim() function.

Suggested change
$svg = (string) preg_replace( '/^<svg /', $repl, trim( $arr[ $icon ] ) ); // Add extra attributes to SVG code.
$svg = preg_replace( '/^<svg /', $repl, trim( (string) $arr[ $icon ] ) ); // Add extra attributes to SVG code.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue that PHPStan is warning about is that preg_replace() can return false. So then we'd need to add two casts. However, what about cfb02ce? This ensures the proper type up front.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I prefer checking is_string( $arr[ $icon ] ) instead of casting it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if ( isset( $arr[ $icon ] ) && is_string( $arr[ $icon ] ) ) { approach make sense here

}

// @phpstan-ignore-next-line.
return $svg;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,12 +339,12 @@ function twenty_twenty_one_get_non_latin_css( $type = 'front-end' ) {
}

// Return the specified styles.
return twenty_twenty_one_generate_css( // @phpstan-ignore-line.
return twenty_twenty_one_generate_css(
implode( ',', $elements[ $type ] ),
'font-family',
implode( ',', $font_family[ $locale ] ),
null,
null,
'',
'',
false
);
}
Expand Down
8 changes: 8 additions & 0 deletions src/wp-includes/class-wp-theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,14 @@ public function cache_delete() {
*
* @param string $header Theme header. Name, Description, Author, Version, ThemeURI, AuthorURI, Status, Tags.
* @return string|array|false String or array (for Tags header) on success, false on failure.
*
* @phpstan-return (
* $header is 'Tags'
* ? string[]|false
* : ( $header is 'Name'|'ThemeURI'|'Description'|'Author'|'AuthorURI'|'Version'|'Template'|'Status'|'TextDomain'|'DomainPath'|'RequiresWP'|'RequiresPHP'|'UpdateURI'
* ? string|false
* : false )
* )
Comment on lines +869 to +876

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does class-wp-theme.php belong in this PR?

Copy link
Member Author

@westonruter westonruter Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, because it fixes issues with calls to wp_get_theme()->get( 'Version' ).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For example:

wp_enqueue_style( 'twenty-twenty-one-style', get_template_directory_uri() . '/style.css', array(), wp_get_theme()->get( 'Version' ) );

PHPStan is flagging this:

Parameter #4 $ver of function wp_enqueue_style expects bool|string|null, array|string|false given.

With the inclusion of the @phpstan-return, the issue is resolved.

*/
public function get( $header ) {
if ( ! isset( $this->headers[ $header ] ) ) {
Expand Down
Loading