diff --git a/src/wp-includes/class-wp-error.php b/src/wp-includes/class-wp-error.php
index ae8b237801..4925d11166 100644
|
a
|
b
|
class WP_Error { |
| 31 | 31 | * |
| 32 | 32 | * @since 2.1.0 |
| 33 | 33 | * @var array |
| 34 | | */ |
| | 34 | */ |
| 35 | 35 | public $error_data = array(); |
| 36 | 36 | |
| 37 | 37 | /** |
| … |
… |
class WP_Error { |
| 71 | 71 | * @return array List of error codes, if available. |
| 72 | 72 | */ |
| 73 | 73 | public function get_error_codes() { |
| 74 | | if ( empty( $this->errors ) ) { |
| | 74 | if ( ! $this->has_errors() ) { |
| 75 | 75 | return array(); |
| 76 | 76 | } |
| 77 | 77 | |
| … |
… |
class WP_Error { |
| 161 | 161 | } |
| 162 | 162 | } |
| 163 | 163 | |
| | 164 | /** |
| | 165 | * Verify if instance contains errors. |
| | 166 | * |
| | 167 | * @since 5.0.0 |
| | 168 | * |
| | 169 | * @return bool |
| | 170 | */ |
| | 171 | public function has_errors() { |
| | 172 | if ( ! empty( $this->errors ) ) { |
| | 173 | return true; |
| | 174 | } |
| | 175 | return false; |
| | 176 | } |
| | 177 | |
| 164 | 178 | /** |
| 165 | 179 | * Add an error or append additional message to an existing error. |
| 166 | 180 | * |
diff --git a/tests/phpunit/tests/general/wpError.php b/tests/phpunit/tests/general/wpError.php
index 655c15a1b3..acef3ca21f 100644
|
a
|
b
|
class Tests_WP_Error extends WP_UnitTestCase { |
| 415 | 415 | $this->assertSame( 'data2', $this->WP_Error->get_error_data( 'code' ) ); |
| 416 | 416 | } |
| 417 | 417 | |
| | 418 | /** |
| | 419 | * @covers WP_Error::has_errors() |
| | 420 | */ |
| | 421 | public function test_has_errors_with_no_errors_returns_false() { |
| | 422 | $this->assertFalse( $this->WP_Error->has_errors() ); |
| | 423 | } |
| | 424 | |
| | 425 | /** |
| | 426 | * @covers WP_Error::has_errors() |
| | 427 | */ |
| | 428 | public function test_has_errors_with_errors_returns_true() { |
| | 429 | $this->WP_Error->add( 'code', 'message', 'data' ); |
| | 430 | $this->assertTrue( $this->WP_Error->has_errors() ); |
| | 431 | } |
| | 432 | |
| 418 | 433 | /** |
| 419 | 434 | * @covers WP_Error::add() |
| 420 | 435 | */ |