wp_filter_global_styles_post

函式
wp_filter_global_styles_post ( $data )
引數
  • (string) $data Post content to filter.
    Required:
返回值
  • (string) Filtered post content with unsafe rules removed.
定義位置
相關方法
wp_get_global_styleswp_get_global_stylesheetwp_get_global_styles_svg_filterswp_enqueue_global_styleswp_add_global_styles_for_blocks
引入
5.9.0
棄用
-

wp_filter_global_styles_post:當全域性樣式被新增到一個文章時,這個動作鉤子被呼叫。開發人員可以使用這個鉤子來修改或刪除應用於文章的全域性樣式。

淨化全域性樣式的使用者內容,去除不安全的規則。

function wp_filter_global_styles_post( $data ) {
	$decoded_data        = json_decode( wp_unslash( $data ), true );
	$json_decoding_error = json_last_error();
	if (
		JSON_ERROR_NONE === $json_decoding_error &&
		is_array( $decoded_data ) &&
		isset( $decoded_data['isGlobalStylesUserThemeJSON'] ) &&
		$decoded_data['isGlobalStylesUserThemeJSON']
	) {
		unset( $decoded_data['isGlobalStylesUserThemeJSON'] );

		$data_to_encode = WP_Theme_JSON::remove_insecure_properties( $decoded_data );

		$data_to_encode['isGlobalStylesUserThemeJSON'] = true;
		return wp_slash( wp_json_encode( $data_to_encode ) );
	}
	return $data;
}

常見問題

FAQs
檢視更多 >