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