"mb_user_meta & mb_rest_api" has problem
Support › MB User Meta › "mb_user_meta & mb_rest_api" has problemResolved
- This topic has 5 replies, 2 voices, and was last updated 6 years, 1 month ago by
Jiro.
-
AuthorPosts
-
March 18, 2019 at 8:44 PM #13779
Jiro
ParticipantI want to use mb_user_meta & mb_rest_api.
I purchased mb_user_meta. and I followed example code on https://docs.metabox.io/extensions/mb-user-meta/
and I can see the proper page in admin and I can update the mb value on that page.but I can not update my user MB data with rest-api.
Below is my Server code.
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 ‘context’ => ‘normal’, ‘priority’ => ‘high’, 'fields' => array( array( 'name' => 'test mb for user', 'desc' => '', 'id' => 'test4', 'type' => 'string', ), ) );
and this is trying & result page from POSTMAN.
fail update
PS.
meta-box version: 4.17.0
mb_meta_user version: 1.2.3
mb_rest_api: 1.3.2When I try with POSTMAN I logged in admin role user.
I checked there is no problem to update other type(Post)’s MB data.Only problem in updating “user” type.
I checked “activate” of my mb_user_meta plugin.I tried to find any errors from php-error.log or php-fpm-error.log.
but didn’t find anything.March 19, 2019 at 4:58 PM #13791Anh 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
type
of 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:
March 19, 2019 at 8:09 PM #13796Jiro
ParticipantThanks for your effort, but I found something strange.
As your kindly support, that was not working with me.Instead of that in MB-REST-API...
I found '$field' has wrong value. in 198 line of class-mb-rest-api.php
foreach ( $data as $field_id => $value ) { $field = rwmb_get_registry( 'field' )->get( $field_id, 'user' ); $this->update_value( $field, $value, $object->ID ); }
and I change the code like below and everything works fine.
foreach ( $data as $field_id => $value ) { $field = rwmb_get_registry( 'field' )->get( $field_id, 'user', 'user' ); $this->update_value( $field, $value, $object->ID ); }
The code which I used for MB user meta is below.
<?php add_filter( 'rwmb_meta_boxes', 'prefix_register_meta_boxes' ); function prefix_register_meta_boxes( $meta_boxes ) { $meta_boxes[] = array( 'title' => 'Personal Information', 'type' => 'user', // Specifically for user 'fields' => array( array( 'name' => 'test mb for user', 'desc' => '', 'id' => 'test5', 'type' => 'text', ), ) ); return $meta_boxes; }
and when I print var_dump(rwmb_get_registry( 'field' )).
it printed out as like below. as you can see there is "user" under the "user".
So strange, isn't it?I never modify any Metabox source code in before includes (mb-rest-api, mb-user-meta,...)
March 19, 2019 at 8:16 PM #13797Jiro
Participantimgur is so strange in this moment. anyway,
var_dump pritns...object(RWMB_Field_Registry)#4507 (1) { ["data":"RWMB_Field_Registry":private]=> array(3) { ["user"]=> array(1) { ["user"]=> array(1) { ["test5"]=> array(33) { ["size"]=> int(30) ["maxlength"]=> .......
March 20, 2019 at 9:33 AM #13806Anh Tran
KeymasterHi Jiro, you're right about the missing
user
in theupdate_user_meta
call. 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 2
For posts,
object_type
ispost
andspecific_type
is post type. For terms, it'sterm
and taxonomy. For users, as there's no specific type, we useuser
anduser
.March 20, 2019 at 9:39 AM #13807Jiro
Participantthanks Anh!
- The
-
AuthorPosts
- You must be logged in to reply to this topic.