get_error_codes example

echo '<form method="post">';

    wp_nonce_field( 'install-network-1' );

    $error_codes = array();
    if ( is_wp_error( $errors ) ) {
        echo '<div class="error"><p><strong>' . __( 'Error: The network could not be created.' ) . '</strong></p>';
        foreach ( $errors->get_error_messages() as $error ) {
            echo "<p>$error</p>";
        }
        echo '</div>';
        $error_codes = $errors->get_error_codes();
    }

    if ( ! empty( $_POST['sitename'] ) && ! in_array( 'empty_sitename', $error_codes, true ) ) {
        $site_name = $_POST['sitename'];
    } else {
        /* translators: %s: Default network title. */
        $site_name = sprintf( __( '%s Sites' )get_option( 'blogname' ) );
    }

    if ( ! empty( $_POST['email'] ) && ! in_array( 'invalid_email', $error_codes, true ) ) {
        $admin_email = $_POST['email'];
    }
// In case a plugin uses $error rather than the $wp_errors object.     if ( ! empty( $error ) ) {
        $wp_error->add( 'error', $error );
        unset( $error );
    }

    if ( $wp_error->has_errors() ) {
        $errors   = '';
        $messages = '';

        foreach ( $wp_error->get_error_codes() as $code ) {
            $severity = $wp_error->get_error_data( $code );
            foreach ( $wp_error->get_error_messages( $code ) as $error_message ) {
                if ( 'message' === $severity ) {
                    $messages .= ' ' . $error_message . "<br />\n";
                } else {
                    $errors .= ' ' . $error_message . "<br />\n";
                }
            }
        }

        if ( ! empty( $errors ) ) {
            
/** * Retrieves a string for error messages. * * @since 4.6.0 * * @return string Error messages during an upgrade. */
    public function get_error_messages() {
        $messages = array();

        foreach ( $this->errors->get_error_codes() as $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 );
            }
        }

        return implode( ', ', $messages );
    }

    
/** * Determines whether the theme exists. * * A theme with errors exists. A theme with the error of 'theme_not_found', * meaning that the theme's directory was not found, does not exist. * * @since 3.4.0 * * @return bool Whether the theme exists. */
    public function exists() {
        return ! ( $this->errors() && in_array( 'theme_not_found', $this->errors()->get_error_codes(), true ) );
    }

    /** * Returns reference to the parent theme. * * @since 3.4.0 * * @return WP_Theme|false Parent theme, or false if the active theme is not a child theme. */
    public function parent() {
        return isset( $this->parent ) ? $this->parent : false;
    }
check_admin_referer( 'install-network-1' );

    require_once ABSPATH . 'wp-admin/includes/upgrade.php';
    // Create network tables.     install_network();
    $base              = parse_url( trailingslashit( get_option( 'home' ) ), PHP_URL_PATH );
    $subdomain_install = allow_subdomain_install() ? ! empty( $_POST['subdomain_install'] ) : false;
    if ( ! network_domain_check() ) {
        $result = populate_network( 1, get_clean_basedomain()sanitize_email( $_POST['email'] )wp_unslash( $_POST['sitename'] )$base$subdomain_install );
        if ( is_wp_error( $result ) ) {
            if ( 1 === count( $result->get_error_codes() ) && 'no_wildcard_dns' === $result->get_error_code() ) {
                network_step2( $result );
            } else {
                network_step1( $result );
            }
        } else {
            network_step2();
        }
    } else {
        network_step2();
    }
} elseif ( is_multisite() || network_domain_check() ) {
    
$action   = $parsed_args['action'];
        $old_id   = $parsed_args['old_id'];
        $data     = $parsed_args['data'];

        if ( is_wp_error( $id ) ) {
            $data = $id;
            $id   = 0;
        }

        $response = '';
        if ( is_wp_error( $data ) ) {
            foreach ( (array) $data->get_error_codes() as $code ) {
                $response  .= "<wp_error code='$code'><![CDATA[" . $data->get_error_message( $code ) . ']]></wp_error>';
                $error_data = $data->get_error_data( $code );
                if ( ! $error_data ) {
                    continue;
                }
                $class = '';
                if ( is_object( $error_data ) ) {
                    $class      = ' class="' . get_class( $error_data ) . '"';
                    $error_data = get_object_vars( $error_data );
                }

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

        $term = wp_update_nav_menu_object( 0, wp_slash( (array) $prepared_term ) );

        if ( is_wp_error( $term ) ) {
            /* * If we're going to inform the client that the term already exists, * give them the identifier for future use. */

            if ( in_array( 'menu_exists', $term->get_error_codes(), true ) ) {
                $existing_term = get_term_by( 'name', $prepared_term->{'menu-name'}$this->taxonomy );
                $term->add_data( $existing_term->term_id, 'menu_exists' );
                $term->add_data(
                    array(
                        'status'  => 400,
                        'term_id' => $existing_term->term_id,
                    )
                );
            } else {
                $term->add_data( array( 'status' => 400 ) );
            }

            
return array_keys( $this->errors );
    }

    /** * Retrieves the first error code available. * * @since 2.1.0 * * @return string|int Empty string, if no error codes. */
    public function get_error_code() {
        $codes = $this->get_error_codes();

        if ( empty( $codes ) ) {
            return '';
        }

        return $codes[0];
    }

    /** * Retrieves all error messages, or the error messages for the given error code. * * @since 2.1.0 * * @param string|int $code Optional. Error code to retrieve the messages for. * Default empty string. * @return string[] Error strings on success, or empty array if there are none. */
Home | Imprint | This part of the site doesn't use cookies.