Make WordPress Core


Ignore:
Timestamp:
03/30/2026 05:31:56 AM (5 months ago)
Author:
westonruter
Message:

Code Quality: Replace void with proper return types in union PHPDoc annotations.

In PHP's type system, void means a function does not return a value and cannot be part of a union type. Many functions in core were documented as returning e.g. string|void while actually returning null implicitly via bare return; statements. This replaces void with null in union return types, adds explicit return null; statements, and updates @return annotations across 22 files in wp-includes.

Additionally:

  • Adds @return never for WP_Recovery_Mode::redirect_protected().
  • Fixes WP_Theme_JSON::set_spacing_sizes() to use @return void instead of @return null|void.
  • Removes void from return types where the function always returns a value or dies: remove_theme_support(), WP_Recovery_Mode::handle_error().
  • Fixes wp_die() return type from never|void to void with clarified description.
  • Initializes $primary variable in get_active_blog_for_user() to prevent a possible undefined variable notice.

Developed in https://github.com/WordPress/wordpress-develop/pull/11012

Follow-up to r62177, r61766, r61719.

Props apermo, xateman, westonruter, parthvataliya, nimeshatxecurify.
See #64704.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/ms-functions.php

    r61074 r62178  
    4141 *
    4242 * @param int $user_id The unique ID of the user
    43  * @return WP_Site|void The blog object
     43 * @return WP_Site|object|null|false The blog object
    4444 */
    4545function get_active_blog_for_user( $user_id ) {
    4646        $blogs = get_blogs_of_user( $user_id );
    4747        if ( empty( $blogs ) ) {
    48                 return;
     48                return null;
    4949        }
    5050
     
    5353        }
    5454
     55        $primary      = null;
    5556        $primary_blog = get_user_meta( $user_id, 'primary_blog', true );
    5657        $first_blog   = current( $blogs );
     
    101102                        }
    102103                } else {
    103                         return;
     104                        return null;
    104105                }
    105106
     
    22702271 *     @type string $role    The role to be assigned to the user.
    22712272 * }
    2272  * @return true|WP_Error|void True on success or a WP_Error object if the user doesn't exist
    2273  *                            or could not be added. Void if $details array was not provided.
     2273 * @return true|WP_Error|null True on success or a WP_Error object if the user doesn't exist
     2274 *                            or could not be added. Null if $details array was not provided.
    22742275 */
    22752276function add_existing_user_to_blog( $details = false ) {
     
    22912292                return $result;
    22922293        }
     2294        return null;
    22932295}
    22942296
Note: See TracChangeset for help on using the changeset viewer.