/** * Populate a Post object with Post_Taxonomy relationships. * * @param Post $post */ public function get_post_taxonomy_relationships(Post $post) { $query = $this->wpdb->prepare('SELECT * FROM ' . $this->get_table() . ' WHERE object_id = %d', $post->get_id()); foreach ($this->wpdb->get_results($query, ARRAY_A) as $relationship) { $taxonomy = $this->taxonomy_dao->find($relationship['term_taxonomy_id']); if ($taxonomy instanceof Taxonomy) { $post->add_post_taxonomy(new Post_Taxonomy($post, $taxonomy)); } } }
/** * Post has just been imported. * * @param Post $post * @param Batch $batch */ public function post_imported(Post $post, Batch $batch) { $message = sprintf('Post <strong>%s</strong> has been successfully imported.', $post->get_title()); $this->api->add_deploy_message($batch->get_id(), $message, 'success', 103); }
/** * Display checkbox (e.g. for bulk actions). The checkbox should have the * value of the post ID. * * @param Post $post * @return string Text to be placed inside the column. */ public function column_cb($post) { return sprintf('<input type="checkbox" id="sme_select_post_%s" class="sme-select-post" name="%s[]" value="%s"/>', $post->get_id(), $this->_args['plural'], $post->get_id()); }
/** * Make sure parent post exist (if post has any) either in production * database or in batch. * * @param Post $post * @param array $posts * @return bool True if parent post exist (or post does not have a parent), false * otherwise. */ private function parent_post_exists(Post $post, $posts) { // Check if the post has a parent post. if ($post->get_parent() === null) { return true; } // Check if parent post exist on production server. if ($this->post_dao->get_by_guid($post->get_parent()->get_guid())) { return true; } // Parent post is not on production, look in this batch for parent post. foreach ($posts as $item) { if ($item->get_id() == $post->get_parent()->get_id()) { return true; } } return false; }
/** * @param Post $post */ public function set_post(Post $post) { $this->set_id($post->get_id() . '-' . $this->taxonomy->get_id()); $this->post = $post; }
/** * Publish a post sent to production. * * New posts that are sent to production will have a post status of * 'publish'. Since we don't want the post to go public until all data * has been synced from content stage, post status has been changed to * 'draft'. Post status is now changed back to 'publish'. * * @param Post $post */ public function publish_post(Post $post) { $prod_id = $this->post_dao->get_id_by_guid($post->get_guid()); if (!$prod_id) { $msg = sprintf('No post with GUID %s found on production.', $post->get_guid()); $this->api->add_deploy_message($this->batch->get_id(), $msg, 'error'); return; } /* * Trigger an action before changing the post status to give other plug-ins * a chance to act before the post goes public (e.g. cache warm-up). */ do_action('sme_pre_publish_post', $prod_id, get_current_blog_id()); /* * Publish the new post if post status from staging environment is set to * "publish". */ if ($post->get_post_status() == 'publish') { $this->post_dao->update_post_status($prod_id, 'publish'); } }
/** * Provide a Post object you want to add to the current batch. * * @param Batch $batch * @param Post $post */ private function add_post(Batch $batch, Post $post) { // Make sure the post is not already in the batch. foreach ($batch->get_posts() as $post_in_batch) { if ($post->get_id() === $post_in_batch->get_id()) { return; } } if ($post->get_type() === 'attachment') { $this->add_attachment($batch, $post->get_id()); } // Catch issue with term ID not being set properly. try { $this->post_taxonomy_dao->get_post_taxonomy_relationships($post); } catch (Exception $e) { $this->api->add_preflight_message($batch->get_id(), $e->getMessage(), 'warning'); } $post->set_meta($this->postmeta_dao->get_postmetas_by_post_id($post->get_id())); /* * Make it possible for third-party developers to modify post before it * is added to batch. */ do_action('sme_prepare_post', $post, $batch); $batch->add_post($post); $post_meta = $post->get_meta(); $record_count = count($post_meta); for ($i = 0; $i < $record_count; $i++) { $post_meta[$i] = $this->add_related_posts($batch, $post_meta[$i]); } $post->set_meta($post_meta); }
/** * @param array $raw * @return Post */ protected function do_create_object(array $raw) { $obj = new Post($raw['ID']); if (($parent = $this->find($raw['post_parent'])) !== null) { $obj->set_parent($parent); } $obj->set_author($raw['post_author']); $obj->set_date($raw['post_date']); $obj->set_date_gmt($raw['post_date_gmt']); $obj->set_modified($raw['post_modified']); $obj->set_modified_gmt($raw['post_modified_gmt']); $obj->set_content($raw['post_content']); $obj->set_title($raw['post_title']); $obj->set_excerpt($raw['post_excerpt']); $obj->set_post_status($raw['post_status']); $obj->set_comment_status($raw['comment_status']); $obj->set_ping_status($raw['ping_status']); $obj->set_password($raw['post_password']); $obj->set_name($raw['post_name']); $obj->set_to_ping($raw['to_ping']); $obj->set_pinged($raw['pinged']); $obj->set_content_filtered($raw['post_content_filtered']); $obj->set_guid($raw['guid']); $obj->set_menu_order($raw['menu_order']); $obj->set_type($raw['post_type']); $obj->set_mime_type($raw['post_mime_type']); $obj->set_comment_count($raw['comment_count']); return $obj; }