mirror of
https://github.com/WordPress/WordPress.git
synced 2025-01-03 06:57:35 +01:00
Add access modifiers to methods/members in WP_Error
. Add a magic __get()
method for BC.
See #27881, #22234. Built from https://develop.svn.wordpress.org/trunk@28511 git-svn-id: http://core.svn.wordpress.org/trunk@28337 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
aabcfd658b
commit
72d096b007
@ -26,7 +26,7 @@ class WP_Error {
|
|||||||
* @var array
|
* @var array
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
var $errors = array();
|
private $errors = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stores the list of data for error codes.
|
* Stores the list of data for error codes.
|
||||||
@ -35,7 +35,7 @@ class WP_Error {
|
|||||||
* @var array
|
* @var array
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
var $error_data = array();
|
private $error_data = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor - Sets up error message.
|
* Constructor - Sets up error message.
|
||||||
@ -54,7 +54,7 @@ class WP_Error {
|
|||||||
* @param mixed $data Optional. Error data.
|
* @param mixed $data Optional. Error data.
|
||||||
* @return WP_Error
|
* @return WP_Error
|
||||||
*/
|
*/
|
||||||
function __construct($code = '', $message = '', $data = '') {
|
public function __construct($code = '', $message = '', $data = '') {
|
||||||
if ( empty($code) )
|
if ( empty($code) )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -64,6 +64,17 @@ class WP_Error {
|
|||||||
$this->error_data[$code] = $data;
|
$this->error_data[$code] = $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Make private properties readable for backwards compatibility
|
||||||
|
*
|
||||||
|
* @since 4.0.0
|
||||||
|
* @param string $name
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function __get( $name ) {
|
||||||
|
return $this->$name;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve all error codes.
|
* Retrieve all error codes.
|
||||||
*
|
*
|
||||||
@ -72,7 +83,7 @@ class WP_Error {
|
|||||||
*
|
*
|
||||||
* @return array List of error codes, if available.
|
* @return array List of error codes, if available.
|
||||||
*/
|
*/
|
||||||
function get_error_codes() {
|
public function get_error_codes() {
|
||||||
if ( empty($this->errors) )
|
if ( empty($this->errors) )
|
||||||
return array();
|
return array();
|
||||||
|
|
||||||
@ -87,7 +98,7 @@ class WP_Error {
|
|||||||
*
|
*
|
||||||
* @return string|int Empty string, if no error codes.
|
* @return string|int Empty string, if no error codes.
|
||||||
*/
|
*/
|
||||||
function get_error_code() {
|
public function get_error_code() {
|
||||||
$codes = $this->get_error_codes();
|
$codes = $this->get_error_codes();
|
||||||
|
|
||||||
if ( empty($codes) )
|
if ( empty($codes) )
|
||||||
@ -104,7 +115,7 @@ class WP_Error {
|
|||||||
* @param string|int $code Optional. Retrieve messages matching code, if exists.
|
* @param string|int $code Optional. Retrieve messages matching code, if exists.
|
||||||
* @return array Error strings on success, or empty array on failure (if using code parameter).
|
* @return array Error strings on success, or empty array on failure (if using code parameter).
|
||||||
*/
|
*/
|
||||||
function get_error_messages($code = '') {
|
public function get_error_messages($code = '') {
|
||||||
// Return all messages if no code specified.
|
// Return all messages if no code specified.
|
||||||
if ( empty($code) ) {
|
if ( empty($code) ) {
|
||||||
$all_messages = array();
|
$all_messages = array();
|
||||||
@ -131,7 +142,7 @@ class WP_Error {
|
|||||||
* @param string|int $code Optional. Error code to retrieve message.
|
* @param string|int $code Optional. Error code to retrieve message.
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function get_error_message($code = '') {
|
public function get_error_message($code = '') {
|
||||||
if ( empty($code) )
|
if ( empty($code) )
|
||||||
$code = $this->get_error_code();
|
$code = $this->get_error_code();
|
||||||
$messages = $this->get_error_messages($code);
|
$messages = $this->get_error_messages($code);
|
||||||
@ -148,7 +159,7 @@ class WP_Error {
|
|||||||
* @param string|int $code Optional. Error code.
|
* @param string|int $code Optional. Error code.
|
||||||
* @return mixed Null, if no errors.
|
* @return mixed Null, if no errors.
|
||||||
*/
|
*/
|
||||||
function get_error_data($code = '') {
|
public function get_error_data($code = '') {
|
||||||
if ( empty($code) )
|
if ( empty($code) )
|
||||||
$code = $this->get_error_code();
|
$code = $this->get_error_code();
|
||||||
|
|
||||||
@ -167,7 +178,7 @@ class WP_Error {
|
|||||||
* @param string $message Error message.
|
* @param string $message Error message.
|
||||||
* @param mixed $data Optional. Error data.
|
* @param mixed $data Optional. Error data.
|
||||||
*/
|
*/
|
||||||
function add($code, $message, $data = '') {
|
public function add($code, $message, $data = '') {
|
||||||
$this->errors[$code][] = $message;
|
$this->errors[$code][] = $message;
|
||||||
if ( ! empty($data) )
|
if ( ! empty($data) )
|
||||||
$this->error_data[$code] = $data;
|
$this->error_data[$code] = $data;
|
||||||
@ -183,7 +194,7 @@ class WP_Error {
|
|||||||
* @param mixed $data Error data.
|
* @param mixed $data Error data.
|
||||||
* @param string|int $code Error code.
|
* @param string|int $code Error code.
|
||||||
*/
|
*/
|
||||||
function add_data($data, $code = '') {
|
public function add_data($data, $code = '') {
|
||||||
if ( empty($code) )
|
if ( empty($code) )
|
||||||
$code = $this->get_error_code();
|
$code = $this->get_error_code();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user