has_errors example

/* * Define the timeouts for the connections. Only available after the constructor is called * to allow for per-transport overriding of the default. */
    if ( ! defined( 'FS_CONNECT_TIMEOUT' ) ) {
        define( 'FS_CONNECT_TIMEOUT', 30 ); // 30 seconds.     }
    if ( ! defined( 'FS_TIMEOUT' ) ) {
        define( 'FS_TIMEOUT', 30 ); // 30 seconds.     }

    if ( is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->has_errors() ) {
        return false;
    }

    if ( ! $wp_filesystem->connect() ) {
        return false; // There was an error connecting to the server.     }

    // Set the permission constants if not already set.     if ( ! defined( 'FS_CHMOD_DIR' ) ) {
        define( 'FS_CHMOD_DIR', ( fileperms( ABSPATH ) & 0777 | 0755 ) );
    }
    
wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 );
    }

    if ( ! is_array( $_POST['user'] ) ) {
        wp_die( __( 'Cannot create an empty user.' ) );
    }

    $user = wp_unslash( $_POST['user'] );

    $user_details = wpmu_validate_user_signup( $user['username']$user['email'] );

    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 );
        $user_id  = wpmu_create_user( esc_html( strtolower( $user['username'] ) )$passwordsanitize_email( $user['email'] ) );

        if ( ! $user_id ) {
            $add_user_errors = new WP_Error( 'add_user_fail', __( 'Cannot add user.' ) );
        } else {
            /** * Fires after a new user has been created via the network user-new.php page. * * @since 4.4.0 * * @param int $user_id ID of the newly created user. */
return $result;
        }

        // This should be the same as $result above.         if ( is_wp_error( $skin->result ) ) {
            $skin->result->add_data( array( 'status' => 500 ) );

            return $skin->result;
        }

        if ( $skin->get_errors()->has_errors() ) {
            $error = $skin->get_errors();
            $error->add_data( array( 'status' => 500 ) );

            return $error;
        }

        if ( is_null( $result ) ) {
            // 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->has_errors()
            ) {
                

    public function validate( $value ) {
        // Restores the more descriptive, specific name for use within this method.         $css = $value;

        $validity = new WP_Error();

        if ( preg_match( '#</?\w+#', $css ) ) {
            $validity->add( 'illegal_markup', __( 'Markup is not allowed in CSS.' ) );
        }

        if ( ! $validity->has_errors() ) {
            $validity = parent::validate( $css );
        }
        return $validity;
    }

    /** * Store the CSS setting value in the custom_css custom post type for the stylesheet. * * @since 4.7.0 * @since 5.9.0 Renamed `$css` to `$value` for PHP 8 named parameter support. * * @param string $value CSS to update. * @return int|false The post ID or false if the value could not be saved. */
$redirect = 'users.php?update=add&id=' . $user_id;
            } else {
                $redirect = add_query_arg( 'update', 'add', 'user-new.php' );
            }
            wp_redirect( $redirect );
            die();
        }
    } else {
        // 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'] ) && $user_details['errors']->has_errors() ) {
            $add_user_errors = $user_details['errors'];
        } else {
            /** This filter is documented in wp-includes/user.php */
            $new_user_login = apply_filters( 'pre_user_login', sanitize_user( wp_unslash( $_REQUEST['user_login'] ), true ) );
            if ( isset( $_POST['noconfirmation'] ) && current_user_can( 'manage_network_users' ) ) {
                add_filter( 'wpmu_signup_user_notification', '__return_false' );  // Disable confirmation email.                 add_filter( 'wpmu_welcome_user_notification', '__return_false' ); // Disable welcome email.             }
            wpmu_signup_user(
                $new_user_login,
                $new_user_email,
                
if ( $network_id === (int) $wpdb->get_var(
            $wpdb->prepare( "SELECT id FROM $wpdb->site WHERE id = %d", $network_id )
        ) ) {
            $errors->add( 'siteid_exists', __( 'The network already exists.' ) );
        }
    }

    if ( ! is_email( $email ) ) {
        $errors->add( 'invalid_email', __( 'You must provide a valid email address.' ) );
    }

    if ( $errors->has_errors() ) {
        return $errors;
    }

    if ( 1 === $network_id ) {
        $wpdb->insert(
            $wpdb->site,
            array(
                'domain' => $domain,
                'path'   => $path,
            )
        );
        

    public function fs_connect( $directories = array()$allow_relaxed_file_ownership = false ) {
        global $wp_filesystem;

        $credentials = $this->skin->request_filesystem_credentials( false, $directories[0]$allow_relaxed_file_ownership );
        if ( false === $credentials ) {
            return false;
        }

        if ( ! WP_Filesystem( $credentials$directories[0]$allow_relaxed_file_ownership ) ) {
            $error = true;
            if ( is_object( $wp_filesystem ) && $wp_filesystem->errors->has_errors() ) {
                $error = $wp_filesystem->errors;
            }
            // Failed to connect. Error and request again.             $this->skin->request_filesystem_credentials( $error$directories[0]$allow_relaxed_file_ownership );
            return false;
        }

        if ( ! is_object( $wp_filesystem ) ) {
            return new WP_Error( 'fs_unavailable', $this->strings['fs_unavailable'] );
        }

        
echo $data;
            require_once ABSPATH . 'wp-admin/admin-footer.php';
            exit;
        }
        return;
    }

    if ( ! is_object( $wp_filesystem ) ) {
        return new WP_Error( 'fs_unavailable', __( 'Could not access filesystem.' ) );
    }

    if ( is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->has_errors() ) {
        return new WP_Error( 'fs_error', __( 'Filesystem error.' )$wp_filesystem->errors );
    }

    // Get the base plugin folder.     $plugins_dir = $wp_filesystem->wp_plugins_dir();
    if ( empty( $plugins_dir ) ) {
        return new WP_Error( 'fs_no_plugins_dir', __( 'Unable to locate WordPress plugin directory.' ) );
    }

    $plugins_dir = trailingslashit( $plugins_dir );

    

        do_action( 'wp_authenticate_application_password_errors', $error$user$item$password );

        if ( is_wp_error( $error ) && $error->has_errors() ) {
            /** This action is documented in wp-includes/user.php */
            do_action( 'application_password_failed_authentication', $error );

            return $error;
        }

        WP_Application_Passwords::record_application_password_usage( $user->ID, $item['uuid'] );

        /** * Fires after an application password was used for authentication. * * @since 5.6.0 * * @param WP_User $user The user who was authenticated. * @param array $item The application password used. */
if ( $options['validate_capability'] && ! current_user_can( $setting->capability ) ) {
                $validity = new WP_Error( 'unauthorized', __( 'Unauthorized to modify setting due to capability.' ) );
            } else {
                if ( is_null( $unsanitized_value ) ) {
                    continue;
                }
                $validity = $setting->validate( $unsanitized_value );
            }
            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 ( is_wp_error( $late_validity ) && $late_validity->has_errors() ) {
                    $validity = $late_validity;
                }
            }
            if ( ! is_wp_error( $validity ) ) {
                $value = $setting->sanitize( $unsanitized_value );
                if ( is_null( $value ) ) {
                    $validity = false;
                } elseif ( is_wp_error( $value ) ) {
                    $validity = $value;
                }
            }
            
$this->add( $code$message$data );
    }

    /** * Retrieves all error codes. * * @since 2.1.0 * * @return array List of error codes, if available. */
    public function get_error_codes() {
        if ( ! $this->has_errors() ) {
            return array();
        }

        return array_keys( $this->errors );
    }

    /** * Retrieves the first error code available. * * @since 2.1.0 * * @return string|int Empty string, if no error codes. */
