Forum Replies Created
-
AuthorPosts
-
Anh Tran
KeymasterHi Jiro, you're right about the missing
userin theupdate_user_metacall. I've just added that fixed.Regarding the var_dump, it's not strange as the field registry (where all fields are stored) is structured like this:
object_type specific_type field 1 field 2For posts,
object_typeispostandspecific_typeis post type. For terms, it'stermand taxonomy. For users, as there's no specific type, we useuseranduser.Anh Tran
KeymasterHi, you can do like this with Meta Box:
First, separate the code that get list of BuddyPress groups into a function (it's a good practice to keep this logic away from plugins):
function prefix_get_bp_groups() { global $wpdb; $table = $wpdb->prefix."bp_groups"; $groups = $wpdb->get_results( "SELECT id,name FROM $table" ); if ( !empty( $groups ) ) { return []; } $return = []; foreach( $groups as $group ) { $return[$group->id] = $group->name; } return $return; }Then register a meta box with the following code:
add_filter( 'rwmb_meta_boxes', 'prefix_register_meta_boxes' ); function prefix_register_meta_boxes( $meta_boxes ) { $meta_boxes[] = [ 'title' => 'Your title', 'fields' => [ [ 'id' => 'your_key', 'name' => 'BuddyPress group', 'type' => 'select', 'options' => prefix_get_bp_groups(), // THIS ], ], ]; return $meta_boxes; }Anh Tran
KeymasterHi, please change the priority in the
add_actionfrom 0 to something greater than 20. Meta Box plugin register fields at priority 20 (to make sure all custom post types and custom taxonomies are available when they also use theinithook with priority 10). So, changing it to a number greater than 20 makes the meta boxes and fields available and you're able to use the helper functions to get the value.Anh Tran
KeymasterI'm afraid it's not possible. I'll see if we can add that to the plugin. This is a good idea.
March 19, 2019 at 5:04 PM in reply to: disable user from submitting mobile and email in text area using frontend form #13793Anh Tran
KeymasterHi,
I think this can be done with custom JavaScript only. So you need to enqueue your JS file on the page that has the form, then in the code, when the form is being submitted, check if the value of the textarea is a mobile number or email address. If it is, then return
falseto prevent the submission.This is a pseudo-code that might give you some idea:
jQuery( function( $ ) { $( '.your-form' ).on( 'submit', function() { var value = $( '#your-field' ).val(); if ( checkIfIsMobileNumberOrEmail( value ) ) { return false; } } ); } );Anh Tran
KeymasterIt works fine, but when you add a custom capability then that capability needs to be given to any roles who need it, including administrators.
This isn’t the responsibility of Meta Box, it’s up to the admin to provide the appropriate permissions to any roles that need it.That's correct. I think a plugin like Members would do the job better than Meta Box, since it's too verbose for capability management.
I'll add the info to the docs when updating the plugin.
Anh Tran
KeymasterHi Jiro, please change the code for meta boxes to:
add_action( 'rwmb_meta_boxes', 'prefix_register_meta_boxes' ); function prefix_register_meta_boxes( $meta_boxes ) { $meta_boxes[] = array( 'id' => 'personal', 'title' => 'Personal Information', 'type' => 'user', // Specifically for user 'fields' => array( array( 'name' => 'test mb for user', 'desc' => '', 'id' => 'test4', 'type' => 'text', ), ) ); return $meta_boxes; }Your code has 2 issues:
- The
typeof the field should not bestring, it'stext. - The function doesn't return
$meta_boxes.
I've just made a test with Postman and here is the result:
Anh Tran
KeymasterIt's fixed here and will be available in the new version soon.
Anh Tran
KeymasterAssume you have this code to register your meta box:
add_filter( 'rwmb_meta_boxes', 'prefix_register_meta_boxes' ); function prefix_register_meta_boxes( $meta_boxes ) { $meta_boxes[] = array( // Your meta box code goes here ); }Then change it to:
add_action( 'init', function() { add_filter( 'rwmb_meta_boxes', 'prefix_register_meta_boxes' ); } ); function prefix_register_meta_boxes( $meta_boxes ) { $meta_boxes[] = array( // Your meta box code goes here ); }Anh Tran
KeymasterHi,
For the date picker, as the plugin already supports a custom 'date' field, so it's not available to use default HTML5 input types. In short, the field types that are already supported by the plugin will overwrite the HTML input types.
Anh Tran
KeymasterHi Guy,
I've added that attribute. But in my test, even when adding it, the post type doesn't show in the admin menu for admins to view/edit them.
March 15, 2019 at 11:31 AM in reply to: ✅Showing decimal field leave extra zeros at the end. Any filter to solve that? #13747Anh Tran
KeymasterGlad that you found the filter. I missed it, too. Just added the docs for it. Thanks for your feedback!
Anh Tran
KeymasterHi Infolu, you just need to include the meta box with ID
rwmb-user-infoto the list of meta boxes in the shortcode, like this:[mb_user_profile_info id="your-meta-box-id,rwmb-user-info"]March 15, 2019 at 11:23 AM in reply to: ✅Enable Edit For admin while on Front end read only metabox #13745Anh Tran
KeymasterYou can modify the
readonlyattribute with the value like this:'readonly' => ! is_admin(),So, on the admin, it's
true, on the front end -false.Anh Tran
KeymasterHi,
Good trick on
get_current_screen()!Regarding the user language, the field ID (for user meta) is
locale. However, the list of options you need to make by yourself.The display name has the field ID
display_name.The "Sessions" button is just a simple button and you can do that with
buttonfield. However, to make sure it works like WordPress, you have to do the code to log out from everywhere by yourself. - The
-
AuthorPosts