Пример #1
0
 /**
  * Copy various properties from one post to another.
  *
  * @param int $source_id The source post, to copy FROM
  * @param int $target_id The target post, to copy TO
  * @return void
  **/
 public function sync_properties($source_id, $target_id)
 {
     if (!($source_post = get_post($source_id))) {
         return;
     }
     $source_lang_code = bbl_get_post_lang_code($source_id);
     $target_lang_code = bbl_get_post_lang_code($target_id);
     $target_parent_post = false;
     if ($source_post->post_parent) {
         $source_parent_post = $this->get_post_in_lang($source_post->post_parent, $source_lang_code);
         $target_parent_post = $this->get_post_in_lang($source_parent_post, $target_lang_code);
     }
     $target_post = get_post($target_id);
     $postdata = array('ID' => $target_id, 'post_author' => $source_post->post_author, 'post_modified' => $target_post->post_modified, 'post_modified_gmt' => $target_post->post_modified_gmt, 'ping_status' => $source_post->ping_status, 'post_password' => $source_post->post_password, 'menu_order' => $source_post->menu_order, 'post_mime_type' => $source_post->post_mime_type);
     if ($target_parent_post) {
         $postdata['post_parent'] = $target_parent_post->ID;
     } else {
         $postdata['post_parent'] = 0;
     }
     if (bbl_get_default_lang_code() == $source_lang_code) {
         $postdata['post_date'] = $source_post->post_date;
         $postdata['post_date_gmt'] = $source_post->post_date_gmt;
     }
     // Comment status only synced when going from the default lang code
     if (bbl_get_default_lang_code() == $source_lang_code) {
         $postdata['comment_status'] = $source_post->comment_status;
     }
     $postdata = apply_filters('bbl_pre_sync_properties', $postdata, $source_id);
     wp_update_post($postdata);
 }
 /**
  * Hooks the Babble bbl_pre_sync_properties filter to
  * log any changes to parent. We're not making changes
  * to the data, just logging significant changes for
  * debug purposes.
  *
  * @param array $postdata The data which will be applied to the post as part of the sync
  * @param int $origin_id The ID of the post we are syncing from
  * @return array The data which will be applied to the post as part of the sync
  **/
 public function pre_sync_properties($postdata, $origin_id)
 {
     $current_post = get_post($postdata['ID']);
     if ($current_post->post_parent != $postdata['post_parent']) {
         $user = wp_get_current_user();
         $remote_ip = $_SERVER['REMOTE_ADDR'];
         $referer = $_SERVER['HTTP_REFERER'];
         $lang = bbl_get_current_lang_code();
         $origin_lang = bbl_get_post_lang_code($origin_id);
         bbl_log("Babble: {$user->user_login} has changed {$postdata['ID']} parent from {$current_post->post_parent} ({$current_post->post_type}) to {$postdata['post_parent']}. \tOrigin: {$origin_id}. Origin lang: {$origin_lang}. IP {$remote_ip}. User lang: {$lang}. Referer {$referer}.", true);
     }
     return $postdata;
 }
                    ?>
">remove from group</a>
									<?php 
                }
                ?>
								</th>
								<td class="manage-column column-type"><?php 
                echo esc_html($post->post_type);
                ?>
</td>
								<td class="manage-column column-status"><?php 
                echo esc_html($post->post_status);
                ?>
</td>
								<td class="manage-column column-lang"><?php 
                echo esc_html(bbl_get_post_lang_code($post->ID));
                ?>
</td>
							</tr>
					<?php 
            }
            ?>

						<?php 
        }
        ?>
						<?php 
    } else {
        ?>

				<tr><td colspan="4"><em>no posts found for this translation group</em></td></tr>
Пример #4
0
                    ?>
">remove from group</a>
									<?php 
                }
                ?>
								</th>
								<td class="manage-column column-type"><?php 
                echo $post->post_type;
                ?>
</td>
								<td class="manage-column column-status"><?php 
                echo $post->post_status;
                ?>
</td>
								<td class="manage-column column-lang"><?php 
                echo bbl_get_post_lang_code($post->ID);
                ?>
