Esempio n. 1
0
 public static function pll_after_post_column($column, $post_id)
 {
     if (false === strpos($column, 'language_')) {
         return;
     }
     $language = Pll()->model->get_language(substr($column, 9));
     $translation_id = pll_get_post($post_id, $language->slug);
     if (get_post_meta($translation_id, Endpoints::TRAPP_META_TRANSLATED, true)) {
         echo '</span>';
     }
 }
Esempio n. 2
0
<div id="post-translations" class="translations">

    <h4><?php 
_e('Translations', $text_domain);
?>
</h4>

    <table>

        <?php 
foreach ($languages as $language) {
    ?>

            <?php 
    $value = Pll()->model->post->get_translation($post_id, $language);
    if (!$value || $value == $post_id) {
        // $value == $post_id happens if the post has been (auto)saved before changing the language
        $value = '';
    }
    if (isset($_GET['from_post'])) {
        $value = PLL()->model->get_post((int) $_GET['from_post'], $language);
    }
    $add_link = sprintf('<a href="%1$s" class="pll_icon_add" title="%2$s"></a>', esc_url(PLL()->links->get_new_post_translation_link($post_id, $language)), __('Add new', $text_domain));
    ?>

            <?php 
    if ($value || $is_master || !$has_trapp_key) {
        ?>

            <tr>
                <td class="pll-language-column"><?php 
Esempio n. 3
0
 /**
  * Avoid post link cache when a link is updated - See PLL_Frontend_Filters_Links::post_type_link
  */
 public static function clear_post_filters_links_cache($postId)
 {
     if (!is_admin()) {
         $cacheKey = 'post:' . $postId;
         Pll()->filters_links->cache->clean($cacheKey);
     }
 }
Esempio n. 4
0
 /**
  * Remove Polylang save_post hook if the post does not already have a language.
  *
  * @param int $postId Post id of the edited post.
  *
  * @return void.
  */
 public static function removeSavePost($postId)
 {
     if (get_post_status($postId) == 'auto-draft') {
         return;
     }
     $screen = get_current_screen();
     if (!$screen || $screen->base != 'post') {
         return;
     }
     if (empty($_POST['post_lang_choice'])) {
         // We will handle the translations instead of Polylang
         remove_action('save_post', array(Pll()->filters_post, 'save_post'), 21, 3);
     }
 }
Esempio n. 5
0
 public function saveImage($translationId, $languageSlug, $image)
 {
     // Check if the translations already exists
     if ($translation = Pll()->model->post->get_translation($image['id'], $languageSlug)) {
         return update_post_meta($translationId, $image['key'], $translation);
     }
     $translationImagePost = $image['post'];
     // Create a new attachment
     $translationImagePost->ID = null;
     $translationImagePost->post_parent = $translationId;
     $translationImageId = wp_insert_attachment($translationImagePost);
     add_post_meta($translationImageId, '_wp_attachment_metadata', get_post_meta($image['id'], '_wp_attachment_metadata', true));
     add_post_meta($translationImageId, '_wp_attached_file', get_post_meta($image['id'], '_wp_attached_file', true));
     add_post_meta($translationImageId, '_wp_attachment_image_alt', get_post_meta($image['id'], '_wp_attachment_image_alt', true));
     $mediaTranslations = Pll()->model->post->get_translations($image['id']);
     if (!$mediaTranslations && ($lang = Pll()->model->post->get_language($image['id']))) {
         $mediaTranslations[$lang->slug] = $image['id'];
     }
     $mediaTranslations[$languageSlug] = $translationImageId;
     pll_save_post_translations($mediaTranslations);
     update_post_meta($translationId, $image['key'], $translationImageId);
     do_action('bp_trapp_after_save_post_image', $translationImageId, $image);
 }