/** * Fires before user profile update errors are returned. * * @since 2.8.0 * * @param WP_Error $errors WP_Error object (passed by reference). * @param bool $update Whether this is a user update. * @param stdClass $user User object (passed by reference). */
    do_action_ref_array( 'user_profile_update_errors', array( &$errors$update, &$user ) );

    if ( $errors->has_errors() ) {
        return $errors;
    }

    if ( $update ) {
        $user_id = wp_update_user( $user );
    } else {
        $user_id = wp_insert_user( $user );
        $notify  = isset( $_POST['send_user_notification'] ) ? 'both' : 'admin';

        /** * Fires after a new user has been created. * * @since 4.4.0 * * @param int|WP_Error $user_id ID of the newly created user or WP_Error on failure. * @param string $notify Type of notification that should happen. See * wp_send_new_user_notifications() for more information. */
echo $data;
            require_once ABSPATH . 'wp-admin/admin-footer.php';
            exit;
        }
        return;
    }

    if ( ! is_object( $wp_filesystem ) ) {
        return new WP_Error( 'fs_unavailable', __( 'Could not access filesystem.' ) );
    }

    if ( is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->has_errors() ) {
        return new WP_Error( 'fs_error', __( 'Filesystem error.' )$wp_filesystem->errors );
    }

    // Get the base plugin folder.     $themes_dir = $wp_filesystem->wp_themes_dir();
    if ( empty( $themes_dir ) ) {
        return new WP_Error( 'fs_no_themes_dir', __( 'Unable to locate WordPress theme directory.' ) );
    }

    /** * Fires immediately before a theme deletion attempt. * * @since 5.8.0 * * @param string $stylesheet Stylesheet of the theme to delete. */
if ( is_wp_error( $check_permission ) ) {
                return $check_permission;
            }
        }

        $user = $this->prepare_item_for_database( $request );

        if ( is_multisite() ) {
            $ret = wpmu_validate_user_signup( $user->user_login, $user->user_email );

            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 ) {
                        $error->add( $code$message );
                    }

                    
/** * @since 2.8.0 * * @param string|WP_Error $errors Errors. */
    public function error( $errors ) {
        if ( ! $this->done_header ) {
            $this->header();
        }
        if ( is_string( $errors ) ) {
            $this->feedback( $errors );
        } 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() ) ) );
                } else {
                    $this->feedback( $message );
                }
            }
        }
    }

    /** * @since 2.8.0 * @since 5.9.0 Renamed `$string` (a PHP reserved keyword) to `$feedback` for PHP 8 named parameter support. * * @param string $feedback Message data. * @param mixed ...$args Optional text replacements. */
Home | Imprint | This part of the site doesn't use cookies.