/** * Returns the given properties with added data of all schema-aware fields registered for the given object type. * * @since 2.0.0 * * @param array $properties Schema properties definition. * @param string $object_type Object type. * * @return array Properties with added data of all schema-aware fields registered for the given object type. */ public function get_extended_properties(array $properties, $object_type) { $fields = $this->field_access->get_fields($object_type); foreach ($fields as $name => $definition) { if (empty($definition['schema'])) { continue; } $properties['properties'][$name] = $definition['schema']; } return $properties; }
/** * Updates all registered updatable fields of the given object. * * @since 2.0.0 * * @param array $object Object data in array form. * @param WP_REST_Request $request Request object. * @param string $object_type Optional. Object type. Defaults to empty string. * * @return int Number of fields updated. */ public function update_fields_for_object($object, WP_REST_Request $request, $object_type = '') { $updated = 0; $fields = $this->field_access->get_fields($object_type); foreach ($fields as $name => $definition) { if (!isset($request[$name])) { continue; } if (empty($definition['update_callback'])) { continue; } if (!is_callable($definition['update_callback'])) { if (defined('WP_DEBUG') && WP_DEBUG) { trigger_error("Invalid callback. Cannot update {$name} field for {$object_type}."); } continue; } call_user_func($definition['update_callback'], $request[$name], $object, $name, $request, $object_type); $updated++; } return $updated; }