wpseek.com
A WordPress-centric search engine for devs and theme authors



site_editor_preload_data › WordPress Function

Sincen/a
Deprecatedn/a
site_editor_preload_data ( No parameters )
Defined at:
Codex:

Preload REST API data for the site-editor page.

Automatically called during page rendering.


Source

function site_editor_preload_data() {
		// Define paths to preload - same for all pages
		$preload_paths = array(
			'/?_fields=description,gmt_offset,home,name,site_icon,site_icon_url,site_logo,timezone_string,url,page_for_posts,page_on_front,show_on_front',
			array( '/wp/v2/settings', 'OPTIONS' ),
		);

		// Use rest_preload_api_request to gather the preloaded data
		$preload_data = array_reduce(
			$preload_paths,
			'rest_preload_api_request',
			array()
		);

		// Register the preloading middleware with wp-api-fetch
		wp_add_inline_script(
			'wp-api-fetch',
			sprintf(
				'wp.apiFetch.use( wp.apiFetch.createPreloadingMiddleware( %s ) );',
				wp_json_encode( $preload_data )
			),
			'after'
		);
	}
}