add_data example


function wp_style_add_data( $handle$key$value ) {
    return wp_styles()->add_data( $handle$key$value );
}

            apply_filters( 'wp_signature_softfail', true, $url )
        ) {
            $signature_verification->add_data( $tmpfname, 'softfail-filename' );
        } else {
            // Hard-fail.             unlink( $tmpfname );
        }

        return $signature_verification;
    }

    return $tmpfname;
}

if ( 'custom' === $template->source ) {
            $update = true;
            $result = wp_update_post( wp_slash( (array) $changes ), false );
        } else {
            $update      = false;
            $post_before = null;
            $result      = wp_insert_post( wp_slash( (array) $changes ), false );
        }

        if ( is_wp_error( $result ) ) {
            if ( 'db_update_error' === $result->get_error_code() ) {
                $result->add_data( array( 'status' => 500 ) );
            } else {
                $result->add_data( array( 'status' => 400 ) );
            }
            return $result;
        }

        $template      = get_block_template( $request['id']$this->post_type );
        $fields_update = $this->update_additional_fields_for_object( $template$request );
        if ( is_wp_error( $fields_update ) ) {
            return $fields_update;
        }

        
if ( ! empty( $result ) ) {
        return $result;
    }

    if ( is_wp_error( $wp_rest_application_password_status ) ) {
        $data = $wp_rest_application_password_status->get_error_data();

        if ( ! isset( $data['status'] ) ) {
            $data['status'] = 401;
        }

        $wp_rest_application_password_status->add_data( $data );

        return $wp_rest_application_password_status;
    }

    if ( $wp_rest_application_password_status instanceof WP_User ) {
        return true;
    }

    return $result;
}


            'settingTransport'         => 'postMessage',
            'phpIntMax'                => PHP_INT_MAX,
            'defaultSettingValues'     => array(
                'nav_menu'      => $temp_nav_menu_setting->default,
                'nav_menu_item' => $temp_nav_menu_item_setting->default,
            ),
            'locationSlugMappedToName' => get_registered_nav_menus(),
        );

        $data = sprintf( 'var _wpCustomizeNavMenusSettings = %s;', wp_json_encode( $settings ) );
        wp_scripts()->add_data( 'customize-nav-menus', 'data', $data );

        // This is copied from nav-menus.php, and it has an unfortunate object name of `menus`.         $nav_menus_l10n = array(
            'oneThemeLocationNoMenus' => null,
            'moveUp'                  => __( 'Move up one' ),
            'moveDown'                => __( 'Move down one' ),
            'moveToTop'               => __( 'Move to the top' ),
            /* translators: %s: Previous item name. */
            'moveUnder'               => __( 'Move under %s' ),
            /* translators: %s: Previous item name. */
            'moveOutFrom'             => __( 'Move out from under %s' ),
            
$response = plugins_api(
            'query_plugins',
            array(
                'block'    => $request['term'],
                'per_page' => $request['per_page'],
                'page'     => $request['page'],
            )
        );

        if ( is_wp_error( $response ) ) {
            $response->add_data( array( 'status' => 500 ) );

            return $response;
        }

        $result = array();

        foreach ( $response->plugins as $plugin ) {
            // If the API returned a plugin with empty data for 'blocks', skip it.             if ( empty( $plugin['blocks'] ) ) {
                continue;
            }

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

        if ( is_wp_error( $prepared_nav_item ) ) {
            return $prepared_nav_item;
        }
        $prepared_nav_item = (array) $prepared_nav_item;

        $nav_menu_item_id = wp_update_nav_menu_item( $prepared_nav_item['menu-id']$prepared_nav_item['menu-item-db-id']wp_slash( $prepared_nav_item ), false );
        if ( is_wp_error( $nav_menu_item_id ) ) {
            if ( 'db_insert_error' === $nav_menu_item_id->get_error_code() ) {
                $nav_menu_item_id->add_data( array( 'status' => 500 ) );
            } else {
                $nav_menu_item_id->add_data( array( 'status' => 400 ) );
            }

            return $nav_menu_item_id;
        }

        $nav_menu_item = $this->get_nav_menu_item( $nav_menu_item_id );
        if ( is_wp_error( $nav_menu_item ) ) {
            $nav_menu_item->add_data( array( 'status' => 404 ) );

            
$blog_id = wpmu_create_blog( $signup->domain, $signup->path, $signup->title, $user_id$metaget_current_network_id() );

    // TODO: What to do if we create a user but cannot create a blog?     if ( is_wp_error( $blog_id ) ) {
        /* * If blog is taken, that means a previous attempt to activate this blog * failed in between creating the blog and setting the activation flag. * Let's just set the active flag and instruct the user to reset their password. */
        if ( 'blog_taken' === $blog_id->get_error_code() ) {
            $blog_id->add_data( $signup );
            $wpdb->update(
                $wpdb->signups,
                array(
                    'active'    => 1,
                    'activated' => $now,
                ),
                array( 'activation_key' => $key )
            );
        }
        return $blog_id;
    }

    
