当更新非公共定制帖子类型时,它会显示“帖子已更新。查看帖子”

时间:2019-11-21 作者:Gavin

我创建了如下自定义帖子类型:

add_action( \'init\', function() {
    $args = array(
        \'description\'           => \'\',
        \'public\'                => false,
        \'publicly_queryable\'    => false,
        \'show_ui\'               => true,
        \'show_in_rest\'          => false,
        \'rest_base\'             => \'\',
        \'has_archive\'           => false,
        \'show_in_menu\'          => true,
        \'exclude_from_search\'   => false,
        \'capability_type\'       => \'post\',
        \'map_meta_cap\'          => true,
        \'hierarchical\'          => false,
        \'rewrite\'               => array(
                                        \'slug\'              => \'job\',
                                        \'with_front\'        => false
                                ),
        \'query_var\'             => true,
        \'supports\'              => array(
                                        \'title\'
                                    ),
        \'label\'                 => \'Jobs\',
        \'labels\'                => array(
                                        \'name\'              => \'Jobs\',
                                        \'singular_name\'     => \'Job\',
                                        \'menu_name\'         => \'Jobs\',
                                        \'all_items\'         => \'All Jobs\',
                                        \'add_new_item\'      => \'Add New Job\',
                                        \'new_item\'          => \'New Job\',
                                        \'edit_item\'         => \'Edit Job\',
                                        \'view_item\'         => \'View Job\',
                                        \'featured_image\'    => \'Job Photo\'
                                    ),
    );

    register_post_type( \'job\', $args );
} );
你可以看到我有publicpublicly_queryable 设置为false.

然而,当我创建或更新一篇新文章时,它会显示“post updated.View post”,其中“View post”是指向该文章的链接。此帖子不是公开的,因此不应该有“查看帖子”链接。如何阻止它将此链接添加到更新的邮件中?

1 个回复
最合适的回答,由SO网友:Kaperto 整理而成

要自定义编辑页面上的消息,可以使用此筛选器:

add_filter("post_updated_messages", function ($messages) {

    $post_type = "job";

    if ($post_type === $GLOBALS["post_type"]) {

        $messages[$post_type] = [
            1 => "the object is updated",
            6 => "the object is created",
        ];

    }

    return $messages;

});

相关推荐