如何永久修改 Wordpress 的 wp-admin/post.php?
How can I permanently modify Wordpress' wp-admin/post.php?
为了解决第 3 方插件的愚蠢问题,我不得不为订阅者级别的用户提供一些我不希望他们实际拥有的编辑功能。 (这不会让他们访问编辑链接,但如果他们聪明的话,他们可以直接访问编辑 URL。)由于我的站点只有订阅者和管理用户,我可以通过简单地修改能力检查来解决问题在 wp-admin/post.php 中要求订阅者没有的附加功能,例如:
if ( ! current_user_can( 'edit_post', $post_id ))
wp_die( __( 'Sorry, you are not allowed to edit this item.' ) );
变为:
if ( ! current_user_can( 'edit_post', $post_id ) OR ! current_user_can('edit_pages'))
wp_die( __( 'Sorry, you are not allowed to edit this item.' ) );
这很完美,但我知道它会被覆盖,每次 Wordpress 更新时都需要重新完成。有没有办法通过过滤器或类似方式以更永久的方式应用此修复程序?
您不需要修改 post.php 文件。在您的 functions.php:
中使用此代码
add_filter('user_has_cap',function($allcaps,$need_caps, $args) {
if ($_SERVER['SCRIPT_NAME']=='/wp-admin/post.php' && isset($_GET['action']) && $_GET['action']=='edit' && $args[0]=='edit_post' && ! current_user_can('edit_pages')) {
foreach ($need_caps as $cap) {
unset($allcaps[$cap]);
}
}
return $allcaps;
},10,3);
上面的评论是有效的……这个也是如此,只需将其中一个添加到您的函数文件中即可。
function authority_check(){
global $pagenow;
if(is_admin() && !current_user_can('manage-capabilities')){
if(in_array($pagenow,array('post.php')) || in_array($pagenow, array('post-new.php'))){
wp_die(__( 'Sorry, you are not allowed to edit this item.'));
}
}
}
add_action('admin_init', 'authority_check');
为了解决第 3 方插件的愚蠢问题,我不得不为订阅者级别的用户提供一些我不希望他们实际拥有的编辑功能。 (这不会让他们访问编辑链接,但如果他们聪明的话,他们可以直接访问编辑 URL。)由于我的站点只有订阅者和管理用户,我可以通过简单地修改能力检查来解决问题在 wp-admin/post.php 中要求订阅者没有的附加功能,例如:
if ( ! current_user_can( 'edit_post', $post_id ))
wp_die( __( 'Sorry, you are not allowed to edit this item.' ) );
变为:
if ( ! current_user_can( 'edit_post', $post_id ) OR ! current_user_can('edit_pages'))
wp_die( __( 'Sorry, you are not allowed to edit this item.' ) );
这很完美,但我知道它会被覆盖,每次 Wordpress 更新时都需要重新完成。有没有办法通过过滤器或类似方式以更永久的方式应用此修复程序?
您不需要修改 post.php 文件。在您的 functions.php:
中使用此代码add_filter('user_has_cap',function($allcaps,$need_caps, $args) {
if ($_SERVER['SCRIPT_NAME']=='/wp-admin/post.php' && isset($_GET['action']) && $_GET['action']=='edit' && $args[0]=='edit_post' && ! current_user_can('edit_pages')) {
foreach ($need_caps as $cap) {
unset($allcaps[$cap]);
}
}
return $allcaps;
},10,3);
上面的评论是有效的……这个也是如此,只需将其中一个添加到您的函数文件中即可。
function authority_check(){
global $pagenow;
if(is_admin() && !current_user_can('manage-capabilities')){
if(in_array($pagenow,array('post.php')) || in_array($pagenow, array('post-new.php'))){
wp_die(__( 'Sorry, you are not allowed to edit this item.'));
}
}
}
add_action('admin_init', 'authority_check');