首页 > 解决方案 > 如何在 WP-admin UI 中隐藏高级自定义字段(ACF)?

问题描述

检查下面的屏幕截图;我要做的就是在 wordpress 后端为自定义用户隐藏某些 ACF 字段。

在此处输入图像描述

标签: wordpresswordpress-themingcustom-wordpress-pageswordpress-thesis-theme

解决方案


从 ACF 5.0.0 开始,有一种更简单的方法可以做到这一点,而无需输出 CSS。如果您使用acf/prepare_field钩子并返回false该字段将不会呈现。

<?php
function so37111468_hide_field( $field ) {

  // hide the field if the current user is not able to save options within the admin
  if ( ! current_user_can( 'manage_options' ) ) {
    return false;
  }

  return $field;
}

add_filter( 'acf/prepare_field/key=MYFIELDKEY', 'so37111468_hide_field' );
?>

可以在此处找到该过滤器的文档:https ://www.advancedcustomfields.com/resources/acf-prepare_field/


推荐阅读