Bricks 中文文档:bricks/dynamic_data/after_do_action

📄 原始资料  |  展开查看原始 JSON(bricks-dynamic_data-after_do_action.json){ “name”: “bricks/dynamic_data/after_do_action”, “kind”: “action”, “url”: “https://academy.bricksbuilder.io/developer/hooks/actions/bricks-dynamic_data-after_do_action/”, “scraped_at”: “2026-08-29”, “hook_name”: “bricks/dynami…

📄 原始资料  |  展开查看原始 JSON(bricks-dynamic_data-after_do_action.json)
{
  "name": "bricks/dynamic_data/after_do_action",
  "kind": "action",
  "url": "https://academy.bricksbuilder.io/developer/hooks/actions/bricks-dynamic_data-after_do_action/",
  "scraped_at": "2026-08-29",
  "hook_name": "bricks/dynamic_data/after_do_action",
  "description": {
    "en": "Runs after the dynamic data  tag is processed. This allows you to execute code after a specific do_action tag has been rendered.",
    "zh": "动态数据  标签处理完毕之后触发。允许你在指定的 do_action 标签渲染完成后执行代码。"
  },
  "parameters": [
    {
      "name": "action",
      "type": "string",
      "type_zh": null,
      "description": {
        "en": "The action name specified in the tag (e.g. my_hook in  ).",
        "zh": "标签中指定的动作名称(例如  中的 my_hook)。"
      }
    },
    {
      "name": "filters",
      "type": "array",
      "type_zh": null,
      "description": {
        "en": "Array of filters applied to the tag.",
        "zh": "应用于标签的筛选器数组。"
      }
    },
    {
      "name": "context",
      "type": "string",
      "type_zh": null,
      "description": {
        "en": "The context in which the tag is being rendered (e.g., ‘text’).",
        "zh": "标签被渲染所处的上下文(例如 'text')。"
      }
    },
    {
      "name": "post",
      "type": "WP_Post|null",
      "type_zh": null,
      "description": {
        "en": "The current post object, or null.",
        "zh": "当前文章对象,或 null。"
      }
    },
    {
      "name": "value",
      "type": "string",
      "type_zh": null,
      "description": {
        "en": "The rendered output of the action (captured via output buffering).",
        "zh": "该动作的渲染输出(通过输出缓冲捕获)。"
      }
    }
  ],
  "example_usage": "add_action( 'bricks/dynamic_data/after_do_action', function( $action, $filters, $context, $post, $value ) {\n    if ( $action === 'my_custom_hook' ) {\n        // Code to run after 'my_custom_hook' is processed via dynamic data\n        error_log( 'Finished processing my_custom_hook' );\n    }\n}, 10, 5 );"
}

前言

动态数据 标签处理完毕之后触发。允许你在指定的 do_action 标签渲染完成后执行代码。

用法

将代码加入子主题的 functions.php

add_action( 'bricks/dynamic_data/after_do_action', function( $action, $filters, $context, $post, $value ) {
    if ( $action === 'my_custom_hook' ) {
        // Code to run after 'my_custom_hook' is processed via dynamic data
        error_log( 'Finished processing my_custom_hook' );
    }
}, 10, 5 );

参数

  • $action (string):标签中指定的动作名称(例如 中的 my_hook)。
  • $filters (array):应用于标签的筛选器数组。
  • $context (string):标签被渲染所处的上下文(例如 ‘text’)。
  • $post (WP_Post|null):当前文章对象,或 null。
  • $value (string):该动作的渲染输出(通过输出缓冲捕获)。

示例代码

触发自定义动作

add_action( 'bricks/dynamic_data/after_do_action', function( $action, $filters, $context, $post, $value ) {
    if ( $action === 'my_custom_hook' ) {
        // Code to run after 'my_custom_hook' is processed via dynamic data
        error_log( 'Finished processing my_custom_hook' );
    }
}, 10, 5 );

根据条件短路返回原值

根据条件跳过或修改返回值:

add_filter( 'bricks/dynamic_data/after_do_action', function( $value, $action ) {
    if ( is_admin() ) { return $value; }
    // TODO: custom logic here
    return $value;
} );

补充说明

更多细节可参考 官方文档