| @@ -9,9 +9,39 @@ | ||
| 9 | 9 | * |
| 10 | 10 | * @since 2.4 |
| 11 | 11 | */ |
| 12 | 12 | class PLL_CRUD_Terms { |
| 13 | - public $model, $curlang, $filter_lang, $pref_lang; | |
| 13 | + /** | |
| 14 | + * @var PLL_Model | |
| 15 | + */ | |
| 16 | + public $model; | |
| 17 | + | |
| 18 | + /** | |
| 19 | + * Current language (used to filter the content). | |
| 20 | + * | |
| 21 | + * @var PLL_Language | |
| 22 | + */ | |
| 23 | + public $curlang; | |
| 24 | + | |
| 25 | + /** | |
| 26 | + * Language selected in the admin language filter. | |
| 27 | + * | |
| 28 | + * @var PLL_Language | |
| 29 | + */ | |
| 30 | + public $filter_lang; | |
| 31 | + | |
| 32 | + /** | |
| 33 | + * Preferred language to assign to new contents. | |
| 34 | + * | |
| 35 | + * @var PLL_Language | |
| 36 | + */ | |
| 37 | + public $pref_lang; | |
| 38 | + | |
| 39 | + /** | |
| 40 | + * Stores the 'lang' query var from WP_Query. | |
| 41 | + * | |
| 42 | + * @var string | |
| 43 | + */ | |
| 14 | 44 | private $tax_query_lang; |
| 15 | 45 | |
| 16 | 46 | /** |
| 17 | 47 | * Constructor |
| @@ -48,8 +78,9 @@ | ||
| 48 | 78 | * @since 1.5.4 |
| 49 | 79 | * |
| 50 | 80 | * @param int $term_id |
| 51 | 81 | * @param string $taxonomy |
| 82 | + * @return void | |
| 52 | 83 | */ |
| 53 | 84 | protected function set_default_language( $term_id, $taxonomy ) { |
| 54 | 85 | if ( ! $this->model->term->get_language( $term_id ) ) { |
| 55 | 86 | if ( ! isset( $this->pref_lang ) && ! empty( $_REQUEST['lang'] ) && $lang = $this->model->get_language( sanitize_key( $_REQUEST['lang'] ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
| @@ -68,16 +99,17 @@ | ||
| 68 | 99 | } |
| 69 | 100 | } |
| 70 | 101 | |
| 71 | 102 | /** |
| 72 | - * Called when a category or post tag is created or edited | |
| 73 | - * Does nothing except on taxonomies which are filterable | |
| 103 | + * Called when a category or post tag is created or edited. | |
| 104 | + * Does nothing except on taxonomies which are filterable. | |
| 74 | 105 | * |
| 75 | 106 | * @since 0.1 |
| 76 | 107 | * |
| 77 | - * @param int $term_id | |
| 78 | - * @param int $tt_id Term taxonomy id | |
| 79 | - * @param string $taxonomy | |
| 108 | + * @param int $term_id Term id of the term being saved. | |
| 109 | + * @param int $tt_id Term taxonomy id. | |
| 110 | + * @param string $taxonomy Taxonomy name. | |
| 111 | + * @return void | |
| 80 | 112 | */ |
| 81 | 113 | public function save_term( $term_id, $tt_id, $taxonomy ) { |
| 82 | 114 | if ( $this->model->is_translated_taxonomy( $taxonomy ) ) { |
| 83 | 115 | |
| @@ -87,15 +119,15 @@ | ||
| 87 | 119 | $this->set_default_language( $term_id, $taxonomy ); |
| 88 | 120 | } |
| 89 | 121 | |
| 90 | 122 | /** |
| 91 | - * Fires after the term language and translations are saved | |
| 123 | + * Fires after the term language and translations are saved. | |
| 92 | 124 | * |
| 93 | 125 | * @since 1.2 |
| 94 | 126 | * |
| 95 | - * @param int $term_id term id | |
| 96 | - * @param string $taxonomy taxonomy name | |
| 97 | - * @param array $translations the list of translations term ids | |
| 127 | + * @param int $term_id Term id. | |
| 128 | + * @param string $taxonomy Taxonomy name. | |
| 129 | + * @param int[] $translations The list of translations term ids. | |
| 98 | 130 | */ |
| 99 | 131 | do_action( 'pll_save_term', $term_id, $taxonomy, $this->model->term->get_translations( $term_id ) ); |
| 100 | 132 | } |
| 101 | 133 | } |
| @@ -100,17 +132,19 @@ | ||
| 100 | 132 | } |
| 101 | 133 | } |
| 102 | 134 | |
| 103 | 135 | /** |
| 104 | - * Get the language(s) to filter get_terms | |
| 136 | + * Get the language(s) to filter WP_Term_Query. | |
| 105 | 137 | * |
| 106 | 138 | * @since 1.7.6 |
| 107 | 139 | * |
| 108 | - * @param array $taxonomies queried taxonomies | |
| 109 | - * @param array $args get_terms arguments | |
| 110 | - * @return object|string|bool the language(s) to use in the filter, false otherwise | |
| 140 | + * @param string[] $taxonomies Queried taxonomies. | |
| 141 | + * @param array $args WP_Term_Query arguments. | |
| 142 | + * @return PLL_Language|string|false The language(s) to use in the filter, false otherwise. | |
| 111 | 143 | */ |
| 112 | 144 | protected function get_queried_language( $taxonomies, $args ) { |
| 145 | + global $pagenow; | |
| 146 | + | |
| 113 | 147 | // Does nothing except on taxonomies which are filterable |
| 114 | 148 | // Since WP 4.7, make sure not to filter wp_get_object_terms() |
| 115 | 149 | if ( ! $this->model->is_translated_taxonomy( $taxonomies ) || ! empty( $args['object_ids'] ) ) { |
| 116 | 150 | return false; |
| @@ -121,9 +155,9 @@ | ||
| 121 | 155 | return $args['lang']; |
| 122 | 156 | } |
| 123 | 157 | |
| 124 | 158 | // On tags page, everything should be filtered according to the admin language filter except the parent dropdown |
| 125 | - if ( 'edit-tags.php' === $GLOBALS['pagenow'] && empty( $args['class'] ) ) { | |
| 159 | + if ( 'edit-tags.php' === $pagenow && empty( $args['class'] ) ) { | |
| 126 | 160 | return $this->filter_lang; |
| 127 | 161 | } |
| 128 | 162 | |
| 129 | 163 | return $this->curlang; |
| @@ -129,19 +163,19 @@ | ||
| 129 | 163 | return $this->curlang; |
| 130 | 164 | } |
| 131 | 165 | |
| 132 | 166 | /** |
| 133 | - * Adds language dependent cache domain when querying terms | |
| 134 | - * Useful as the 'lang' parameter is not included in cache key by WordPress | |
| 167 | + * Adds language dependent cache domain when querying terms. | |
| 168 | + * Useful as the 'lang' parameter is not included in cache key by WordPress. | |
| 135 | 169 | * |
| 136 | 170 | * @since 1.3 |
| 137 | 171 | * |
| 138 | - * @param array $args | |
| 139 | - * @param array $taxonomies | |
| 140 | - * @return array modified arguments | |
| 172 | + * @param array $args WP_Term_Query arguments. | |
| 173 | + * @param string[] $taxonomies Queried taxonomies. | |
| 174 | + * @return array Modified arguments. | |
| 141 | 175 | */ |
| 142 | 176 | public function get_terms_args( $args, $taxonomies ) { |
| 143 | - // Don't break _get_term_hierarchy() | |
| 177 | + // Don't break _get_term_hierarchy(). | |
| 144 | 178 | if ( 'all' === $args['get'] && 'id' === $args['orderby'] && 'id=>parent' === $args['fields'] ) { |
| 145 | 179 | $args['lang'] = ''; |
| 146 | 180 | } |
| 147 | 181 | |
| @@ -161,12 +195,12 @@ | ||
| 161 | 195 | * Filters categories and post tags by language(s) when needed on admin side |
| 162 | 196 | * |
| 163 | 197 | * @since 0.2 |
| 164 | 198 | * |
| 165 | - * @param array $clauses list of sql clauses | |
| 166 | - * @param array $taxonomies list of taxonomies | |
| 167 | - * @param array $args get_terms arguments | |
| 168 | - * @return array modified sql clauses | |
| 199 | + * @param string[] $clauses List of sql clauses. | |
| 200 | + * @param string[] $taxonomies List of taxonomies. | |
| 201 | + * @param array $args WP_Term_Query arguments. | |
| 202 | + * @return string[] Modified sql clauses. | |
| 169 | 203 | */ |
| 170 | 204 | public function terms_clauses( $clauses, $taxonomies, $args ) { |
| 171 | 205 | $lang = $this->get_queried_language( $taxonomies, $args ); |
| 172 | 206 | return $this->model->terms_clauses( $clauses, $lang ); |
| @@ -172,14 +206,15 @@ | ||
| 172 | 206 | return $this->model->terms_clauses( $clauses, $lang ); |
| 173 | 207 | } |
| 174 | 208 | |
| 175 | 209 | /** |
| 176 | - * Sets the WP_Term_Query language when doing a WP_Query | |
| 177 | - * Needed since WP 4.9 | |
| 210 | + * Sets the WP_Term_Query language when doing a WP_Query. | |
| 211 | + * Needed since WP 4.9. | |
| 178 | 212 | * |
| 179 | 213 | * @since 2.3.2 |
| 180 | 214 | * |
| 181 | - * @param object $query WP_Query object | |
| 215 | + * @param WP_Query $query WP_Query object. | |
| 216 | + * @return void | |
| 182 | 217 | */ |
| 183 | 218 | public function set_tax_query_lang( $query ) { |
| 184 | 219 | $this->tax_query_lang = isset( $query->query_vars['lang'] ) ? $query->query_vars['lang'] : ''; |
| 185 | 220 | } |
| @@ -184,12 +219,14 @@ | ||
| 184 | 219 | $this->tax_query_lang = isset( $query->query_vars['lang'] ) ? $query->query_vars['lang'] : ''; |
| 185 | 220 | } |
| 186 | 221 | |
| 187 | 222 | /** |
| 188 | - * Removes the WP_Term_Query language filter for WP_Query | |
| 189 | - * Needed since WP 4.9 | |
| 223 | + * Removes the WP_Term_Query language filter for WP_Query. | |
| 224 | + * Needed since WP 4.9. | |
| 190 | 225 | * |
| 191 | 226 | * @since 2.3.2 |
| 227 | + * | |
| 228 | + * @return void | |
| 192 | 229 | */ |
| 193 | 230 | public function unset_tax_query_lang() { |
| 194 | 231 | unset( $this->tax_query_lang ); |
| 195 | 232 | } |
| @@ -200,8 +237,9 @@ | ||
| 200 | 237 | * |
| 201 | 238 | * @since 0.1 |
| 202 | 239 | * |
| 203 | 240 | * @param int $term_id |
| 241 | + * @return void | |
| 204 | 242 | */ |
| 205 | 243 | public function delete_term( $term_id ) { |
| 206 | 244 | $this->model->term->delete_translation( $term_id ); |
| 207 | 245 | $this->model->term->delete_language( $term_id ); |