Archived
WP 4.0++
This commit is contained in:
1 parent
ff5eca21d2
commit
03777ef2b0
578 files changed
+36396
-19889
No files matched your search
@@ -26,7 +26,7 @@ class WP_Error {
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $errors = array();
|
||||
private $errors = array();
|
||||
|
||||
/**
|
||||
* Stores the list of data for error codes.
|
||||
@@ -35,17 +35,18 @@ class WP_Error {
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $error_data = array();
|
||||
private $error_data = array();
|
||||
|
||||
/**
|
||||
* Constructor - Sets up error message.
|
||||
* Initialize the error.
|
||||
*
|
||||
* If code parameter is empty then nothing will be done. It is possible to
|
||||
* add multiple messages to the same code, but with other methods in the
|
||||
* class.
|
||||
* If `$code` is empty, the other parameters will be ignored.
|
||||
* When `$code` is not empty, `$message` will be used even if
|
||||
* it is empty. The `$data` parameter will be used only if it
|
||||
* is not empty.
|
||||
*
|
||||
* All parameters are optional, but if the code parameter is set, then the
|
||||
* data parameter is optional.
|
||||
* Though the class is constructed with a single error code and
|
||||
* message, multiple codes can be added using the `add()` method.
|
||||
*
|
||||
* @since 2.1.0
|
||||
*
|
||||
@@ -54,7 +55,7 @@ class WP_Error {
|
||||
* @param mixed $data Optional. Error data.
|
||||
* @return WP_Error
|
||||
*/
|
||||
function __construct($code = '', $message = '', $data = '') {
|
||||
public function __construct( $code = '', $message = '', $data = '' ) {
|
||||
if ( empty($code) )
|
||||
return;
|
||||
|
||||
@@ -64,6 +65,58 @@ class WP_Error {
|
||||
$this->error_data[$code] = $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make private properties readable for backwards compatibility.
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @access public
|
||||
*
|
||||
* @param string $name Property to get.
|
||||
* @return mixed Property.
|
||||
*/
|
||||
public function __get( $name ) {
|
||||
return $this->$name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make private properties settable for backwards compatibility.
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @access public
|
||||
*
|
||||
* @param string $name Property to set.
|
||||
* @param mixed $value Property value.
|
||||
* @return mixed Newly-set property.
|
||||
*/
|
||||
public function __set( $name, $value ) {
|
||||
return $this->$name = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make private properties checkable for backwards compatibility.
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @access public
|
||||
*
|
||||
* @param string $name Property to check if set.
|
||||
* @return bool Whether the property is set.
|
||||
*/
|
||||
public function __isset( $name ) {
|
||||
return isset( $this->$name );
|
||||
}
|
||||
|
||||
/**
|
||||
* Make private properties un-settable for backwards compatibility.
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @access public
|
||||
*
|
||||
* @param string $name Property to unset.
|
||||
*/
|
||||
public function __unset( $name ) {
|
||||
unset( $this->$name );
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve all error codes.
|
||||
*
|
||||
@@ -72,7 +125,7 @@ class WP_Error {
|
||||
*
|
||||
* @return array List of error codes, if available.
|
||||
*/
|
||||
function get_error_codes() {
|
||||
public function get_error_codes() {
|
||||
if ( empty($this->errors) )
|
||||
return array();
|
||||
|
||||
@@ -87,7 +140,7 @@ class WP_Error {
|
||||
*
|
||||
* @return string|int Empty string, if no error codes.
|
||||
*/
|
||||
function get_error_code() {
|
||||
public function get_error_code() {
|
||||
$codes = $this->get_error_codes();
|
||||
|
||||
if ( empty($codes) )
|
||||
@@ -104,7 +157,7 @@ class WP_Error {
|
||||
* @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).
|
||||
*/
|
||||
function get_error_messages($code = '') {
|
||||
public function get_error_messages($code = '') {
|
||||
// Return all messages if no code specified.
|
||||
if ( empty($code) ) {
|
||||
$all_messages = array();
|
||||
@@ -131,7 +184,7 @@ class WP_Error {
|
||||
* @param string|int $code Optional. Error code to retrieve message.
|
||||
* @return string
|
||||
*/
|
||||
function get_error_message($code = '') {
|
||||
public function get_error_message($code = '') {
|
||||
if ( empty($code) )
|
||||
$code = $this->get_error_code();
|
||||
$messages = $this->get_error_messages($code);
|
||||
@@ -148,7 +201,7 @@ class WP_Error {
|
||||
* @param string|int $code Optional. Error code.
|
||||
* @return mixed Null, if no errors.
|
||||
*/
|
||||
function get_error_data($code = '') {
|
||||
public function get_error_data($code = '') {
|
||||
if ( empty($code) )
|
||||
$code = $this->get_error_code();
|
||||
|
||||
@@ -158,7 +211,7 @@ class WP_Error {
|
||||
}
|
||||
|
||||
/**
|
||||
* Append more error messages to list of error messages.
|
||||
* Add an error or append additional message to an existing error.
|
||||
*
|
||||
* @since 2.1.0
|
||||
* @access public
|
||||
@@ -167,7 +220,7 @@ class WP_Error {
|
||||
* @param string $message Error message.
|
||||
* @param mixed $data Optional. Error data.
|
||||
*/
|
||||
function add($code, $message, $data = '') {
|
||||
public function add($code, $message, $data = '') {
|
||||
$this->errors[$code][] = $message;
|
||||
if ( ! empty($data) )
|
||||
$this->error_data[$code] = $data;
|
||||
@@ -183,7 +236,7 @@ class WP_Error {
|
||||
* @param mixed $data Error data.
|
||||
* @param string|int $code Error code.
|
||||
*/
|
||||
function add_data($data, $code = '') {
|
||||
public function add_data($data, $code = '') {
|
||||
if ( empty($code) )
|
||||
$code = $this->get_error_code();
|
||||
|
||||
|
||||
Reference in new issue
Block a user