Make WordPress Core

Changeset 61300


Ignore:
Timestamp:
11/25/2025 02:18:04 AM (11 months ago)
Author:
westonruter
Message:

Docs: Improve docblocks and types for WP_Screen properties.

  • Correctly hint that WP_Screen::$_show_screen_options is null before being instantiated.
  • Correctly hint that ::get_option(), get_help_tab() and get_screen_reader_text() can return null.
  • Ensure $this->columns is an int, by casting $this->get_option( 'layout_columns', 'default' ) from its numeric string.

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

Props justlevine, peterwilsoncc, westonruter.
See #64238, #64224.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-screen.php

    r60658 r61300  
    176176         * Stores the result of the public show_screen_options function.
    177177         *
    178          * @since 3.3.0
    179          * @var bool
     178         * Set when calling {@see self::show_screen_options()} for the first time.
     179         *
     180         * @since 3.3.0
     181         * @var ?bool
    180182         */
    181183        private $_show_screen_options;
    … …  
    546548         * @param string|false $key    Optional. Specific array key for when the option is an array.
    547549         *                             Default false.
    548          * @return string The option value if set, null otherwise.
     550         * @return ?string The option value if set, null otherwise.
    549551         */
    550552        public function get_option( $option, $key = false ) {
    … …  
    599601         *
    600602         * @param string $id Help Tab ID.
    601          * @return array Help tab arguments.
     603         * @return ?array Help tab arguments, or null if no help tabs added.
    602604         */
    603605        public function get_help_tab( $id ) {
    … …  
    734736         *
    735737         * @param string $key Screen reader text array named key.
    736          * @return string Screen reader text string.
     738         * @return ?string Screen reader text string, or null if no text is associated with the key.
    737739         */
    738740        public function get_screen_reader_text( $key ) {
    … …  
    950952                        $this->columns = (int) get_user_option( "screen_layout_$this->id" );
    951953
    952                         if ( ! $this->columns && $this->get_option( 'layout_columns', 'default' ) ) {
    953                                 $this->columns = $this->get_option( 'layout_columns', 'default' );
     954                        $layout_columns = (int) $this->get_option( 'layout_columns', 'default' );
     955                        if ( ! $this->columns && $layout_columns ) {
     956                                $this->columns = $layout_columns;
    954957                        }
    955958                }
Note: See TracChangeset for help on using the changeset viewer.