Giter VIP home page Giter VIP logo

mb-rest-api's People

Contributors

btsimonh avatar caco26i avatar latiosthinh avatar mertonium avatar nhatrangnet avatar rilwis avatar truongwp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

mb-rest-api's Issues

Get the data of MB Settings Pages via REST APIs

Currently, there is no way to fetch the data for the MB Settings Pages via the REST APIs. I came across this old support ticket which states that the settings values are not sent to the REST API via MB REST API.

I'd like to know if there is a way through which we can get the data of the MB Settings Pages via REST APIs.

not working in updating "MB User Meta"

I purchased "MB USER META" and installed well.

I setup the "MB USER META Fields" like below.
image
(I can see the proper fields in Profile Page(admin) and when I modify data in DB, it looks well in the admin page)

but update user meta data with rest-api, this is not work.
for example.
image

this "POST Method Request" is not work.

PS.
I tested "mb-rest-api" with other type (like post) this was worked.
only with "user" wasn't work.
I checked so many times "post method" "application/json" type in header... etc...

Filter fields

Any idea how to filter the fields?

I'm trying to use filter[meta_query][0][key]=post_id&filter[meta_query][0][value]=77 but it does not apply any filter.

I'm using the rest-filter-master plugin

Thanks!

Normalize values

Because WP lacking any better classification on datas (no matter it is legacy implementation) then all API metabox response fields are not described enought.

All fields values all called with https://developer.wordpress.org/reference/functions/get_metadata/ and it has very unhappy implementation for 2 main situations when somebody else want to work with data:

  1. Lacking any information if value exists or not. Everytime is returned empty string (very big mistake) https://codex.wordpress.org/Function_Reference/get_post_custom_values returns null what is right.
  2. Every field is returned as string. No matter when field is defined as number or association and whatever other.

Both situations should be fixed easy:

adding normalization function

    protected function has_array_value($array)
    {
        return !empty(array_filter(array_values($array), function ($value) {
            return is_array($value);
        }));
    }

    protected function has_string_key($array)
    {
        return !empty(array_filter(array_keys($array), function ($key) {
            return is_string($key);
        }));
    }

    protected function normalize_value($field, $value)
    {
        if ($value == '') {
            return null;
        }

        if (is_array($value)) {
            if (empty($value)) {
                return [];
            } elseif ($this->has_array_value($value) || $this->has_string_key($value)) {
                return $value;
            } else {
                return array_map([$this, 'sanitize_value'], $field, $value);
            }
        }

        if (in_array($field['type'], $this->numeric_fields)) {
            return numfmt_parse($field);
        }

        return $value;
    }

numeric fields are all association fields, media fields, and number fields

$this->numeric_fields = array_merge($this->media_fields, ['number', 'post', 'taxonomy']);

and then just wrap it on

$values[ $field['id'] ] = $value;

with

$values[ $field['id'] ] = $this->normalize_value($field, $field_value);

Results are:

  1. All not set and empty string fields are null
  2. Empty array is still empty array (collection)
  3. All integer stringed fields are converted to integer
  4. Objects (assoc_array) is without touch

API returning an empty array

Hi.

The Custom Post Types are now returning an empty array in the meta_box key API response.
I have updated to WordPress 5.0.1 today, and I have noticed about this after that. I really don't know if is something related to WP version.

The field type is date.

image

I already have updated the plugins too, but no success.

There's something that I have lost?

Fatal error: Uncaught Error: Call to undefined method RWMB_Field::process_value()

When I try to post and save a CPT with a custom field managed with Meta Box I get this error.
FastCGI sent in stderr: "PHP message: PHP Fatal error: Uncaught Error: Call to undefined method RWMB_Field::process_value() in /var/www/html/wp-content/plugins/mb-rest-api/class-mb-rest-api.php:221 web_1 | Stack trace: web_1 | #0 /var/www/html/wp-content/plugins/mb-rest-api/class-mb-rest-api.php(113): MB_Rest_API->update_value(Array, 1, 82818) web_1 | #1 /var/www/html/wp-includes/rest-api/endpoints/class-wp-rest-controller.php(461): MB_Rest_API->update_post_meta(Array, Object(WP_Post), 'meta_box', Object(WP_REST_Request), 'familygo_offert...') web_1 | #2 /var/www/html/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php(659): WP_REST_Controller->update_additional_fields_for_object(Object(WP_Post), Object(WP_REST_Request)) web_1 | #3 /var/www/html/wp-includes/rest-api/class-wp-rest-server.php(1050): WP_REST_Posts_Controller->create_item(Object(WP_REST_Request)) web_1 | #4 /var/www/html/wp-includes/rest-api/class-wp-rest-server.php(376): WP_REST_Server->dispatch(Object(WP_REST_Request)) web_1 | #5 /var/www/html/wp-includes/rest-api.php(339): WP_REST_Server->serve_request('/wp/v2/offerta') web_1 | #6 /var/www/html/w in /var/www/html/wp-content/plugins/mb-rest-api/class-mb-rest-api.php on line 221

WordPress 5.5.3
MB Rest API 1.4.0
Meta Box 4.18.4

PHP 7.4

access control on metadata

One challenge we have is restricting user access to the metadata......
I'm toying with the idea of adding an entry to each metadata defn containing a set of required capabilities (maybe an entry for read, entry for write), and a check with 'current_user_can' against these for data read and data write.
Any thoughts/plans on this?

On POST, WP 4.7.3 seems to pass an object rather than a JSON string?

line 84 complains that json_decode is being passed an array rather than a json string.
A quick debug showed this. Maybe they changed something in WP 4.7.3?
Also, if any of the meta-box fields is an array or an object, then strip_tags() complains, and the content of the array/object is destroyed on POST. so either way, writing meta-box data this way is currently broken.

Term meta not saved for custom taxonomies

When a custom taxonomy is created via POST request to rest api, the meta box fields are not saved on said request.

e.g. create a new custom taxonomy called Article tag. When registering the taxonomy make sure the rest api properties are set:

'show_in_rest'          => true,
'rest_base'             => 'video-tags',            
'rest_controller_class' => 'WP_REST_Terms_Controller', 

Register a simple meta box text field with your custom taxonomy.

array(
    'id' => 'video_id',
    'name' => esc_html__( 'Video ID', 'digg-core' ),
    'type' => 'text',
)

A subsequent POST request to /wp-json/wp/v2/article-tags will result in a new tag being created with the parameter video_id value not set. The parameters passed in are:

"title": "A test video tag",
"meta_box": "{
    "video_id": "12345"
}"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.