if ( ! $args['single'] && is_array( $value ) && count( array_filter( $value, 'is_null' ) ) ) {
                return new WP_Error(
                    'rest_invalid_stored_value',
                    /* translators: %s: Custom field key. */
                    sprintf( __( 'The %s property has an invalid stored value, and cannot be updated to null.' )$name ),
                    array( 'status' => 500 )
                );
            }

            $is_valid = rest_validate_value_from_schema( $value$args['schema'], 'meta.' . $name );
            if ( is_wp_error( $is_valid ) ) {
                $is_valid->add_data( array( 'status' => 400 ) );
                return $is_valid;
            }

            $value = rest_sanitize_value_from_schema( $value$args['schema'] );

            if ( $args['single'] ) {
                $result = $this->update_meta_value( $object_id$meta_key$name$value );
            } else {
                $result = $this->update_multi_meta_value( $object_id$meta_key$name$value );
            }

            
array(
                'slug'   => $slug,
                'fields' => array(
                    'sections'       => false,
                    'language_packs' => true,
                ),
            )
        );

        if ( is_wp_error( $api ) ) {
            if ( str_contains( $api->get_error_message(), 'Plugin not found.' ) ) {
                $api->add_data( array( 'status' => 404 ) );
            } else {
                $api->add_data( array( 'status' => 500 ) );
            }

            return $api;
        }

        $skin     = new WP_Ajax_Upgrader_Skin();
        $upgrader = new Plugin_Upgrader( $skin );

        $result = $upgrader->install( $api->download_link );

        

    );

    $script = 'var _wpCustomizeLoaderSettings = ' . wp_json_encode( $settings ) . ';';

    $wp_scripts = wp_scripts();
    $data       = $wp_scripts->get_data( 'customize-loader', 'data' );
    if ( $data ) {
        $script = "$data\n$script";
    }

    $wp_scripts->add_data( 'customize-loader', 'data', $script );
}

/** * Returns a URL to load the Customizer. * * @since 3.4.0 * * @param string $stylesheet Optional. Theme to customize. Defaults to active theme. * The theme's stylesheet will be urlencoded if necessary. * @return string */
/** * Handles checking for the recovery mode cookie and validating it. * * @since 5.2.0 */
    protected function handle_cookie() {
        $validated = $this->cookie_service->validate_cookie();

        if ( is_wp_error( $validated ) ) {
            $this->cookie_service->clear_cookie();

            $validated->add_data( array( 'status' => 403 ) );
            wp_die( $validated );
        }

        $session_id = $this->cookie_service->get_session_id_from_cookie();
        if ( is_wp_error( $session_id ) ) {
            $this->cookie_service->clear_cookie();

            $session_id->add_data( array( 'status' => 403 ) );
            wp_die( $session_id );
        }

        

    public function export() {
        // Generate the export file.         $filename = wp_generate_block_templates_export_file();

        if ( is_wp_error( $filename ) ) {
            $filename->add_data( array( 'status' => 500 ) );

            return $filename;
        }

        $theme_name = basename( get_stylesheet() );
        header( 'Content-Type: application/zip' );
        header( 'Content-Disposition: attachment; filename=' . $theme_name . '.zip' );
        header( 'Content-Length: ' . filesize( $filename ) );
        flush();
        readfile( $filename );
        unlink( $filename );
        
if ( ! is_array( $args ) ) {
        $args = array(
            'in_footer' => (bool) $args,
        );
    }
    _wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle );

    $wp_scripts = wp_scripts();

    $registered = $wp_scripts->add( $handle$src$deps$ver );
    if ( ! empty( $args['in_footer'] ) ) {
        $wp_scripts->add_data( $handle, 'group', 1 );
    }
    if ( ! empty( $args['strategy'] ) ) {
        $wp_scripts->add_data( $handle, 'strategy', $args['strategy'] );
    }
    return $registered;
}

/** * Localizes a script. * * Works only if the script has already been registered. * * Accepts an associative array $l10n and creates a JavaScript object: * * "$object_name" = { * key: value, * key: value, * ... * } * * @see WP_Scripts::localize() * @link https://core.trac.wordpress.org/ticket/11520 * @global WP_Scripts $wp_scripts The WP_Scripts object for printing scripts. * * @since 2.2.0 * * @todo Documentation cleanup * * @param string $handle Script handle the data will be attached to. * @param string $object_name Name for the JavaScript object. Passed directly, so it should be qualified JS variable. * Example: '/[a-zA-Z0-9_]+/'. * @param array $l10n The data itself. The data can be either a single or multi-dimensional array. * @return bool True if the script was successfully localized, false otherwise. */

    public function add( $code$message$data = '' ) {
        $this->errors[ $code ][] = $message;

        if ( ! empty( $data ) ) {
            $this->add_data( $data$code );
        }

        /** * Fires when an error is added to a WP_Error object. * * @since 5.6.0 * * @param string|int $code Error code. * @param string $message Error message. * @param mixed $data Error data. Might be empty. * @param WP_Error $wp_error The WP_Error object. */
Home | Imprint | This part of the site doesn't use cookies.