Private Hidden Admin Note for User meta - only Admin, Manager can see per User
Support › MB User Meta › Private Hidden Admin Note for User meta - only Admin, Manager can see per UserResolved
- This topic has 5 replies, 2 voices, and was last updated 3 years, 7 months ago by
Long Nguyen.
-
AuthorPosts
-
September 5, 2021 at 9:11 PM #30604
justdoit123
ParticipantI want to add a custom field "Note" per user (i use MB custom table)
User cannot see this custom field "Note", only Admin, Manager can see and edit note per User.
How can i do that in MB ?
thanks
September 6, 2021 at 12:57 PM #30617Long Nguyen
ModeratorHi,
You can use the extension MB Include Exclude to load a meta box for a/some predefined roles. Please get more details here https://docs.metabox.io/extensions/meta-box-include-exclude/
September 6, 2021 at 4:02 PM #30621justdoit123
Participantmy php is limited. can you give me some more example ??
in this sample code below, i don't know how to assign this to specific metabox ID ??
thanks
add_filter( 'rwmb_meta_boxes', 'prefix_include_exclude_demo' ); function prefix_include_exclude_demo( $meta_boxes ) { $meta_boxes[] = array( 'title' => 'Include Meta Box', // Register this meta box for posts matched below conditions 'include' => array( // With all conditions below, use this logical operator to combine them. Default is 'OR'. Case insensitive. Optional. 'relation' => 'OR', // List of post IDs. Can be array or comma separated. Optional. 'ID' => array( 1, 2 ), // List of post parent IDs. Can be array or comma separated. Optional. 'parent' => array( 3, 4 ), // List of post slugs. Can be array or comma separated. Optional. 'slug' => array( 'contact', 'about' ), // List of page templates. Can be array or comma separated. Optional. 'template' => array( 'full-width.php', 'sidebar-page.php' ), // List of categories IDs or names or slugs. Can be array or comma separated. Optional. 'category' => array( 1, 'Blog', 'another' ), // List of tag IDs or names or slugs. Can be array or comma separated. Optional. 'tag' => array( 1, 'fun' ), // Custom taxonomy. Optional. // Format: 'taxonomy' => list of term IDs or names or slugs (can be array or comma separated) 'location' => array( 12, 'USA', 'europe' ), 'os' => array( 'Windows', 'mac-os' ), // List of parent categories IDs or names or slugs. Can be array or comma separated. Optional. 'parent_category' => 'Parent', // List of parent tag IDs or names or slugs. Can be array or comma separated. Optional. 'parent_tag' => 'Parent', // Parent custom taxonomy. Optional. // Format: 'parent_taxonomy' => list of term IDs or names or slugs (can be array or comma separated) 'parent_location' => array( 12, 'USA', 'europe' ), // Check if current post/page is a child page 'is_child' => true, // List of user roles. Can be array or comma separated. Optional. 'user_role' => 'administrator', // List of user IDs. Can be array or comma separated. Optional. 'user_id' => array( 1, 2 ), // Custom condition. Optional. // Format: 'custom' => 'callback_function' // The function will take 1 parameter which is the meta box itself 'custom' => 'manual_include', ), 'fields' => array( array( 'name' => 'Name', 'id' => 'name', 'type' => 'text', ), ), ); // 2nd meta box $meta_boxes[] = array( 'title' => 'Exclude Meta Box', // Don't register this meta box for posts matched below conditions 'exclude' => array( 'relation' => 'OR', 'ID' => array( 1, 2 ), 'parent' => array( 3, 4 ), 'slug' => array( 'contact', 'about' ), 'template' => array( 'full-width.php', 'left-sidebar.php' ), 'category' => array( 1, 'News' ), 'tag' => array( 1, 'fun' ), 'user_role' => array( 'administrator', 'editor' ), 'user_id' => array( 1, 2 ), 'location' => array( 12, 'USA', 'europe' ), 'os' => array( 'Windows', 'mac-os' ), 'is_child' => true, 'custom' => 'manual_exclude', ), 'fields' => array( array( 'name' => 'Job', 'id' => 'job', 'type' => 'text', ), ), ); return $meta_boxes; } function prefix_include_exclude_manual_include( $meta_box ) { if ( $meta_box['title'] == 'Include Meta Box' ) return true; return false; }
September 6, 2021 at 10:12 PM #30637Long Nguyen
ModeratorHi,
Here is the sample code:
function your_prefix_function_name( $meta_boxes ) { $meta_boxes[] = [ 'title' => __( 'User Meta', 'your-text-domain' ), 'id' => 'user-meta', 'type' => 'user', 'include' => [ 'relation' => 'OR', 'user_role' => ['editor'], ], 'fields' => [ ... ], ]; return $meta_boxes; }
FYI, you can use the Builder to set the role as well, option Advanced Location Rules. Please read more on the documentation https://docs.metabox.io/extensions/meta-box-builder/#field-group-settings
September 8, 2021 at 8:52 AM #30658justdoit123
Participantdo i need to add_filter or add_action with this function ?? thanks
function your_prefix_function_name( $meta_boxes ) { $meta_boxes[] = [ 'title' => __( 'User Meta', 'your-text-domain' ), 'id' => 'user-meta', 'type' => 'user', 'include' => [ 'relation' => 'OR', 'user_role' => ['editor'], ], 'fields' => [ ... ], ]; return $meta_boxes; }
September 8, 2021 at 9:43 AM #30661Long Nguyen
ModeratorHi,
It looks like the same question here https://support.metabox.io/topic/can-i-create-custom-field-for-user-meta-in-wp-admin-and-add-php-code-generated
You can find the answer there. -
AuthorPosts
- You must be logged in to reply to this topic.