Skip to content

Commit

Permalink
Add cmb2_get_metabox_sanitized_values helper-function
Browse files Browse the repository at this point in the history
  • Loading branch information
jtsternberg committed Oct 17, 2016
1 parent a08a0ac commit e7a0f12
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions misc/helper-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,21 @@ function cmb2_save_metabox_fields_data( $meta_box_id, $object_id, array $data_to
$cmb = cmb2_get_metabox( $meta_box_id, $object_id );
$cmb->save_fields( $object_id, $cmb->object_type(), $data_to_save );
}

/**
* Returns array of sanitized field values (without saving them) from
* provided array of values (Likely $_POST data.)
*
* Combined with the metabox `'save_fields' => false` config option, you can use this to
* save the box data somewhere else.
*
* @link https://wordpress.org/support/topic/sanitizing-data-outside-metabox-context Forum post
*
* @param mixed $meta_box_id Metabox ID (or metabox config array)
* @param int $object_id ID of post/user/comment/options-page to save the data against
* @param array $data_to_save Array of key => value data for saving. Likely $_POST data.
*/
function cmb2_get_metabox_sanitized_values( $meta_box_id, array $data_to_save ) {
$cmb = cmb2_get_metabox( $meta_box_id );
$cmb->get_sanitized_values( $data_to_save );
}

0 comments on commit e7a0f12

Please sign in to comment.