Make WordPress Core

Changeset 48575


Ignore:
Timestamp:
07/23/2020 03:12:49 AM (5 years ago)
Author:
jorbin
Message:

General: Update code for readability and inclusion

There are two pieces in here:

1) The update to change blacklist to blocklist is moved to disallowed_list. "Block" has a meaning in our code, and there could be ambiguity between this code and code related to blocks.

2) This improves backwards compatibility for code that was accessing the now deprecated code.

Previously: [48477], [48405], [48400], [48121], [48122], [48124], [48142], [48566]

Props: desrosj, SergeyBiryukov, johnjamesjacoby
Fixes: #50413

Location:
trunk
Files:
9 edited

Legend:

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

    r48397 r48575  
    533533
    534534        // 5.5.0
    535         'blocklist_keys'                  => '',
     535        'disallowed_keys'                 => '',
    536536        'comment_previously_approved'     => 1,
    537537        'auto_plugin_theme_update_emails' => array(),
     
    557557        'moderation_keys',
    558558        'recently_edited',
    559         'blocklist_keys',
     559        'disallowed_keys',
    560560        'uninstall_plugins',
    561561        'auto_plugin_theme_update_emails',
  • trunk/src/wp-admin/includes/upgrade.php

    r48405 r48575  
    21782178        wp_schedule_single_event( time() + ( 1 * MINUTE_IN_SECONDS ), 'wp_update_comment_type_batch' );
    21792179
    2180         // Use more clear and inclusive language.
    2181         $blocklist = get_option( 'blacklist_keys', '' );
    2182         update_option( 'blocklist_keys', $blocklist );
    2183         delete_option( 'blacklist_keys' );
    2184 
    21852180        $comment_previously_approved = get_option( 'comment_whitelist', '' );
    21862181        update_option( 'comment_previously_approved', $comment_previously_approved );
    21872182        delete_option( 'comment_whitelist' );
     2183    }
     2184
     2185    if ( $wp_current_db_version < 48572 ) {
     2186        // Use more clear and inclusive language.
     2187        $disallowed_list = get_option( 'blacklist_keys' );
     2188
     2189        if ( false === $disallowed_list ) {
     2190            $disallowed_list = get_option( 'blocklist_keys' );
     2191        }
     2192
     2193        update_option( 'disallowed_keys', $disallowed_list );
     2194        delete_option( 'blacklist_keys' );
     2195        delete_option( 'blocklist_keys' );
    21882196    }
    21892197}
  • trunk/src/wp-admin/options-discussion.php

    r48121 r48575  
    205205</tr>
    206206<tr>
    207 <th scope="row"><?php _e( 'Comment Blocklist' ); ?></th>
    208 <td><fieldset><legend class="screen-reader-text"><span><?php _e( 'Comment Blocklist' ); ?></span></legend>
    209 <p><label for="blocklist_keys"><?php _e( 'When a comment contains any of these words in its content, author name, URL, email, IP address, or browser&#8217;s user agent string, it will be put in the Trash. One word or IP address per line. It will match inside words, so &#8220;press&#8221; will match &#8220;WordPress&#8221;.' ); ?></label></p>
     207<th scope="row"><?php _e( 'Disallowed Comment Keys' ); ?></th>
     208<td><fieldset><legend class="screen-reader-text"><span><?php _e( 'Disallowed Comment Keys' ); ?></span></legend>
     209<p><label for="disallowed_keys"><?php _e( 'When a comment contains any of these words in its content, author name, URL, email, IP address, or browser&#8217;s user agent string, it will be put in the Trash. One word or IP address per line. It will match inside words, so &#8220;press&#8221; will match &#8220;WordPress&#8221;.' ); ?></label></p>
    210210<p>
    211 <textarea name="blocklist_keys" rows="10" cols="50" id="blocklist_keys" class="large-text code"><?php echo esc_textarea( get_option( 'blocklist_keys' ) ); ?></textarea>
     211<textarea name="disallowed_keys" rows="10" cols="50" id="disallowed_keys" class="large-text code"><?php echo esc_textarea( get_option( 'disallowed_keys' ) ); ?></textarea>
    212212</p>
    213213</fieldset></td>
  • trunk/src/wp-admin/options.php

    r48570 r48575  
    104104        'comment_max_links',
    105105        'moderation_keys',
    106         'blocklist_keys',
     106        'disallowed_keys',
    107107        'show_avatars',
    108108        'avatar_rating',
  • trunk/src/wp-includes/comment.php

    r48574 r48575  
    821821        }
    822822
    823         if ( wp_blocklist_check(
     823        if ( wp_check_comment_disallowed_list(
    824824            $commentdata['comment_author'],
    825825            $commentdata['comment_author_email'],
     
    13211321 * @return bool True if comment contains disallowed content, false if comment does not
    13221322 */
    1323 function wp_blocklist_check( $author, $email, $url, $comment, $user_ip, $user_agent ) {
     1323function wp_check_comment_disallowed_list( $author, $email, $url, $comment, $user_ip, $user_agent ) {
    13241324    /**
    13251325     * Fires before the comment is tested for disallowed characters or words.
    13261326     *
    13271327     * @since 1.5.0
    1328      * @deprecated 5.5.0 Use {@see 'wp_blocklist_check'} instead.
     1328     * @deprecated 5.5.0 Use {@see 'wp_check_comment_disallowed_list'} instead.
    13291329     *
    13301330     * @param string $author     Comment author.
     
    13391339        array( $author, $email, $url, $comment, $user_ip, $user_agent ),
    13401340        '5.5.0',
    1341         'wp_blocklist_check',
     1341        'wp_check_comment_disallowed_list',
    13421342        __( 'Please consider writing more inclusive code.' )
    13431343    );
     
    13551355     * @param string $user_agent Comment author's browser user agent.
    13561356     */
    1357     do_action( 'wp_blocklist_check', $author, $email, $url, $comment, $user_ip, $user_agent );
    1358 
    1359     $mod_keys = trim( get_option( 'blocklist_keys' ) );
     1357    do_action( 'wp_check_comment_disallowed_list', $author, $email, $url, $comment, $user_ip, $user_agent );
     1358
     1359    $mod_keys = trim( get_option( 'disallowed_keys' ) );
    13601360    if ( '' === $mod_keys ) {
    13611361        return false; // If moderation keys are empty.
  • trunk/src/wp-includes/deprecated.php

    r48566 r48575  
    40264026 *
    40274027 * @since 1.5.0
    4028  * @deprecated 5.5.0 Use wp_blocklist_check() instead.
     4028 * @deprecated 5.5.0 Use wp_check_comment_disallowed_list() instead.
    40294029 *                   Please consider writing more inclusive code.
    40304030 *
     
    40384038 */
    40394039function wp_blacklist_check( $author, $email, $url, $comment, $user_ip, $user_agent ) {
    4040     _deprecated_function( __FUNCTION__, '5.5.0', 'wp_blocklist_check()' );
    4041 
    4042     return wp_blocklist_check( $author, $email, $url, $comment, $user_ip, $user_agent );
     4040    _deprecated_function( __FUNCTION__, '5.5.0', 'wp_check_comment_disallowed_list()' );
     4041
     4042    return wp_check_comment_disallowed_list( $author, $email, $url, $comment, $user_ip, $user_agent );
    40434043}
    40444044
  • trunk/src/wp-includes/formatting.php

    r48444 r48575  
    48604860
    48614861        case 'moderation_keys':
    4862         case 'blocklist_keys':
     4862        case 'disallowed_keys':
    48634863            $value = $wpdb->strip_invalid_text_for_column( $wpdb->options, 'option_value', $value );
    48644864            if ( is_wp_error( $value ) ) {
  • trunk/src/wp-includes/option.php

    r48477 r48575  
    3434    if ( empty( $option ) ) {
    3535        return false;
     36    }
     37
     38    /*
     39     * Until a proper _deprecated_option() function can be introduced,
     40     * redirect requests to deprecated keys to the new, correct ones.
     41     */
     42    $deprecated_keys = array(
     43        'blacklist_keys'    => 'disallowed_keys',
     44        'comment_whitelist' => 'comment_previously_approved',
     45    );
     46
     47    if ( ! wp_installing() && isset( $deprecated_keys[ $option ] ) ) {
     48        _deprecated_argument(
     49            __FUNCTION__,
     50            '5.5.0',
     51            sprintf(
     52                /* translators: 1: Deprecated option key, 2: New option key. */
     53                __( 'The "%1$s" option key has been renamed to "%2$s".' ),
     54                $option,
     55                $deprecated_keys[ $option ]
     56            )
     57        );
     58        return get_option( $deprecated_keys[ $option ], $default );
    3659    }
    3760
     
    314337    }
    315338
     339    /*
     340     * Until a proper _deprecated_option() function can be introduced,
     341     * redirect requests to deprecated keys to the new, correct ones.
     342     */
     343    $deprecated_keys = array(
     344        'blacklist_keys'    => 'disallowed_keys',
     345        'comment_whitelist' => 'comment_previously_approved',
     346    );
     347
     348    if ( ! wp_installing() && isset( $deprecated_keys[ $option ] ) ) {
     349        _deprecated_argument(
     350            __FUNCTION__,
     351            '5.5.0',
     352            sprintf(
     353                /* translators: 1: Deprecated option key, 2: New option key. */
     354                __( 'The "%1$s" option key has been renamed to "%2$s".' ),
     355                $option,
     356                $deprecated_keys[ $option ]
     357            )
     358        );
     359        return update_option( $deprecated_keys[ $option ], $value, $autoload );
     360    }
     361
    316362    wp_protect_special_option( $option );
    317363
     
    476522    if ( empty( $option ) ) {
    477523        return false;
     524    }
     525
     526    /*
     527     * Until a proper _deprecated_option() function can be introduced,
     528     * redirect requests to deprecated keys to the new, correct ones.
     529     */
     530    $deprecated_keys = array(
     531        'blacklist_keys'    => 'disallowed_keys',
     532        'comment_whitelist' => 'comment_previously_approved',
     533    );
     534
     535    if ( ! wp_installing() && isset( $deprecated_keys[ $option ] ) ) {
     536        _deprecated_argument(
     537            __FUNCTION__,
     538            '5.5.0',
     539            sprintf(
     540                /* translators: 1: Deprecated option key, 2: New option key. */
     541                __( 'The "%1$s" option key has been renamed to "%2$s".' ),
     542                $option,
     543                $deprecated_keys[ $option ]
     544            )
     545        );
     546        return add_option( $deprecated_keys[ $option ], $value, $deprecated, $autoload );
    478547    }
    479548
  • trunk/tests/phpunit/tests/comment/wpBlacklistCheck.php

    r48121 r48575  
    66class Tests_WP_Blocklist_Check extends WP_UnitTestCase {
    77
    8     public function test_should_return_true_when_content_matches_blocklist_keys() {
     8    public function test_should_return_true_when_content_matches_disallowed_keys() {
    99        $author       = 'Sting';
    1010        $author_email = 'sting@example.com';
     
    1414        $user_agent   = '';
    1515
    16         update_option( 'blocklist_keys', "well\nfoo" );
     16        update_option( 'disallowed_keys', "well\nfoo" );
    1717
    18         $result = wp_blocklist_check( $author, $author_email, $author_url, $comment, $author_ip, $user_agent );
     18        $result = wp_check_comment_disallowed_list( $author, $author_email, $author_url, $comment, $author_ip, $user_agent );
    1919
    2020        $this->assertTrue( $result );
     
    2424     * @ticket 37208
    2525     */
    26     public function test_should_return_true_when_content_with_html_matches_blocklist_keys() {
     26    public function test_should_return_true_when_content_with_html_matches_disallowed_keys() {
    2727        $author       = 'Sting';
    2828        $author_email = 'sting@example.com';
     
    3232        $user_agent   = '';
    3333
    34         update_option( 'blocklist_keys', "halfway\nfoo" );
     34        update_option( 'disallowed_keys', "halfway\nfoo" );
    3535
    36         $result = wp_blocklist_check( $author, $author_email, $author_url, $comment, $author_ip, $user_agent );
     36        $result = wp_check_comment_disallowed_list( $author, $author_email, $author_url, $comment, $author_ip, $user_agent );
    3737
    3838        $this->assertTrue( $result );
    3939    }
    4040
    41     public function test_should_return_true_when_author_matches_blocklist_keys() {
     41    public function test_should_return_true_when_author_matches_disallowed_keys() {
    4242        $author       = 'Sideshow Mel';
    4343        $author_email = 'mel@example.com';
     
    4747        $user_agent   = '';
    4848
    49         update_option( 'blocklist_keys', "sideshow\nfoo" );
     49        update_option( 'disallowed_keys', "sideshow\nfoo" );
    5050
    51         $result = wp_blocklist_check( $author, $author_email, $author_url, $comment, $author_ip, $user_agent );
     51        $result = wp_check_comment_disallowed_list( $author, $author_email, $author_url, $comment, $author_ip, $user_agent );
    5252
    5353        $this->assertTrue( $result );
    5454    }
    5555
    56     public function test_should_return_true_when_url_matches_blocklist_keys() {
     56    public function test_should_return_true_when_url_matches_disallowed_keys() {
    5757        $author       = 'Rainier Wolfcastle';
    5858        $author_email = 'rainier@wolfcastle.com';
     
    6262        $user_agent   = '';
    6363
    64         update_option( 'blocklist_keys', "example\nfoo" );
     64        update_option( 'disallowed_keys', "example\nfoo" );
    6565
    66         $result = wp_blocklist_check( $author, $author_email, $author_url, $comment, $author_ip, $user_agent );
     66        $result = wp_check_comment_disallowed_list( $author, $author_email, $author_url, $comment, $author_ip, $user_agent );
    6767
    6868        $this->assertTrue( $result );
     
    7272     * @ticket 37208
    7373     */
    74     public function test_should_return_true_when_link_matches_blocklist_keys() {
     74    public function test_should_return_true_when_link_matches_disallowed_keys() {
    7575        $author       = 'Rainier Wolfcastle';
    7676        $author_email = 'rainier@wolfcastle.com';
     
    8080        $user_agent   = '';
    8181
    82         update_option( 'blocklist_keys', '/spam/' );
     82        update_option( 'disallowed_keys', '/spam/' );
    8383
    84         $result = wp_blocklist_check( $author, $author_email, $author_url, $comment, $author_ip, $user_agent );
     84        $result = wp_check_comment_disallowed_list( $author, $author_email, $author_url, $comment, $author_ip, $user_agent );
    8585
    8686        $this->assertTrue( $result );
     
    9595        $user_agent   = '';
    9696
    97         update_option( 'blocklist_keys', "sideshow\nfoobar" );
     97        update_option( 'disallowed_keys', "sideshow\nfoobar" );
    9898
    99         $result = wp_blocklist_check( $author, $author_email, $author_url, $comment, $author_ip, $user_agent );
     99        $result = wp_check_comment_disallowed_list( $author, $author_email, $author_url, $comment, $author_ip, $user_agent );
    100100
    101101        $this->assertFalse( $result );
Note: See TracChangeset for help on using the changeset viewer.