</td>
							</tr>
					<?php 
            }
            ?>
							
						<?php 
        }
        ?>
						<?php 
    } else {
        ?>
							
				<tr><td colspan="4"><em>no posts found for this translation group</em></td></tr>
 /**
  * Hooks the WP filter get_edit_post_link
  *
  * @filter get_edit_post_link
  * @param string $url The edit post link URL
  * @param int $post_ID The ID of the post to edit
  * @param string $context The link context.
  *
  * @return string The edit post link URL
  * @author Simon Wheatley
  **/
 public function get_edit_post_link($url, $post_ID, $context)
 {
     if ($this->no_recursion) {
         return $url;
     }
     if (bbl_get_default_lang_code() == bbl_get_post_lang_code($post_ID)) {
         return $url;
     }
     $completed_jobs = $this->get_completed_post_jobs(bbl_get_default_lang_post($post_ID));
     if (!isset($completed_jobs[bbl_get_current_lang_code()])) {
         return $url;
     }
     $job = $completed_jobs[bbl_get_current_lang_code()];
     if (!current_user_can('publish_post', $job->ID)) {
         return $url;
     }
     $this->no_recursion = true;
     $url = get_edit_post_link($completed_jobs[bbl_get_current_lang_code()]->ID);
     $this->no_recursion = false;
     return $url;
 }
 /**
  * Hooks the WP post_class filter to add some language specific classes.
  *
  * @param array $classes The post classes 
  * @param array $class One or more classes which have been added to the class list.
  * @param int $post_id The ID of the post we're providing classes for 
  * @return array The body classes 
  **/
 public function post_class(array $classes, $class, $post_id)
 {
     $post = get_post($post_id);
     $post_lang_code = bbl_get_post_lang_code($post);
     $lang = bbl_get_lang($post_lang_code);
     if (self::use_default_text_direction($post)) {
         $default_lang = bbl_get_default_lang();
         $classes[] = 'bbl-post-' . sanitize_html_class($default_lang->text_direction);
     } else {
         $classes[] = 'bbl-post-' . sanitize_html_class($lang->text_direction);
     }
     # @TODO I don't think this class should be included:
     $classes[] = 'bbl-post-' . sanitize_html_class($lang->name);
     $classes[] = 'bbl-post-' . sanitize_html_class($lang->url_prefix);
     $classes[] = 'bbl-post-' . sanitize_html_class($lang->code);
     # @TODO I don't think this class should be included:
     $classes[] = 'bbl-post-' . sanitize_html_class($lang->display_name);
     return $classes;
 }
Пример #7
0
 /**
  * Hooks the WP set_object_terms action to sync any untranslated
  * taxonomies across to the translations.
  *
  * @param int $object_id The object to relate to
  * @param array $terms The slugs or ids of the terms
  * @param array $tt_ids The term_taxonomy_ids
  * @param string $taxonomy The name of the taxonomy for which terms are being set
  * @param bool $append If false will delete difference of terms
  * @return void
  **/
 public function set_object_terms($object_id, $terms, $tt_ids, $taxonomy, $append)
 {
     if ($this->no_recursion) {
         return;
     }
     $this->no_recursion = true;
     // DO NOT SYNC THE TRANSID TAXONOMIES!!
     if (in_array($taxonomy, $this->ignored_taxonomies())) {
         $this->no_recursion = false;
         return;
     }
     if ($this->is_taxonomy_translated($taxonomy)) {
         // Here we assume that this taxonomy is on a post type
         $translations = bbl_get_post_translations($object_id);
         foreach ($translations as $lang_code => &$translation) {
             if (bbl_get_post_lang_code($object_id) == $lang_code) {
                 continue;
             }
             $translated_taxonomy = bbl_get_taxonomy_in_lang($taxonomy, $lang_code);
             $translated_terms = array();
             foreach ($terms as $term) {
                 if (is_int($term)) {
                     $_term = get_term($term, $taxonomy);
                 } else {
                     $_term = get_term_by('name', $term, $taxonomy);
                 }
                 if (is_wp_error($_term) or empty($_term)) {
                     continue;
                 }
                 $translated_term = $this->get_term_in_lang($_term->term_id, $taxonomy, $lang_code, false);
                 $translated_terms[] = (int) $translated_term->term_id;
             }
             $result = wp_set_object_terms($translation->ID, $translated_terms, $translated_taxonomy, $append);
         }
     } else {
         // Here we assume that this taxonomy is on a post type
         $translations = bbl_get_post_translations($object_id);
         foreach ($translations as $lang_code => &$translation) {
             if (bbl_get_post_lang_code($object_id) == $lang_code) {
                 continue;
             }
             wp_set_object_terms($translation->ID, $terms, $taxonomy, $append);
         }
     }
     $this->no_recursion = false;
 }