diff --git a/wp-admin/includes/ajax-actions.php b/wp-admin/includes/ajax-actions.php index 4593d0f3c7..8d5fd4c5e5 100644 --- a/wp-admin/includes/ajax-actions.php +++ b/wp-admin/includes/ajax-actions.php @@ -3692,7 +3692,7 @@ function wp_ajax_install_theme() { $status['errorCode'] = $skin->result->get_error_code(); $status['errorMessage'] = $skin->result->get_error_message(); wp_send_json_error( $status ); - } elseif ( $skin->get_errors()->get_error_code() ) { + } elseif ( $skin->get_errors()->has_errors() ) { $status['errorMessage'] = $skin->get_error_messages(); wp_send_json_error( $status ); } elseif ( is_null( $result ) ) { @@ -3702,7 +3702,7 @@ function wp_ajax_install_theme() { $status['errorMessage'] = __( 'Unable to connect to the filesystem. Please confirm your credentials.' ); // Pass through the error from WP_Filesystem if one was raised. - if ( $wp_filesystem instanceof WP_Filesystem_Base && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->get_error_code() ) { + if ( $wp_filesystem instanceof WP_Filesystem_Base && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->has_errors() ) { $status['errorMessage'] = esc_html( $wp_filesystem->errors->get_error_message() ); } @@ -3805,7 +3805,7 @@ function wp_ajax_update_theme() { $status['errorCode'] = $skin->result->get_error_code(); $status['errorMessage'] = $skin->result->get_error_message(); wp_send_json_error( $status ); - } elseif ( $skin->get_errors()->get_error_code() ) { + } elseif ( $skin->get_errors()->has_errors() ) { $status['errorMessage'] = $skin->get_error_messages(); wp_send_json_error( $status ); } elseif ( is_array( $result ) && ! empty( $result[ $stylesheet ] ) ) { @@ -3829,7 +3829,7 @@ function wp_ajax_update_theme() { $status['errorMessage'] = __( 'Unable to connect to the filesystem. Please confirm your credentials.' ); // Pass through the error from WP_Filesystem if one was raised. - if ( $wp_filesystem instanceof WP_Filesystem_Base && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->get_error_code() ) { + if ( $wp_filesystem instanceof WP_Filesystem_Base && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->has_errors() ) { $status['errorMessage'] = esc_html( $wp_filesystem->errors->get_error_message() ); } @@ -3891,7 +3891,7 @@ function wp_ajax_delete_theme() { $status['errorMessage'] = __( 'Unable to connect to the filesystem. Please confirm your credentials.' ); // Pass through the error from WP_Filesystem if one was raised. - if ( $wp_filesystem instanceof WP_Filesystem_Base && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->get_error_code() ) { + if ( $wp_filesystem instanceof WP_Filesystem_Base && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->has_errors() ) { $status['errorMessage'] = esc_html( $wp_filesystem->errors->get_error_message() ); } @@ -3980,7 +3980,7 @@ function wp_ajax_install_plugin() { $status['errorCode'] = $skin->result->get_error_code(); $status['errorMessage'] = $skin->result->get_error_message(); wp_send_json_error( $status ); - } elseif ( $skin->get_errors()->get_error_code() ) { + } elseif ( $skin->get_errors()->has_errors() ) { $status['errorMessage'] = $skin->get_error_messages(); wp_send_json_error( $status ); } elseif ( is_null( $result ) ) { @@ -3990,7 +3990,7 @@ function wp_ajax_install_plugin() { $status['errorMessage'] = __( 'Unable to connect to the filesystem. Please confirm your credentials.' ); // Pass through the error from WP_Filesystem if one was raised. - if ( $wp_filesystem instanceof WP_Filesystem_Base && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->get_error_code() ) { + if ( $wp_filesystem instanceof WP_Filesystem_Base && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->has_errors() ) { $status['errorMessage'] = esc_html( $wp_filesystem->errors->get_error_message() ); } @@ -4081,7 +4081,7 @@ function wp_ajax_update_plugin() { $status['errorCode'] = $skin->result->get_error_code(); $status['errorMessage'] = $skin->result->get_error_message(); wp_send_json_error( $status ); - } elseif ( $skin->get_errors()->get_error_code() ) { + } elseif ( $skin->get_errors()->has_errors() ) { $status['errorMessage'] = $skin->get_error_messages(); wp_send_json_error( $status ); } elseif ( is_array( $result ) && ! empty( $result[ $plugin ] ) ) { @@ -4115,7 +4115,7 @@ function wp_ajax_update_plugin() { $status['errorMessage'] = __( 'Unable to connect to the filesystem. Please confirm your credentials.' ); // Pass through the error from WP_Filesystem if one was raised. - if ( $wp_filesystem instanceof WP_Filesystem_Base && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->get_error_code() ) { + if ( $wp_filesystem instanceof WP_Filesystem_Base && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->has_errors() ) { $status['errorMessage'] = esc_html( $wp_filesystem->errors->get_error_message() ); } @@ -4182,7 +4182,7 @@ function wp_ajax_delete_plugin() { $status['errorMessage'] = __( 'Unable to connect to the filesystem. Please confirm your credentials.' ); // Pass through the error from WP_Filesystem if one was raised. - if ( $wp_filesystem instanceof WP_Filesystem_Base && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->get_error_code() ) { + if ( $wp_filesystem instanceof WP_Filesystem_Base && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->has_errors() ) { $status['errorMessage'] = esc_html( $wp_filesystem->errors->get_error_message() ); } diff --git a/wp-admin/includes/class-wp-ajax-upgrader-skin.php b/wp-admin/includes/class-wp-ajax-upgrader-skin.php index 8ea2b67570..12afb44e25 100644 --- a/wp-admin/includes/class-wp-ajax-upgrader-skin.php +++ b/wp-admin/includes/class-wp-ajax-upgrader-skin.php @@ -61,8 +61,10 @@ class WP_Ajax_Upgrader_Skin extends Automatic_Upgrader_Skin { $messages = array(); foreach ( $this->errors->get_error_codes() as $error_code ) { - if ( $this->errors->get_error_data( $error_code ) && is_string( $this->errors->get_error_data( $error_code ) ) ) { - $messages[] = $this->errors->get_error_message( $error_code ) . ' ' . esc_html( strip_tags( $this->errors->get_error_data( $error_code ) ) ); + $error_data = $this->errors->get_error_data( $error_code ); + + if ( $error_data && is_string( $error_data ) ) { + $messages[] = $this->errors->get_error_message( $error_code ) . ' ' . esc_html( strip_tags( $error_data ) ); } else { $messages[] = $this->errors->get_error_message( $error_code ); } diff --git a/wp-admin/includes/class-wp-upgrader-skin.php b/wp-admin/includes/class-wp-upgrader-skin.php index 9465ed3401..27656aa2de 100644 --- a/wp-admin/includes/class-wp-upgrader-skin.php +++ b/wp-admin/includes/class-wp-upgrader-skin.php @@ -127,7 +127,7 @@ class WP_Upgrader_Skin { } if ( is_string( $errors ) ) { $this->feedback( $errors ); - } elseif ( is_wp_error( $errors ) && $errors->get_error_code() ) { + } elseif ( is_wp_error( $errors ) && $errors->has_errors() ) { foreach ( $errors->get_error_messages() as $message ) { if ( $errors->get_error_data() && is_string( $errors->get_error_data() ) ) { $this->feedback( $message . ' ' . esc_html( strip_tags( $errors->get_error_data() ) ) ); diff --git a/wp-admin/includes/class-wp-upgrader.php b/wp-admin/includes/class-wp-upgrader.php index f22f5a8ff6..ca6c5acde3 100644 --- a/wp-admin/includes/class-wp-upgrader.php +++ b/wp-admin/includes/class-wp-upgrader.php @@ -191,7 +191,7 @@ class WP_Upgrader { if ( ! WP_Filesystem( $credentials, $directories[0], $allow_relaxed_file_ownership ) ) { $error = true; - if ( is_object( $wp_filesystem ) && $wp_filesystem->errors->get_error_code() ) { + if ( is_object( $wp_filesystem ) && $wp_filesystem->errors->has_errors() ) { $error = $wp_filesystem->errors; } // Failed to connect, Error and request again @@ -203,7 +203,7 @@ class WP_Upgrader { return new WP_Error( 'fs_unavailable', $this->strings['fs_unavailable'] ); } - if ( is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->get_error_code() ) { + if ( is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->has_errors() ) { return new WP_Error( 'fs_error', $this->strings['fs_error'], $wp_filesystem->errors ); } diff --git a/wp-admin/includes/file.php b/wp-admin/includes/file.php index 01eb5e5774..2a0c879b10 100644 --- a/wp-admin/includes/file.php +++ b/wp-admin/includes/file.php @@ -1460,7 +1460,7 @@ function WP_Filesystem( $args = false, $context = false, $allow_relaxed_file_own define( 'FS_TIMEOUT', 30 ); } - if ( is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->get_error_code() ) { + if ( is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->has_errors() ) { return false; } diff --git a/wp-admin/includes/plugin.php b/wp-admin/includes/plugin.php index 0fb5080580..b310d19cbb 100644 --- a/wp-admin/includes/plugin.php +++ b/wp-admin/includes/plugin.php @@ -865,7 +865,7 @@ function delete_plugins( $plugins, $deprecated = '' ) { return new WP_Error( 'fs_unavailable', __( 'Could not access filesystem.' ) ); } - if ( is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->get_error_code() ) { + if ( is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->has_errors() ) { return new WP_Error( 'fs_error', __( 'Filesystem error.' ), $wp_filesystem->errors ); } diff --git a/wp-admin/includes/schema.php b/wp-admin/includes/schema.php index edba6973a0..c7dc9d879e 100644 --- a/wp-admin/includes/schema.php +++ b/wp-admin/includes/schema.php @@ -980,7 +980,7 @@ function populate_network( $network_id = 1, $domain = '', $email = '', $site_nam $errors->add( 'invalid_email', __( 'You must provide a valid email address.' ) ); } - if ( $errors->get_error_code() ) { + if ( $errors->has_errors() ) { return $errors; } diff --git a/wp-admin/includes/theme.php b/wp-admin/includes/theme.php index 90ecbc216e..a22235ee73 100644 --- a/wp-admin/includes/theme.php +++ b/wp-admin/includes/theme.php @@ -60,7 +60,7 @@ function delete_theme( $stylesheet, $redirect = '' ) { return new WP_Error( 'fs_unavailable', __( 'Could not access filesystem.' ) ); } - if ( is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->get_error_code() ) { + if ( is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->has_errors() ) { return new WP_Error( 'fs_error', __( 'Filesystem error.' ), $wp_filesystem->errors ); } diff --git a/wp-admin/includes/user.php b/wp-admin/includes/user.php index 269d64fb26..34554f6187 100644 --- a/wp-admin/includes/user.php +++ b/wp-admin/includes/user.php @@ -207,7 +207,7 @@ function edit_user( $user_id = 0 ) { */ do_action_ref_array( 'user_profile_update_errors', array( &$errors, $update, &$user ) ); - if ( $errors->get_error_codes() ) { + if ( $errors->has_errors() ) { return $errors; } diff --git a/wp-admin/network/user-new.php b/wp-admin/network/user-new.php index 57f54124ca..5a230e069e 100644 --- a/wp-admin/network/user-new.php +++ b/wp-admin/network/user-new.php @@ -44,7 +44,7 @@ if ( isset( $_REQUEST['action'] ) && 'add-user' == $_REQUEST['action'] ) { $user = wp_unslash( $_POST['user'] ); $user_details = wpmu_validate_user_signup( $user['username'], $user['email'] ); - if ( is_wp_error( $user_details['errors'] ) && ! empty( $user_details['errors']->errors ) ) { + if ( is_wp_error( $user_details['errors'] ) && $user_details['errors']->has_errors() ) { $add_user_errors = $user_details['errors']; } else { $password = wp_generate_password( 12, false ); diff --git a/wp-admin/update-core.php b/wp-admin/update-core.php index 0808364216..c49b000553 100644 --- a/wp-admin/update-core.php +++ b/wp-admin/update-core.php @@ -499,7 +499,7 @@ if ( ! WP_Filesystem( $credentials, ABSPATH, $allow_relaxed_file_ownership ) ) { return; } -if ( $wp_filesystem->errors->get_error_code() ) { +if ( $wp_filesystem->errors->has_errors() ) { foreach ( $wp_filesystem->errors->get_error_messages() as $message ) { show_message( $message ); } diff --git a/wp-admin/user-new.php b/wp-admin/user-new.php index 87955860d4..91ba0ace58 100644 --- a/wp-admin/user-new.php +++ b/wp-admin/user-new.php @@ -160,7 +160,7 @@ Please click the following link to confirm the invite: // Adding a new user to this site $new_user_email = wp_unslash( $_REQUEST['email'] ); $user_details = wpmu_validate_user_signup( $_REQUEST['user_login'], $new_user_email ); - if ( is_wp_error( $user_details['errors'] ) && ! empty( $user_details['errors']->errors ) ) { + if ( is_wp_error( $user_details['errors'] ) && $user_details['errors']->has_errors() ) { $add_user_errors = $user_details['errors']; } else { /** diff --git a/wp-includes/class-wp-customize-manager.php b/wp-includes/class-wp-customize-manager.php index 2749b0bf81..dc31945d1c 100644 --- a/wp-includes/class-wp-customize-manager.php +++ b/wp-includes/class-wp-customize-manager.php @@ -2302,7 +2302,7 @@ final class WP_Customize_Manager { if ( ! is_wp_error( $validity ) ) { /** This filter is documented in wp-includes/class-wp-customize-setting.php */ $late_validity = apply_filters( "customize_validate_{$setting->id}", new WP_Error(), $unsanitized_value, $setting ); - if ( ! empty( $late_validity->errors ) ) { + if ( $late_validity->has_errors() ) { $validity = $late_validity; } } diff --git a/wp-includes/class-wp-customize-setting.php b/wp-includes/class-wp-customize-setting.php index a5cbabb484..4052bc3b1b 100644 --- a/wp-includes/class-wp-customize-setting.php +++ b/wp-includes/class-wp-customize-setting.php @@ -594,7 +594,7 @@ class WP_Customize_Setting { */ $validity = apply_filters( "customize_validate_{$this->id}", $validity, $value, $this ); - if ( is_wp_error( $validity ) && empty( $validity->errors ) ) { + if ( is_wp_error( $validity ) && ! $validity->has_errors() ) { $validity = true; } return $validity; diff --git a/wp-includes/class-wp-error.php b/wp-includes/class-wp-error.php index ae8b237801..adbfb21c2c 100644 --- a/wp-includes/class-wp-error.php +++ b/wp-includes/class-wp-error.php @@ -71,7 +71,7 @@ class WP_Error { * @return array List of error codes, if available. */ public function get_error_codes() { - if ( empty( $this->errors ) ) { + if ( ! $this->has_errors() ) { return array(); } @@ -161,6 +161,20 @@ class WP_Error { } } + /** + * Verify if the instance contains errors. + * + * @since 5.0.0 + * + * @return bool + */ + public function has_errors() { + if ( ! empty( $this->errors ) ) { + return true; + } + return false; + } + /** * Add an error or append additional message to an existing error. * diff --git a/wp-includes/customize/class-wp-customize-custom-css-setting.php b/wp-includes/customize/class-wp-customize-custom-css-setting.php index d18b9aaaa9..967f459357 100644 --- a/wp-includes/customize/class-wp-customize-custom-css-setting.php +++ b/wp-includes/customize/class-wp-customize-custom-css-setting.php @@ -161,7 +161,7 @@ final class WP_Customize_Custom_CSS_Setting extends WP_Customize_Setting { $validity->add( 'illegal_markup', __( 'Markup is not allowed in CSS.' ) ); } - if ( empty( $validity->errors ) ) { + if ( ! $validity->has_errors() ) { $validity = parent::validate( $css ); } return $validity; diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php index e741b2149d..8b03e80d9b 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php @@ -470,7 +470,7 @@ class WP_REST_Users_Controller extends WP_REST_Controller { if ( is_multisite() ) { $ret = wpmu_validate_user_signup( $user->user_login, $user->user_email ); - if ( is_wp_error( $ret['errors'] ) && ! empty( $ret['errors']->errors ) ) { + if ( is_wp_error( $ret['errors'] ) && $ret['errors']->has_errors() ) { $error = new WP_Error( 'rest_invalid_param', __( 'Invalid user parameter(s).' ), array( 'status' => 400 ) ); foreach ( $ret['errors']->errors as $code => $messages ) { foreach ( $messages as $message ) { diff --git a/wp-includes/user.php b/wp-includes/user.php index dd5d5367ba..66a54cda47 100644 --- a/wp-includes/user.php +++ b/wp-includes/user.php @@ -2469,7 +2469,7 @@ function register_new_user( $user_login, $user_email ) { */ $errors = apply_filters( 'registration_errors', $errors, $sanitized_user_login, $user_email ); - if ( $errors->get_error_code() ) { + if ( $errors->has_errors() ) { return $errors; } diff --git a/wp-includes/version.php b/wp-includes/version.php index 8ac8ec6aee..82f5b252eb 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '5.0-alpha-42760'; +$wp_version = '5.0-alpha-42761'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. diff --git a/wp-login.php b/wp-login.php index 6415b1544a..f82661d2ca 100644 --- a/wp-login.php +++ b/wp-login.php @@ -53,7 +53,7 @@ function login_header( $title = 'Log In', $message = '', $wp_error = '' ) { */ $shake_error_codes = apply_filters( 'shake_error_codes', $shake_error_codes ); - if ( $shake_error_codes && $wp_error->get_error_code() && in_array( $wp_error->get_error_code(), $shake_error_codes ) ) { + if ( $shake_error_codes && $wp_error->has_errors() && in_array( $wp_error->get_error_code(), $shake_error_codes ) ) { add_action( 'login_head', 'wp_shake_js', 12 ); } @@ -208,7 +208,7 @@ function login_header( $title = 'Log In', $message = '', $wp_error = '' ) { unset( $error ); } - if ( $wp_error->get_error_code() ) { + if ( $wp_error->has_errors() ) { $errors = ''; $messages = ''; foreach ( $wp_error->get_error_codes() as $code ) { @@ -341,7 +341,7 @@ function retrieve_password() { */ do_action( 'lostpassword_post', $errors ); - if ( $errors->get_error_code() ) { + if ( $errors->has_errors() ) { return $errors; } @@ -687,7 +687,7 @@ switch ( $action ) { */ do_action( 'validate_password_reset', $errors, $user ); - if ( ( ! $errors->get_error_code() ) && isset( $_POST['pass1'] ) && ! empty( $_POST['pass1'] ) ) { + if ( ( ! $errors->has_errors() ) && isset( $_POST['pass1'] ) && ! empty( $_POST['pass1'] ) ) { reset_password( $user, $_POST['pass1'] ); setcookie( $rp_cookie, ' ', time() - YEAR_IN_SECONDS, $rp_path, COOKIE_DOMAIN, is_ssl(), true ); login_header( __( 'Password Reset' ), '

' . __( 'Your password has been reset.' ) . ' ' . __( 'Log in' ) . '

' ); @@ -973,7 +973,7 @@ switch ( $action ) { } if ( $interim_login ) { - if ( ! $errors->get_error_code() ) { + if ( ! $errors->has_errors() ) { $errors->add( 'expired', __( 'Your session has expired. Please log in to continue where you left off.' ), 'message' ); } } else { @@ -1015,7 +1015,7 @@ switch ( $action ) { } $rememberme = ! empty( $_POST['rememberme'] ); - if ( ! empty( $errors->errors ) ) { + if ( $errors->has_errors() ) { $aria_describedby_error = ' aria-describedby="login_error"'; } else { $aria_describedby_error = ''; diff --git a/wp-signup.php b/wp-signup.php index cecaf989e5..92b6a21b4a 100644 --- a/wp-signup.php +++ b/wp-signup.php @@ -323,7 +323,7 @@ function signup_another_blog( $blogname = '', $blog_title = '', $errors = '' ) { echo '

' . sprintf( __( 'Get another %s site in seconds' ), get_network()->site_name ) . '

'; - if ( $errors->get_error_code() ) { + if ( $errors->has_errors() ) { echo '

' . __( 'There was a problem, please correct the form below and try again.' ) . '

'; } ?> @@ -389,7 +389,7 @@ function validate_another_blog_signup() { $blog_title = $result['blog_title']; $errors = $result['errors']; - if ( $errors->get_error_code() ) { + if ( $errors->has_errors() ) { signup_another_blog( $blogname, $blog_title, $errors ); return false; } @@ -604,7 +604,7 @@ function validate_user_signup() { $user_email = $result['user_email']; $errors = $result['errors']; - if ( $errors->get_error_code() ) { + if ( $errors->has_errors() ) { signup_user( $user_name, $user_email, $errors ); return false; } @@ -729,7 +729,7 @@ function validate_blog_signup() { $user_email = $user_result['user_email']; $user_errors = $user_result['errors']; - if ( $user_errors->get_error_code() ) { + if ( $user_errors->has_errors() ) { signup_user( $user_name, $user_email, $user_errors ); return false; } @@ -741,7 +741,7 @@ function validate_blog_signup() { $blog_title = $result['blog_title']; $errors = $result['errors']; - if ( $errors->get_error_code() ) { + if ( $errors->has_errors() ) { signup_blog( $user_name, $user_email, $blogname, $blog_title, $errors ); return false; }