* * @param $post_ID */ function save_meta($post_ID) { // Make sure we should be here! if (!isset($_POST['_rbm_fields']) || !wp_verify_nonce($_POST['rbm-meta'], 'rbm-save-meta') || !current_user_can('edit_posts')) { return; } foreach ($_POST['_rbm_fields'] as $field) { $value = $_POST[$field]; // If array, and told to do so, store in DB as a broken apart, non-unique meta field. // Someday I'd like to remove the 3rd conditional and simply assume this, but for now, to be safe, // it is manual. if (is_array($value) && isset($value[0]) && isset($_POST["_rbm_field_{$field}_multi_field"])) { // Delete all instances of meta field first, as add_post_meta will simply continuously add, forever, // even if the value already exists (like an indexed array) delete_post_meta($post_ID, $field); foreach ($value as $_value) { add_post_meta($post_ID, $field, $_value); } } else { update_post_meta($post_ID, $field, $_POST[$field]); } } } } // Primary instantiation require_once __DIR__ . '/includes/rbm-fh-functions.php'; RBMFH(); }
/** * Initializes a field. * * @since 1.1.0 */ private function field_init() { static $i; $i = $i === null ? 0 : $i + 1; if (empty(RBMFH()->fields)) { wp_nonce_field('rbm-save-meta', 'rbm-meta'); } RBMFH()->fields[] = $this->name; ?> <input type="hidden" name="_rbm_fields[<?php echo $i; ?> ]" value="<?php echo $this->name; ?> "/> <?php if ($this->args['multi_field']) { ?> <input type="hidden" name="_rbm_field_<?php echo $this->name; ?> _multi_field" value="1"/> <?php } }