source_post() public méthode

Returns the source post object.
Since: 3.0.0
public source_post ( ) : WP_Pos\WP_Post | null
Résultat WP_Pos\WP_Post | null Source post object.
 /**
  * Connects the current post with a new remote one.
  *
  * @return bool|WP_Error Whether or not the relationship was updated successfully, or an error object.
  */
 private function connect_new_post()
 {
     $source_post = $this->context->source_post();
     if (!$source_post) {
         return false;
     }
     $remote_site_id = $this->context->remote_site_id();
     $save_context = ['source_blog' => $this->context->source_site_id(), 'source_post' => $source_post, 'real_post_type' => $this->get_real_post_type($source_post), 'real_post_id' => empty($_POST['post_ID']) ? $this->context->source_post_id() : (int) $_POST['post_ID']];
     /** This action is documented in inc/advanced-translator/Mlp_Advanced_Translator_Data.php */
     do_action('mlp_before_post_synchronization', $save_context);
     switch_to_blog($remote_site_id);
     $new_post_id = wp_insert_post(['post_type' => $source_post->post_type, 'post_status' => 'draft', 'post_title' => $this->context->new_post_title()], true);
     restore_current_blog();
     $save_context['target_blog_id'] = $remote_site_id;
     /** This action is documented in inc/advanced-translator/Mlp_Advanced_Translator_Data.php */
     do_action('mlp_after_post_synchronization', $save_context);
     if (is_wp_error($new_post_id)) {
         $this->last_error = $new_post_id;
         return false;
     }
     $this->context = RelationshipContext::from_existing($this->context, [RelationshipContext::KEY_NEW_POST_ID => $new_post_id]);
     return $this->connect_existing_post();
 }
 /**
  * Returns the latest/best-matching posts with respect to the given context.
  *
  * @since 3.0.0
  *
  * @param RelationshipContext $context Relationship context data object.
  *
  * @return WP_Post[] The latest/best-matching posts.
  */
 public function get_posts(RelationshipContext $context)
 {
     $remote_site_id = $context->remote_site_id();
     if (!$remote_site_id) {
         return [];
     }
     $source_post = $context->source_post();
     if (!$source_post) {
         return [];
     }
     $args = ['numberposts' => 10, 'post_type' => $source_post->post_type, 'post_status' => ['draft', 'future', 'private', 'publish']];
     $remote_post_id = $context->remote_post_id();
     if ($remote_post_id) {
         $args['exclude'] = $remote_post_id;
     }
     $search_query = $this->get_search_query();
     if ($search_query) {
         $args = array_merge($args, ['s' => $search_query, 'orderby' => 'relevance']);
     }
     switch_to_blog($remote_site_id);
     $posts = get_posts($args);
     restore_current_blog();
     return $posts;
 }