Changeset 53698
- Timestamp:
- 07/12/2022 09:03:39 PM (2 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/pluggable.php
r53483 r53698 2111 2111 $blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); 2112 2112 2113 if ( 'user' !== $notify ) { 2113 /** 2114 * Filters whether the admin is notified of a new user registration. 2115 * 2116 * @since 6.1.0 2117 * 2118 * @param bool $send Whether to send the email. Default true. 2119 * @param WP_User $user User object for new user. 2120 */ 2121 $send_notification_to_admin = apply_filters( 'wp_send_new_user_notification_to_admin', true, $user ); 2122 2123 if ( 'user' !== $notify && true === $send_notification_to_admin ) { 2114 2124 $switched_locale = switch_to_locale( get_locale() ); 2115 2125 … … 2159 2169 } 2160 2170 2171 /** 2172 * Filters whether the user is notified of their new user registration. 2173 * 2174 * @since 6.1.0 2175 * 2176 * @param bool $send Whether to send the email. Default true. 2177 * @param WP_User $user User object for new user. 2178 */ 2179 $send_notification_to_user = apply_filters( 'wp_send_new_user_notification_to_user', true, $user ); 2180 2161 2181 // `$deprecated` was pre-4.3 `$plaintext_pass`. An empty `$plaintext_pass` didn't sent a user notification. 2162 if ( 'admin' === $notify || ( empty( $deprecated ) && empty( $notify ) ) ) {2182 if ( 'admin' === $notify || true !== $send_notification_to_user || ( empty( $deprecated ) && empty( $notify ) ) ) { 2163 2183 return; 2164 2184 } -
trunk/tests/phpunit/tests/user.php
r53408 r53698 1345 1345 1346 1346 /** 1347 * Test that admin notification of a new user registration is dependent 1348 * on the 'wp_send_new_user_notification_to_admin' filter. 1349 * 1350 * @dataProvider data_wp_send_new_user_notification_filters 1351 * 1352 * @ticket 54874 1353 * 1354 * @covers ::wp_new_user_notification 1355 * 1356 * @param bool $expected Whether the email should be sent. 1357 * @param string $callback The callback to pass to the filter. 1358 */ 1359 public function test_wp_send_new_user_notification_to_admin_filter( $expected, $callback ) { 1360 reset_phpmailer_instance(); 1361 1362 add_filter( 'wp_send_new_user_notification_to_admin', $callback ); 1363 1364 wp_new_user_notification( self::$contrib_id, null, 'admin' ); 1365 1366 $mailer = tests_retrieve_phpmailer_instance(); 1367 $recipient = $mailer->get_recipient( 'to' ); 1368 $actual = $recipient ? WP_TESTS_EMAIL === $recipient->address : false; 1369 1370 $this->assertSame( $expected, $actual, 'Admin email result was not as expected in test_wp_send_new_user_notification_to_admin_filter' ); 1371 } 1372 1373 /** 1374 * Test that user notification of a new user registration is dependent 1375 * on the 'wp_send_new_user_notification_to_user' filter. 1376 * 1377 * @dataProvider data_wp_send_new_user_notification_filters 1378 * 1379 * @ticket 54874 1380 * 1381 * @covers ::wp_new_user_notification 1382 * 1383 * @param bool $expected Whether the email should be sent. 1384 * @param string $callback The callback to pass to the filter. 1385 */ 1386 public function test_wp_send_new_user_notification_to_user_filter( $expected, $callback ) { 1387 reset_phpmailer_instance(); 1388 1389 add_filter( 'wp_send_new_user_notification_to_user', $callback ); 1390 1391 wp_new_user_notification( self::$contrib_id, null, 'user' ); 1392 1393 $mailer = tests_retrieve_phpmailer_instance(); 1394 $recipient = $mailer->get_recipient( 'to' ); 1395 $actual = $recipient ? 'blackburn@battlefield3.com' === $recipient->address : false; 1396 1397 $this->assertSame( $expected, $actual, 'User email result was not as expected in test_wp_send_new_user_notification_to_user_filter' ); 1398 } 1399 1400 /** 1401 * Data provider. 1402 * 1403 * @return array 1404 */ 1405 public function data_wp_send_new_user_notification_filters() { 1406 return array( 1407 'true' => array( 1408 'expected' => true, 1409 'callback' => '__return_true', 1410 ), 1411 'false' => array( 1412 'expected' => false, 1413 'callback' => '__return_false', 1414 ), 1415 'null' => array( 1416 'expected' => false, 1417 'callback' => '__return_null', 1418 ), 1419 'empty array' => array( 1420 'expected' => false, 1421 'callback' => '__return_empty_array', 1422 ), 1423 'zero int' => array( 1424 'expected' => false, 1425 'callback' => '__return_zero', 1426 ), 1427 'zero float' => array( 1428 'expected' => false, 1429 'callback' => array( $this, 'cb_return_zero_float' ), 1430 ), 1431 'zero string' => array( 1432 'expected' => false, 1433 'callback' => array( $this, 'cb_return_zero_string' ), 1434 ), 1435 'array( true )' => array( 1436 'expected' => false, 1437 'callback' => array( $this, 'cb_return_array_true' ), 1438 ), 1439 ); 1440 } 1441 1442 /** 1443 * Callback that returns 0.0. 1444 * 1445 * @return float 0.0. 1446 */ 1447 public function cb_return_zero_float() { 1448 return 0.0; 1449 } 1450 1451 /** 1452 * Callback that returns '0'. 1453 * 1454 * @return string '0'. 1455 */ 1456 public function cb_return_zero_string() { 1457 return '0'; 1458 } 1459 1460 /** 1461 * Callback that returns array( true ). 1462 * 1463 * @return array array( true ) 1464 */ 1465 public function cb_return_array_true() { 1466 return array( true ); 1467 } 1468 1469 /** 1347 1470 * Ensure blog's admin email change notification emails do not contain encoded HTML entities 1348 1471 *
Note: See TracChangeset
for help on using the changeset viewer.