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