get_block_editor_theme_styles

函数
get_block_editor_theme_styles ( No parameters )
返回值
  • (array) An array of theme styles for the block editor.
定义位置
相关方法
get_block_editor_settingsget_block_theme_foldersthe_block_editor_meta_boxesget_block_editor_server_block_settingsuse_block_editor_for_post_type
引入
5.8.0
弃用
-

get_block_editor_theme_styles:此函数返回块编辑器的样式数组,例如字体大小、颜色和其他设置。它不接受任何参数。

创建一个主题样式数组,以加载到区块编辑器中。

function get_block_editor_theme_styles() {
	global $editor_styles;

	$styles = array();

	if ( $editor_styles && current_theme_supports( 'editor-styles' ) ) {
		foreach ( $editor_styles as $style ) {
			if ( preg_match( '~^(https?:)?//~', $style ) ) {
				$response = wp_remote_get( $style );
				if ( ! is_wp_error( $response ) ) {
					$styles[] = array(
						'css'            => wp_remote_retrieve_body( $response ),
						'__unstableType' => 'theme',
						'isGlobalStyles' => false,
					);
				}
			} else {
				$file = get_theme_file_path( $style );
				if ( is_file( $file ) ) {
					$styles[] = array(
						'css'            => file_get_contents( $file ),
						'baseURL'        => get_theme_file_uri( $style ),
						'__unstableType' => 'theme',
						'isGlobalStyles' => false,
					);
				}
			}
		}
	}

	return $styles;
}

常见问题

FAQs
查看更多 >