/**
  * Updates the translation completed setting of the post with the given ID.
  *
  * @since   3.0.0
  * @wp-hook save_post
  *
  * @param int     $post_id Post ID.
  * @param WP_Post $post    Post object.
  *
  * @return bool Whether or not the translation completed setting was updated successfully.
  */
 public function update_setting($post_id, WP_Post $post)
 {
     if (!$this->nonce->is_valid()) {
         return false;
     }
     if (!in_array($post->post_status, ['publish', 'draft'], true)) {
         return false;
     }
     $value = array_key_exists(PostRepository::META_KEY, $_POST) ? (bool) $_POST[PostRepository::META_KEY] : false;
     return $this->post_repository->update_post($post_id, $value);
 }
    /**
     * Renders the setting markup.
     *
     * @since   3.0.0
     * @wp-hook post_submitbox_misc_actions
     *
     * @param WP_Post $post Post object.
     *
     * @return void
     */
    public function render(WP_Post $post)
    {
        $post_id = $post->ID;
        $translated = $this->post_repository->is_post_translated($post_id);
        /**
         * Filters whether or not the checkbox for the current post should be rendered.
         *
         * @since 3.0.0
         *
         * @param bool $show_checkbox Whether or not to show the checkbox.
         * @param int  $post_id       Post ID.
         * @param bool $translated    Whether or not the post is translated.
         */
        if (!apply_filters('multilingualpress.show_translation_completed_checkbox', true, $post_id, $translated)) {
            return;
        }
        $id = 'mlp-translation-completed';
        ?>
		<div class="misc-pub-section misc-pub-mlp-translation-completed">
			<?php 
        echo \Inpsyde\MultilingualPress\nonce_field($this->nonce);
        ?>
			<label for="<?php 
        echo esc_attr($id);
        ?>
">
				<input type="checkbox" name="<?php 
        echo esc_attr(PostRepository::META_KEY);
        ?>
"
					value="1" id="<?php 
        echo esc_attr($id);
        ?>
" <?php 
        checked($translated);
        ?>
>
				<?php 
        _e('Translation completed', 'multilingual-press');
        ?>
			</label>
		</div>
		<?php 
    }
    /**
     * Renders the widget's view.
     *
     * @since 3.0.0
     *
     * @param mixed $object   Queried object, or other stuff.
     * @param array $instance Widget settings.
     *
     * @return void
     */
    public function render($object, array $instance)
    {
        $related_site_ids = $this->site_relations->get_related_site_ids();
        if (!$related_site_ids) {
            return;
        }
        $have_untranslated_posts = false;
        ?>
		<table class="widefat">
			<?php 
        foreach ($related_site_ids as $related_site_id) {
            ?>
				<?php 
            switch_to_blog($related_site_id);
            ?>
				<?php 
            $untranslated_posts = $this->post_repository->get_untranslated_posts();
            ?>
				<?php 
            if ($untranslated_posts) {
                ?>
					<?php 
                $have_untranslated_posts = true;
                ?>
					<tr>
						<th colspan="3">
							<strong>
								<?php 
                /* translators: %s: site name */
                $message = __('Pending Translations for %s', 'multilingual-press');
                printf($message, get_bloginfo('name'));
                ?>
							</strong>
						</th>
					</tr>
					<?php 
                foreach ($untranslated_posts as $post) {
                    ?>
						<tr>
							<td style="width: 20%;">
								<?php 
                    edit_post_link(__('Translate', 'multilingual-press'), '', '', $post->ID);
                    ?>
							</td>
							<td style="width: 55%;">
								<?php 
                    echo esc_html(get_the_title($post->ID));
                    ?>
							</td>
							<td style="width: 25%;">
								<?php 
                    echo esc_html(get_the_time(get_option('date_format'), $post->ID));
                    ?>
							</td>
						</tr>
					<?php 
                }
                ?>
				<?php 
            }
            ?>
				<?php 
            restore_current_blog();
            ?>
			<?php 
        }
        ?>
			<?php 
        if (!$have_untranslated_posts) {
            ?>
				<tr>
					<td colspan="3">
						<?php 
            esc_html_e('No untranslated posts found.', 'multilingual-press');
            ?>
					</td>
				</tr>
			<?php 
        }
        ?>
		</table>
		<?php 
    }