Thanks to @GTsvetanov from Stackoverflow.com.
Missing part of my code is $request->get_json_params();
for getting json request then compare it with schema using rest_validate_value_from_schema()
then using rest_sanitize_value_from_schema()
for saving proper data to database.
$schema = $this->user_playtime_meta_schema();
$val = $request->get_json_params();//<-- my mistake
$result = rest_validate_value_from_schema( $values, $schema );
if ( ! is_wp_error( rest_validate_value_from_schema( $val, $schema ) ) ) {
$sanitized = rest_sanitize_value_from_schema( $val, $schema );
} else {
return $result;
}
$user_meta = update_user_meta( $user_id, 'playtime', $sanitized );
Related Posts:
- Who is responsible for data sanitization in WordPress development?
- Safely store code(html/js..) into database
- Is sanitize_text_field() is enough to save to DB?
- Default WordPress settings API data sanitization
- How to display data from custom table in wordpress database?
- How does WordPress store data?
- Get all tags not just first 10 with wp api 2.0
- Data storage for JS app using WP REST API
- Permit Login if table row exists
- data (html) migration to posts
- What’s the proper way to sanitize checkbox value sent to the database
- Sending posts from Python to WordPress
- Using $wpdb | checking entered email against existing emails in db
- How to access a table in a wordpress database using REST API?
- How to rerieve comments and their replies from DB
- Where is the HTML-handler part in the wpdb class?
- WordPress API standard compliance and specification for external database [closed]
- oneOf two possible objects in WP REST API?
- Is it fine to have foreign key as primary key?
- Custom form that store input in database
- Restoring WordPress posts from database only
- Can a post ID be 0?
- Issue with wp_insert_post and post_content field error Could not update post in the database
- wp_posts – guid update
- WordPress REST API validation
- Performance Gains of Relational DB Setup
- what is the wp_5_posts table in the database?
- Migrating data between local and development server
- WordPress Database Charset/Collate
- Using Dynamic Data Pulled from a MySQL Table in a WordPress Page
- Migrating non-WordPress CMS to WordPress, lots of data to move — possible solutions?
- storing database in version control
- Is deleting orphaned wp_options entries safe?
- How to build a movie database with wordpress?
- Sub-domain or 2nd, temporary different domain?
- Hook to be used when creating a database table
- Delete all post meta except featured image
- Where is custom template file chosen for a post stored in the DB?
- How do i get user data from a custom table in the wordpress database by user ID?
- Converting WordPress into Android or iPhone app
- Safe way to find last inserted id in a table?
- Delete duplicate rows from wordpress database where a column is duplicate in phpmyadmin
- WooCommerce sku location in DB
- WordPress DATABASE Update Manually?
- I don’t see site_url and home_url fields in wp_options table (phpMyAdmin)?
- Multiple postmeta with same name for one post in wp_postmeta table
- Which is more efficient? Using usermeta, or creating a new MySQL table?
- Can I have multiple database users within WordPress?
- A field with dashes in the slug [closed]
- Is it necessary to sanitize wp_set_password user input?
- change wp user status from wp_users table
- How to resolve Connections using insecure transport are prohibited while –require_secure_transport=ON
- Is MariaDB’s Aria storage engine suitable for WordPress?
- Difficulty importing my live site to local
- WordPress returns to an old version
- Super slow queries from author archive pages killing my database
- localize elements in database
- How to fix database error duplicate entry
- WPDB SQL query with prepare() returning variable, not db value
- Get value form wordpress database
- Moving to another server database connection error [closed]
- Output Sanitation
- Best practice to limit results in get_row()?
- How to display content from external db with relevant urls
- Is there an easy way of exporting posts with their category already asigned and pictures from localhost?
- Connect to another WP install and grab post based on custom field
- Which table (and column) has the content of configured get_post_meta?
- Serialize data before inserting into the DB
- Pages from custom table
- content disappearing minutes after it’s published
- What is the most efficient way to reset a WordPress site?
- Add pdf to a website
- Optimizing function that automatically creates internal links based on post title string
- Can I customised default WP table
- WordPress where clauses in db select
- How to display data from db in select list [closed]
- Will adding & modifying default WordPress table index break future WordPress update
- echo site_url() returns a different value than what is in the database siteurl field
- Native timestamp on wp_options option
- _wp_attachment_metadata is not being added to database when PDF files uploaded
- SELECT rows between two datetimes when the range is dynamic [closed]
- How do I loop/iterate through posts to edit all img tags?
- error establishing a database connection 3
- How to edit posts/pages without making the change live?
- Correct and secure way to access a custom SQL database in a custom PHP template file
- How to optimise this database query?
- How to retrieve user data based on role using SQL?
- Does WordPress Support Using Named Pipes on the Windows Operating System?
- Missing latest posts and options after DB migration via phpMyAdmin
- Store the wordpress “featured image” under »wp_posts« Database table
- Custom metabox does not store data
- wordpress database error
- How do i get value from wp_postmeta?
- Local host to server import problem
- featured image not showing up with mysql_connect
- Options of accessing wordpress data from mobile app
- wp_usermeta key problem
- How to properly configure SSL connection to remote azure database for running queries within a WordPress environment
- Database Queries are crashing the server
- Uploading to WordPress Database