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