WordPress后台的文章列表、页面列表或自定义文章类型的列表提供了快速编辑的小功能,使用快速编辑功能,用户不需要进入文章编辑界面即可以修改标题、分类、标签、状态、日期、密码等,非常实用。如果不想要快速编辑这个功能怎么办?今天就分享一下WordPress移除后台文章/页面/标签/分类的快速编辑按钮教程。

FILTER过滤器

文章

apply_filters( \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’post_row_actions\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, string[] $actions, WP_Post $post )

页面

apply_filters( \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’page_row_actions\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, string[] $actions, WP_Post $post )

标签

apply_filters( \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’tag_row_actions\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, string[] $actions, WP_Term $tag )

分类目录、自定义分类法(把{$taxonomy}替换为分类类型名称

apply_filters( \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”{$taxonomy}_row_actions\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”, string[] $actions, WP_Term $tag )

作用:

筛选页面列表表上的行操作链接数组。

参数:

$actions – 行操作链接的数组。默认值为“编辑”、“快速编辑”、“还原”、“垃圾箱”、“永久删除”、“预览”和“查看”。

$post – post对象(或者获取文章ID、文章类型等)

示例:

移除文章、页面的快速编辑按钮代码:

function boke8_remove_row_actions($actions, $post) {

if(isset($actions[\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’inline hide-if-no-js\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’])){

unset($actions[\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’inline hide-if-no-js\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’]);

}

return $actions;

}

add_filter(\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’page_row_actions\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’boke8_remove_row_actions\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, 10, 2);

add_filter(\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’post_row_actions\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’boke8_remove_row_actions\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, 10, 2);

按钮值对应:

编辑 – edit

快速编辑 – inline hide-if-no-js

查看 – view

删除 – delete

移至回收站 – trash

还原 – untrash

扩展

移动指定自定义文章类product的快速编辑按钮

function boke8_remove_row_actions($actions, $post) {

if($post->post_type == \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’product\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ && isset($actions[\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’inline hide-if-no-js\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’])){

unset($actions[\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’inline hide-if-no-js\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’]);

}

return $actions;

}

add_filter(\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’post_row_actions\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’boke8_remove_row_actions\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, 10, 2);

或者

function boke8_remove_row_actions($actions, $post) {

if(in_array(get_post_type($post),[\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’product\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’]) && isset($actions[\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’inline hide-if-no-js\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’])){

unset($actions[\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’inline hide-if-no-js\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’]);

}

return $actions;

}

add_filter(\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’post_row_actions\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’boke8_remove_row_actions\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, 10, 2);

源文件

wp-admin/includes/class-wp-posts-list-table.php

相关新闻

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

联系我们

联系我们

151-1101-0018

在线咨询:
邮件:30115776@qq.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信
关注微信
分享本页
返回顶部