/** * Save the metabox data * @since 1.0 */ public function save_meta($post_id) { // Verify nonce if (!isset($_POST['grfwp_nonce']) || !wp_verify_nonce($_POST['grfwp_nonce'], basename(__FILE__))) { return $post_id; } // Check autosave if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return $post_id; } // Check permissions if (!current_user_can('edit_page', $post_id)) { return $post_id; } elseif (!current_user_can('edit_post', $post_id)) { return $post_id; } // Save the metadata if (GRFWP_REVIEW_POST_TYPE == $_REQUEST['post_type']) { $cur = get_post_meta($post_id, 'grfwp', true); $new = grfwpInit::array_filter_recursive($_REQUEST['grfwp'], 'sanitize_text_field'); if ($new && $new != $cur) { update_post_meta($post_id, 'grfwp', $new); } elseif ($new == '' && $cur) { delete_post_meta($post_id, 'grfwp', $cur); } } }
/** * Run callback on every element in array recursively * * Used to sanitize all values in an array * @since 0.1 */ public static function array_filter_recursive($arr, $callback) { foreach ($arr as &$value) { if (is_array($value)) { $value = grfwpInit::array_filter_recursive($value, $callback); } } return array_filter($arr, $callback); }