钩子文档

update_custom_css_data

💡 云策文档标注

概述

update_custom_css_data 过滤器用于在更新 custom_css 帖子时,过滤 css(post_content)和 preprocessed(post_content_filtered)参数。它允许插件(如 CSS 预处理器)存储原始预处理 CSS 和处理后 CSS。

关键要点

  • 过滤器名称:update_custom_css_data
  • 主要用途:过滤 custom_css 帖子的 css 和 preprocessed 参数,支持 CSS 预处理器存储数据
  • 参数:$data(自定义 CSS 数据数组,包含 css 和 preprocessed 字符串)和 $args(传递给 wp_update_custom_css_post() 的参数数组)
  • 典型应用:通过 customize_value_custom_css 过滤器提供 post_content_filtered 作为设置值

代码示例

add_filter( 'customize_value_custom_css', function( $value, $setting ) {
    $post = wp_get_custom_css_post( $setting->stylesheet );
    if ( $post && ! empty( $post->post_content_filtered ) ) {
        $css = $post->post_content_filtered;
    }
    return $css;
}, 10, 2 );

📄 原文内容

Filters the css (post_content) and preprocessed (post_content_filtered) args for a custom_css post being updated.

Description

This filter can be used by plugin that offer CSS pre-processors, to store the original pre-processed CSS in post_content_filtered and then store processed CSS in post_content.
When used in this way, the post_content_filtered should be supplied as the setting value instead of post_content via a the customize_value_custom_css filter, for example:

add_filter( 'customize_value_custom_css', function( $value, $setting ) {
    $post = wp_get_custom_css_post( $setting->stylesheet );
    if ( $post && ! empty( $post->post_content_filtered ) ) {
        $css = $post->post_content_filtered;
    }
    return $css;
}, 10, 2 );

Parameters

$dataarray
Custom CSS data.

  • css string
    CSS stored in post_content.
  • preprocessed string
    Pre-processed CSS stored in post_content_filtered.
    Normally empty string.

$argsarray
The args passed into wp_update_custom_css_post() merged with defaults.

  • css string
    The original CSS passed in to be updated.
  • preprocessed string
    The original preprocessed CSS passed in to be updated.
  • stylesheet string
    The stylesheet (theme) being updated.

Source

$data = apply_filters( 'update_custom_css_data', $data, array_merge( $args, compact( 'css' ) ) );

Changelog

Version Description
4.7.0 Introduced.