WordPress.org

Make WordPress Core


Ignore:
Timestamp:
04/20/2021 02:47:02 PM (5 months ago)
Author:
SergeyBiryukov
Message:

Code Modernization: Bring consistency to preparing some fields on Network Settings screen:

  • illegal_names
  • limited_email_domains
  • banned_email_domains

If any of these options have a falsey value, treat it as an empty string. This addresses a PHP 8.1+ deprecation notice when passing a null value to str_replace().

Additionally, avoid unnecessary type casting for better performance.

Props hellofromTonya, jrf, SergeyBiryukov.
See #51423.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/network/settings.php

    r49912 r50772  
    243243                <th scope="row"><label for="illegal_names"><?php _e( 'Banned Names' ); ?></label></th>
    244244                <td>
    245                     <input name="illegal_names" type="text" id="illegal_names" aria-describedby="illegal-names-desc" class="large-text" value="<?php echo esc_attr( implode( ' ', (array) get_site_option( 'illegal_names' ) ) ); ?>" size="45" />
     245                    <?php
     246                    $illegal_names = get_site_option( 'illegal_names' );
     247
     248                    if ( empty( $illegal_names ) ) {
     249                        $illegal_names = '';
     250                    } elseif ( is_array( $illegal_names ) ) {
     251                        $illegal_names = implode( ' ', $illegal_names );
     252                    }
     253                    ?>
     254                    <input name="illegal_names" type="text" id="illegal_names" aria-describedby="illegal-names-desc" class="large-text" value="<?php echo esc_attr( $illegal_names ); ?>" size="45" />
    246255                    <p class="description" id="illegal-names-desc">
    247256                        <?php _e( 'Users are not allowed to register these sites. Separate names by spaces.' ); ?>
     
    255264                    <?php
    256265                    $limited_email_domains = get_site_option( 'limited_email_domains' );
    257                     $limited_email_domains = str_replace( ' ', "\n", $limited_email_domains );
    258 
    259                     if ( $limited_email_domains ) {
    260                         $limited_email_domains = implode( "\n", (array) $limited_email_domains );
     266
     267                    if ( empty( $limited_email_domains ) ) {
     268                        $limited_email_domains = '';
     269                    } else {
     270                        // Convert from an input field. Back-compat for WPMU < 1.0.
     271                        $limited_email_domains = str_replace( ' ', "\n", $limited_email_domains );
     272
     273                        if ( is_array( $limited_email_domains ) ) {
     274                            $limited_email_domains = implode( "\n", $limited_email_domains );
     275                        }
    261276                    }
    262277                    ?>
     
    275290                    $banned_email_domains = get_site_option( 'banned_email_domains' );
    276291
    277                     if ( $banned_email_domains ) {
    278                         $banned_email_domains = implode( "\n", (array) $banned_email_domains );
     292                    if ( empty( $banned_email_domains ) ) {
     293                        $banned_email_domains = '';
     294                    } elseif ( is_array( $banned_email_domains ) ) {
     295                        $banned_email_domains = implode( "\n", $banned_email_domains );
    279296                    }
    280297                    ?>
Note: See TracChangeset for help on using the changeset viewer.