钩子文档

post_updated_messages

💡 云策文档标注

概述

post_updated_messages 是一个 WordPress 过滤器,用于修改文章、页面和附件更新后的提示消息。开发者可以通过此 Hook 自定义后台管理界面的消息内容。

关键要点

  • 过滤器名称:post_updated_messages
  • 参数:$messages(数组),包含文章、页面和附件的默认消息
  • 用法示例:$messages = apply_filters( 'post_updated_messages', $messages );
  • 消息数组索引从 1 开始,0 为未使用
  • 支持文章(post)、页面(page)和附件(attachment)类型

代码示例

$messages['post'] = array(
    0  => '', // 未使用,消息从索引 1 开始
    1  => __( 'Post updated.' ) . $view_post_link_html,
    2  => __( 'Custom field updated.' ),
    3  => __( 'Custom field deleted.' ),
    4  => __( 'Post updated.' ),
    /* translators: %s: date and time of the revision */
    5  => isset( $_GET['revision'] ) ? sprintf( __( 'Post restored to revision from %s.' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
    6  => __( 'Post published.' ) . $view_post_link_html,
    7  => __( 'Post saved.' ),
    8  => __( 'Post submitted.' ) . $preview_post_link_html,
    9  => sprintf( __( 'Post scheduled for: %s.' ), '' . $scheduled_date . '' ) . $scheduled_post_link_html,
    10 => __( 'Post draft updated.' ) . $preview_post_link_html,
);

📄 原文内容

Filters the post updated messages.

Parameters

$messagesarray[]
Post updated messages. For defaults see $messages declarations above.

Source

$messages = apply_filters( 'post_updated_messages', $messages );

Changelog

Version Description
3.0.0 Introduced.

User Contributed Notes

  1. Skip to note 2 content

    This is the $messages declaration mentioned in the notes above:

    $messages['post'] = array(
        0  => '', // Unused. Messages start at index 1.
        1  => __( 'Post updated.' ) . $view_post_link_html,
        2  => __( 'Custom field updated.' ),
        3  => __( 'Custom field deleted.' ),
        4  => __( 'Post updated.' ),
        /* translators: %s: date and time of the revision */
        5  => isset( $_GET['revision'] ) ? sprintf( __( 'Post restored to revision from %s.' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
        6  => __( 'Post published.' ) . $view_post_link_html,
        7  => __( 'Post saved.' ),
        8  => __( 'Post submitted.' ) . $preview_post_link_html,
        9  => sprintf( __( 'Post scheduled for: %s.' ), '<strong>' . $scheduled_date . '</strong>' ) . $scheduled_post_link_html,
        10 => __( 'Post draft updated.' ) . $preview_post_link_html,
    );
    $messages['page'] = array(
        0  => '', // Unused. Messages start at index 1.
        1  => __( 'Page updated.' ) . $view_page_link_html,
        2  => __( 'Custom field updated.' ),
        3  => __( 'Custom field deleted.' ),
        4  => __( 'Page updated.' ),
        /* translators: %s: date and time of the revision */
        5  => isset( $_GET['revision'] ) ? sprintf( __( 'Page restored to revision from %s.' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
        6  => __( 'Page published.' ) . $view_page_link_html,
        7  => __( 'Page saved.' ),
        8  => __( 'Page submitted.' ) . $preview_page_link_html,
        9  => sprintf( __( 'Page scheduled for: %s.' ), '<strong>' . $scheduled_date . '</strong>' ) . $scheduled_page_link_html,
        10 => __( 'Page draft updated.' ) . $preview_page_link_html,
    );
    $messages['attachment'] = array_fill( 1, 10, __( 'Media file updated.' ) ); // Hack, for now.