Commit d68fc631 authored by Aaron Jorbin's avatar Aaron Jorbin
Browse files

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


Built from https://develop.svn.wordpress.org/trunk@48575


git-svn-id: https://core.svn.wordpress.org/trunk@48337 1a063a9b-81f0-0310-95a4-ce76da25c4cd
parent a7f58974
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -532,7 +532,7 @@ function populate_options( array $options = array() ) {
		'admin_email_lifespan'            => ( time() + 6 * MONTH_IN_SECONDS ),

		// 5.5.0
		'blocklist_keys'                  => '',
		'disallowed_keys'                 => '',
		'comment_previously_approved'     => 1,
		'auto_plugin_theme_update_emails' => array(),
	);
@@ -556,7 +556,7 @@ function populate_options( array $options = array() ) {
	$fat_options = array(
		'moderation_keys',
		'recently_edited',
		'blocklist_keys',
		'disallowed_keys',
		'uninstall_plugins',
		'auto_plugin_theme_update_emails',
	);
+13 −5
Original line number Diff line number Diff line
@@ -2177,15 +2177,23 @@ function upgrade_550() {
		update_option( 'finished_updating_comment_type', 0 );
		wp_schedule_single_event( time() + ( 1 * MINUTE_IN_SECONDS ), 'wp_update_comment_type_batch' );

		// Use more clear and inclusive language.
		$blocklist = get_option( 'blacklist_keys', '' );
		update_option( 'blocklist_keys', $blocklist );
		delete_option( 'blacklist_keys' );

		$comment_previously_approved = get_option( 'comment_whitelist', '' );
		update_option( 'comment_previously_approved', $comment_previously_approved );
		delete_option( 'comment_whitelist' );
	}

	if ( $wp_current_db_version < 48572 ) {
		// Use more clear and inclusive language.
		$disallowed_list = get_option( 'blacklist_keys' );

		if ( false === $disallowed_list ) {
			$disallowed_list = get_option( 'blocklist_keys' );
		}

		update_option( 'disallowed_keys', $disallowed_list );
		delete_option( 'blacklist_keys' );
		delete_option( 'blocklist_keys' );
	}
}

/**
+4 −4
Original line number Diff line number Diff line
@@ -204,11 +204,11 @@ printf(
</fieldset></td>
</tr>
<tr>
<th scope="row"><?php _e( 'Comment Blocklist' ); ?></th>
<td><fieldset><legend class="screen-reader-text"><span><?php _e( 'Comment Blocklist' ); ?></span></legend>
<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>
<th scope="row"><?php _e( 'Disallowed Comment Keys' ); ?></th>
<td><fieldset><legend class="screen-reader-text"><span><?php _e( 'Disallowed Comment Keys' ); ?></span></legend>
<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>
<p>
<textarea name="blocklist_keys" rows="10" cols="50" id="blocklist_keys" class="large-text code"><?php echo esc_textarea( get_option( 'blocklist_keys' ) ); ?></textarea>
<textarea name="disallowed_keys" rows="10" cols="50" id="disallowed_keys" class="large-text code"><?php echo esc_textarea( get_option( 'disallowed_keys' ) ); ?></textarea>
</p>
</fieldset></td>
</tr>
+1 −1
Original line number Diff line number Diff line
@@ -103,7 +103,7 @@ $allowed_options = array(
		'comment_previously_approved',
		'comment_max_links',
		'moderation_keys',
		'blocklist_keys',
		'disallowed_keys',
		'show_avatars',
		'avatar_rating',
		'avatar_default',
+6 −6
Original line number Diff line number Diff line
@@ -820,7 +820,7 @@ function wp_allow_comment( $commentdata, $wp_error = false ) {
			$approved = 0;
		}

		if ( wp_blocklist_check(
		if ( wp_check_comment_disallowed_list(
			$commentdata['comment_author'],
			$commentdata['comment_author_email'],
			$commentdata['comment_author_url'],
@@ -1320,12 +1320,12 @@ function wp_check_comment_data_max_lengths( $comment_data ) {
 * @param string $user_agent The author's browser user agent
 * @return bool True if comment contains disallowed content, false if comment does not
 */
function wp_blocklist_check( $author, $email, $url, $comment, $user_ip, $user_agent ) {
function wp_check_comment_disallowed_list( $author, $email, $url, $comment, $user_ip, $user_agent ) {
	/**
	 * Fires before the comment is tested for disallowed characters or words.
	 *
	 * @since 1.5.0
	 * @deprecated 5.5.0 Use {@see 'wp_blocklist_check'} instead.
	 * @deprecated 5.5.0 Use {@see 'wp_check_comment_disallowed_list'} instead.
	 *
	 * @param string $author     Comment author.
	 * @param string $email      Comment author's email.
@@ -1338,7 +1338,7 @@ function wp_blocklist_check( $author, $email, $url, $comment, $user_ip, $user_ag
		'wp_blacklist_check',
		array( $author, $email, $url, $comment, $user_ip, $user_agent ),
		'5.5.0',
		'wp_blocklist_check',
		'wp_check_comment_disallowed_list',
		__( 'Please consider writing more inclusive code.' )
	);

@@ -1354,9 +1354,9 @@ function wp_blocklist_check( $author, $email, $url, $comment, $user_ip, $user_ag
	 * @param string $user_ip    Comment author's IP address.
	 * @param string $user_agent Comment author's browser user agent.
	 */
	do_action( 'wp_blocklist_check', $author, $email, $url, $comment, $user_ip, $user_agent );
	do_action( 'wp_check_comment_disallowed_list', $author, $email, $url, $comment, $user_ip, $user_agent );

	$mod_keys = trim( get_option( 'blocklist_keys' ) );
	$mod_keys = trim( get_option( 'disallowed_keys' ) );
	if ( '' === $mod_keys ) {
		return false; // If moderation keys are empty.
	}
Loading