| @@ -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 PLL_Model $model PLL_Model instance. | |
| 18 | + * @param object $model | |
| 19 | 19 | */ |
| 20 | 20 | public function __construct( &$model ) { |
| 21 | 21 | // init properties |
| 22 | 22 | $this->object_type = null; // For taxonomies |
| @@ -37,23 +37,20 @@ | ||
| 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|PLL_Language $lang Language (term_id or slug or object). | |
| 47 | - * @return void | |
| 45 | + * @param int $post_id post id | |
| 46 | + * @param int|string|object $lang language ( term_id or slug or object ) | |
| 48 | 47 | */ |
| 49 | 48 | public function set_language( $post_id, $lang ) { |
| 50 | 49 | $old_lang = $this->get_language( $post_id ); |
| 51 | 50 | $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 | - | |
| 56 | 53 | if ( $old_lang !== $lang ) { |
| 57 | 54 | wp_set_post_terms( (int) $post_id, $lang, 'language' ); |
| 58 | 55 | } |
| 59 | 56 | } |
| @@ -63,9 +60,9 @@ | ||
| 63 | 60 | * |
| 64 | 61 | * @since 0.1 |
| 65 | 62 | * |
| 66 | 63 | * @param int $post_id post id |
| 67 | - * @return PLL_Language|false PLL_Language object, false if no language is associated to that post | |
| 64 | + * @return bool|object PLL_Language object, false if no language is associated to that post | |
| 68 | 65 | */ |
| 69 | 66 | public function get_language( $post_id ) { |
| 70 | 67 | $lang = $this->get_object_term( $post_id, 'language' ); |
| 71 | 68 | return ( $lang ) ? $this->model->get_language( $lang ) : false; |
| @@ -71,18 +68,17 @@ | ||
| 71 | 68 | return ( $lang ) ? $this->model->get_language( $lang ) : false; |
| 72 | 69 | } |
| 73 | 70 | |
| 74 | 71 | /** |
| 75 | - * Deletes a translation. | |
| 72 | + * Deletes a translation | |
| 76 | 73 | * |
| 77 | 74 | * @since 0.5 |
| 78 | 75 | * |
| 79 | - * @param int $id Post id. | |
| 80 | - * @return void | |
| 76 | + * @param int $id post id | |
| 81 | 77 | */ |
| 82 | 78 | public function delete_translation( $id ) { |
| 83 | 79 | parent::delete_translation( $id ); |
| 84 | - wp_set_object_terms( $id, array(), $this->tax_translations ); | |
| 80 | + wp_set_object_terms( $id, null, $this->tax_translations ); | |
| 85 | 81 | } |
| 86 | 82 | |
| 87 | 83 | /** |
| 88 | 84 | * A join clause to add to sql queries when filtering by language is needed directly in query |
| @@ -103,10 +99,8 @@ | ||
| 103 | 99 | /** |
| 104 | 100 | * Register the language taxonomy |
| 105 | 101 | * |
| 106 | 102 | * @since 1.2 |
| 107 | - * | |
| 108 | - * @return void | |
| 109 | 103 | */ |
| 110 | 104 | public function register_taxonomy() { |
| 111 | 105 | register_taxonomy( |
| 112 | 106 | 'language', |
| @@ -133,9 +127,8 @@ | ||
| 133 | 127 | * |
| 134 | 128 | * @since 1.2 |
| 135 | 129 | * |
| 136 | 130 | * @param string $post_type post type name |
| 137 | - * @return void | |
| 138 | 131 | */ |
| 139 | 132 | public function registered_post_type( $post_type ) { |
| 140 | 133 | if ( $this->model->is_translated_post_type( $post_type ) ) { |
| 141 | 134 | register_taxonomy_for_object_type( 'language', $post_type ); |
| @@ -143,16 +136,15 @@ | ||
| 143 | 136 | } |
| 144 | 137 | } |
| 145 | 138 | |
| 146 | 139 | /** |
| 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. | |
| 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 | |
| 150 | 143 | * |
| 151 | 144 | * @since 1.8 |
| 152 | 145 | * |
| 153 | - * @param WP_Query $query Reference to the query object. | |
| 154 | - * @return void | |
| 146 | + * @param object $query reference to the query object | |
| 155 | 147 | */ |
| 156 | 148 | public function pre_get_posts( $query ) { |
| 157 | 149 | if ( ! empty( $query->query['post_type'] ) && $this->model->is_translated_post_type( $query->query['post_type'] ) ) { |
| 158 | 150 | $query->query_vars['update_post_term_cache'] = true; |
| @@ -176,12 +168,8 @@ | ||
| 176 | 168 | } |
| 177 | 169 | |
| 178 | 170 | if ( 'inherit' === $post->post_status && $post->post_parent ) { |
| 179 | 171 | $post = get_post( $post->post_parent ); |
| 180 | - | |
| 181 | - if ( empty( $post ) ) { | |
| 182 | - return false; | |
| 183 | - } | |
| 184 | 172 | } |
| 185 | 173 | |
| 186 | 174 | if ( 'inherit' === $post->post_status || in_array( $post->post_status, get_post_stati( array( 'public' => true ) ) ) ) { |
| 187 | 175 | return true; |
| @@ -213,17 +201,17 @@ | ||
| 213 | 201 | } |
| 214 | 202 | |
| 215 | 203 | /** |
| 216 | 204 | * Returns a list of posts in a language ( $lang ) |
| 217 | - * not translated in another language ( $untranslated_in ). | |
| 205 | + * not translated in another language ( $untranslated_in ) | |
| 218 | 206 | * |
| 219 | 207 | * @since 2.6 |
| 220 | 208 | * |
| 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. | |
| 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 | |
| 226 | 214 | */ |
| 227 | 215 | public function get_untranslated( $type, $untranslated_in, $lang, $search = '' ) { |
| 228 | 216 | $return = array(); |
| 229 | 217 | |
| @@ -257,9 +245,9 @@ | ||
| 257 | 245 | $args = apply_filters( 'pll_ajax_posts_not_translated_args', $args ); |
| 258 | 246 | $posts = get_posts( $args ); |
| 259 | 247 | |
| 260 | 248 | 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' ) ) { | |
| 249 | + if ( ! $this->get_translation( $post->ID, $untranslated_in ) && $this->current_user_can_read( $post->ID, 'edit' ) ) { | |
| 262 | 250 | $return[] = $post; |
| 263 | 251 | } |
| 264 | 252 | } |
| 265 | 253 | |