Mlp_Translatable_Post_Data::get_remote_post PHP Method

get_remote_post() public method

public get_remote_post ( WP_Post $source_post, integer $blog_id ) : WP_Post
$source_post WP_Post
$blog_id integer
return WP_Post
    public function get_remote_post(WP_Post $source_post, $blog_id)
    {
        $linked = \Inpsyde\MultilingualPress\get_translation_ids($source_post->ID);
        if (!empty($linked[$blog_id]) && \Inpsyde\MultilingualPress\site_exists($blog_id)) {
            $post = get_blog_post($blog_id, $linked[$blog_id]);
            if ($post) {
                return $post;
            }
        }
        return $this->get_dummy_post($source_post->post_type);
    }

Usage Example

 /**
  * Register one box for each connected site.
  *
  * @param int     $blog_id
  * @param WP_Post $post
  * @param int     $current_blog_id
  *
  * @return void
  */
 private function register_metabox_per_language($blog_id, WP_Post $post, $current_blog_id)
 {
     $remote_post = $this->data->get_remote_post($post, $blog_id);
     $lang = $this->data->get_remote_language($blog_id);
     $title = $this->get_metabox_title($blog_id, $remote_post, $lang);
     $metabox_data = array('remote_blog_id' => $blog_id, 'remote_post' => $remote_post, 'language' => $lang);
     $nonce_validator = Mlp_Nonce_Validator_Factory::create("save_translation_of_post_{$post->ID}_for_site_{$blog_id}", $current_blog_id);
     $view = new Mlp_Translation_Metabox_View($nonce_validator);
     add_meta_box("inpsyde_multilingual_{$blog_id}", $title, array($view, 'render'), null, 'advanced', 'default', $metabox_data);
     if (empty($remote_post->dummy)) {
         $this->register_metabox_view_details($view, $post, $blog_id);
     } else {
         $callback = array($view, 'show_translation_checkbox');
         /**
          * Filter the post translator activation checkbox callback.
          *
          * @param array|string $callback Callback name or class-method array.
          *
          * @return array|string
          */
         $checkbox_callback = apply_filters('mlp_post_translator_activation_checkbox', $callback);
         if ($checkbox_callback) {
             add_action("mlp_translation_meta_box_top_{$blog_id}", $checkbox_callback, 10, 3);
         }
     }
     /**
      * Runs after registration of the meta box for the given blog's language.
      *
      * @param WP_Post $post    Post object.
      * @param int     $blog_id Blog ID.
      */
     do_action('mlp_translation_meta_box_registered', $post, $blog_id);
 }
All Usage Examples Of Mlp_Translatable_Post_Data::get_remote_post