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