最新消息:

WordPress 禁止编辑“已发布”的文章

很多小伙伴的网站都有注册功能,而且大家都拥有发布文章的权限。为了保护大家的文章不会被随意更改,就需要对“已发布”的文章进行“编辑”的限制。下面分享个来自 prevent-publish-edit-plugin 插件的代码,可以实现禁止编辑“已发布”的文章。

复制以下代码到当前使用主题的 functions.php 文件中即可。

/*
 功能描述: 禁止编辑“已发布”的文章
 功能介绍页面: https://www.ivicos.com/55.html
*/
function pep_post_row_actions( $actions , $post ) {
 if ( $post->post_status == 'publish' ) unset( $actions['edit'] );
 return $actions;
}
add_filter( 'post_row_actions' , 'pep_post_row_actions' , 1 , 2 );

function pep_edit_post_link( $link ) {
 global $post;
 if ( $post->post_status == 'publish' ) $link = '';
 return $link;
}
add_filter( 'edit_post_link' , 'pep_edit_post_link' , 1 );

function pep_before_admin_bar_render() {
 global $wp_admin_bar, $post;
 if( is_single() && $post->post_status == 'publish' ) $wp_admin_bar->remove_menu('edit');
}
add_action( 'wp_before_admin_bar_render' , 'pep_before_admin_bar_render' );

好了,WordPress 禁止编辑“已发布”的文章 的方法就分享到这里,非常感谢你的来访。如果你喜欢本站,请不要忘记收藏本站,以便下次继续访问;也可以 关注站长微博 随时获取最新动态。你的支持就是我最大的动力!

转载请注明:爱维科斯 » WordPress 禁止编辑“已发布”的文章

支付宝打赏支付宝打赏 微信打赏微信打赏

如果文章对你有帮助,欢迎点击上方按钮打赏作者