/** * This gets the template for a single entry. * * @since 1.0 * @author Heather Anderson * @access private * * @uses current_user_can() Returns true if current user has given cap * @uses $this->get_entry_html() Returns our form HTML * @return string $html Our HTML form */ private function get_entry_html($entries) { $html = ''; if (is_wp_error($entries) || empty($entries)) { $html .= 'No entries'; } else { $html .= '<ul id="awpd-ha-3-entry-list">'; foreach ($entries as $e) { $html .= awpd_ha_3_get_single_entry($e); } $html .= '</ul>'; } return $html; }
/** * Save my task and return arguements * * @since 1.0 * @author Heather Anderson * * @param array $posted_values required Array of values from $_POST * @uses esc_attr() Keep things safe * @uses wp_kses_post() Safety for 'post like' content * @uses get_current_user_id() Returns current user_id * @uses wp_insert_post() Insert post to WP database * @uses is_wp_error() Returns true if passed value is an WP error object * @return array $args Success/fail args */ private function save_entry($posted_values) { ?> <pre><?php print_r($posted_values); ?> </pre><?php $post_content = isset($posted_values['content']) ? $posted_values['content'] : ''; $post_args = array('post_title' => esc_attr($posted_values['title']), 'post_type' => 'member-post', 'post_content' => wp_kses_post($post_content), 'post_author' => absint(get_current_user_id()), 'post_status' => 'publish'); if (isset($posted_values['post_id']) && !empty($posted_values['post_id'])) { $post_args['ID'] = absint($posted_values['post_id']); } $post_id = wp_insert_post($post_args); if (!is_wp_error($post_id)) { $args = array('success' => true, 'message' => 'Task saved'); if ($post_id == $posted_values['post_id']) { $args['updated'] = true; $args['entry_title'] = esc_attr($posted_values['title']); $args['entry_entry'] = esc_textarea($posted_values['entry']); } else { $entry = get_post($post_id); $args['html'] = awpd_ha_3_get_single_entry($entry); } } else { $args = array('success' => false, 'message' => 'Had a post title but somethin went wrong saving the task'); } return $args; }