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

时间:2022-04-23
本文章向大家介绍WordPress 中禁止编辑“已发布”的文章,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

出于某些目的(如多人博客要保护自己已经发表的文章不受篡改),我们可能需要对WordPress 中“已发布”的文章进行“编辑”的限制。下面由Jeff 分享个来自prevent-publish-edit-plugin 插件的代码,可以实现WordPress 中禁止编辑“已发布”的文章。

<?php /* * Removes the edit action from the post row actions if the post is published */ function pep_post_row_actions( $actions , $post ) {   if ( $post->post_status == 'publish' ) unset( $actions['edit'] );   return $actions; }   /* * Blanks the Edit link shown in the public interface if the post is published */ function pep_edit_post_link( $link ) {   global $post;   if ( $post->post_status == 'publish' ) $link = '';   return $link;   }   /* * Removes the Edit Post option from the admin bar if a single post is being shown and * the post is published */ function pep_before_admin_bar_render() {   global $wp_admin_bar, $post;   if ( is_single() && $post->post_status == 'publish' ) $wp_admin_bar->remove_menu('edit');   }   // set up the filters add_filter( 'post_row_actions' , 'pep_post_row_actions' , 1 , 2 ); add_filter( 'edit_post_link' , 'pep_edit_post_link' , 1 );   // set up the action add_action( 'wp_before_admin_bar_render' , 'pep_before_admin_bar_render' ); ?>

你可以自行添加到主题的functions.php 文件下或者做成一个插件激活使用。