"mb_user_meta & mb_rest_api" has problem

Support MB User Meta "mb_user_meta & mb_rest_api" has problemResolved

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #13779
    JiroJiro
    Participant

    I 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.2

    When 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.

    #13791
    Anh TranAnh Tran
    Keymaster

    Hi 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 be string, it's text.
    • The function doesn't return $meta_boxes.

    I've just made a test with Postman and here is the result:

    https://i.imgur.com/F92ilAA.png

    #13796
    JiroJiro
    Participant

    Thanks 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,...)

    #13797
    JiroJiro
    Participant

    imgur 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"]=>
    .......
    
    #13806
    Anh TranAnh Tran
    Keymaster

    Hi Jiro, you're right about the missing user in the update_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 is post and specific_type is post type. For terms, it's term and taxonomy. For users, as there's no specific type, we use user and user.

    #13807
    JiroJiro
    Participant

    thanks Anh!

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.