PluginProbe
Polylang / 2.7.3
Polylang v2.7.3
3.8.9 3.8.8 3.8.7 3.8.6 3.8.5 3.8.4 3.8.3 2.7 2.7.0.1 2.7.1 2.7.2 2.7.3 2.7.4 2.8 2.8.1 2.8.2 2.8.3 2.8.4 2.9 2.9.1 2.9.2 3.0 3.0.1 3.0.2 3.0.3 All 233 releases
← All changes | include/translated-post.php +21 -36 3.02.7.3 View file →
@@ -1,8 +1,5 @@
1 1 <?php
2 -/**
3 - * @package Polylang
4 - */
5 2
6 3 /**
7 4 * Setups the posts languages and translations model
8 5 *
@@ -10,13 +7,13 @@
10 7 */
11 8 class PLL_Translated_Post extends PLL_Translated_Object {
12 9
13 10 /**
14 - * Constructor.
11 + * Constructor
15 12 *
16 13 * @since 1.8
17 14 *
18 - * @param PLL_Model $model PLL_Model instance.
15 + * @param object $model
19 16 */
20 17 public function __construct( &$model ) {
21 18 // init properties
22 19 $this->object_type = null; // For taxonomies
@@ -37,23 +34,20 @@
37 34 add_action( 'pre_get_posts', array( $this, 'pre_get_posts' ) );
38 35 }
39 36
40 37 /**
41 - * Store the post language in the database.
38 + * Store the post language in the database
42 39 *
43 40 * @since 0.6
44 41 *
45 - * @param int $post_id Post id.
46 - * @param int|string|PLL_Language $lang Language (term_id or slug or object).
47 - * @return void
42 + * @param int $post_id post id
43 + * @param int|string|object $lang language ( term_id or slug or object )
48 44 */
49 45 public function set_language( $post_id, $lang ) {
50 46 $old_lang = $this->get_language( $post_id );
51 47 $old_lang = $old_lang ? $old_lang->slug : '';
48 + $lang = $lang ? $this->model->get_language( $lang )->slug : '';
52 49
53 - $lang = $this->model->get_language( $lang );
54 - $lang = $lang ? $lang->slug : '';
55 -
56 50 if ( $old_lang !== $lang ) {
57 51 wp_set_post_terms( (int) $post_id, $lang, 'language' );
58 52 }
59 53 }
@@ -63,9 +57,9 @@
63 57 *
64 58 * @since 0.1
65 59 *
66 60 * @param int $post_id post id
67 - * @return PLL_Language|false PLL_Language object, false if no language is associated to that post
61 + * @return bool|object PLL_Language object, false if no language is associated to that post
68 62 */
69 63 public function get_language( $post_id ) {
70 64 $lang = $this->get_object_term( $post_id, 'language' );
71 65 return ( $lang ) ? $this->model->get_language( $lang ) : false;
@@ -71,18 +65,17 @@
71 65 return ( $lang ) ? $this->model->get_language( $lang ) : false;
72 66 }
73 67
74 68 /**
75 - * Deletes a translation.
69 + * Deletes a translation
76 70 *
77 71 * @since 0.5
78 72 *
79 - * @param int $id Post id.
80 - * @return void
73 + * @param int $id post id
81 74 */
82 75 public function delete_translation( $id ) {
83 76 parent::delete_translation( $id );
84 - wp_set_object_terms( $id, array(), $this->tax_translations );
77 + wp_set_object_terms( $id, null, $this->tax_translations );
85 78 }
86 79
87 80 /**
88 81 * A join clause to add to sql queries when filtering by language is needed directly in query
@@ -103,10 +96,8 @@
103 96 /**
104 97 * Register the language taxonomy
105 98 *
106 99 * @since 1.2
107 - *
108 - * @return void
109 100 */
110 101 public function register_taxonomy() {
111 102 register_taxonomy(
112 103 'language',
@@ -133,9 +124,8 @@
133 124 *
134 125 * @since 1.2
135 126 *
136 127 * @param string $post_type post type name
137 - * @return void
138 128 */
139 129 public function registered_post_type( $post_type ) {
140 130 if ( $this->model->is_translated_post_type( $post_type ) ) {
141 131 register_taxonomy_for_object_type( 'language', $post_type );
@@ -143,16 +133,15 @@
143 133 }
144 134 }
145 135
146 136 /**
147 - * Forces calling 'update_object_term_cache' when querying posts or pages.
148 - * This is especially useful for nav menus with a lot of pages as, without doing this,
149 - * we would have one query per page in the menu to get the page language for the permalink.
137 + * Forces calling 'update_object_term_cache' when querying posts or pages
138 + * this is especially useful for nav menus with a lot of pages
139 + * without doing this, we would have one query per page in the menu to get the page language for the permalink
150 140 *
151 141 * @since 1.8
152 142 *
153 - * @param WP_Query $query Reference to the query object.
154 - * @return void
143 + * @param object $query reference to the query object
155 144 */
156 145 public function pre_get_posts( $query ) {
157 146 if ( ! empty( $query->query['post_type'] ) && $this->model->is_translated_post_type( $query->query['post_type'] ) ) {
158 147 $query->query_vars['update_post_term_cache'] = true;
@@ -176,12 +165,8 @@
176 165 }
177 166
178 167 if ( 'inherit' === $post->post_status && $post->post_parent ) {
179 168 $post = get_post( $post->post_parent );
180 -
181 - if ( empty( $post ) ) {
182 - return false;
183 - }
184 169 }
185 170
186 171 if ( 'inherit' === $post->post_status || in_array( $post->post_status, get_post_stati( array( 'public' => true ) ) ) ) {
187 172 return true;
@@ -213,17 +198,17 @@
213 198 }
214 199
215 200 /**
216 201 * Returns a list of posts in a language ( $lang )
217 - * not translated in another language ( $untranslated_in ).
202 + * not translated in another language ( $untranslated_in )
218 203 *
219 204 * @since 2.6
220 205 *
221 - * @param string $type Post type.
222 - * @param PLL_Language $untranslated_in The language the posts must not be translated in.
223 - * @param PLL_Language $lang Language of the searched posts.
224 - * @param string $search Limit the results to the posts matching this string.
225 - * @return WP_Post[] Array of posts.
206 + * @param string $type Post type
207 + * @param string $untranslated_in The posts must not be translated in this language
208 + * @param string $lang Language of the search posts
209 + * @param string $search Limit results to posts matching this string
210 + * @return array Array of posts
226 211 */
227 212 public function get_untranslated( $type, $untranslated_in, $lang, $search = '' ) {
228 213 $return = array();
229 214
@@ -257,9 +242,9 @@
257 242 $args = apply_filters( 'pll_ajax_posts_not_translated_args', $args );
258 243 $posts = get_posts( $args );
259 244
260 245 foreach ( $posts as $post ) {
261 - if ( $post instanceof WP_Post && ! $this->get_translation( $post->ID, $untranslated_in ) && $this->current_user_can_read( $post->ID, 'edit' ) ) {
246 + if ( ! $this->get_translation( $post->ID, $untranslated_in ) && $this->current_user_can_read( $post->ID, 'edit' ) ) {
262 247 $return[] = $post;
263 248 }
264 249 }
265 250