/** * Handler for updating custom field data. * * @since 2.5.6 * * @param mixed $value Value to write * @param object $object The object from the response * @param string $field_name Name of field * * @return bool|int */ public function write_handler($value, $object, $field_name) { $pod_name = pods_v('type', $object); $id = pods_v('id', $object); $pod = self::get_pod($pod_name, $id); if ($pod && PodsRESTFields::field_allowed_to_extend($field_name, $pod, 'write')) { $pod->save($field_name, $value, $id); return $pod->field($field_name); } return false; }
/** * Handler for updating custom field data. * * @since 2.5.6 * * @param mixed $value Value to write * @param object $object The object from the response * @param string $field_name Name of field * @param WP_REST_Request $request Current request * @param string $object_type Type of object * * @return bool|int */ public static function write_handler($value, $object, $field_name, $request, $object_type) { $pod_name = pods_v('type', $object); /** * If $pod_name in the line above is empty then the route invoked * may be for a taxonomy, so lets try and check for that * */ if (empty($pod_name)) { $pod_name = pods_v('taxonomy', $object); } /** * $pod_name is still empty, so check lets check $object_type * */ if (empty($pod_name)) { if ('attachment' == $object_type) { $pod_name = 'media'; } else { $pod_name = $object_type; } } /** * Filter the pod name * * @since 2.6.7 * * @param array $pod_name Pod name * @param Pods $object Rest object * @param string $field_name Name of the field * @param WP_REST_Request $request Current request * @param string $object_type Rest Object type */ $pod_name = apply_filters('pods_rest_api_pod_name', $pod_name, $object, $field_name, $request, $object_type); $id = pods_v('id', $object); if (empty($id)) { $id = pods_v('ID', $object); } $pod = self::get_pod($pod_name, $id); if ($pod && PodsRESTFields::field_allowed_to_extend($field_name, $pod, 'write')) { $pod->save($field_name, $value, $id); return $pod->field($field_name); } return false; }