Automattic\WooCommerce\EmailEditor\Engine
Assets_Manager::preload_rest_api_data
Preload REST API data for the email editor.
Метод класса: Assets_Manager{}
Хуки из метода
Возвращает
null. Ничего (null).
Использование
// private - только в коде основоного (родительского) класса $result = $this->preload_rest_api_data( $post_id, $post_type ): void;
- $post_id(int|строка) (обязательный)
- The post ID.
- $post_type(строка) (обязательный)
- The post type.
Код Assets_Manager::preload_rest_api_data() Assets Manager::preload rest api data WC 11.2.2
private function preload_rest_api_data( $post_id, string $post_type ): void {
$email_post_type = $post_type;
$user_theme_post_id = $this->user_theme->get_user_theme_post()->ID;
$post = is_numeric( $post_id ) ? get_post( (int) $post_id ) : null;
$template_slug = get_post_meta( (int) $post_id, '_wp_page_template', true );
$routes = array(
"/wp/v2/{$email_post_type}/" . intval( $post_id ) . '?context=edit',
"/wp/v2/types/{$email_post_type}?context=edit",
'/wp/v2/global-styles/' . intval( $user_theme_post_id ) . '?context=view', // Global email styles.
'/wp/v2/block-patterns/patterns',
'/wp/v2/templates?context=view',
'/wp/v2/block-patterns/categories',
'/wp/v2/settings',
'/wp/v2/types?context=view',
'/wp/v2/taxonomies?context=view',
);
if ( is_string( $template_slug ) && '' !== $template_slug ) {
$routes[] = '/wp/v2/templates/lookup?slug=' . $template_slug;
}
// Recent emails listed by the template selection modal, which opens on emails with no content.
if ( $post instanceof \WP_Post && '' === $post->post_content ) {
$routes[] = "/wp/v2/{$email_post_type}?context=edit&per_page=30&status=publish,sent";
}
/**
* Filters the REST API routes preloaded for the email editor.
*
* @param string[] $routes The routes to preload.
* @param string $post_type The edited post type.
* @param int|string $post_id The edited post ID.
*
* @since 11.2.0
*/
$routes = apply_filters( 'woocommerce_email_editor_preload_rest_api_routes', $routes, $post_type, $post_id );
if ( ! is_array( $routes ) ) {
$routes = array();
}
$preload_data = array_reduce(
$routes,
'rest_preload_api_request',
array()
);
// Add inline script to set up preloading middleware.
wp_add_inline_script(
'wp-blocks',
sprintf(
'wp.apiFetch.use( wp.apiFetch.createPreloadingMiddleware( %s ) );',
wp_json_encode( $preload_data, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES )
)
);
}