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 | admin/admin-filters-post.php +17 -64 3.0.3 → 2.5 View file →
@@ -1,8 +1,5 @@
1 1 <?php
2 -/**
3 - * @package Polylang
4 - */
5 2
6 3 /**
7 4 * Manages filters and actions related to posts on admin side
8 5 *
@@ -8,13 +5,8 @@
8 5 *
9 6 * @since 1.2
10 7 */
11 8 class PLL_Admin_Filters_Post extends PLL_Admin_Filters_Post_Base {
12 - /**
13 - * Current language (used to filter the content).
14 - *
15 - * @var PLL_Language
16 - */
17 9 public $curlang;
18 10
19 11 /**
20 12 * Constructor: setups filters and actions
@@ -47,22 +39,15 @@
47 39 * Outputs a javascript list of pages ordered by language
48 40 * to filter the parent dropdown per post language in quick edit
49 41 *
50 42 * @since 1.7
51 - *
52 - * @return void
53 43 */
54 44 public function admin_enqueue_scripts() {
55 45 $screen = get_current_screen();
56 46
57 - if ( empty( $screen ) ) {
58 - return;
59 - }
60 -
61 47 // Hierarchical taxonomies
62 48 if ( 'edit' == $screen->base && $taxonomies = get_object_taxonomies( $screen->post_type, 'object' ) ) {
63 49 // Get translated hierarchical taxonomies
64 - $hierarchical_taxonomies = array();
65 50 foreach ( $taxonomies as $taxonomy ) {
66 51 if ( $taxonomy->hierarchical && $taxonomy->show_in_quick_edit && $this->model->is_translated_taxonomy( $taxonomy->name ) ) {
67 52 $hierarchical_taxonomies[] = $taxonomy->name;
68 53 }
@@ -68,16 +53,13 @@
68 53 }
69 54 }
70 55
71 56 if ( ! empty( $hierarchical_taxonomies ) ) {
72 - $terms = get_terms( $hierarchical_taxonomies, array( 'get' => 'all' ) );
73 - $term_languages = array();
57 + $terms = get_terms( $hierarchical_taxonomies, array( 'get' => 'all' ) );
74 58
75 - if ( is_array( $terms ) ) {
76 - foreach ( $terms as $term ) {
77 - if ( $lang = $this->model->term->get_language( $term->term_id ) ) {
78 - $term_languages[ $lang->slug ][ $term->taxonomy ][] = $term->term_id;
79 - }
59 + foreach ( $terms as $term ) {
60 + if ( $lang = $this->model->term->get_language( $term->term_id ) ) {
61 + $term_languages[ $lang->slug ][ $term->taxonomy ][] = $term->term_id;
80 62 }
81 63 }
82 64
83 65 // Send all these data to javascript
@@ -88,13 +70,10 @@
88 70 }
89 71
90 72 // Hierarchical post types
91 73 if ( 'edit' == $screen->base && is_post_type_hierarchical( $screen->post_type ) ) {
92 - $pages = get_pages( array( 'sort_column' => 'menu_order, post_title' ) ); // Same arguments as the parent pages dropdown to avoid an extra query.
93 - update_post_caches( $pages, $screen->post_type );
74 + $pages = get_pages();
94 75
95 - $page_languages = array();
96 -
97 76 foreach ( $pages as $page ) {
98 77 if ( $lang = $this->model->post->get_language( $page->ID ) ) {
99 78 $page_languages[ $lang->slug ][] = $page->ID;
100 79 }
@@ -107,14 +86,13 @@
107 86 }
108 87 }
109 88
110 89 /**
111 - * Filters posts, pages and media by language.
90 + * Filters posts, pages and media by language
112 91 *
113 92 * @since 0.1
114 93 *
115 - * @param WP_Query $query WP_Query object.
116 - * @return void
94 + * @param object $query a WP_Query object
117 95 */
118 96 public function parse_query( $query ) {
119 97 $pll_query = new PLL_Query( $query, $this->model );
120 98 $pll_query->filter_query( $this->curlang );
@@ -123,32 +101,21 @@
123 101 /**
124 102 * Save language and translation when editing a post (post.php)
125 103 *
126 104 * @since 2.3
127 - *
128 - * @return void
129 105 */
130 106 public function edit_post() {
131 - if ( isset( $_POST['post_lang_choice'], $_POST['post_ID'] ) && $post_id = (int) $_POST['post_ID'] ) { // phpcs:ignore WordPress.Security.NonceVerification
107 + if ( isset( $_POST['post_lang_choice'], $_POST['post_ID'] ) && $post_id = (int) $_POST['post_ID'] ) {
132 108 check_admin_referer( 'pll_language', '_pll_nonce' );
133 109
134 110 $post = get_post( $post_id );
135 -
136 - if ( empty( $post ) ) {
137 - return;
138 - }
139 -
140 111 $post_type_object = get_post_type_object( $post->post_type );
141 112
142 - if ( empty( $post_type_object ) ) {
143 - return;
144 - }
145 -
146 113 if ( current_user_can( $post_type_object->cap->edit_post, $post_id ) ) {
147 - $this->model->post->set_language( $post_id, $this->model->get_language( sanitize_key( $_POST['post_lang_choice'] ) ) );
114 + $this->model->post->set_language( $post_id, $this->model->get_language( $_POST['post_lang_choice'] ) );
148 115
149 116 if ( isset( $_POST['post_tr_lang'] ) ) {
150 - $this->save_translations( $post_id, array_map( 'absint', $_POST['post_tr_lang'] ) );
117 + $this->save_translations( $post_id, $_POST['post_tr_lang'] );
151 118 }
152 119 }
153 120 }
154 121 }
@@ -153,30 +120,20 @@
153 120 }
154 121 }
155 122
156 123 /**
157 - * Saves a post language when inline editing or bulk editing.
158 - * Fixes the translations if necessary.
124 + * Save language when inline editing or bulk editing a post
125 + * Fix translations if necessary
159 126 *
160 127 * @since 2.3
161 128 *
162 - * @param int $post_id Post ID.
163 - * @param PLL_Language $lang Language.
164 - * @return void
129 + * @param int $post_id Post ID
130 + * @param object $lang Language
165 131 */
166 132 protected function inline_save_language( $post_id, $lang ) {
167 133 $post = get_post( $post_id );
168 -
169 - if ( empty( $post ) ) {
170 - return;
171 - }
172 -
173 134 $post_type_object = get_post_type_object( $post->post_type );
174 135
175 - if ( empty( $post_type_object ) ) {
176 - return;
177 - }
178 -
179 136 if ( current_user_can( $post_type_object->cap->edit_post, $post_id ) ) {
180 137 $old_lang = $this->model->post->get_language( $post_id ); // Stores the old language
181 138 $this->model->post->set_language( $post_id, $lang ); // set new language
182 139
@@ -200,16 +157,14 @@
200 157 /**
201 158 * Save language when bulk editing a post
202 159 *
203 160 * @since 2.3
204 - *
205 - * @return void
206 161 */
207 162 public function bulk_edit_posts() {
208 - if ( isset( $_GET['bulk_edit'], $_GET['inline_lang_choice'], $_REQUEST['post'] ) && -1 !== $_GET['inline_lang_choice'] ) { // phpcs:ignore WordPress.Security.NonceVerification
163 + if ( isset( $_GET['bulk_edit'], $_GET['inline_lang_choice'] ) && -1 !== $_GET['inline_lang_choice'] ) {
209 164 check_admin_referer( 'bulk-posts' );
210 165
211 - if ( $lang = $this->model->get_language( sanitize_key( $_GET['inline_lang_choice'] ) ) ) {
166 + if ( $lang = $this->model->get_language( $_GET['inline_lang_choice'] ) ) {
212 167 $post_ids = array_map( 'intval', (array) $_REQUEST['post'] );
213 168 foreach ( $post_ids as $post_id ) {
214 169 $this->inline_save_language( $post_id, $lang );
215 170 }
@@ -220,10 +175,8 @@
220 175 /**
221 176 * Save language when inline editing a post
222 177 *
223 178 * @since 2.3
224 - *
225 - * @return void
226 179 */
227 180 public function inline_edit_post() {
228 181 check_admin_referer( 'inlineeditnonce', '_inline_edit' );
229 182
@@ -228,9 +181,9 @@
228 181 check_admin_referer( 'inlineeditnonce', '_inline_edit' );
229 182
230 183 if ( isset( $_POST['post_ID'], $_POST['inline_lang_choice'] ) ) {
231 184 $post_id = (int) $_POST['post_ID'];
232 - $lang = $this->model->get_language( sanitize_key( $_POST['inline_lang_choice'] ) );
185 + $lang = $this->model->get_language( $_POST['inline_lang_choice'] );
233 186 if ( $post_id && $lang ) {
234 187 $this->inline_save_language( $post_id, $lang );
235 188 }
236 189 }