/** * * * @since 1.4 */ public function &sanitiseData(&$data, $page_id, $tab_id = null) { $output = array(); $tab = null; $page = $this->page($page_id); $sections =& $page->sections; if ($tab_id) { $tab = $this->tab($page, $tab_id); $sections =& $page->sections[$tab->id]; } foreach ($sections as $section) { if ($section->id && isset($tab->context)) { $output[$tab->context][$section->id]['content_type'] = $section->id; $output[$tab->context][$section->id]['callback'] = $section->callback; foreach ($section->fields as $field) { $value = isset($data[$section->id][$field->id]) ? $data[$section->id][$field->id] : null; $validator = new SiteTreeDataValidator($value, $field->type, $field->default, $field->conditions); $output[$tab->context][$section->id][$field->id] = $validator->value(); } continue; } foreach ($section->fields as $field) { $value = isset($data[$field->id]) ? $data[$field->id] : null; $validator = new SiteTreeDataValidator($value, $field->type, $field->default, $field->conditions); $output[$field->id] = $validator->value(); } } return $output; }
/** * Validates a post request and saves the metadata. * * This method is hooked into the save_post action hook. * * @since 1.3 * * @param $post_id string * @param $post object */ public function process_metadata($post_id, $post) { if (!isset($_POST['_sitetree_nonce']) || $post->post_status == 'auto-draft' || wp_is_post_revision($post)) { return false; } if (!($post->post_type == 'post' || $post->post_type == 'page')) { return false; } check_admin_referer('save_post_meta', '_sitetree_nonce'); if (!current_user_can('edit_post', $post)) { wp_die(__('Cheatin’ uh?')); } $input = isset($_POST['sitetree']) ? $_POST['sitetree'] : array(); $this->load_sections($post->post_type); foreach ($this->sections as $section) { foreach ($section->fields as $field) { $value = isset($input[$field->id]) ? $input[$field->id] : null; $validator = new SiteTreeDataValidator($value, $field->type, $field->default, $field->conditions); $value = $validator->value(); // The metadata associated to the checkboxes needs to be processes separatedly. if (isset($field->config['context'])) { $exclude = $this->db->getOption($field->config['context'], array(), 'exclude'); $excluded = in_array($post->ID, $exclude); // If the checkbox has been ticked and the ID of the current post/page was not excluded yet // we add it to the $exclude array if ($value && !$excluded) { $exclude[] = $post->ID; $this->db->invalidateCache($field->config['context']); } elseif (!$value) { $this->db->invalidateCache($field->config['context']); // New post published? if ($post->post_date == $post->post_modified && $post->post_status == 'publish' && $field->config['context'] == 'xml') { $this->plugin->pingController()->schedulePing(); } // If it was previously excluded, we remove the post from the $exclude array. if ($excluded) { $exclude = array_diff($exclude, array($post->ID)); } } $this->db->setOption($field->config['context'], $exclude, 'exclude'); } else { if ($value == 'reset') { $this->db->deletePostMeta($post->ID, $field->id); } else { $this->db->setPostMeta($post->ID, $field->id, $value); } } } } }
/** * * * @since 1.4 */ public function pageViewFieldValue($field, $section, $tab) { $context = $group = $section->id; if ($group && isset($tab->context)) { $context = $tab->context; } $value = $this->db->getOption($field->id, $field->default, $group, $context); $validator = new SiteTreeDataValidator($value, $field->type, $field->default, $field->conditions); return $validator->value(); }