Ejemplo n.º 1
0
 /**
  * Creates the individual test data object.
  *
  * Create individual posts for testing with. Gathers basic information such
  * as title, content, thumbnail, etc. and inserts them with the post. Also
  * adds metaboxes if applicable .
  *
  * @access private
  *
  * @see TestContent, wp_insert_post, add_post_meta, update_post_meta, $this->random_metabox_content
  *
  * @param string $slug a custom post type ID.
  */
 private function create_test_object($slug)
 {
     // Get a random title
     $title = apply_filters("tc_{$slug}_term_title", TestContent::title());
     $return = wp_insert_term($title, $slug, apply_filters("tc_{$slug}_term_arguments", array('description' => TestContent::title(), 'slug' => sanitize_title($title))));
     // Then, set a test content flag on the new post for later deletion
     add_term_meta($return['term_id'], 'evans_test_content', '__test__', true);
     // Check if we have errors and return them or created message
     if (is_wp_error($return)) {
         error_log($return->get_error_message());
         return $return;
     } else {
         return array('action' => 'created', 'object' => 'term', 'oid' => $return['term_id'], 'type' => $slug, 'link_edit' => admin_url('/edit-tags.php?action=edit&taxonomy=' . $slug . '&tag_ID=' . $return['term_id']), 'link_view' => get_term_link($return['term_id']));
     }
 }
Ejemplo n.º 2
0
 /**
  * Creates the individual test data post.
  *
  * Create individual posts for testing with. Gathers basic information such
  * as title, content, thumbnail, etc. and inserts them with the post. Also
  * adds metaboxes if applicable .
  *
  * @access private
  *
  * @see TestContent, wp_insert_post, add_post_meta, update_post_meta, $this->random_metabox_content
  *
  * @param string $slug a custom post type ID.
  * @param array $supports Features that the post type supports.
  * @param array $supports All CMB2 metaboxes attached to the post type.
  */
 private function create_test_object($slug, $supports, $metaboxes)
 {
     $return = '';
     // Get a random title
     $title = apply_filters("tc_{$slug}_post_title", TestContent::title());
     // First, insert our post
     $post = array('post_name' => sanitize_title($title), 'post_status' => 'publish', 'post_type' => $slug, 'ping_status' => 'closed', 'comment_status' => 'closed');
     // Add title if supported
     if ($supports['title'] === true) {
         $post['post_title'] = $title;
     }
     // Add main content if supported
     if ($supports['editor'] === true) {
         $post['post_content'] = apply_filters("tc_{$slug}_post_content", TestContent::paragraphs());
     }
     // Add excerpt content if supported
     if ($supports['excerpt'] === true) {
         $post['post_excerpt'] = apply_filters("tc_{$slug}_post_excerpt", TestContent::plain_text());
     }
     // Insert then post object
     $post_id = wp_insert_post(apply_filters("tc_{$slug}_post_arguments", $post));
     // Then, set a test content flag on the new post for later deletion
     add_post_meta($post_id, 'evans_test_content', '__test__', true);
     // Add thumbnail if supported
     if ($this->connected == true && ($supports['thumbnail'] === true || in_array($slug, array('post', 'page')))) {
         update_post_meta($post_id, '_thumbnail_id', TestContent::image($post_id));
     }
     $taxonomies = get_object_taxonomies($slug);
     // Assign the post to terms
     if (!empty($taxonomies)) {
         $return .= $this->assign_terms($post_id, $taxonomies);
     }
     // Spin up metaboxes
     if (!empty($metaboxes)) {
         foreach ($metaboxes as $cmb) {
             $return .= $this->metaboxes->random_metabox_content($post_id, $cmb, $this->connected);
         }
     }
     // Check if we have errors and return them or created message
     if (is_wp_error($post_id)) {
         error_log($post_id->get_error_message());
         return $post_id;
     } else {
         return array('action' => 'created', 'object' => 'post', 'oid' => $post_id, 'type' => get_post_type($post_id), 'link_edit' => admin_url('/post.php?post=' . $post_id . '&action=edit'), 'link_view' => get_permalink($post_id));
     }
 }