@@ -49,7 +49,7 @@ |
||
49 | 49 | |
50 | 50 | /** |
51 | 51 | * |
52 | - * @return array |
|
52 | + * @return string[] |
|
53 | 53 | */ |
54 | 54 | protected function get_table_classes() { |
55 | 55 | // todo: remove and add CSS for .themes |
@@ -1,11 +1,11 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * List Table API: WP_Post_Comments_List_Table class |
|
4 | - * |
|
5 | - * @package WordPress |
|
6 | - * @subpackage Administration |
|
7 | - * @since 4.4.0 |
|
8 | - */ |
|
3 | + * List Table API: WP_Post_Comments_List_Table class |
|
4 | + * |
|
5 | + * @package WordPress |
|
6 | + * @subpackage Administration |
|
7 | + * @since 4.4.0 |
|
8 | + */ |
|
9 | 9 | |
10 | 10 | /** |
11 | 11 | * Core class used to implement displaying post comments in a list table. |
@@ -24,8 +24,8 @@ discard block |
||
24 | 24 | protected function get_column_info() { |
25 | 25 | return array( |
26 | 26 | array( |
27 | - 'author' => __( 'Author' ), |
|
28 | - 'comment' => _x( 'Comment', 'column name' ), |
|
27 | + 'author' => __('Author'), |
|
28 | + 'comment' => _x('Comment', 'column name'), |
|
29 | 29 | ), |
30 | 30 | array(), |
31 | 31 | array(), |
@@ -48,17 +48,17 @@ discard block |
||
48 | 48 | * |
49 | 49 | * @param bool $output_empty |
50 | 50 | */ |
51 | - public function display( $output_empty = false ) { |
|
51 | + public function display($output_empty = false) { |
|
52 | 52 | $singular = $this->_args['singular']; |
53 | 53 | |
54 | - wp_nonce_field( "fetch-list-" . get_class( $this ), '_ajax_fetch_list_nonce' ); |
|
54 | + wp_nonce_field("fetch-list-".get_class($this), '_ajax_fetch_list_nonce'); |
|
55 | 55 | ?> |
56 | -<table class="<?php echo implode( ' ', $this->get_table_classes() ); ?>" style="display:none;"> |
|
56 | +<table class="<?php echo implode(' ', $this->get_table_classes()); ?>" style="display:none;"> |
|
57 | 57 | <tbody id="the-comment-list"<?php |
58 | - if ( $singular ) { |
|
58 | + if ($singular) { |
|
59 | 59 | echo " data-wp-lists='list:$singular'"; |
60 | 60 | } ?>> |
61 | - <?php if ( ! $output_empty ) { |
|
61 | + <?php if ( ! $output_empty) { |
|
62 | 62 | $this->display_rows_or_placeholder(); |
63 | 63 | } ?> |
64 | 64 | </tbody> |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | * @param bool $comment_status |
72 | 72 | * @return int |
73 | 73 | */ |
74 | - public function get_per_page( $comment_status = false ) { |
|
74 | + public function get_per_page($comment_status = false) { |
|
75 | 75 | return 10; |
76 | 76 | } |
77 | 77 | } |
@@ -484,7 +484,7 @@ discard block |
||
484 | 484 | |
485 | 485 | /** |
486 | 486 | * |
487 | - * @return array |
|
487 | + * @return string[] |
|
488 | 488 | */ |
489 | 489 | protected function get_table_classes() { |
490 | 490 | return array( 'widefat', 'fixed', 'striped', is_post_type_hierarchical( $this->screen->post_type ) ? 'pages' : 'posts' ); |
@@ -1162,7 +1162,7 @@ discard block |
||
1162 | 1162 | * @since 4.3.0 |
1163 | 1163 | * @access protected |
1164 | 1164 | * |
1165 | - * @param object $post Post being acted upon. |
|
1165 | + * @param WP_Post $post Post being acted upon. |
|
1166 | 1166 | * @param string $column_name Current column name. |
1167 | 1167 | * @param string $primary Primary column name. |
1168 | 1168 | * @return string Row actions output for posts. |
@@ -1,11 +1,11 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * List Table API: WP_Posts_List_Table class |
|
4 | - * |
|
5 | - * @package WordPress |
|
6 | - * @subpackage Administration |
|
7 | - * @since 3.1.0 |
|
8 | - */ |
|
3 | + * List Table API: WP_Posts_List_Table class |
|
4 | + * |
|
5 | + * @package WordPress |
|
6 | + * @subpackage Administration |
|
7 | + * @since 3.1.0 |
|
8 | + */ |
|
9 | 9 | |
10 | 10 | /** |
11 | 11 | * Core class used to implement displaying posts in a list table. |
@@ -1131,10 +1131,10 @@ discard block |
||
1131 | 1131 | } |
1132 | 1132 | |
1133 | 1133 | if ( $post->post_parent ) { |
1134 | - $count = count( get_post_ancestors( $post->ID ) ); |
|
1135 | - $classes .= ' level-'. $count; |
|
1134 | + $count = count( get_post_ancestors( $post->ID ) ); |
|
1135 | + $classes .= ' level-'. $count; |
|
1136 | 1136 | } else { |
1137 | - $classes .= ' level-0'; |
|
1137 | + $classes .= ' level-0'; |
|
1138 | 1138 | } |
1139 | 1139 | ?> |
1140 | 1140 | <tr id="post-<?php echo $post->ID; ?>" class="<?php echo implode( ' ', get_post_class( $classes, $post->ID ) ); ?>"> |
@@ -1508,7 +1508,7 @@ discard block |
||
1508 | 1508 | <?php |
1509 | 1509 | /** This filter is documented in wp-admin/includes/meta-boxes.php */ |
1510 | 1510 | $default_title = apply_filters( 'default_page_template_title', __( 'Default Template' ), 'quick-edit' ); |
1511 | - ?> |
|
1511 | + ?> |
|
1512 | 1512 | <option value="default"><?php echo esc_html( $default_title ); ?></option> |
1513 | 1513 | <?php page_template_dropdown() ?> |
1514 | 1514 | </select> |
@@ -77,35 +77,35 @@ discard block |
||
77 | 77 | * |
78 | 78 | * @param array $args An associative array of arguments. |
79 | 79 | */ |
80 | - public function __construct( $args = array() ) { |
|
80 | + public function __construct($args = array()) { |
|
81 | 81 | global $post_type_object, $wpdb; |
82 | 82 | |
83 | - parent::__construct( array( |
|
83 | + parent::__construct(array( |
|
84 | 84 | 'plural' => 'posts', |
85 | - 'screen' => isset( $args['screen'] ) ? $args['screen'] : null, |
|
86 | - ) ); |
|
85 | + 'screen' => isset($args['screen']) ? $args['screen'] : null, |
|
86 | + )); |
|
87 | 87 | |
88 | 88 | $post_type = $this->screen->post_type; |
89 | - $post_type_object = get_post_type_object( $post_type ); |
|
89 | + $post_type_object = get_post_type_object($post_type); |
|
90 | 90 | |
91 | - $exclude_states = get_post_stati( array( |
|
91 | + $exclude_states = get_post_stati(array( |
|
92 | 92 | 'show_in_admin_all_list' => false, |
93 | - ) ); |
|
94 | - $this->user_posts_count = intval( $wpdb->get_var( $wpdb->prepare( " |
|
93 | + )); |
|
94 | + $this->user_posts_count = intval($wpdb->get_var($wpdb->prepare(" |
|
95 | 95 | SELECT COUNT( 1 ) |
96 | 96 | FROM $wpdb->posts |
97 | 97 | WHERE post_type = %s |
98 | - AND post_status NOT IN ( '" . implode( "','", $exclude_states ) . "' ) |
|
98 | + AND post_status NOT IN ( '".implode("','", $exclude_states)."' ) |
|
99 | 99 | AND post_author = %d |
100 | - ", $post_type, get_current_user_id() ) ) ); |
|
100 | + ", $post_type, get_current_user_id()))); |
|
101 | 101 | |
102 | - if ( $this->user_posts_count && ! current_user_can( $post_type_object->cap->edit_others_posts ) && empty( $_REQUEST['post_status'] ) && empty( $_REQUEST['all_posts'] ) && empty( $_REQUEST['author'] ) && empty( $_REQUEST['show_sticky'] ) ) { |
|
102 | + if ($this->user_posts_count && ! current_user_can($post_type_object->cap->edit_others_posts) && empty($_REQUEST['post_status']) && empty($_REQUEST['all_posts']) && empty($_REQUEST['author']) && empty($_REQUEST['show_sticky'])) { |
|
103 | 103 | $_GET['author'] = get_current_user_id(); |
104 | 104 | } |
105 | 105 | |
106 | - if ( 'post' === $post_type && $sticky_posts = get_option( 'sticky_posts' ) ) { |
|
107 | - $sticky_posts = implode( ', ', array_map( 'absint', (array) $sticky_posts ) ); |
|
108 | - $this->sticky_posts_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT( 1 ) FROM $wpdb->posts WHERE post_type = %s AND post_status NOT IN ('trash', 'auto-draft') AND ID IN ($sticky_posts)", $post_type ) ); |
|
106 | + if ('post' === $post_type && $sticky_posts = get_option('sticky_posts')) { |
|
107 | + $sticky_posts = implode(', ', array_map('absint', (array) $sticky_posts)); |
|
108 | + $this->sticky_posts_count = $wpdb->get_var($wpdb->prepare("SELECT COUNT( 1 ) FROM $wpdb->posts WHERE post_type = %s AND post_status NOT IN ('trash', 'auto-draft') AND ID IN ($sticky_posts)", $post_type)); |
|
109 | 109 | } |
110 | 110 | } |
111 | 111 | |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | * |
117 | 117 | * @param bool $display Whether the table layout should be hierarchical. |
118 | 118 | */ |
119 | - public function set_hierarchical_display( $display ) { |
|
119 | + public function set_hierarchical_display($display) { |
|
120 | 120 | $this->hierarchical_display = $display; |
121 | 121 | } |
122 | 122 | |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | * @return bool |
126 | 126 | */ |
127 | 127 | public function ajax_user_can() { |
128 | - return current_user_can( get_post_type_object( $this->screen->post_type )->cap->edit_posts ); |
|
128 | + return current_user_can(get_post_type_object($this->screen->post_type)->cap->edit_posts); |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | /** |
@@ -141,50 +141,50 @@ discard block |
||
141 | 141 | // is going to call wp() |
142 | 142 | $avail_post_stati = wp_edit_posts_query(); |
143 | 143 | |
144 | - $this->set_hierarchical_display( is_post_type_hierarchical( $this->screen->post_type ) && 'menu_order title' === $wp_query->query['orderby'] ); |
|
144 | + $this->set_hierarchical_display(is_post_type_hierarchical($this->screen->post_type) && 'menu_order title' === $wp_query->query['orderby']); |
|
145 | 145 | |
146 | 146 | $post_type = $this->screen->post_type; |
147 | - $per_page = $this->get_items_per_page( 'edit_' . $post_type . '_per_page' ); |
|
147 | + $per_page = $this->get_items_per_page('edit_'.$post_type.'_per_page'); |
|
148 | 148 | |
149 | 149 | /** This filter is documented in wp-admin/includes/post.php */ |
150 | - $per_page = apply_filters( 'edit_posts_per_page', $per_page, $post_type ); |
|
150 | + $per_page = apply_filters('edit_posts_per_page', $per_page, $post_type); |
|
151 | 151 | |
152 | - if ( $this->hierarchical_display ) { |
|
152 | + if ($this->hierarchical_display) { |
|
153 | 153 | $total_items = $wp_query->post_count; |
154 | - } elseif ( $wp_query->found_posts || $this->get_pagenum() === 1 ) { |
|
154 | + } elseif ($wp_query->found_posts || $this->get_pagenum() === 1) { |
|
155 | 155 | $total_items = $wp_query->found_posts; |
156 | 156 | } else { |
157 | - $post_counts = (array) wp_count_posts( $post_type, 'readable' ); |
|
157 | + $post_counts = (array) wp_count_posts($post_type, 'readable'); |
|
158 | 158 | |
159 | - if ( isset( $_REQUEST['post_status'] ) && in_array( $_REQUEST['post_status'] , $avail_post_stati ) ) { |
|
160 | - $total_items = $post_counts[ $_REQUEST['post_status'] ]; |
|
161 | - } elseif ( isset( $_REQUEST['show_sticky'] ) && $_REQUEST['show_sticky'] ) { |
|
159 | + if (isset($_REQUEST['post_status']) && in_array($_REQUEST['post_status'], $avail_post_stati)) { |
|
160 | + $total_items = $post_counts[$_REQUEST['post_status']]; |
|
161 | + } elseif (isset($_REQUEST['show_sticky']) && $_REQUEST['show_sticky']) { |
|
162 | 162 | $total_items = $this->sticky_posts_count; |
163 | - } elseif ( isset( $_GET['author'] ) && $_GET['author'] == get_current_user_id() ) { |
|
163 | + } elseif (isset($_GET['author']) && $_GET['author'] == get_current_user_id()) { |
|
164 | 164 | $total_items = $this->user_posts_count; |
165 | 165 | } else { |
166 | - $total_items = array_sum( $post_counts ); |
|
166 | + $total_items = array_sum($post_counts); |
|
167 | 167 | |
168 | 168 | // Subtract post types that are not included in the admin all list. |
169 | - foreach ( get_post_stati( array( 'show_in_admin_all_list' => false ) ) as $state ) { |
|
170 | - $total_items -= $post_counts[ $state ]; |
|
169 | + foreach (get_post_stati(array('show_in_admin_all_list' => false)) as $state) { |
|
170 | + $total_items -= $post_counts[$state]; |
|
171 | 171 | } |
172 | 172 | } |
173 | 173 | } |
174 | 174 | |
175 | - if ( ! empty( $_REQUEST['mode'] ) ) { |
|
175 | + if ( ! empty($_REQUEST['mode'])) { |
|
176 | 176 | $mode = $_REQUEST['mode'] === 'excerpt' ? 'excerpt' : 'list'; |
177 | - set_user_setting( 'posts_list_mode', $mode ); |
|
177 | + set_user_setting('posts_list_mode', $mode); |
|
178 | 178 | } else { |
179 | - $mode = get_user_setting( 'posts_list_mode', 'list' ); |
|
179 | + $mode = get_user_setting('posts_list_mode', 'list'); |
|
180 | 180 | } |
181 | 181 | |
182 | - $this->is_trash = isset( $_REQUEST['post_status'] ) && $_REQUEST['post_status'] === 'trash'; |
|
182 | + $this->is_trash = isset($_REQUEST['post_status']) && $_REQUEST['post_status'] === 'trash'; |
|
183 | 183 | |
184 | - $this->set_pagination_args( array( |
|
184 | + $this->set_pagination_args(array( |
|
185 | 185 | 'total_items' => $total_items, |
186 | 186 | 'per_page' => $per_page |
187 | - ) ); |
|
187 | + )); |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | /** |
@@ -199,10 +199,10 @@ discard block |
||
199 | 199 | * @access public |
200 | 200 | */ |
201 | 201 | public function no_items() { |
202 | - if ( isset( $_REQUEST['post_status'] ) && 'trash' === $_REQUEST['post_status'] ) |
|
203 | - echo get_post_type_object( $this->screen->post_type )->labels->not_found_in_trash; |
|
202 | + if (isset($_REQUEST['post_status']) && 'trash' === $_REQUEST['post_status']) |
|
203 | + echo get_post_type_object($this->screen->post_type)->labels->not_found_in_trash; |
|
204 | 204 | else |
205 | - echo get_post_type_object( $this->screen->post_type )->labels->not_found; |
|
205 | + echo get_post_type_object($this->screen->post_type)->labels->not_found; |
|
206 | 206 | } |
207 | 207 | |
208 | 208 | /** |
@@ -214,15 +214,15 @@ discard block |
||
214 | 214 | */ |
215 | 215 | protected function is_base_request() { |
216 | 216 | $vars = $_GET; |
217 | - unset( $vars['paged'] ); |
|
217 | + unset($vars['paged']); |
|
218 | 218 | |
219 | - if ( empty( $vars ) ) { |
|
219 | + if (empty($vars)) { |
|
220 | 220 | return true; |
221 | - } elseif ( 1 === count( $vars ) && ! empty( $vars['post_type'] ) ) { |
|
221 | + } elseif (1 === count($vars) && ! empty($vars['post_type'])) { |
|
222 | 222 | return $this->screen->post_type === $vars['post_type']; |
223 | 223 | } |
224 | 224 | |
225 | - return 1 === count( $vars ) && ! empty( $vars['mode'] ); |
|
225 | + return 1 === count($vars) && ! empty($vars['mode']); |
|
226 | 226 | } |
227 | 227 | |
228 | 228 | /** |
@@ -236,20 +236,20 @@ discard block |
||
236 | 236 | * @param string $class Optional. Class attribute. Default empty string. |
237 | 237 | * @return string The formatted link string. |
238 | 238 | */ |
239 | - protected function get_edit_link( $args, $label, $class = '' ) { |
|
240 | - $url = add_query_arg( $args, 'edit.php' ); |
|
239 | + protected function get_edit_link($args, $label, $class = '') { |
|
240 | + $url = add_query_arg($args, 'edit.php'); |
|
241 | 241 | |
242 | 242 | $class_html = ''; |
243 | - if ( ! empty( $class ) ) { |
|
243 | + if ( ! empty($class)) { |
|
244 | 244 | $class_html = sprintf( |
245 | 245 | ' class="%s"', |
246 | - esc_attr( $class ) |
|
246 | + esc_attr($class) |
|
247 | 247 | ); |
248 | 248 | } |
249 | 249 | |
250 | 250 | return sprintf( |
251 | 251 | '<a href="%s"%s>%s</a>', |
252 | - esc_url( $url ), |
|
252 | + esc_url($url), |
|
253 | 253 | $class_html, |
254 | 254 | $label |
255 | 255 | ); |
@@ -266,25 +266,25 @@ discard block |
||
266 | 266 | |
267 | 267 | $post_type = $this->screen->post_type; |
268 | 268 | |
269 | - if ( !empty($locked_post_status) ) |
|
269 | + if ( ! empty($locked_post_status)) |
|
270 | 270 | return array(); |
271 | 271 | |
272 | 272 | $status_links = array(); |
273 | - $num_posts = wp_count_posts( $post_type, 'readable' ); |
|
274 | - $total_posts = array_sum( (array) $num_posts ); |
|
273 | + $num_posts = wp_count_posts($post_type, 'readable'); |
|
274 | + $total_posts = array_sum((array) $num_posts); |
|
275 | 275 | $class = ''; |
276 | 276 | |
277 | 277 | $current_user_id = get_current_user_id(); |
278 | - $all_args = array( 'post_type' => $post_type ); |
|
278 | + $all_args = array('post_type' => $post_type); |
|
279 | 279 | $mine = ''; |
280 | 280 | |
281 | 281 | // Subtract post types that are not included in the admin all list. |
282 | - foreach ( get_post_stati( array( 'show_in_admin_all_list' => false ) ) as $state ) { |
|
282 | + foreach (get_post_stati(array('show_in_admin_all_list' => false)) as $state) { |
|
283 | 283 | $total_posts -= $num_posts->$state; |
284 | 284 | } |
285 | 285 | |
286 | - if ( $this->user_posts_count && $this->user_posts_count !== $total_posts ) { |
|
287 | - if ( isset( $_GET['author'] ) && ( $_GET['author'] == $current_user_id ) ) { |
|
286 | + if ($this->user_posts_count && $this->user_posts_count !== $total_posts) { |
|
287 | + if (isset($_GET['author']) && ($_GET['author'] == $current_user_id)) { |
|
288 | 288 | $class = 'current'; |
289 | 289 | } |
290 | 290 | |
@@ -300,16 +300,16 @@ discard block |
||
300 | 300 | $this->user_posts_count, |
301 | 301 | 'posts' |
302 | 302 | ), |
303 | - number_format_i18n( $this->user_posts_count ) |
|
303 | + number_format_i18n($this->user_posts_count) |
|
304 | 304 | ); |
305 | 305 | |
306 | - $mine = $this->get_edit_link( $mine_args, $mine_inner_html, $class ); |
|
306 | + $mine = $this->get_edit_link($mine_args, $mine_inner_html, $class); |
|
307 | 307 | |
308 | 308 | $all_args['all_posts'] = 1; |
309 | 309 | $class = ''; |
310 | 310 | } |
311 | 311 | |
312 | - if ( empty( $class ) && ( $this->is_base_request() || isset( $_REQUEST['all_posts'] ) ) ) { |
|
312 | + if (empty($class) && ($this->is_base_request() || isset($_REQUEST['all_posts']))) { |
|
313 | 313 | $class = 'current'; |
314 | 314 | } |
315 | 315 | |
@@ -320,24 +320,24 @@ discard block |
||
320 | 320 | $total_posts, |
321 | 321 | 'posts' |
322 | 322 | ), |
323 | - number_format_i18n( $total_posts ) |
|
323 | + number_format_i18n($total_posts) |
|
324 | 324 | ); |
325 | 325 | |
326 | - $status_links['all'] = $this->get_edit_link( $all_args, $all_inner_html, $class ); |
|
327 | - if ( $mine ) { |
|
326 | + $status_links['all'] = $this->get_edit_link($all_args, $all_inner_html, $class); |
|
327 | + if ($mine) { |
|
328 | 328 | $status_links['mine'] = $mine; |
329 | 329 | } |
330 | 330 | |
331 | - foreach ( get_post_stati(array('show_in_admin_status_list' => true), 'objects') as $status ) { |
|
331 | + foreach (get_post_stati(array('show_in_admin_status_list' => true), 'objects') as $status) { |
|
332 | 332 | $class = ''; |
333 | 333 | |
334 | 334 | $status_name = $status->name; |
335 | 335 | |
336 | - if ( ! in_array( $status_name, $avail_post_stati ) || empty( $num_posts->$status_name ) ) { |
|
336 | + if ( ! in_array($status_name, $avail_post_stati) || empty($num_posts->$status_name)) { |
|
337 | 337 | continue; |
338 | 338 | } |
339 | 339 | |
340 | - if ( isset($_REQUEST['post_status']) && $status_name === $_REQUEST['post_status'] ) { |
|
340 | + if (isset($_REQUEST['post_status']) && $status_name === $_REQUEST['post_status']) { |
|
341 | 341 | $class = 'current'; |
342 | 342 | } |
343 | 343 | |
@@ -347,15 +347,15 @@ discard block |
||
347 | 347 | ); |
348 | 348 | |
349 | 349 | $status_label = sprintf( |
350 | - translate_nooped_plural( $status->label_count, $num_posts->$status_name ), |
|
351 | - number_format_i18n( $num_posts->$status_name ) |
|
350 | + translate_nooped_plural($status->label_count, $num_posts->$status_name), |
|
351 | + number_format_i18n($num_posts->$status_name) |
|
352 | 352 | ); |
353 | 353 | |
354 | - $status_links[ $status_name ] = $this->get_edit_link( $status_args, $status_label, $class ); |
|
354 | + $status_links[$status_name] = $this->get_edit_link($status_args, $status_label, $class); |
|
355 | 355 | } |
356 | 356 | |
357 | - if ( ! empty( $this->sticky_posts_count ) ) { |
|
358 | - $class = ! empty( $_REQUEST['show_sticky'] ) ? 'current' : ''; |
|
357 | + if ( ! empty($this->sticky_posts_count)) { |
|
358 | + $class = ! empty($_REQUEST['show_sticky']) ? 'current' : ''; |
|
359 | 359 | |
360 | 360 | $sticky_args = array( |
361 | 361 | 'post_type' => $post_type, |
@@ -369,16 +369,16 @@ discard block |
||
369 | 369 | $this->sticky_posts_count, |
370 | 370 | 'posts' |
371 | 371 | ), |
372 | - number_format_i18n( $this->sticky_posts_count ) |
|
372 | + number_format_i18n($this->sticky_posts_count) |
|
373 | 373 | ); |
374 | 374 | |
375 | 375 | $sticky_link = array( |
376 | - 'sticky' => $this->get_edit_link( $sticky_args, $sticky_inner_html, $class ) |
|
376 | + 'sticky' => $this->get_edit_link($sticky_args, $sticky_inner_html, $class) |
|
377 | 377 | ); |
378 | 378 | |
379 | 379 | // Sticky comes after Publish, or if not listed, after All. |
380 | - $split = 1 + array_search( ( isset( $status_links['publish'] ) ? 'publish' : 'all' ), array_keys( $status_links ) ); |
|
381 | - $status_links = array_merge( array_slice( $status_links, 0, $split ), $sticky_link, array_slice( $status_links, $split ) ); |
|
380 | + $split = 1 + array_search((isset($status_links['publish']) ? 'publish' : 'all'), array_keys($status_links)); |
|
381 | + $status_links = array_merge(array_slice($status_links, 0, $split), $sticky_link, array_slice($status_links, $split)); |
|
382 | 382 | } |
383 | 383 | |
384 | 384 | return $status_links; |
@@ -390,21 +390,21 @@ discard block |
||
390 | 390 | */ |
391 | 391 | protected function get_bulk_actions() { |
392 | 392 | $actions = array(); |
393 | - $post_type_obj = get_post_type_object( $this->screen->post_type ); |
|
393 | + $post_type_obj = get_post_type_object($this->screen->post_type); |
|
394 | 394 | |
395 | - if ( current_user_can( $post_type_obj->cap->edit_posts ) ) { |
|
396 | - if ( $this->is_trash ) { |
|
397 | - $actions['untrash'] = __( 'Restore' ); |
|
395 | + if (current_user_can($post_type_obj->cap->edit_posts)) { |
|
396 | + if ($this->is_trash) { |
|
397 | + $actions['untrash'] = __('Restore'); |
|
398 | 398 | } else { |
399 | - $actions['edit'] = __( 'Edit' ); |
|
399 | + $actions['edit'] = __('Edit'); |
|
400 | 400 | } |
401 | 401 | } |
402 | 402 | |
403 | - if ( current_user_can( $post_type_obj->cap->delete_posts ) ) { |
|
404 | - if ( $this->is_trash || ! EMPTY_TRASH_DAYS ) { |
|
405 | - $actions['delete'] = __( 'Delete Permanently' ); |
|
403 | + if (current_user_can($post_type_obj->cap->delete_posts)) { |
|
404 | + if ($this->is_trash || ! EMPTY_TRASH_DAYS) { |
|
405 | + $actions['delete'] = __('Delete Permanently'); |
|
406 | 406 | } else { |
407 | - $actions['trash'] = __( 'Move to Trash' ); |
|
407 | + $actions['trash'] = __('Move to Trash'); |
|
408 | 408 | } |
409 | 409 | } |
410 | 410 | |
@@ -415,18 +415,18 @@ discard block |
||
415 | 415 | * @global int $cat |
416 | 416 | * @param string $which |
417 | 417 | */ |
418 | - protected function extra_tablenav( $which ) { |
|
418 | + protected function extra_tablenav($which) { |
|
419 | 419 | global $cat; |
420 | 420 | ?> |
421 | 421 | <div class="alignleft actions"> |
422 | 422 | <?php |
423 | - if ( 'top' === $which && !is_singular() ) { |
|
423 | + if ('top' === $which && ! is_singular()) { |
|
424 | 424 | |
425 | - $this->months_dropdown( $this->screen->post_type ); |
|
425 | + $this->months_dropdown($this->screen->post_type); |
|
426 | 426 | |
427 | - if ( is_object_in_taxonomy( $this->screen->post_type, 'category' ) ) { |
|
427 | + if (is_object_in_taxonomy($this->screen->post_type, 'category')) { |
|
428 | 428 | $dropdown_options = array( |
429 | - 'show_option_all' => get_taxonomy( 'category' )->labels->all_items, |
|
429 | + 'show_option_all' => get_taxonomy('category')->labels->all_items, |
|
430 | 430 | 'hide_empty' => 0, |
431 | 431 | 'hierarchical' => 1, |
432 | 432 | 'show_count' => 0, |
@@ -434,8 +434,8 @@ discard block |
||
434 | 434 | 'selected' => $cat |
435 | 435 | ); |
436 | 436 | |
437 | - echo '<label class="screen-reader-text" for="cat">' . __( 'Filter by category' ) . '</label>'; |
|
438 | - wp_dropdown_categories( $dropdown_options ); |
|
437 | + echo '<label class="screen-reader-text" for="cat">'.__('Filter by category').'</label>'; |
|
438 | + wp_dropdown_categories($dropdown_options); |
|
439 | 439 | } |
440 | 440 | |
441 | 441 | /** |
@@ -449,13 +449,13 @@ discard block |
||
449 | 449 | * |
450 | 450 | * @param string $post_type The post type slug. |
451 | 451 | */ |
452 | - do_action( 'restrict_manage_posts', $this->screen->post_type ); |
|
452 | + do_action('restrict_manage_posts', $this->screen->post_type); |
|
453 | 453 | |
454 | - submit_button( __( 'Filter' ), 'button', 'filter_action', false, array( 'id' => 'post-query-submit' ) ); |
|
454 | + submit_button(__('Filter'), 'button', 'filter_action', false, array('id' => 'post-query-submit')); |
|
455 | 455 | } |
456 | 456 | |
457 | - if ( $this->is_trash && current_user_can( get_post_type_object( $this->screen->post_type )->cap->edit_others_posts ) ) { |
|
458 | - submit_button( __( 'Empty Trash' ), 'apply', 'delete_all', false ); |
|
457 | + if ($this->is_trash && current_user_can(get_post_type_object($this->screen->post_type)->cap->edit_others_posts)) { |
|
458 | + submit_button(__('Empty Trash'), 'apply', 'delete_all', false); |
|
459 | 459 | } |
460 | 460 | ?> |
461 | 461 | </div> |
@@ -468,7 +468,7 @@ discard block |
||
468 | 468 | * |
469 | 469 | * @param string $which The location of the extra table nav markup: 'top' or 'bottom'. |
470 | 470 | */ |
471 | - do_action( 'manage_posts_extra_tablenav', $which ); |
|
471 | + do_action('manage_posts_extra_tablenav', $which); |
|
472 | 472 | } |
473 | 473 | |
474 | 474 | /** |
@@ -476,7 +476,7 @@ discard block |
||
476 | 476 | * @return string |
477 | 477 | */ |
478 | 478 | public function current_action() { |
479 | - if ( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) ) |
|
479 | + if (isset($_REQUEST['delete_all']) || isset($_REQUEST['delete_all2'])) |
|
480 | 480 | return 'delete_all'; |
481 | 481 | |
482 | 482 | return parent::current_action(); |
@@ -487,7 +487,7 @@ discard block |
||
487 | 487 | * @return array |
488 | 488 | */ |
489 | 489 | protected function get_table_classes() { |
490 | - return array( 'widefat', 'fixed', 'striped', is_post_type_hierarchical( $this->screen->post_type ) ? 'pages' : 'posts' ); |
|
490 | + return array('widefat', 'fixed', 'striped', is_post_type_hierarchical($this->screen->post_type) ? 'pages' : 'posts'); |
|
491 | 491 | } |
492 | 492 | |
493 | 493 | /** |
@@ -502,14 +502,14 @@ discard block |
||
502 | 502 | $posts_columns['cb'] = '<input type="checkbox" />'; |
503 | 503 | |
504 | 504 | /* translators: manage posts column name */ |
505 | - $posts_columns['title'] = _x( 'Title', 'column name' ); |
|
505 | + $posts_columns['title'] = _x('Title', 'column name'); |
|
506 | 506 | |
507 | - if ( post_type_supports( $post_type, 'author' ) ) { |
|
508 | - $posts_columns['author'] = __( 'Author' ); |
|
507 | + if (post_type_supports($post_type, 'author')) { |
|
508 | + $posts_columns['author'] = __('Author'); |
|
509 | 509 | } |
510 | 510 | |
511 | - $taxonomies = get_object_taxonomies( $post_type, 'objects' ); |
|
512 | - $taxonomies = wp_filter_object_list( $taxonomies, array( 'show_admin_column' => true ), 'and', 'name' ); |
|
511 | + $taxonomies = get_object_taxonomies($post_type, 'objects'); |
|
512 | + $taxonomies = wp_filter_object_list($taxonomies, array('show_admin_column' => true), 'and', 'name'); |
|
513 | 513 | |
514 | 514 | /** |
515 | 515 | * Filter the taxonomy columns in the Posts list table. |
@@ -522,27 +522,27 @@ discard block |
||
522 | 522 | * @param array $taxonomies Array of taxonomies to show columns for. |
523 | 523 | * @param string $post_type The post type. |
524 | 524 | */ |
525 | - $taxonomies = apply_filters( "manage_taxonomies_for_{$post_type}_columns", $taxonomies, $post_type ); |
|
526 | - $taxonomies = array_filter( $taxonomies, 'taxonomy_exists' ); |
|
525 | + $taxonomies = apply_filters("manage_taxonomies_for_{$post_type}_columns", $taxonomies, $post_type); |
|
526 | + $taxonomies = array_filter($taxonomies, 'taxonomy_exists'); |
|
527 | 527 | |
528 | - foreach ( $taxonomies as $taxonomy ) { |
|
529 | - if ( 'category' === $taxonomy ) |
|
528 | + foreach ($taxonomies as $taxonomy) { |
|
529 | + if ('category' === $taxonomy) |
|
530 | 530 | $column_key = 'categories'; |
531 | - elseif ( 'post_tag' === $taxonomy ) |
|
531 | + elseif ('post_tag' === $taxonomy) |
|
532 | 532 | $column_key = 'tags'; |
533 | 533 | else |
534 | - $column_key = 'taxonomy-' . $taxonomy; |
|
534 | + $column_key = 'taxonomy-'.$taxonomy; |
|
535 | 535 | |
536 | - $posts_columns[ $column_key ] = get_taxonomy( $taxonomy )->labels->name; |
|
536 | + $posts_columns[$column_key] = get_taxonomy($taxonomy)->labels->name; |
|
537 | 537 | } |
538 | 538 | |
539 | - $post_status = !empty( $_REQUEST['post_status'] ) ? $_REQUEST['post_status'] : 'all'; |
|
540 | - if ( post_type_supports( $post_type, 'comments' ) && !in_array( $post_status, array( 'pending', 'draft', 'future' ) ) ) |
|
541 | - $posts_columns['comments'] = '<span class="vers comment-grey-bubble" title="' . esc_attr__( 'Comments' ) . '"><span class="screen-reader-text">' . __( 'Comments' ) . '</span></span>'; |
|
539 | + $post_status = ! empty($_REQUEST['post_status']) ? $_REQUEST['post_status'] : 'all'; |
|
540 | + if (post_type_supports($post_type, 'comments') && ! in_array($post_status, array('pending', 'draft', 'future'))) |
|
541 | + $posts_columns['comments'] = '<span class="vers comment-grey-bubble" title="'.esc_attr__('Comments').'"><span class="screen-reader-text">'.__('Comments').'</span></span>'; |
|
542 | 542 | |
543 | - $posts_columns['date'] = __( 'Date' ); |
|
543 | + $posts_columns['date'] = __('Date'); |
|
544 | 544 | |
545 | - if ( 'page' === $post_type ) { |
|
545 | + if ('page' === $post_type) { |
|
546 | 546 | |
547 | 547 | /** |
548 | 548 | * Filter the columns displayed in the Pages list table. |
@@ -551,7 +551,7 @@ discard block |
||
551 | 551 | * |
552 | 552 | * @param array $post_columns An array of column names. |
553 | 553 | */ |
554 | - $posts_columns = apply_filters( 'manage_pages_columns', $posts_columns ); |
|
554 | + $posts_columns = apply_filters('manage_pages_columns', $posts_columns); |
|
555 | 555 | } else { |
556 | 556 | |
557 | 557 | /** |
@@ -562,7 +562,7 @@ discard block |
||
562 | 562 | * @param array $posts_columns An array of column names. |
563 | 563 | * @param string $post_type The post type slug. |
564 | 564 | */ |
565 | - $posts_columns = apply_filters( 'manage_posts_columns', $posts_columns, $post_type ); |
|
565 | + $posts_columns = apply_filters('manage_posts_columns', $posts_columns, $post_type); |
|
566 | 566 | } |
567 | 567 | |
568 | 568 | /** |
@@ -574,7 +574,7 @@ discard block |
||
574 | 574 | * |
575 | 575 | * @param array $post_columns An array of column names. |
576 | 576 | */ |
577 | - return apply_filters( "manage_{$post_type}_posts_columns", $posts_columns ); |
|
577 | + return apply_filters("manage_{$post_type}_posts_columns", $posts_columns); |
|
578 | 578 | } |
579 | 579 | |
580 | 580 | /** |
@@ -586,7 +586,7 @@ discard block |
||
586 | 586 | 'title' => 'title', |
587 | 587 | 'parent' => 'parent', |
588 | 588 | 'comments' => 'comment_count', |
589 | - 'date' => array( 'date', true ) |
|
589 | + 'date' => array('date', true) |
|
590 | 590 | ); |
591 | 591 | } |
592 | 592 | |
@@ -596,18 +596,18 @@ discard block |
||
596 | 596 | * @param array $posts |
597 | 597 | * @param int $level |
598 | 598 | */ |
599 | - public function display_rows( $posts = array(), $level = 0 ) { |
|
599 | + public function display_rows($posts = array(), $level = 0) { |
|
600 | 600 | global $wp_query, $per_page; |
601 | 601 | |
602 | - if ( empty( $posts ) ) |
|
602 | + if (empty($posts)) |
|
603 | 603 | $posts = $wp_query->posts; |
604 | 604 | |
605 | - add_filter( 'the_title', 'esc_html' ); |
|
605 | + add_filter('the_title', 'esc_html'); |
|
606 | 606 | |
607 | - if ( $this->hierarchical_display ) { |
|
608 | - $this->_display_rows_hierarchical( $posts, $this->get_pagenum(), $per_page ); |
|
607 | + if ($this->hierarchical_display) { |
|
608 | + $this->_display_rows_hierarchical($posts, $this->get_pagenum(), $per_page); |
|
609 | 609 | } else { |
610 | - $this->_display_rows( $posts, $level ); |
|
610 | + $this->_display_rows($posts, $level); |
|
611 | 611 | } |
612 | 612 | } |
613 | 613 | |
@@ -615,17 +615,17 @@ discard block |
||
615 | 615 | * @param array $posts |
616 | 616 | * @param int $level |
617 | 617 | */ |
618 | - private function _display_rows( $posts, $level = 0 ) { |
|
618 | + private function _display_rows($posts, $level = 0) { |
|
619 | 619 | // Create array of post IDs. |
620 | 620 | $post_ids = array(); |
621 | 621 | |
622 | - foreach ( $posts as $a_post ) |
|
622 | + foreach ($posts as $a_post) |
|
623 | 623 | $post_ids[] = $a_post->ID; |
624 | 624 | |
625 | - $this->comment_pending_count = get_pending_comments_num( $post_ids ); |
|
625 | + $this->comment_pending_count = get_pending_comments_num($post_ids); |
|
626 | 626 | |
627 | - foreach ( $posts as $post ) |
|
628 | - $this->single_row( $post, $level ); |
|
627 | + foreach ($posts as $post) |
|
628 | + $this->single_row($post, $level); |
|
629 | 629 | } |
630 | 630 | |
631 | 631 | /** |
@@ -635,15 +635,15 @@ discard block |
||
635 | 635 | * @param int $pagenum |
636 | 636 | * @param int $per_page |
637 | 637 | */ |
638 | - private function _display_rows_hierarchical( $pages, $pagenum = 1, $per_page = 20 ) { |
|
638 | + private function _display_rows_hierarchical($pages, $pagenum = 1, $per_page = 20) { |
|
639 | 639 | global $wpdb; |
640 | 640 | |
641 | 641 | $level = 0; |
642 | 642 | |
643 | - if ( ! $pages ) { |
|
644 | - $pages = get_pages( array( 'sort_column' => 'menu_order' ) ); |
|
643 | + if ( ! $pages) { |
|
644 | + $pages = get_pages(array('sort_column' => 'menu_order')); |
|
645 | 645 | |
646 | - if ( ! $pages ) |
|
646 | + if ( ! $pages) |
|
647 | 647 | return; |
648 | 648 | } |
649 | 649 | |
@@ -654,56 +654,56 @@ discard block |
||
654 | 654 | * It only takes O( N ) to arrange this and it takes O( 1 ) for subsequent lookup operations |
655 | 655 | * If searching, ignore hierarchy and treat everything as top level |
656 | 656 | */ |
657 | - if ( empty( $_REQUEST['s'] ) ) { |
|
657 | + if (empty($_REQUEST['s'])) { |
|
658 | 658 | |
659 | 659 | $top_level_pages = array(); |
660 | 660 | $children_pages = array(); |
661 | 661 | |
662 | - foreach ( $pages as $page ) { |
|
662 | + foreach ($pages as $page) { |
|
663 | 663 | |
664 | 664 | // Catch and repair bad pages. |
665 | - if ( $page->post_parent == $page->ID ) { |
|
665 | + if ($page->post_parent == $page->ID) { |
|
666 | 666 | $page->post_parent = 0; |
667 | - $wpdb->update( $wpdb->posts, array( 'post_parent' => 0 ), array( 'ID' => $page->ID ) ); |
|
668 | - clean_post_cache( $page ); |
|
667 | + $wpdb->update($wpdb->posts, array('post_parent' => 0), array('ID' => $page->ID)); |
|
668 | + clean_post_cache($page); |
|
669 | 669 | } |
670 | 670 | |
671 | - if ( 0 == $page->post_parent ) |
|
671 | + if (0 == $page->post_parent) |
|
672 | 672 | $top_level_pages[] = $page; |
673 | 673 | else |
674 | - $children_pages[ $page->post_parent ][] = $page; |
|
674 | + $children_pages[$page->post_parent][] = $page; |
|
675 | 675 | } |
676 | 676 | |
677 | 677 | $pages = &$top_level_pages; |
678 | 678 | } |
679 | 679 | |
680 | 680 | $count = 0; |
681 | - $start = ( $pagenum - 1 ) * $per_page; |
|
681 | + $start = ($pagenum - 1) * $per_page; |
|
682 | 682 | $end = $start + $per_page; |
683 | 683 | $to_display = array(); |
684 | 684 | |
685 | - foreach ( $pages as $page ) { |
|
686 | - if ( $count >= $end ) |
|
685 | + foreach ($pages as $page) { |
|
686 | + if ($count >= $end) |
|
687 | 687 | break; |
688 | 688 | |
689 | - if ( $count >= $start ) { |
|
689 | + if ($count >= $start) { |
|
690 | 690 | $to_display[$page->ID] = $level; |
691 | 691 | } |
692 | 692 | |
693 | 693 | $count++; |
694 | 694 | |
695 | - if ( isset( $children_pages ) ) |
|
696 | - $this->_page_rows( $children_pages, $count, $page->ID, $level + 1, $pagenum, $per_page, $to_display ); |
|
695 | + if (isset($children_pages)) |
|
696 | + $this->_page_rows($children_pages, $count, $page->ID, $level + 1, $pagenum, $per_page, $to_display); |
|
697 | 697 | } |
698 | 698 | |
699 | 699 | // If it is the last pagenum and there are orphaned pages, display them with paging as well. |
700 | - if ( isset( $children_pages ) && $count < $end ){ |
|
701 | - foreach ( $children_pages as $orphans ){ |
|
702 | - foreach ( $orphans as $op ) { |
|
703 | - if ( $count >= $end ) |
|
700 | + if (isset($children_pages) && $count < $end) { |
|
701 | + foreach ($children_pages as $orphans) { |
|
702 | + foreach ($orphans as $op) { |
|
703 | + if ($count >= $end) |
|
704 | 704 | break; |
705 | 705 | |
706 | - if ( $count >= $start ) { |
|
706 | + if ($count >= $start) { |
|
707 | 707 | $to_display[$op->ID] = 0; |
708 | 708 | } |
709 | 709 | |
@@ -712,16 +712,16 @@ discard block |
||
712 | 712 | } |
713 | 713 | } |
714 | 714 | |
715 | - $ids = array_keys( $to_display ); |
|
716 | - _prime_post_caches( $ids ); |
|
715 | + $ids = array_keys($to_display); |
|
716 | + _prime_post_caches($ids); |
|
717 | 717 | |
718 | - if ( ! isset( $GLOBALS['post'] ) ) { |
|
719 | - $GLOBALS['post'] = reset( $ids ); |
|
718 | + if ( ! isset($GLOBALS['post'])) { |
|
719 | + $GLOBALS['post'] = reset($ids); |
|
720 | 720 | } |
721 | 721 | |
722 | - foreach ( $to_display as $page_id => $level ) { |
|
722 | + foreach ($to_display as $page_id => $level) { |
|
723 | 723 | echo "\t"; |
724 | - $this->single_row( $page_id, $level ); |
|
724 | + $this->single_row($page_id, $level); |
|
725 | 725 | } |
726 | 726 | } |
727 | 727 | |
@@ -740,51 +740,51 @@ discard block |
||
740 | 740 | * @param int $per_page |
741 | 741 | * @param array $to_display List of pages to be displayed. Passed by reference. |
742 | 742 | */ |
743 | - private function _page_rows( &$children_pages, &$count, $parent, $level, $pagenum, $per_page, &$to_display ) { |
|
744 | - if ( ! isset( $children_pages[$parent] ) ) |
|
743 | + private function _page_rows(&$children_pages, &$count, $parent, $level, $pagenum, $per_page, &$to_display) { |
|
744 | + if ( ! isset($children_pages[$parent])) |
|
745 | 745 | return; |
746 | 746 | |
747 | - $start = ( $pagenum - 1 ) * $per_page; |
|
747 | + $start = ($pagenum - 1) * $per_page; |
|
748 | 748 | $end = $start + $per_page; |
749 | 749 | |
750 | - foreach ( $children_pages[$parent] as $page ) { |
|
751 | - if ( $count >= $end ) |
|
750 | + foreach ($children_pages[$parent] as $page) { |
|
751 | + if ($count >= $end) |
|
752 | 752 | break; |
753 | 753 | |
754 | 754 | // If the page starts in a subtree, print the parents. |
755 | - if ( $count == $start && $page->post_parent > 0 ) { |
|
755 | + if ($count == $start && $page->post_parent > 0) { |
|
756 | 756 | $my_parents = array(); |
757 | 757 | $my_parent = $page->post_parent; |
758 | - while ( $my_parent ) { |
|
758 | + while ($my_parent) { |
|
759 | 759 | // Get the ID from the list or the attribute if my_parent is an object |
760 | 760 | $parent_id = $my_parent; |
761 | - if ( is_object( $my_parent ) ) { |
|
761 | + if (is_object($my_parent)) { |
|
762 | 762 | $parent_id = $my_parent->ID; |
763 | 763 | } |
764 | 764 | |
765 | - $my_parent = get_post( $parent_id ); |
|
765 | + $my_parent = get_post($parent_id); |
|
766 | 766 | $my_parents[] = $my_parent; |
767 | - if ( !$my_parent->post_parent ) |
|
767 | + if ( ! $my_parent->post_parent) |
|
768 | 768 | break; |
769 | 769 | $my_parent = $my_parent->post_parent; |
770 | 770 | } |
771 | - $num_parents = count( $my_parents ); |
|
772 | - while ( $my_parent = array_pop( $my_parents ) ) { |
|
771 | + $num_parents = count($my_parents); |
|
772 | + while ($my_parent = array_pop($my_parents)) { |
|
773 | 773 | $to_display[$my_parent->ID] = $level - $num_parents; |
774 | 774 | $num_parents--; |
775 | 775 | } |
776 | 776 | } |
777 | 777 | |
778 | - if ( $count >= $start ) { |
|
778 | + if ($count >= $start) { |
|
779 | 779 | $to_display[$page->ID] = $level; |
780 | 780 | } |
781 | 781 | |
782 | 782 | $count++; |
783 | 783 | |
784 | - $this->_page_rows( $children_pages, $count, $page->ID, $level + 1, $pagenum, $per_page, $to_display ); |
|
784 | + $this->_page_rows($children_pages, $count, $page->ID, $level + 1, $pagenum, $per_page, $to_display); |
|
785 | 785 | } |
786 | 786 | |
787 | - unset( $children_pages[$parent] ); //required in order to keep track of orphans |
|
787 | + unset($children_pages[$parent]); //required in order to keep track of orphans |
|
788 | 788 | } |
789 | 789 | |
790 | 790 | /** |
@@ -795,10 +795,10 @@ discard block |
||
795 | 795 | * |
796 | 796 | * @param WP_Post $post The current WP_Post object. |
797 | 797 | */ |
798 | - public function column_cb( $post ) { |
|
799 | - if ( current_user_can( 'edit_post', $post->ID ) ): ?> |
|
798 | + public function column_cb($post) { |
|
799 | + if (current_user_can('edit_post', $post->ID)): ?> |
|
800 | 800 | <label class="screen-reader-text" for="cb-select-<?php the_ID(); ?>"><?php |
801 | - printf( __( 'Select %s' ), _draft_or_post_title() ); |
|
801 | + printf(__('Select %s'), _draft_or_post_title()); |
|
802 | 802 | ?></label> |
803 | 803 | <input id="cb-select-<?php the_ID(); ?>" type="checkbox" name="post[]" value="<?php the_ID(); ?>" /> |
804 | 804 | <div class="locked-indicator"></div> |
@@ -814,10 +814,10 @@ discard block |
||
814 | 814 | * @param string $data |
815 | 815 | * @param string $primary |
816 | 816 | */ |
817 | - protected function _column_title( $post, $classes, $data, $primary ) { |
|
818 | - echo '<td class="' . $classes . ' page-title" ', $data, '>'; |
|
819 | - echo $this->column_title( $post ); |
|
820 | - echo $this->handle_row_actions( $post, 'title', $primary ); |
|
817 | + protected function _column_title($post, $classes, $data, $primary) { |
|
818 | + echo '<td class="'.$classes.' page-title" ', $data, '>'; |
|
819 | + echo $this->column_title($post); |
|
820 | + echo $this->handle_row_actions($post, 'title', $primary); |
|
821 | 821 | echo '</td>'; |
822 | 822 | } |
823 | 823 | |
@@ -831,90 +831,90 @@ discard block |
||
831 | 831 | * |
832 | 832 | * @param WP_Post $post The current WP_Post object. |
833 | 833 | */ |
834 | - public function column_title( $post ) { |
|
834 | + public function column_title($post) { |
|
835 | 835 | global $mode; |
836 | 836 | |
837 | - if ( $this->hierarchical_display ) { |
|
838 | - if ( 0 === $this->current_level && (int) $post->post_parent > 0 ) { |
|
837 | + if ($this->hierarchical_display) { |
|
838 | + if (0 === $this->current_level && (int) $post->post_parent > 0) { |
|
839 | 839 | // Sent level 0 by accident, by default, or because we don't know the actual level. |
840 | 840 | $find_main_page = (int) $post->post_parent; |
841 | - while ( $find_main_page > 0 ) { |
|
842 | - $parent = get_post( $find_main_page ); |
|
841 | + while ($find_main_page > 0) { |
|
842 | + $parent = get_post($find_main_page); |
|
843 | 843 | |
844 | - if ( is_null( $parent ) ) { |
|
844 | + if (is_null($parent)) { |
|
845 | 845 | break; |
846 | 846 | } |
847 | 847 | |
848 | 848 | $this->current_level++; |
849 | 849 | $find_main_page = (int) $parent->post_parent; |
850 | 850 | |
851 | - if ( ! isset( $parent_name ) ) { |
|
851 | + if ( ! isset($parent_name)) { |
|
852 | 852 | /** This filter is documented in wp-includes/post-template.php */ |
853 | - $parent_name = apply_filters( 'the_title', $parent->post_title, $parent->ID ); |
|
853 | + $parent_name = apply_filters('the_title', $parent->post_title, $parent->ID); |
|
854 | 854 | } |
855 | 855 | } |
856 | 856 | } |
857 | 857 | } |
858 | 858 | |
859 | - $pad = str_repeat( '— ', $this->current_level ); |
|
859 | + $pad = str_repeat('— ', $this->current_level); |
|
860 | 860 | echo "<strong>"; |
861 | 861 | |
862 | - $format = get_post_format( $post->ID ); |
|
863 | - if ( $format ) { |
|
864 | - $label = get_post_format_string( $format ); |
|
862 | + $format = get_post_format($post->ID); |
|
863 | + if ($format) { |
|
864 | + $label = get_post_format_string($format); |
|
865 | 865 | |
866 | - $format_class = 'post-state-format post-format-icon post-format-' . $format; |
|
866 | + $format_class = 'post-state-format post-format-icon post-format-'.$format; |
|
867 | 867 | |
868 | 868 | $format_args = array( |
869 | 869 | 'post_format' => $format, |
870 | 870 | 'post_type' => $post->post_type |
871 | 871 | ); |
872 | 872 | |
873 | - echo $this->get_edit_link( $format_args, $label . ':', $format_class ); |
|
873 | + echo $this->get_edit_link($format_args, $label.':', $format_class); |
|
874 | 874 | } |
875 | 875 | |
876 | - $can_edit_post = current_user_can( 'edit_post', $post->ID ); |
|
876 | + $can_edit_post = current_user_can('edit_post', $post->ID); |
|
877 | 877 | $title = _draft_or_post_title(); |
878 | 878 | |
879 | - if ( $can_edit_post && $post->post_status != 'trash' ) { |
|
879 | + if ($can_edit_post && $post->post_status != 'trash') { |
|
880 | 880 | printf( |
881 | 881 | '<a class="row-title" href="%s" aria-label="%s">%s%s</a>', |
882 | - get_edit_post_link( $post->ID ), |
|
882 | + get_edit_post_link($post->ID), |
|
883 | 883 | /* translators: %s: post title */ |
884 | - esc_attr( sprintf( __( '“%s” (Edit)' ), $title ) ), |
|
884 | + esc_attr(sprintf(__('“%s” (Edit)'), $title)), |
|
885 | 885 | $pad, |
886 | 886 | $title |
887 | 887 | ); |
888 | 888 | } else { |
889 | - echo $pad . $title; |
|
889 | + echo $pad.$title; |
|
890 | 890 | } |
891 | - _post_states( $post ); |
|
891 | + _post_states($post); |
|
892 | 892 | |
893 | - if ( isset( $parent_name ) ) { |
|
894 | - $post_type_object = get_post_type_object( $post->post_type ); |
|
895 | - echo ' | ' . $post_type_object->labels->parent_item_colon . ' ' . esc_html( $parent_name ); |
|
893 | + if (isset($parent_name)) { |
|
894 | + $post_type_object = get_post_type_object($post->post_type); |
|
895 | + echo ' | '.$post_type_object->labels->parent_item_colon.' '.esc_html($parent_name); |
|
896 | 896 | } |
897 | 897 | echo "</strong>\n"; |
898 | 898 | |
899 | - if ( $can_edit_post && $post->post_status != 'trash' ) { |
|
900 | - $lock_holder = wp_check_post_lock( $post->ID ); |
|
899 | + if ($can_edit_post && $post->post_status != 'trash') { |
|
900 | + $lock_holder = wp_check_post_lock($post->ID); |
|
901 | 901 | |
902 | - if ( $lock_holder ) { |
|
903 | - $lock_holder = get_userdata( $lock_holder ); |
|
904 | - $locked_avatar = get_avatar( $lock_holder->ID, 18 ); |
|
905 | - $locked_text = esc_html( sprintf( __( '%s is currently editing' ), $lock_holder->display_name ) ); |
|
902 | + if ($lock_holder) { |
|
903 | + $lock_holder = get_userdata($lock_holder); |
|
904 | + $locked_avatar = get_avatar($lock_holder->ID, 18); |
|
905 | + $locked_text = esc_html(sprintf(__('%s is currently editing'), $lock_holder->display_name)); |
|
906 | 906 | } else { |
907 | 907 | $locked_avatar = $locked_text = ''; |
908 | 908 | } |
909 | 909 | |
910 | - echo '<div class="locked-info"><span class="locked-avatar">' . $locked_avatar . '</span> <span class="locked-text">' . $locked_text . "</span></div>\n"; |
|
910 | + echo '<div class="locked-info"><span class="locked-avatar">'.$locked_avatar.'</span> <span class="locked-text">'.$locked_text."</span></div>\n"; |
|
911 | 911 | } |
912 | 912 | |
913 | - if ( ! is_post_type_hierarchical( $this->screen->post_type ) && 'excerpt' === $mode && current_user_can( 'read_post', $post->ID ) ) { |
|
913 | + if ( ! is_post_type_hierarchical($this->screen->post_type) && 'excerpt' === $mode && current_user_can('read_post', $post->ID)) { |
|
914 | 914 | the_excerpt(); |
915 | 915 | } |
916 | 916 | |
917 | - get_inline_data( $post ); |
|
917 | + get_inline_data($post); |
|
918 | 918 | } |
919 | 919 | |
920 | 920 | /** |
@@ -927,39 +927,39 @@ discard block |
||
927 | 927 | * |
928 | 928 | * @param WP_Post $post The current WP_Post object. |
929 | 929 | */ |
930 | - public function column_date( $post ) { |
|
930 | + public function column_date($post) { |
|
931 | 931 | global $mode; |
932 | 932 | |
933 | - if ( '0000-00-00 00:00:00' === $post->post_date ) { |
|
934 | - $t_time = $h_time = __( 'Unpublished' ); |
|
933 | + if ('0000-00-00 00:00:00' === $post->post_date) { |
|
934 | + $t_time = $h_time = __('Unpublished'); |
|
935 | 935 | $time_diff = 0; |
936 | 936 | } else { |
937 | - $t_time = get_the_time( __( 'Y/m/d g:i:s a' ) ); |
|
937 | + $t_time = get_the_time(__('Y/m/d g:i:s a')); |
|
938 | 938 | $m_time = $post->post_date; |
939 | - $time = get_post_time( 'G', true, $post ); |
|
939 | + $time = get_post_time('G', true, $post); |
|
940 | 940 | |
941 | 941 | $time_diff = time() - $time; |
942 | 942 | |
943 | - if ( $time_diff > 0 && $time_diff < DAY_IN_SECONDS ) { |
|
944 | - $h_time = sprintf( __( '%s ago' ), human_time_diff( $time ) ); |
|
943 | + if ($time_diff > 0 && $time_diff < DAY_IN_SECONDS) { |
|
944 | + $h_time = sprintf(__('%s ago'), human_time_diff($time)); |
|
945 | 945 | } else { |
946 | - $h_time = mysql2date( __( 'Y/m/d' ), $m_time ); |
|
946 | + $h_time = mysql2date(__('Y/m/d'), $m_time); |
|
947 | 947 | } |
948 | 948 | } |
949 | 949 | |
950 | - if ( 'publish' === $post->post_status ) { |
|
951 | - _e( 'Published' ); |
|
952 | - } elseif ( 'future' === $post->post_status ) { |
|
953 | - if ( $time_diff > 0 ) { |
|
954 | - echo '<strong class="error-message">' . __( 'Missed schedule' ) . '</strong>'; |
|
950 | + if ('publish' === $post->post_status) { |
|
951 | + _e('Published'); |
|
952 | + } elseif ('future' === $post->post_status) { |
|
953 | + if ($time_diff > 0) { |
|
954 | + echo '<strong class="error-message">'.__('Missed schedule').'</strong>'; |
|
955 | 955 | } else { |
956 | - _e( 'Scheduled' ); |
|
956 | + _e('Scheduled'); |
|
957 | 957 | } |
958 | 958 | } else { |
959 | - _e( 'Last Modified' ); |
|
959 | + _e('Last Modified'); |
|
960 | 960 | } |
961 | 961 | echo '<br />'; |
962 | - if ( 'excerpt' === $mode ) { |
|
962 | + if ('excerpt' === $mode) { |
|
963 | 963 | /** |
964 | 964 | * Filter the published time of the post. |
965 | 965 | * |
@@ -974,11 +974,11 @@ discard block |
||
974 | 974 | * @param string $column_name The column name. |
975 | 975 | * @param string $mode The list display mode ('excerpt' or 'list'). |
976 | 976 | */ |
977 | - echo apply_filters( 'post_date_column_time', $t_time, $post, 'date', $mode ); |
|
977 | + echo apply_filters('post_date_column_time', $t_time, $post, 'date', $mode); |
|
978 | 978 | } else { |
979 | 979 | |
980 | 980 | /** This filter is documented in wp-admin/includes/class-wp-posts-list-table.php */ |
981 | - echo '<abbr title="' . $t_time . '">' . apply_filters( 'post_date_column_time', $h_time, $post, 'date', $mode ) . '</abbr>'; |
|
981 | + echo '<abbr title="'.$t_time.'">'.apply_filters('post_date_column_time', $h_time, $post, 'date', $mode).'</abbr>'; |
|
982 | 982 | } |
983 | 983 | } |
984 | 984 | |
@@ -990,13 +990,13 @@ discard block |
||
990 | 990 | * |
991 | 991 | * @param WP_Post $post The current WP_Post object. |
992 | 992 | */ |
993 | - public function column_comments( $post ) { |
|
993 | + public function column_comments($post) { |
|
994 | 994 | ?> |
995 | 995 | <div class="post-com-count-wrapper"> |
996 | 996 | <?php |
997 | - $pending_comments = isset( $this->comment_pending_count[$post->ID] ) ? $this->comment_pending_count[$post->ID] : 0; |
|
997 | + $pending_comments = isset($this->comment_pending_count[$post->ID]) ? $this->comment_pending_count[$post->ID] : 0; |
|
998 | 998 | |
999 | - $this->comments_bubble( $post->ID, $pending_comments ); |
|
999 | + $this->comments_bubble($post->ID, $pending_comments); |
|
1000 | 1000 | ?> |
1001 | 1001 | </div> |
1002 | 1002 | <?php |
@@ -1010,12 +1010,12 @@ discard block |
||
1010 | 1010 | * |
1011 | 1011 | * @param WP_Post $post The current WP_Post object. |
1012 | 1012 | */ |
1013 | - public function column_author( $post ) { |
|
1013 | + public function column_author($post) { |
|
1014 | 1014 | $args = array( |
1015 | 1015 | 'post_type' => $post->post_type, |
1016 | - 'author' => get_the_author_meta( 'ID' ) |
|
1016 | + 'author' => get_the_author_meta('ID') |
|
1017 | 1017 | ); |
1018 | - echo $this->get_edit_link( $args, get_the_author() ); |
|
1018 | + echo $this->get_edit_link($args, get_the_author()); |
|
1019 | 1019 | } |
1020 | 1020 | |
1021 | 1021 | /** |
@@ -1027,45 +1027,45 @@ discard block |
||
1027 | 1027 | * @param WP_Post $post The current WP_Post object. |
1028 | 1028 | * @param string $column_name The current column name. |
1029 | 1029 | */ |
1030 | - public function column_default( $post, $column_name ) { |
|
1031 | - if ( 'categories' === $column_name ) { |
|
1030 | + public function column_default($post, $column_name) { |
|
1031 | + if ('categories' === $column_name) { |
|
1032 | 1032 | $taxonomy = 'category'; |
1033 | - } elseif ( 'tags' === $column_name ) { |
|
1033 | + } elseif ('tags' === $column_name) { |
|
1034 | 1034 | $taxonomy = 'post_tag'; |
1035 | - } elseif ( 0 === strpos( $column_name, 'taxonomy-' ) ) { |
|
1036 | - $taxonomy = substr( $column_name, 9 ); |
|
1035 | + } elseif (0 === strpos($column_name, 'taxonomy-')) { |
|
1036 | + $taxonomy = substr($column_name, 9); |
|
1037 | 1037 | } else { |
1038 | 1038 | $taxonomy = false; |
1039 | 1039 | } |
1040 | - if ( $taxonomy ) { |
|
1041 | - $taxonomy_object = get_taxonomy( $taxonomy ); |
|
1042 | - $terms = get_the_terms( $post->ID, $taxonomy ); |
|
1043 | - if ( is_array( $terms ) ) { |
|
1040 | + if ($taxonomy) { |
|
1041 | + $taxonomy_object = get_taxonomy($taxonomy); |
|
1042 | + $terms = get_the_terms($post->ID, $taxonomy); |
|
1043 | + if (is_array($terms)) { |
|
1044 | 1044 | $out = array(); |
1045 | - foreach ( $terms as $t ) { |
|
1045 | + foreach ($terms as $t) { |
|
1046 | 1046 | $posts_in_term_qv = array(); |
1047 | - if ( 'post' != $post->post_type ) { |
|
1047 | + if ('post' != $post->post_type) { |
|
1048 | 1048 | $posts_in_term_qv['post_type'] = $post->post_type; |
1049 | 1049 | } |
1050 | - if ( $taxonomy_object->query_var ) { |
|
1051 | - $posts_in_term_qv[ $taxonomy_object->query_var ] = $t->slug; |
|
1050 | + if ($taxonomy_object->query_var) { |
|
1051 | + $posts_in_term_qv[$taxonomy_object->query_var] = $t->slug; |
|
1052 | 1052 | } else { |
1053 | 1053 | $posts_in_term_qv['taxonomy'] = $taxonomy; |
1054 | 1054 | $posts_in_term_qv['term'] = $t->slug; |
1055 | 1055 | } |
1056 | 1056 | |
1057 | - $label = esc_html( sanitize_term_field( 'name', $t->name, $t->term_id, $taxonomy, 'display' ) ); |
|
1058 | - $out[] = $this->get_edit_link( $posts_in_term_qv, $label ); |
|
1057 | + $label = esc_html(sanitize_term_field('name', $t->name, $t->term_id, $taxonomy, 'display')); |
|
1058 | + $out[] = $this->get_edit_link($posts_in_term_qv, $label); |
|
1059 | 1059 | } |
1060 | 1060 | /* translators: used between list items, there is a space after the comma */ |
1061 | - echo join( __( ', ' ), $out ); |
|
1061 | + echo join(__(', '), $out); |
|
1062 | 1062 | } else { |
1063 | - echo '<span aria-hidden="true">—</span><span class="screen-reader-text">' . $taxonomy_object->labels->no_terms . '</span>'; |
|
1063 | + echo '<span aria-hidden="true">—</span><span class="screen-reader-text">'.$taxonomy_object->labels->no_terms.'</span>'; |
|
1064 | 1064 | } |
1065 | 1065 | return; |
1066 | 1066 | } |
1067 | 1067 | |
1068 | - if ( is_post_type_hierarchical( $post->post_type ) ) { |
|
1068 | + if (is_post_type_hierarchical($post->post_type)) { |
|
1069 | 1069 | |
1070 | 1070 | /** |
1071 | 1071 | * Fires in each custom column on the Posts list table. |
@@ -1078,7 +1078,7 @@ discard block |
||
1078 | 1078 | * @param string $column_name The name of the column to display. |
1079 | 1079 | * @param int $post_id The current post ID. |
1080 | 1080 | */ |
1081 | - do_action( 'manage_pages_custom_column', $column_name, $post->ID ); |
|
1081 | + do_action('manage_pages_custom_column', $column_name, $post->ID); |
|
1082 | 1082 | } else { |
1083 | 1083 | |
1084 | 1084 | /** |
@@ -1092,7 +1092,7 @@ discard block |
||
1092 | 1092 | * @param string $column_name The name of the column to display. |
1093 | 1093 | * @param int $post_id The current post ID. |
1094 | 1094 | */ |
1095 | - do_action( 'manage_posts_custom_column', $column_name, $post->ID ); |
|
1095 | + do_action('manage_posts_custom_column', $column_name, $post->ID); |
|
1096 | 1096 | } |
1097 | 1097 | |
1098 | 1098 | /** |
@@ -1105,7 +1105,7 @@ discard block |
||
1105 | 1105 | * @param string $column_name The name of the column to display. |
1106 | 1106 | * @param int $post_id The current post ID. |
1107 | 1107 | */ |
1108 | - do_action( "manage_{$post->post_type}_posts_custom_column", $column_name, $post->ID ); |
|
1108 | + do_action("manage_{$post->post_type}_posts_custom_column", $column_name, $post->ID); |
|
1109 | 1109 | } |
1110 | 1110 | |
1111 | 1111 | /** |
@@ -1114,31 +1114,31 @@ discard block |
||
1114 | 1114 | * @param int|WP_Post $post |
1115 | 1115 | * @param int $level |
1116 | 1116 | */ |
1117 | - public function single_row( $post, $level = 0 ) { |
|
1117 | + public function single_row($post, $level = 0) { |
|
1118 | 1118 | $global_post = get_post(); |
1119 | 1119 | |
1120 | - $post = get_post( $post ); |
|
1120 | + $post = get_post($post); |
|
1121 | 1121 | $this->current_level = $level; |
1122 | 1122 | |
1123 | 1123 | $GLOBALS['post'] = $post; |
1124 | - setup_postdata( $post ); |
|
1124 | + setup_postdata($post); |
|
1125 | 1125 | |
1126 | - $classes = 'iedit author-' . ( get_current_user_id() == $post->post_author ? 'self' : 'other' ); |
|
1126 | + $classes = 'iedit author-'.(get_current_user_id() == $post->post_author ? 'self' : 'other'); |
|
1127 | 1127 | |
1128 | - $lock_holder = wp_check_post_lock( $post->ID ); |
|
1129 | - if ( $lock_holder ) { |
|
1128 | + $lock_holder = wp_check_post_lock($post->ID); |
|
1129 | + if ($lock_holder) { |
|
1130 | 1130 | $classes .= ' wp-locked'; |
1131 | 1131 | } |
1132 | 1132 | |
1133 | - if ( $post->post_parent ) { |
|
1134 | - $count = count( get_post_ancestors( $post->ID ) ); |
|
1135 | - $classes .= ' level-'. $count; |
|
1133 | + if ($post->post_parent) { |
|
1134 | + $count = count(get_post_ancestors($post->ID)); |
|
1135 | + $classes .= ' level-'.$count; |
|
1136 | 1136 | } else { |
1137 | 1137 | $classes .= ' level-0'; |
1138 | 1138 | } |
1139 | 1139 | ?> |
1140 | - <tr id="post-<?php echo $post->ID; ?>" class="<?php echo implode( ' ', get_post_class( $classes, $post->ID ) ); ?>"> |
|
1141 | - <?php $this->single_row_columns( $post ); ?> |
|
1140 | + <tr id="post-<?php echo $post->ID; ?>" class="<?php echo implode(' ', get_post_class($classes, $post->ID)); ?>"> |
|
1141 | + <?php $this->single_row_columns($post); ?> |
|
1142 | 1142 | </tr> |
1143 | 1143 | <?php |
1144 | 1144 | $GLOBALS['post'] = $global_post; |
@@ -1167,85 +1167,85 @@ discard block |
||
1167 | 1167 | * @param string $primary Primary column name. |
1168 | 1168 | * @return string Row actions output for posts. |
1169 | 1169 | */ |
1170 | - protected function handle_row_actions( $post, $column_name, $primary ) { |
|
1171 | - if ( $primary !== $column_name ) { |
|
1170 | + protected function handle_row_actions($post, $column_name, $primary) { |
|
1171 | + if ($primary !== $column_name) { |
|
1172 | 1172 | return ''; |
1173 | 1173 | } |
1174 | 1174 | |
1175 | - $post_type_object = get_post_type_object( $post->post_type ); |
|
1176 | - $can_edit_post = current_user_can( 'edit_post', $post->ID ); |
|
1175 | + $post_type_object = get_post_type_object($post->post_type); |
|
1176 | + $can_edit_post = current_user_can('edit_post', $post->ID); |
|
1177 | 1177 | $actions = array(); |
1178 | 1178 | $title = _draft_or_post_title(); |
1179 | 1179 | |
1180 | - if ( $can_edit_post && 'trash' != $post->post_status ) { |
|
1180 | + if ($can_edit_post && 'trash' != $post->post_status) { |
|
1181 | 1181 | $actions['edit'] = sprintf( |
1182 | 1182 | '<a href="%s" aria-label="%s">%s</a>', |
1183 | - get_edit_post_link( $post->ID ), |
|
1183 | + get_edit_post_link($post->ID), |
|
1184 | 1184 | /* translators: %s: post title */ |
1185 | - esc_attr( sprintf( __( 'Edit “%s”' ), $title ) ), |
|
1186 | - __( 'Edit' ) |
|
1185 | + esc_attr(sprintf(__('Edit “%s”'), $title)), |
|
1186 | + __('Edit') |
|
1187 | 1187 | ); |
1188 | 1188 | $actions['inline hide-if-no-js'] = sprintf( |
1189 | 1189 | '<a href="#" class="editinline" aria-label="%s">%s</a>', |
1190 | 1190 | /* translators: %s: post title */ |
1191 | - esc_attr( sprintf( __( 'Quick edit “%s” inline' ), $title ) ), |
|
1192 | - __( 'Quick Edit' ) |
|
1191 | + esc_attr(sprintf(__('Quick edit “%s” inline'), $title)), |
|
1192 | + __('Quick Edit') |
|
1193 | 1193 | ); |
1194 | 1194 | } |
1195 | 1195 | |
1196 | - if ( current_user_can( 'delete_post', $post->ID ) ) { |
|
1197 | - if ( 'trash' === $post->post_status ) { |
|
1196 | + if (current_user_can('delete_post', $post->ID)) { |
|
1197 | + if ('trash' === $post->post_status) { |
|
1198 | 1198 | $actions['untrash'] = sprintf( |
1199 | 1199 | '<a href="%s" aria-label="%s">%s</a>', |
1200 | - wp_nonce_url( admin_url( sprintf( $post_type_object->_edit_link . '&action=untrash', $post->ID ) ), 'untrash-post_' . $post->ID ), |
|
1200 | + wp_nonce_url(admin_url(sprintf($post_type_object->_edit_link.'&action=untrash', $post->ID)), 'untrash-post_'.$post->ID), |
|
1201 | 1201 | /* translators: %s: post title */ |
1202 | - esc_attr( sprintf( __( 'Restore “%s” from the Trash' ), $title ) ), |
|
1203 | - __( 'Restore' ) |
|
1202 | + esc_attr(sprintf(__('Restore “%s” from the Trash'), $title)), |
|
1203 | + __('Restore') |
|
1204 | 1204 | ); |
1205 | - } elseif ( EMPTY_TRASH_DAYS ) { |
|
1205 | + } elseif (EMPTY_TRASH_DAYS) { |
|
1206 | 1206 | $actions['trash'] = sprintf( |
1207 | 1207 | '<a href="%s" class="submitdelete" aria-label="%s">%s</a>', |
1208 | - get_delete_post_link( $post->ID ), |
|
1208 | + get_delete_post_link($post->ID), |
|
1209 | 1209 | /* translators: %s: post title */ |
1210 | - esc_attr( sprintf( __( 'Move “%s” to the Trash' ), $title ) ), |
|
1211 | - _x( 'Trash', 'verb' ) |
|
1210 | + esc_attr(sprintf(__('Move “%s” to the Trash'), $title)), |
|
1211 | + _x('Trash', 'verb') |
|
1212 | 1212 | ); |
1213 | 1213 | } |
1214 | - if ( 'trash' === $post->post_status || ! EMPTY_TRASH_DAYS ) { |
|
1214 | + if ('trash' === $post->post_status || ! EMPTY_TRASH_DAYS) { |
|
1215 | 1215 | $actions['delete'] = sprintf( |
1216 | 1216 | '<a href="%s" class="submitdelete" aria-label="%s">%s</a>', |
1217 | - get_delete_post_link( $post->ID, '', true ), |
|
1217 | + get_delete_post_link($post->ID, '', true), |
|
1218 | 1218 | /* translators: %s: post title */ |
1219 | - esc_attr( sprintf( __( 'Delete “%s” permanently' ), $title ) ), |
|
1220 | - __( 'Delete Permanently' ) |
|
1219 | + esc_attr(sprintf(__('Delete “%s” permanently'), $title)), |
|
1220 | + __('Delete Permanently') |
|
1221 | 1221 | ); |
1222 | 1222 | } |
1223 | 1223 | } |
1224 | 1224 | |
1225 | - if ( is_post_type_viewable( $post_type_object ) ) { |
|
1226 | - if ( in_array( $post->post_status, array( 'pending', 'draft', 'future' ) ) ) { |
|
1227 | - if ( $can_edit_post ) { |
|
1228 | - $preview_link = get_preview_post_link( $post ); |
|
1225 | + if (is_post_type_viewable($post_type_object)) { |
|
1226 | + if (in_array($post->post_status, array('pending', 'draft', 'future'))) { |
|
1227 | + if ($can_edit_post) { |
|
1228 | + $preview_link = get_preview_post_link($post); |
|
1229 | 1229 | $actions['view'] = sprintf( |
1230 | 1230 | '<a href="%s" rel="permalink" aria-label="%s">%s</a>', |
1231 | - esc_url( $preview_link ), |
|
1231 | + esc_url($preview_link), |
|
1232 | 1232 | /* translators: %s: post title */ |
1233 | - esc_attr( sprintf( __( 'Preview “%s”' ), $title ) ), |
|
1234 | - __( 'Preview' ) |
|
1233 | + esc_attr(sprintf(__('Preview “%s”'), $title)), |
|
1234 | + __('Preview') |
|
1235 | 1235 | ); |
1236 | 1236 | } |
1237 | - } elseif ( 'trash' != $post->post_status ) { |
|
1237 | + } elseif ('trash' != $post->post_status) { |
|
1238 | 1238 | $actions['view'] = sprintf( |
1239 | 1239 | '<a href="%s" rel="permalink" aria-label="%s">%s</a>', |
1240 | - get_permalink( $post->ID ), |
|
1240 | + get_permalink($post->ID), |
|
1241 | 1241 | /* translators: %s: post title */ |
1242 | - esc_attr( sprintf( __( 'View “%s”' ), $title ) ), |
|
1243 | - __( 'View' ) |
|
1242 | + esc_attr(sprintf(__('View “%s”'), $title)), |
|
1243 | + __('View') |
|
1244 | 1244 | ); |
1245 | 1245 | } |
1246 | 1246 | } |
1247 | 1247 | |
1248 | - if ( is_post_type_hierarchical( $post->post_type ) ) { |
|
1248 | + if (is_post_type_hierarchical($post->post_type)) { |
|
1249 | 1249 | |
1250 | 1250 | /** |
1251 | 1251 | * Filter the array of row action links on the Pages list table. |
@@ -1259,7 +1259,7 @@ discard block |
||
1259 | 1259 | * 'Delete Permanently', 'Preview', and 'View'. |
1260 | 1260 | * @param WP_Post $post The post object. |
1261 | 1261 | */ |
1262 | - $actions = apply_filters( 'page_row_actions', $actions, $post ); |
|
1262 | + $actions = apply_filters('page_row_actions', $actions, $post); |
|
1263 | 1263 | } else { |
1264 | 1264 | |
1265 | 1265 | /** |
@@ -1274,10 +1274,10 @@ discard block |
||
1274 | 1274 | * 'Delete Permanently', 'Preview', and 'View'. |
1275 | 1275 | * @param WP_Post $post The post object. |
1276 | 1276 | */ |
1277 | - $actions = apply_filters( 'post_row_actions', $actions, $post ); |
|
1277 | + $actions = apply_filters('post_row_actions', $actions, $post); |
|
1278 | 1278 | } |
1279 | 1279 | |
1280 | - return $this->row_actions( $actions ); |
|
1280 | + return $this->row_actions($actions); |
|
1281 | 1281 | } |
1282 | 1282 | |
1283 | 1283 | /** |
@@ -1292,15 +1292,15 @@ discard block |
||
1292 | 1292 | |
1293 | 1293 | $screen = $this->screen; |
1294 | 1294 | |
1295 | - $post = get_default_post_to_edit( $screen->post_type ); |
|
1296 | - $post_type_object = get_post_type_object( $screen->post_type ); |
|
1295 | + $post = get_default_post_to_edit($screen->post_type); |
|
1296 | + $post_type_object = get_post_type_object($screen->post_type); |
|
1297 | 1297 | |
1298 | - $taxonomy_names = get_object_taxonomies( $screen->post_type ); |
|
1298 | + $taxonomy_names = get_object_taxonomies($screen->post_type); |
|
1299 | 1299 | $hierarchical_taxonomies = array(); |
1300 | 1300 | $flat_taxonomies = array(); |
1301 | - foreach ( $taxonomy_names as $taxonomy_name ) { |
|
1301 | + foreach ($taxonomy_names as $taxonomy_name) { |
|
1302 | 1302 | |
1303 | - $taxonomy = get_taxonomy( $taxonomy_name ); |
|
1303 | + $taxonomy = get_taxonomy($taxonomy_name); |
|
1304 | 1304 | |
1305 | 1305 | $show_in_quick_edit = $taxonomy->show_in_quick_edit; |
1306 | 1306 | |
@@ -1313,39 +1313,39 @@ discard block |
||
1313 | 1313 | * @param string $taxonomy_name Taxonomy name. |
1314 | 1314 | * @param string $post_type Post type of current Quick Edit post. |
1315 | 1315 | */ |
1316 | - if ( ! apply_filters( 'quick_edit_show_taxonomy', $show_in_quick_edit, $taxonomy_name, $screen->post_type ) ) { |
|
1316 | + if ( ! apply_filters('quick_edit_show_taxonomy', $show_in_quick_edit, $taxonomy_name, $screen->post_type)) { |
|
1317 | 1317 | continue; |
1318 | 1318 | } |
1319 | 1319 | |
1320 | - if ( $taxonomy->hierarchical ) |
|
1320 | + if ($taxonomy->hierarchical) |
|
1321 | 1321 | $hierarchical_taxonomies[] = $taxonomy; |
1322 | 1322 | else |
1323 | 1323 | $flat_taxonomies[] = $taxonomy; |
1324 | 1324 | } |
1325 | 1325 | |
1326 | - $m = ( isset( $mode ) && 'excerpt' === $mode ) ? 'excerpt' : 'list'; |
|
1327 | - $can_publish = current_user_can( $post_type_object->cap->publish_posts ); |
|
1328 | - $core_columns = array( 'cb' => true, 'date' => true, 'title' => true, 'categories' => true, 'tags' => true, 'comments' => true, 'author' => true ); |
|
1326 | + $m = (isset($mode) && 'excerpt' === $mode) ? 'excerpt' : 'list'; |
|
1327 | + $can_publish = current_user_can($post_type_object->cap->publish_posts); |
|
1328 | + $core_columns = array('cb' => true, 'date' => true, 'title' => true, 'categories' => true, 'tags' => true, 'comments' => true, 'author' => true); |
|
1329 | 1329 | |
1330 | 1330 | ?> |
1331 | 1331 | |
1332 | 1332 | <form method="get"><table style="display: none"><tbody id="inlineedit"> |
1333 | 1333 | <?php |
1334 | - $hclass = count( $hierarchical_taxonomies ) ? 'post' : 'page'; |
|
1334 | + $hclass = count($hierarchical_taxonomies) ? 'post' : 'page'; |
|
1335 | 1335 | $bulk = 0; |
1336 | - while ( $bulk < 2 ) { ?> |
|
1336 | + while ($bulk < 2) { ?> |
|
1337 | 1337 | |
1338 | - <tr id="<?php echo $bulk ? 'bulk-edit' : 'inline-edit'; ?>" class="inline-edit-row inline-edit-row-<?php echo "$hclass inline-edit-" . $screen->post_type; |
|
1338 | + <tr id="<?php echo $bulk ? 'bulk-edit' : 'inline-edit'; ?>" class="inline-edit-row inline-edit-row-<?php echo "$hclass inline-edit-".$screen->post_type; |
|
1339 | 1339 | echo $bulk ? " bulk-edit-row bulk-edit-row-$hclass bulk-edit-{$screen->post_type}" : " quick-edit-row quick-edit-row-$hclass inline-edit-{$screen->post_type}"; |
1340 | 1340 | ?>" style="display: none"><td colspan="<?php echo $this->get_column_count(); ?>" class="colspanchange"> |
1341 | 1341 | |
1342 | 1342 | <fieldset class="inline-edit-col-left"> |
1343 | - <legend class="inline-edit-legend"><?php echo $bulk ? __( 'Bulk Edit' ) : __( 'Quick Edit' ); ?></legend> |
|
1343 | + <legend class="inline-edit-legend"><?php echo $bulk ? __('Bulk Edit') : __('Quick Edit'); ?></legend> |
|
1344 | 1344 | <div class="inline-edit-col"> |
1345 | 1345 | <?php |
1346 | 1346 | |
1347 | - if ( post_type_supports( $screen->post_type, 'title' ) ) : |
|
1348 | - if ( $bulk ) : ?> |
|
1347 | + if (post_type_supports($screen->post_type, 'title')) : |
|
1348 | + if ($bulk) : ?> |
|
1349 | 1349 | <div id="bulk-title-div"> |
1350 | 1350 | <div id="bulk-titles"></div> |
1351 | 1351 | </div> |
@@ -1353,30 +1353,30 @@ discard block |
||
1353 | 1353 | <?php else : // $bulk ?> |
1354 | 1354 | |
1355 | 1355 | <label> |
1356 | - <span class="title"><?php _e( 'Title' ); ?></span> |
|
1356 | + <span class="title"><?php _e('Title'); ?></span> |
|
1357 | 1357 | <span class="input-text-wrap"><input type="text" name="post_title" class="ptitle" value="" /></span> |
1358 | 1358 | </label> |
1359 | 1359 | |
1360 | 1360 | <label> |
1361 | - <span class="title"><?php _e( 'Slug' ); ?></span> |
|
1361 | + <span class="title"><?php _e('Slug'); ?></span> |
|
1362 | 1362 | <span class="input-text-wrap"><input type="text" name="post_name" value="" /></span> |
1363 | 1363 | </label> |
1364 | 1364 | |
1365 | 1365 | <?php endif; // $bulk |
1366 | 1366 | endif; // post_type_supports title ?> |
1367 | 1367 | |
1368 | - <?php if ( !$bulk ) : ?> |
|
1368 | + <?php if ( ! $bulk) : ?> |
|
1369 | 1369 | <fieldset class="inline-edit-date"> |
1370 | - <legend><span class="title"><?php _e( 'Date' ); ?></span></legend> |
|
1371 | - <?php touch_time( 1, 1, 0, 1 ); ?> |
|
1370 | + <legend><span class="title"><?php _e('Date'); ?></span></legend> |
|
1371 | + <?php touch_time(1, 1, 0, 1); ?> |
|
1372 | 1372 | </fieldset> |
1373 | 1373 | <br class="clear" /> |
1374 | 1374 | <?php endif; // $bulk |
1375 | 1375 | |
1376 | - if ( post_type_supports( $screen->post_type, 'author' ) ) : |
|
1376 | + if (post_type_supports($screen->post_type, 'author')) : |
|
1377 | 1377 | $authors_dropdown = ''; |
1378 | 1378 | |
1379 | - if ( is_super_admin() || current_user_can( $post_type_object->cap->edit_others_posts ) ) : |
|
1379 | + if (is_super_admin() || current_user_can($post_type_object->cap->edit_others_posts)) : |
|
1380 | 1380 | $users_opt = array( |
1381 | 1381 | 'hide_if_only_one_author' => false, |
1382 | 1382 | 'who' => 'authors', |
@@ -1386,39 +1386,39 @@ discard block |
||
1386 | 1386 | 'echo' => 0, |
1387 | 1387 | 'show' => 'display_name_with_login', |
1388 | 1388 | ); |
1389 | - if ( $bulk ) |
|
1390 | - $users_opt['show_option_none'] = __( '— No Change —' ); |
|
1389 | + if ($bulk) |
|
1390 | + $users_opt['show_option_none'] = __('— No Change —'); |
|
1391 | 1391 | |
1392 | - if ( $authors = wp_dropdown_users( $users_opt ) ) : |
|
1392 | + if ($authors = wp_dropdown_users($users_opt)) : |
|
1393 | 1393 | $authors_dropdown = '<label class="inline-edit-author">'; |
1394 | - $authors_dropdown .= '<span class="title">' . __( 'Author' ) . '</span>'; |
|
1394 | + $authors_dropdown .= '<span class="title">'.__('Author').'</span>'; |
|
1395 | 1395 | $authors_dropdown .= $authors; |
1396 | 1396 | $authors_dropdown .= '</label>'; |
1397 | 1397 | endif; |
1398 | 1398 | endif; // authors |
1399 | 1399 | ?> |
1400 | 1400 | |
1401 | - <?php if ( !$bulk ) echo $authors_dropdown; |
|
1401 | + <?php if ( ! $bulk) echo $authors_dropdown; |
|
1402 | 1402 | endif; // post_type_supports author |
1403 | 1403 | |
1404 | - if ( !$bulk && $can_publish ) : |
|
1404 | + if ( ! $bulk && $can_publish) : |
|
1405 | 1405 | ?> |
1406 | 1406 | |
1407 | 1407 | <div class="inline-edit-group wp-clearfix"> |
1408 | 1408 | <label class="alignleft"> |
1409 | - <span class="title"><?php _e( 'Password' ); ?></span> |
|
1409 | + <span class="title"><?php _e('Password'); ?></span> |
|
1410 | 1410 | <span class="input-text-wrap"><input type="text" name="post_password" class="inline-edit-password-input" value="" /></span> |
1411 | 1411 | </label> |
1412 | 1412 | |
1413 | 1413 | <em class="alignleft inline-edit-or"> |
1414 | 1414 | <?php |
1415 | 1415 | /* translators: Between password field and private checkbox on post quick edit interface */ |
1416 | - _e( '–OR–' ); |
|
1416 | + _e('–OR–'); |
|
1417 | 1417 | ?> |
1418 | 1418 | </em> |
1419 | 1419 | <label class="alignleft inline-edit-private"> |
1420 | 1420 | <input type="checkbox" name="keep_private" value="private" /> |
1421 | - <span class="checkbox-title"><?php _e( 'Private' ); ?></span> |
|
1421 | + <span class="checkbox-title"><?php _e('Private'); ?></span> |
|
1422 | 1422 | </label> |
1423 | 1423 | </div> |
1424 | 1424 | |
@@ -1426,16 +1426,16 @@ discard block |
||
1426 | 1426 | |
1427 | 1427 | </div></fieldset> |
1428 | 1428 | |
1429 | - <?php if ( count( $hierarchical_taxonomies ) && !$bulk ) : ?> |
|
1429 | + <?php if (count($hierarchical_taxonomies) && ! $bulk) : ?> |
|
1430 | 1430 | |
1431 | 1431 | <fieldset class="inline-edit-col-center inline-edit-categories"><div class="inline-edit-col"> |
1432 | 1432 | |
1433 | - <?php foreach ( $hierarchical_taxonomies as $taxonomy ) : ?> |
|
1433 | + <?php foreach ($hierarchical_taxonomies as $taxonomy) : ?> |
|
1434 | 1434 | |
1435 | - <span class="title inline-edit-categories-label"><?php echo esc_html( $taxonomy->labels->name ) ?></span> |
|
1436 | - <input type="hidden" name="<?php echo ( $taxonomy->name === 'category' ) ? 'post_category[]' : 'tax_input[' . esc_attr( $taxonomy->name ) . '][]'; ?>" value="0" /> |
|
1437 | - <ul class="cat-checklist <?php echo esc_attr( $taxonomy->name )?>-checklist"> |
|
1438 | - <?php wp_terms_checklist( null, array( 'taxonomy' => $taxonomy->name ) ) ?> |
|
1435 | + <span class="title inline-edit-categories-label"><?php echo esc_html($taxonomy->labels->name) ?></span> |
|
1436 | + <input type="hidden" name="<?php echo ($taxonomy->name === 'category') ? 'post_category[]' : 'tax_input['.esc_attr($taxonomy->name).'][]'; ?>" value="0" /> |
|
1437 | + <ul class="cat-checklist <?php echo esc_attr($taxonomy->name)?>-checklist"> |
|
1438 | + <?php wp_terms_checklist(null, array('taxonomy' => $taxonomy->name)) ?> |
|
1439 | 1439 | </ul> |
1440 | 1440 | |
1441 | 1441 | <?php endforeach; //$hierarchical_taxonomies as $taxonomy ?> |
@@ -1447,27 +1447,27 @@ discard block |
||
1447 | 1447 | <fieldset class="inline-edit-col-right"><div class="inline-edit-col"> |
1448 | 1448 | |
1449 | 1449 | <?php |
1450 | - if ( post_type_supports( $screen->post_type, 'author' ) && $bulk ) |
|
1450 | + if (post_type_supports($screen->post_type, 'author') && $bulk) |
|
1451 | 1451 | echo $authors_dropdown; |
1452 | 1452 | |
1453 | - if ( post_type_supports( $screen->post_type, 'page-attributes' ) ) : |
|
1453 | + if (post_type_supports($screen->post_type, 'page-attributes')) : |
|
1454 | 1454 | |
1455 | - if ( $post_type_object->hierarchical ) : |
|
1455 | + if ($post_type_object->hierarchical) : |
|
1456 | 1456 | ?> |
1457 | 1457 | <label> |
1458 | - <span class="title"><?php _e( 'Parent' ); ?></span> |
|
1458 | + <span class="title"><?php _e('Parent'); ?></span> |
|
1459 | 1459 | <?php |
1460 | 1460 | $dropdown_args = array( |
1461 | 1461 | 'post_type' => $post_type_object->name, |
1462 | 1462 | 'selected' => $post->post_parent, |
1463 | 1463 | 'name' => 'post_parent', |
1464 | - 'show_option_none' => __( 'Main Page (no parent)' ), |
|
1464 | + 'show_option_none' => __('Main Page (no parent)'), |
|
1465 | 1465 | 'option_none_value' => 0, |
1466 | 1466 | 'sort_column' => 'menu_order, post_title', |
1467 | 1467 | ); |
1468 | 1468 | |
1469 | - if ( $bulk ) |
|
1470 | - $dropdown_args['show_option_no_change'] = __( '— No Change —' ); |
|
1469 | + if ($bulk) |
|
1470 | + $dropdown_args['show_option_no_change'] = __('— No Change —'); |
|
1471 | 1471 | |
1472 | 1472 | /** |
1473 | 1473 | * Filter the arguments used to generate the Quick Edit page-parent drop-down. |
@@ -1478,38 +1478,38 @@ discard block |
||
1478 | 1478 | * |
1479 | 1479 | * @param array $dropdown_args An array of arguments. |
1480 | 1480 | */ |
1481 | - $dropdown_args = apply_filters( 'quick_edit_dropdown_pages_args', $dropdown_args ); |
|
1481 | + $dropdown_args = apply_filters('quick_edit_dropdown_pages_args', $dropdown_args); |
|
1482 | 1482 | |
1483 | - wp_dropdown_pages( $dropdown_args ); |
|
1483 | + wp_dropdown_pages($dropdown_args); |
|
1484 | 1484 | ?> |
1485 | 1485 | </label> |
1486 | 1486 | |
1487 | 1487 | <?php |
1488 | 1488 | endif; // hierarchical |
1489 | 1489 | |
1490 | - if ( !$bulk ) : ?> |
|
1490 | + if ( ! $bulk) : ?> |
|
1491 | 1491 | |
1492 | 1492 | <label> |
1493 | - <span class="title"><?php _e( 'Order' ); ?></span> |
|
1493 | + <span class="title"><?php _e('Order'); ?></span> |
|
1494 | 1494 | <span class="input-text-wrap"><input type="text" name="menu_order" class="inline-edit-menu-order-input" value="<?php echo $post->menu_order ?>" /></span> |
1495 | 1495 | </label> |
1496 | 1496 | |
1497 | 1497 | <?php endif; // !$bulk |
1498 | 1498 | |
1499 | - if ( 'page' === $screen->post_type ) : |
|
1499 | + if ('page' === $screen->post_type) : |
|
1500 | 1500 | ?> |
1501 | 1501 | |
1502 | 1502 | <label> |
1503 | - <span class="title"><?php _e( 'Template' ); ?></span> |
|
1503 | + <span class="title"><?php _e('Template'); ?></span> |
|
1504 | 1504 | <select name="page_template"> |
1505 | - <?php if ( $bulk ) : ?> |
|
1506 | - <option value="-1"><?php _e( '— No Change —' ); ?></option> |
|
1505 | + <?php if ($bulk) : ?> |
|
1506 | + <option value="-1"><?php _e('— No Change —'); ?></option> |
|
1507 | 1507 | <?php endif; // $bulk ?> |
1508 | 1508 | <?php |
1509 | 1509 | /** This filter is documented in wp-admin/includes/meta-boxes.php */ |
1510 | - $default_title = apply_filters( 'default_page_template_title', __( 'Default Template' ), 'quick-edit' ); |
|
1510 | + $default_title = apply_filters('default_page_template_title', __('Default Template'), 'quick-edit'); |
|
1511 | 1511 | ?> |
1512 | - <option value="default"><?php echo esc_html( $default_title ); ?></option> |
|
1512 | + <option value="default"><?php echo esc_html($default_title); ?></option> |
|
1513 | 1513 | <?php page_template_dropdown() ?> |
1514 | 1514 | </select> |
1515 | 1515 | </label> |
@@ -1519,13 +1519,13 @@ discard block |
||
1519 | 1519 | endif; // page-attributes |
1520 | 1520 | ?> |
1521 | 1521 | |
1522 | - <?php if ( count( $flat_taxonomies ) && !$bulk ) : ?> |
|
1522 | + <?php if (count($flat_taxonomies) && ! $bulk) : ?> |
|
1523 | 1523 | |
1524 | - <?php foreach ( $flat_taxonomies as $taxonomy ) : ?> |
|
1525 | - <?php if ( current_user_can( $taxonomy->cap->assign_terms ) ) : ?> |
|
1524 | + <?php foreach ($flat_taxonomies as $taxonomy) : ?> |
|
1525 | + <?php if (current_user_can($taxonomy->cap->assign_terms)) : ?> |
|
1526 | 1526 | <label class="inline-edit-tags"> |
1527 | - <span class="title"><?php echo esc_html( $taxonomy->labels->name ) ?></span> |
|
1528 | - <textarea cols="22" rows="1" name="tax_input[<?php echo esc_attr( $taxonomy->name )?>]" class="tax_input_<?php echo esc_attr( $taxonomy->name )?>"></textarea> |
|
1527 | + <span class="title"><?php echo esc_html($taxonomy->labels->name) ?></span> |
|
1528 | + <textarea cols="22" rows="1" name="tax_input[<?php echo esc_attr($taxonomy->name)?>]" class="tax_input_<?php echo esc_attr($taxonomy->name)?>"></textarea> |
|
1529 | 1529 | </label> |
1530 | 1530 | <?php endif; ?> |
1531 | 1531 | |
@@ -1533,26 +1533,26 @@ discard block |
||
1533 | 1533 | |
1534 | 1534 | <?php endif; // count( $flat_taxonomies ) && !$bulk ?> |
1535 | 1535 | |
1536 | - <?php if ( post_type_supports( $screen->post_type, 'comments' ) || post_type_supports( $screen->post_type, 'trackbacks' ) ) : |
|
1537 | - if ( $bulk ) : ?> |
|
1536 | + <?php if (post_type_supports($screen->post_type, 'comments') || post_type_supports($screen->post_type, 'trackbacks')) : |
|
1537 | + if ($bulk) : ?> |
|
1538 | 1538 | |
1539 | 1539 | <div class="inline-edit-group wp-clearfix"> |
1540 | - <?php if ( post_type_supports( $screen->post_type, 'comments' ) ) : ?> |
|
1540 | + <?php if (post_type_supports($screen->post_type, 'comments')) : ?> |
|
1541 | 1541 | <label class="alignleft"> |
1542 | - <span class="title"><?php _e( 'Comments' ); ?></span> |
|
1542 | + <span class="title"><?php _e('Comments'); ?></span> |
|
1543 | 1543 | <select name="comment_status"> |
1544 | - <option value=""><?php _e( '— No Change —' ); ?></option> |
|
1545 | - <option value="open"><?php _e( 'Allow' ); ?></option> |
|
1546 | - <option value="closed"><?php _e( 'Do not allow' ); ?></option> |
|
1544 | + <option value=""><?php _e('— No Change —'); ?></option> |
|
1545 | + <option value="open"><?php _e('Allow'); ?></option> |
|
1546 | + <option value="closed"><?php _e('Do not allow'); ?></option> |
|
1547 | 1547 | </select> |
1548 | 1548 | </label> |
1549 | - <?php endif; if ( post_type_supports( $screen->post_type, 'trackbacks' ) ) : ?> |
|
1549 | + <?php endif; if (post_type_supports($screen->post_type, 'trackbacks')) : ?> |
|
1550 | 1550 | <label class="alignright"> |
1551 | - <span class="title"><?php _e( 'Pings' ); ?></span> |
|
1551 | + <span class="title"><?php _e('Pings'); ?></span> |
|
1552 | 1552 | <select name="ping_status"> |
1553 | - <option value=""><?php _e( '— No Change —' ); ?></option> |
|
1554 | - <option value="open"><?php _e( 'Allow' ); ?></option> |
|
1555 | - <option value="closed"><?php _e( 'Do not allow' ); ?></option> |
|
1553 | + <option value=""><?php _e('— No Change —'); ?></option> |
|
1554 | + <option value="open"><?php _e('Allow'); ?></option> |
|
1555 | + <option value="closed"><?php _e('Do not allow'); ?></option> |
|
1556 | 1556 | </select> |
1557 | 1557 | </label> |
1558 | 1558 | <?php endif; ?> |
@@ -1561,15 +1561,15 @@ discard block |
||
1561 | 1561 | <?php else : // $bulk ?> |
1562 | 1562 | |
1563 | 1563 | <div class="inline-edit-group wp-clearfix"> |
1564 | - <?php if ( post_type_supports( $screen->post_type, 'comments' ) ) : ?> |
|
1564 | + <?php if (post_type_supports($screen->post_type, 'comments')) : ?> |
|
1565 | 1565 | <label class="alignleft"> |
1566 | 1566 | <input type="checkbox" name="comment_status" value="open" /> |
1567 | - <span class="checkbox-title"><?php _e( 'Allow Comments' ); ?></span> |
|
1567 | + <span class="checkbox-title"><?php _e('Allow Comments'); ?></span> |
|
1568 | 1568 | </label> |
1569 | - <?php endif; if ( post_type_supports( $screen->post_type, 'trackbacks' ) ) : ?> |
|
1569 | + <?php endif; if (post_type_supports($screen->post_type, 'trackbacks')) : ?> |
|
1570 | 1570 | <label class="alignleft"> |
1571 | 1571 | <input type="checkbox" name="ping_status" value="open" /> |
1572 | - <span class="checkbox-title"><?php _e( 'Allow Pings' ); ?></span> |
|
1572 | + <span class="checkbox-title"><?php _e('Allow Pings'); ?></span> |
|
1573 | 1573 | </label> |
1574 | 1574 | <?php endif; ?> |
1575 | 1575 | </div> |
@@ -1579,33 +1579,33 @@ discard block |
||
1579 | 1579 | |
1580 | 1580 | <div class="inline-edit-group wp-clearfix"> |
1581 | 1581 | <label class="inline-edit-status alignleft"> |
1582 | - <span class="title"><?php _e( 'Status' ); ?></span> |
|
1582 | + <span class="title"><?php _e('Status'); ?></span> |
|
1583 | 1583 | <select name="_status"> |
1584 | - <?php if ( $bulk ) : ?> |
|
1585 | - <option value="-1"><?php _e( '— No Change —' ); ?></option> |
|
1584 | + <?php if ($bulk) : ?> |
|
1585 | + <option value="-1"><?php _e('— No Change —'); ?></option> |
|
1586 | 1586 | <?php endif; // $bulk ?> |
1587 | - <?php if ( $can_publish ) : // Contributors only get "Unpublished" and "Pending Review" ?> |
|
1588 | - <option value="publish"><?php _e( 'Published' ); ?></option> |
|
1589 | - <option value="future"><?php _e( 'Scheduled' ); ?></option> |
|
1590 | - <?php if ( $bulk ) : ?> |
|
1591 | - <option value="private"><?php _e( 'Private' ) ?></option> |
|
1587 | + <?php if ($can_publish) : // Contributors only get "Unpublished" and "Pending Review" ?> |
|
1588 | + <option value="publish"><?php _e('Published'); ?></option> |
|
1589 | + <option value="future"><?php _e('Scheduled'); ?></option> |
|
1590 | + <?php if ($bulk) : ?> |
|
1591 | + <option value="private"><?php _e('Private') ?></option> |
|
1592 | 1592 | <?php endif; // $bulk ?> |
1593 | 1593 | <?php endif; ?> |
1594 | - <option value="pending"><?php _e( 'Pending Review' ); ?></option> |
|
1595 | - <option value="draft"><?php _e( 'Draft' ); ?></option> |
|
1594 | + <option value="pending"><?php _e('Pending Review'); ?></option> |
|
1595 | + <option value="draft"><?php _e('Draft'); ?></option> |
|
1596 | 1596 | </select> |
1597 | 1597 | </label> |
1598 | 1598 | |
1599 | - <?php if ( 'post' === $screen->post_type && $can_publish && current_user_can( $post_type_object->cap->edit_others_posts ) ) : ?> |
|
1599 | + <?php if ('post' === $screen->post_type && $can_publish && current_user_can($post_type_object->cap->edit_others_posts)) : ?> |
|
1600 | 1600 | |
1601 | - <?php if ( $bulk ) : ?> |
|
1601 | + <?php if ($bulk) : ?> |
|
1602 | 1602 | |
1603 | 1603 | <label class="alignright"> |
1604 | - <span class="title"><?php _e( 'Sticky' ); ?></span> |
|
1604 | + <span class="title"><?php _e('Sticky'); ?></span> |
|
1605 | 1605 | <select name="sticky"> |
1606 | - <option value="-1"><?php _e( '— No Change —' ); ?></option> |
|
1607 | - <option value="sticky"><?php _e( 'Sticky' ); ?></option> |
|
1608 | - <option value="unsticky"><?php _e( 'Not Sticky' ); ?></option> |
|
1606 | + <option value="-1"><?php _e('— No Change —'); ?></option> |
|
1607 | + <option value="sticky"><?php _e('Sticky'); ?></option> |
|
1608 | + <option value="unsticky"><?php _e('Not Sticky'); ?></option> |
|
1609 | 1609 | </select> |
1610 | 1610 | </label> |
1611 | 1611 | |
@@ -1613,7 +1613,7 @@ discard block |
||
1613 | 1613 | |
1614 | 1614 | <label class="alignleft"> |
1615 | 1615 | <input type="checkbox" name="sticky" value="sticky" /> |
1616 | - <span class="checkbox-title"><?php _e( 'Make this post sticky' ); ?></span> |
|
1616 | + <span class="checkbox-title"><?php _e('Make this post sticky'); ?></span> |
|
1617 | 1617 | </label> |
1618 | 1618 | |
1619 | 1619 | <?php endif; // $bulk ?> |
@@ -1624,20 +1624,20 @@ discard block |
||
1624 | 1624 | |
1625 | 1625 | <?php |
1626 | 1626 | |
1627 | - if ( $bulk && current_theme_supports( 'post-formats' ) && post_type_supports( $screen->post_type, 'post-formats' ) ) { |
|
1628 | - $post_formats = get_theme_support( 'post-formats' ); |
|
1627 | + if ($bulk && current_theme_supports('post-formats') && post_type_supports($screen->post_type, 'post-formats')) { |
|
1628 | + $post_formats = get_theme_support('post-formats'); |
|
1629 | 1629 | |
1630 | 1630 | ?> |
1631 | 1631 | <label class="alignleft"> |
1632 | - <span class="title"><?php _ex( 'Format', 'post format' ); ?></span> |
|
1632 | + <span class="title"><?php _ex('Format', 'post format'); ?></span> |
|
1633 | 1633 | <select name="post_format"> |
1634 | - <option value="-1"><?php _e( '— No Change —' ); ?></option> |
|
1635 | - <option value="0"><?php echo get_post_format_string( 'standard' ); ?></option> |
|
1634 | + <option value="-1"><?php _e('— No Change —'); ?></option> |
|
1635 | + <option value="0"><?php echo get_post_format_string('standard'); ?></option> |
|
1636 | 1636 | <?php |
1637 | - if ( is_array( $post_formats[0] ) ) { |
|
1638 | - foreach ( $post_formats[0] as $format ) { |
|
1637 | + if (is_array($post_formats[0])) { |
|
1638 | + foreach ($post_formats[0] as $format) { |
|
1639 | 1639 | ?> |
1640 | - <option value="<?php echo esc_attr( $format ); ?>"><?php echo esc_html( get_post_format_string( $format ) ); ?></option> |
|
1640 | + <option value="<?php echo esc_attr($format); ?>"><?php echo esc_html(get_post_format_string($format)); ?></option> |
|
1641 | 1641 | <?php |
1642 | 1642 | } |
1643 | 1643 | } |
@@ -1652,13 +1652,13 @@ discard block |
||
1652 | 1652 | </div></fieldset> |
1653 | 1653 | |
1654 | 1654 | <?php |
1655 | - list( $columns ) = $this->get_column_info(); |
|
1655 | + list($columns) = $this->get_column_info(); |
|
1656 | 1656 | |
1657 | - foreach ( $columns as $column_name => $column_display_name ) { |
|
1658 | - if ( isset( $core_columns[$column_name] ) ) |
|
1657 | + foreach ($columns as $column_name => $column_display_name) { |
|
1658 | + if (isset($core_columns[$column_name])) |
|
1659 | 1659 | continue; |
1660 | 1660 | |
1661 | - if ( $bulk ) { |
|
1661 | + if ($bulk) { |
|
1662 | 1662 | |
1663 | 1663 | /** |
1664 | 1664 | * Fires once for each column in Bulk Edit mode. |
@@ -1668,7 +1668,7 @@ discard block |
||
1668 | 1668 | * @param string $column_name Name of the column to edit. |
1669 | 1669 | * @param WP_Post $post_type The post type slug. |
1670 | 1670 | */ |
1671 | - do_action( 'bulk_edit_custom_box', $column_name, $screen->post_type ); |
|
1671 | + do_action('bulk_edit_custom_box', $column_name, $screen->post_type); |
|
1672 | 1672 | } else { |
1673 | 1673 | |
1674 | 1674 | /** |
@@ -1679,25 +1679,25 @@ discard block |
||
1679 | 1679 | * @param string $column_name Name of the column to edit. |
1680 | 1680 | * @param string $post_type The post type slug. |
1681 | 1681 | */ |
1682 | - do_action( 'quick_edit_custom_box', $column_name, $screen->post_type ); |
|
1682 | + do_action('quick_edit_custom_box', $column_name, $screen->post_type); |
|
1683 | 1683 | } |
1684 | 1684 | |
1685 | 1685 | } |
1686 | 1686 | ?> |
1687 | 1687 | <p class="submit inline-edit-save"> |
1688 | - <button type="button" class="button-secondary cancel alignleft"><?php _e( 'Cancel' ); ?></button> |
|
1689 | - <?php if ( ! $bulk ) { |
|
1690 | - wp_nonce_field( 'inlineeditnonce', '_inline_edit', false ); |
|
1688 | + <button type="button" class="button-secondary cancel alignleft"><?php _e('Cancel'); ?></button> |
|
1689 | + <?php if ( ! $bulk) { |
|
1690 | + wp_nonce_field('inlineeditnonce', '_inline_edit', false); |
|
1691 | 1691 | ?> |
1692 | - <button type="button" class="button-primary save alignright"><?php _e( 'Update' ); ?></button> |
|
1692 | + <button type="button" class="button-primary save alignright"><?php _e('Update'); ?></button> |
|
1693 | 1693 | <span class="spinner"></span> |
1694 | 1694 | <?php } else { |
1695 | - submit_button( __( 'Update' ), 'button-primary alignright', 'bulk_edit', false ); |
|
1695 | + submit_button(__('Update'), 'button-primary alignright', 'bulk_edit', false); |
|
1696 | 1696 | } ?> |
1697 | - <input type="hidden" name="post_view" value="<?php echo esc_attr( $m ); ?>" /> |
|
1698 | - <input type="hidden" name="screen" value="<?php echo esc_attr( $screen->id ); ?>" /> |
|
1699 | - <?php if ( ! $bulk && ! post_type_supports( $screen->post_type, 'author' ) ) { ?> |
|
1700 | - <input type="hidden" name="post_author" value="<?php echo esc_attr( $post->post_author ); ?>" /> |
|
1697 | + <input type="hidden" name="post_view" value="<?php echo esc_attr($m); ?>" /> |
|
1698 | + <input type="hidden" name="screen" value="<?php echo esc_attr($screen->id); ?>" /> |
|
1699 | + <?php if ( ! $bulk && ! post_type_supports($screen->post_type, 'author')) { ?> |
|
1700 | + <input type="hidden" name="post_author" value="<?php echo esc_attr($post->post_author); ?>" /> |
|
1701 | 1701 | <?php } ?> |
1702 | 1702 | <span class="error" style="display:none"></span> |
1703 | 1703 | <br class="clear" /> |
@@ -199,10 +199,11 @@ discard block |
||
199 | 199 | * @access public |
200 | 200 | */ |
201 | 201 | public function no_items() { |
202 | - if ( isset( $_REQUEST['post_status'] ) && 'trash' === $_REQUEST['post_status'] ) |
|
203 | - echo get_post_type_object( $this->screen->post_type )->labels->not_found_in_trash; |
|
204 | - else |
|
205 | - echo get_post_type_object( $this->screen->post_type )->labels->not_found; |
|
202 | + if ( isset( $_REQUEST['post_status'] ) && 'trash' === $_REQUEST['post_status'] ) { |
|
203 | + echo get_post_type_object( $this->screen->post_type )->labels->not_found_in_trash; |
|
204 | + } else { |
|
205 | + echo get_post_type_object( $this->screen->post_type )->labels->not_found; |
|
206 | + } |
|
206 | 207 | } |
207 | 208 | |
208 | 209 | /** |
@@ -266,8 +267,9 @@ discard block |
||
266 | 267 | |
267 | 268 | $post_type = $this->screen->post_type; |
268 | 269 | |
269 | - if ( !empty($locked_post_status) ) |
|
270 | - return array(); |
|
270 | + if ( !empty($locked_post_status) ) { |
|
271 | + return array(); |
|
272 | + } |
|
271 | 273 | |
272 | 274 | $status_links = array(); |
273 | 275 | $num_posts = wp_count_posts( $post_type, 'readable' ); |
@@ -476,8 +478,9 @@ discard block |
||
476 | 478 | * @return string |
477 | 479 | */ |
478 | 480 | public function current_action() { |
479 | - if ( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) ) |
|
480 | - return 'delete_all'; |
|
481 | + if ( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) ) { |
|
482 | + return 'delete_all'; |
|
483 | + } |
|
481 | 484 | |
482 | 485 | return parent::current_action(); |
483 | 486 | } |
@@ -526,19 +529,21 @@ discard block |
||
526 | 529 | $taxonomies = array_filter( $taxonomies, 'taxonomy_exists' ); |
527 | 530 | |
528 | 531 | foreach ( $taxonomies as $taxonomy ) { |
529 | - if ( 'category' === $taxonomy ) |
|
530 | - $column_key = 'categories'; |
|
531 | - elseif ( 'post_tag' === $taxonomy ) |
|
532 | - $column_key = 'tags'; |
|
533 | - else |
|
534 | - $column_key = 'taxonomy-' . $taxonomy; |
|
532 | + if ( 'category' === $taxonomy ) { |
|
533 | + $column_key = 'categories'; |
|
534 | + } elseif ( 'post_tag' === $taxonomy ) { |
|
535 | + $column_key = 'tags'; |
|
536 | + } else { |
|
537 | + $column_key = 'taxonomy-' . $taxonomy; |
|
538 | + } |
|
535 | 539 | |
536 | 540 | $posts_columns[ $column_key ] = get_taxonomy( $taxonomy )->labels->name; |
537 | 541 | } |
538 | 542 | |
539 | 543 | $post_status = !empty( $_REQUEST['post_status'] ) ? $_REQUEST['post_status'] : 'all'; |
540 | - if ( post_type_supports( $post_type, 'comments' ) && !in_array( $post_status, array( 'pending', 'draft', 'future' ) ) ) |
|
541 | - $posts_columns['comments'] = '<span class="vers comment-grey-bubble" title="' . esc_attr__( 'Comments' ) . '"><span class="screen-reader-text">' . __( 'Comments' ) . '</span></span>'; |
|
544 | + if ( post_type_supports( $post_type, 'comments' ) && !in_array( $post_status, array( 'pending', 'draft', 'future' ) ) ) { |
|
545 | + $posts_columns['comments'] = '<span class="vers comment-grey-bubble" title="' . esc_attr__( 'Comments' ) . '"><span class="screen-reader-text">' . __( 'Comments' ) . '</span></span>'; |
|
546 | + } |
|
542 | 547 | |
543 | 548 | $posts_columns['date'] = __( 'Date' ); |
544 | 549 | |
@@ -599,8 +604,9 @@ discard block |
||
599 | 604 | public function display_rows( $posts = array(), $level = 0 ) { |
600 | 605 | global $wp_query, $per_page; |
601 | 606 | |
602 | - if ( empty( $posts ) ) |
|
603 | - $posts = $wp_query->posts; |
|
607 | + if ( empty( $posts ) ) { |
|
608 | + $posts = $wp_query->posts; |
|
609 | + } |
|
604 | 610 | |
605 | 611 | add_filter( 'the_title', 'esc_html' ); |
606 | 612 | |
@@ -619,13 +625,15 @@ discard block |
||
619 | 625 | // Create array of post IDs. |
620 | 626 | $post_ids = array(); |
621 | 627 | |
622 | - foreach ( $posts as $a_post ) |
|
623 | - $post_ids[] = $a_post->ID; |
|
628 | + foreach ( $posts as $a_post ) { |
|
629 | + $post_ids[] = $a_post->ID; |
|
630 | + } |
|
624 | 631 | |
625 | 632 | $this->comment_pending_count = get_pending_comments_num( $post_ids ); |
626 | 633 | |
627 | - foreach ( $posts as $post ) |
|
628 | - $this->single_row( $post, $level ); |
|
634 | + foreach ( $posts as $post ) { |
|
635 | + $this->single_row( $post, $level ); |
|
636 | + } |
|
629 | 637 | } |
630 | 638 | |
631 | 639 | /** |
@@ -643,8 +651,9 @@ discard block |
||
643 | 651 | if ( ! $pages ) { |
644 | 652 | $pages = get_pages( array( 'sort_column' => 'menu_order' ) ); |
645 | 653 | |
646 | - if ( ! $pages ) |
|
647 | - return; |
|
654 | + if ( ! $pages ) { |
|
655 | + return; |
|
656 | + } |
|
648 | 657 | } |
649 | 658 | |
650 | 659 | /* |
@@ -668,10 +677,11 @@ discard block |
||
668 | 677 | clean_post_cache( $page ); |
669 | 678 | } |
670 | 679 | |
671 | - if ( 0 == $page->post_parent ) |
|
672 | - $top_level_pages[] = $page; |
|
673 | - else |
|
674 | - $children_pages[ $page->post_parent ][] = $page; |
|
680 | + if ( 0 == $page->post_parent ) { |
|
681 | + $top_level_pages[] = $page; |
|
682 | + } else { |
|
683 | + $children_pages[ $page->post_parent ][] = $page; |
|
684 | + } |
|
675 | 685 | } |
676 | 686 | |
677 | 687 | $pages = &$top_level_pages; |
@@ -683,8 +693,9 @@ discard block |
||
683 | 693 | $to_display = array(); |
684 | 694 | |
685 | 695 | foreach ( $pages as $page ) { |
686 | - if ( $count >= $end ) |
|
687 | - break; |
|
696 | + if ( $count >= $end ) { |
|
697 | + break; |
|
698 | + } |
|
688 | 699 | |
689 | 700 | if ( $count >= $start ) { |
690 | 701 | $to_display[$page->ID] = $level; |
@@ -692,16 +703,18 @@ discard block |
||
692 | 703 | |
693 | 704 | $count++; |
694 | 705 | |
695 | - if ( isset( $children_pages ) ) |
|
696 | - $this->_page_rows( $children_pages, $count, $page->ID, $level + 1, $pagenum, $per_page, $to_display ); |
|
706 | + if ( isset( $children_pages ) ) { |
|
707 | + $this->_page_rows( $children_pages, $count, $page->ID, $level + 1, $pagenum, $per_page, $to_display ); |
|
708 | + } |
|
697 | 709 | } |
698 | 710 | |
699 | 711 | // If it is the last pagenum and there are orphaned pages, display them with paging as well. |
700 | 712 | if ( isset( $children_pages ) && $count < $end ){ |
701 | 713 | foreach ( $children_pages as $orphans ){ |
702 | 714 | foreach ( $orphans as $op ) { |
703 | - if ( $count >= $end ) |
|
704 | - break; |
|
715 | + if ( $count >= $end ) { |
|
716 | + break; |
|
717 | + } |
|
705 | 718 | |
706 | 719 | if ( $count >= $start ) { |
707 | 720 | $to_display[$op->ID] = 0; |
@@ -741,15 +754,17 @@ discard block |
||
741 | 754 | * @param array $to_display List of pages to be displayed. Passed by reference. |
742 | 755 | */ |
743 | 756 | private function _page_rows( &$children_pages, &$count, $parent, $level, $pagenum, $per_page, &$to_display ) { |
744 | - if ( ! isset( $children_pages[$parent] ) ) |
|
745 | - return; |
|
757 | + if ( ! isset( $children_pages[$parent] ) ) { |
|
758 | + return; |
|
759 | + } |
|
746 | 760 | |
747 | 761 | $start = ( $pagenum - 1 ) * $per_page; |
748 | 762 | $end = $start + $per_page; |
749 | 763 | |
750 | 764 | foreach ( $children_pages[$parent] as $page ) { |
751 | - if ( $count >= $end ) |
|
752 | - break; |
|
765 | + if ( $count >= $end ) { |
|
766 | + break; |
|
767 | + } |
|
753 | 768 | |
754 | 769 | // If the page starts in a subtree, print the parents. |
755 | 770 | if ( $count == $start && $page->post_parent > 0 ) { |
@@ -764,8 +779,9 @@ discard block |
||
764 | 779 | |
765 | 780 | $my_parent = get_post( $parent_id ); |
766 | 781 | $my_parents[] = $my_parent; |
767 | - if ( !$my_parent->post_parent ) |
|
768 | - break; |
|
782 | + if ( !$my_parent->post_parent ) { |
|
783 | + break; |
|
784 | + } |
|
769 | 785 | $my_parent = $my_parent->post_parent; |
770 | 786 | } |
771 | 787 | $num_parents = count( $my_parents ); |
@@ -1317,10 +1333,11 @@ discard block |
||
1317 | 1333 | continue; |
1318 | 1334 | } |
1319 | 1335 | |
1320 | - if ( $taxonomy->hierarchical ) |
|
1321 | - $hierarchical_taxonomies[] = $taxonomy; |
|
1322 | - else |
|
1323 | - $flat_taxonomies[] = $taxonomy; |
|
1336 | + if ( $taxonomy->hierarchical ) { |
|
1337 | + $hierarchical_taxonomies[] = $taxonomy; |
|
1338 | + } else { |
|
1339 | + $flat_taxonomies[] = $taxonomy; |
|
1340 | + } |
|
1324 | 1341 | } |
1325 | 1342 | |
1326 | 1343 | $m = ( isset( $mode ) && 'excerpt' === $mode ) ? 'excerpt' : 'list'; |
@@ -1350,10 +1367,13 @@ discard block |
||
1350 | 1367 | <div id="bulk-titles"></div> |
1351 | 1368 | </div> |
1352 | 1369 | |
1353 | - <?php else : // $bulk ?> |
|
1370 | + <?php else { |
|
1371 | + : // $bulk ?> |
|
1354 | 1372 | |
1355 | 1373 | <label> |
1356 | - <span class="title"><?php _e( 'Title' ); ?></span> |
|
1374 | + <span class="title"><?php _e( 'Title' ); |
|
1375 | +} |
|
1376 | +?></span> |
|
1357 | 1377 | <span class="input-text-wrap"><input type="text" name="post_title" class="ptitle" value="" /></span> |
1358 | 1378 | </label> |
1359 | 1379 | |
@@ -1386,8 +1406,9 @@ discard block |
||
1386 | 1406 | 'echo' => 0, |
1387 | 1407 | 'show' => 'display_name_with_login', |
1388 | 1408 | ); |
1389 | - if ( $bulk ) |
|
1390 | - $users_opt['show_option_none'] = __( '— No Change —' ); |
|
1409 | + if ( $bulk ) { |
|
1410 | + $users_opt['show_option_none'] = __( '— No Change —' ); |
|
1411 | + } |
|
1391 | 1412 | |
1392 | 1413 | if ( $authors = wp_dropdown_users( $users_opt ) ) : |
1393 | 1414 | $authors_dropdown = '<label class="inline-edit-author">'; |
@@ -1398,7 +1419,9 @@ discard block |
||
1398 | 1419 | endif; // authors |
1399 | 1420 | ?> |
1400 | 1421 | |
1401 | - <?php if ( !$bulk ) echo $authors_dropdown; |
|
1422 | + <?php if ( !$bulk ) { |
|
1423 | + echo $authors_dropdown; |
|
1424 | +} |
|
1402 | 1425 | endif; // post_type_supports author |
1403 | 1426 | |
1404 | 1427 | if ( !$bulk && $can_publish ) : |
@@ -1447,8 +1470,9 @@ discard block |
||
1447 | 1470 | <fieldset class="inline-edit-col-right"><div class="inline-edit-col"> |
1448 | 1471 | |
1449 | 1472 | <?php |
1450 | - if ( post_type_supports( $screen->post_type, 'author' ) && $bulk ) |
|
1451 | - echo $authors_dropdown; |
|
1473 | + if ( post_type_supports( $screen->post_type, 'author' ) && $bulk ) { |
|
1474 | + echo $authors_dropdown; |
|
1475 | + } |
|
1452 | 1476 | |
1453 | 1477 | if ( post_type_supports( $screen->post_type, 'page-attributes' ) ) : |
1454 | 1478 | |
@@ -1466,8 +1490,9 @@ discard block |
||
1466 | 1490 | 'sort_column' => 'menu_order, post_title', |
1467 | 1491 | ); |
1468 | 1492 | |
1469 | - if ( $bulk ) |
|
1470 | - $dropdown_args['show_option_no_change'] = __( '— No Change —' ); |
|
1493 | + if ( $bulk ) { |
|
1494 | + $dropdown_args['show_option_no_change'] = __( '— No Change —' ); |
|
1495 | + } |
|
1471 | 1496 | |
1472 | 1497 | /** |
1473 | 1498 | * Filter the arguments used to generate the Quick Edit page-parent drop-down. |
@@ -1558,13 +1583,16 @@ discard block |
||
1558 | 1583 | <?php endif; ?> |
1559 | 1584 | </div> |
1560 | 1585 | |
1561 | - <?php else : // $bulk ?> |
|
1586 | + <?php else { |
|
1587 | + : // $bulk ?> |
|
1562 | 1588 | |
1563 | 1589 | <div class="inline-edit-group wp-clearfix"> |
1564 | 1590 | <?php if ( post_type_supports( $screen->post_type, 'comments' ) ) : ?> |
1565 | 1591 | <label class="alignleft"> |
1566 | 1592 | <input type="checkbox" name="comment_status" value="open" /> |
1567 | - <span class="checkbox-title"><?php _e( 'Allow Comments' ); ?></span> |
|
1593 | + <span class="checkbox-title"><?php _e( 'Allow Comments' ); |
|
1594 | +} |
|
1595 | +?></span> |
|
1568 | 1596 | </label> |
1569 | 1597 | <?php endif; if ( post_type_supports( $screen->post_type, 'trackbacks' ) ) : ?> |
1570 | 1598 | <label class="alignleft"> |
@@ -1609,11 +1637,14 @@ discard block |
||
1609 | 1637 | </select> |
1610 | 1638 | </label> |
1611 | 1639 | |
1612 | - <?php else : // $bulk ?> |
|
1640 | + <?php else { |
|
1641 | + : // $bulk ?> |
|
1613 | 1642 | |
1614 | 1643 | <label class="alignleft"> |
1615 | 1644 | <input type="checkbox" name="sticky" value="sticky" /> |
1616 | - <span class="checkbox-title"><?php _e( 'Make this post sticky' ); ?></span> |
|
1645 | + <span class="checkbox-title"><?php _e( 'Make this post sticky' ); |
|
1646 | +} |
|
1647 | +?></span> |
|
1617 | 1648 | </label> |
1618 | 1649 | |
1619 | 1650 | <?php endif; // $bulk ?> |
@@ -1655,8 +1686,9 @@ discard block |
||
1655 | 1686 | list( $columns ) = $this->get_column_info(); |
1656 | 1687 | |
1657 | 1688 | foreach ( $columns as $column_name => $column_display_name ) { |
1658 | - if ( isset( $core_columns[$column_name] ) ) |
|
1659 | - continue; |
|
1689 | + if ( isset( $core_columns[$column_name] ) ) { |
|
1690 | + continue; |
|
1691 | + } |
|
1660 | 1692 | |
1661 | 1693 | if ( $bulk ) { |
1662 | 1694 |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | * @param bool $markup Optional. If the returned data should have HTML markup applied. |
52 | 52 | * Default true. |
53 | 53 | * @param bool $translate Optional. If the returned data should be translated. Default true. |
54 | - * @return array { |
|
54 | + * @return string { |
|
55 | 55 | * Plugin data. Values will be empty if not supplied by the plugin. |
56 | 56 | * |
57 | 57 | * @type string $Name Name of the plugin. Should be unique. |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | * @since 2.8.0 |
181 | 181 | * |
182 | 182 | * @param string $plugin Plugin ID |
183 | - * @return array List of files relative to the plugin root. |
|
183 | + * @return string[] List of files relative to the plugin root. |
|
184 | 184 | */ |
185 | 185 | function get_plugin_files($plugin) { |
186 | 186 | $plugin_file = WP_PLUGIN_DIR . '/' . $plugin; |
@@ -978,7 +978,7 @@ discard block |
||
978 | 978 | * @since 2.7.0 |
979 | 979 | * |
980 | 980 | * @param string $plugin Relative plugin path from Plugin Directory. |
981 | - * @return true True if a plugin's uninstall.php file has been found and included. |
|
981 | + * @return boolean|null True if a plugin's uninstall.php file has been found and included. |
|
982 | 982 | */ |
983 | 983 | function uninstall_plugin($plugin) { |
984 | 984 | $file = plugin_basename($plugin); |
@@ -1498,6 +1498,7 @@ discard block |
||
1498 | 1498 | * @global array $_wp_real_parent_file |
1499 | 1499 | * @global array $_wp_menu_nopriv |
1500 | 1500 | * @global array $_wp_submenu_nopriv |
1501 | + * @return string |
|
1501 | 1502 | */ |
1502 | 1503 | function get_admin_page_parent( $parent = '' ) { |
1503 | 1504 | global $parent_file, $menu, $submenu, $pagenow, $typenow, |
@@ -1,10 +1,10 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * WordPress Plugin Administration API |
|
4 | - * |
|
5 | - * @package WordPress |
|
6 | - * @subpackage Administration |
|
7 | - */ |
|
3 | + * WordPress Plugin Administration API |
|
4 | + * |
|
5 | + * @package WordPress |
|
6 | + * @subpackage Administration |
|
7 | + */ |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Parses the plugin contents to retrieve plugin's metadata. |
@@ -1280,21 +1280,21 @@ discard block |
||
1280 | 1280 | return add_submenu_page( $parent, $page_title, $menu_title, $capability, $menu_slug, $function ); |
1281 | 1281 | } |
1282 | 1282 | /** |
1283 | - * Add submenu page to the Dashboard main menu. |
|
1284 | - * |
|
1285 | - * This function takes a capability which will be used to determine whether |
|
1286 | - * or not a page is included in the menu. |
|
1287 | - * |
|
1288 | - * The function which is hooked in to handle the output of the page must check |
|
1289 | - * that the user has the required capability as well. |
|
1290 | - * |
|
1291 | - * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected. |
|
1292 | - * @param string $menu_title The text to be used for the menu. |
|
1293 | - * @param string $capability The capability required for this menu to be displayed to the user. |
|
1294 | - * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu). |
|
1295 | - * @param callable $function The function to be called to output the content for this page. |
|
1296 | - * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required. |
|
1297 | - */ |
|
1283 | + * Add submenu page to the Dashboard main menu. |
|
1284 | + * |
|
1285 | + * This function takes a capability which will be used to determine whether |
|
1286 | + * or not a page is included in the menu. |
|
1287 | + * |
|
1288 | + * The function which is hooked in to handle the output of the page must check |
|
1289 | + * that the user has the required capability as well. |
|
1290 | + * |
|
1291 | + * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected. |
|
1292 | + * @param string $menu_title The text to be used for the menu. |
|
1293 | + * @param string $capability The capability required for this menu to be displayed to the user. |
|
1294 | + * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu). |
|
1295 | + * @param callable $function The function to be called to output the content for this page. |
|
1296 | + * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required. |
|
1297 | + */ |
|
1298 | 1298 | function add_dashboard_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { |
1299 | 1299 | return add_submenu_page( 'index.php', $page_title, $menu_title, $capability, $menu_slug, $function ); |
1300 | 1300 | } |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | * @type bool $Network Whether the plugin can only be activated network-wide. |
66 | 66 | * } |
67 | 67 | */ |
68 | -function get_plugin_data( $plugin_file, $markup = true, $translate = true ) { |
|
68 | +function get_plugin_data($plugin_file, $markup = true, $translate = true) { |
|
69 | 69 | |
70 | 70 | $default_headers = array( |
71 | 71 | 'Name' => 'Plugin Name', |
@@ -81,19 +81,19 @@ discard block |
||
81 | 81 | '_sitewide' => 'Site Wide Only', |
82 | 82 | ); |
83 | 83 | |
84 | - $plugin_data = get_file_data( $plugin_file, $default_headers, 'plugin' ); |
|
84 | + $plugin_data = get_file_data($plugin_file, $default_headers, 'plugin'); |
|
85 | 85 | |
86 | 86 | // Site Wide Only is the old header for Network |
87 | - if ( ! $plugin_data['Network'] && $plugin_data['_sitewide'] ) { |
|
87 | + if ( ! $plugin_data['Network'] && $plugin_data['_sitewide']) { |
|
88 | 88 | /* translators: 1: Site Wide Only: true, 2: Network: true */ |
89 | - _deprecated_argument( __FUNCTION__, '3.0', sprintf( __( 'The %1$s plugin header is deprecated. Use %2$s instead.' ), '<code>Site Wide Only: true</code>', '<code>Network: true</code>' ) ); |
|
89 | + _deprecated_argument(__FUNCTION__, '3.0', sprintf(__('The %1$s plugin header is deprecated. Use %2$s instead.'), '<code>Site Wide Only: true</code>', '<code>Network: true</code>')); |
|
90 | 90 | $plugin_data['Network'] = $plugin_data['_sitewide']; |
91 | 91 | } |
92 | - $plugin_data['Network'] = ( 'true' == strtolower( $plugin_data['Network'] ) ); |
|
93 | - unset( $plugin_data['_sitewide'] ); |
|
92 | + $plugin_data['Network'] = ('true' == strtolower($plugin_data['Network'])); |
|
93 | + unset($plugin_data['_sitewide']); |
|
94 | 94 | |
95 | - if ( $markup || $translate ) { |
|
96 | - $plugin_data = _get_plugin_data_markup_translate( $plugin_file, $plugin_data, $markup, $translate ); |
|
95 | + if ($markup || $translate) { |
|
96 | + $plugin_data = _get_plugin_data_markup_translate($plugin_file, $plugin_data, $markup, $translate); |
|
97 | 97 | } else { |
98 | 98 | $plugin_data['Title'] = $plugin_data['Name']; |
99 | 99 | $plugin_data['AuthorName'] = $plugin_data['Author']; |
@@ -109,66 +109,66 @@ discard block |
||
109 | 109 | * @access private |
110 | 110 | * @see get_plugin_data() |
111 | 111 | */ |
112 | -function _get_plugin_data_markup_translate( $plugin_file, $plugin_data, $markup = true, $translate = true ) { |
|
112 | +function _get_plugin_data_markup_translate($plugin_file, $plugin_data, $markup = true, $translate = true) { |
|
113 | 113 | |
114 | 114 | // Sanitize the plugin filename to a WP_PLUGIN_DIR relative path |
115 | - $plugin_file = plugin_basename( $plugin_file ); |
|
115 | + $plugin_file = plugin_basename($plugin_file); |
|
116 | 116 | |
117 | 117 | // Translate fields |
118 | - if ( $translate ) { |
|
119 | - if ( $textdomain = $plugin_data['TextDomain'] ) { |
|
120 | - if ( ! is_textdomain_loaded( $textdomain ) ) { |
|
121 | - if ( $plugin_data['DomainPath'] ) { |
|
122 | - load_plugin_textdomain( $textdomain, false, dirname( $plugin_file ) . $plugin_data['DomainPath'] ); |
|
118 | + if ($translate) { |
|
119 | + if ($textdomain = $plugin_data['TextDomain']) { |
|
120 | + if ( ! is_textdomain_loaded($textdomain)) { |
|
121 | + if ($plugin_data['DomainPath']) { |
|
122 | + load_plugin_textdomain($textdomain, false, dirname($plugin_file).$plugin_data['DomainPath']); |
|
123 | 123 | } else { |
124 | - load_plugin_textdomain( $textdomain, false, dirname( $plugin_file ) ); |
|
124 | + load_plugin_textdomain($textdomain, false, dirname($plugin_file)); |
|
125 | 125 | } |
126 | 126 | } |
127 | - } elseif ( 'hello.php' == basename( $plugin_file ) ) { |
|
127 | + } elseif ('hello.php' == basename($plugin_file)) { |
|
128 | 128 | $textdomain = 'default'; |
129 | 129 | } |
130 | - if ( $textdomain ) { |
|
131 | - foreach ( array( 'Name', 'PluginURI', 'Description', 'Author', 'AuthorURI', 'Version' ) as $field ) |
|
132 | - $plugin_data[ $field ] = translate( $plugin_data[ $field ], $textdomain ); |
|
130 | + if ($textdomain) { |
|
131 | + foreach (array('Name', 'PluginURI', 'Description', 'Author', 'AuthorURI', 'Version') as $field) |
|
132 | + $plugin_data[$field] = translate($plugin_data[$field], $textdomain); |
|
133 | 133 | } |
134 | 134 | } |
135 | 135 | |
136 | 136 | // Sanitize fields |
137 | 137 | $allowed_tags = $allowed_tags_in_links = array( |
138 | - 'abbr' => array( 'title' => true ), |
|
139 | - 'acronym' => array( 'title' => true ), |
|
138 | + 'abbr' => array('title' => true), |
|
139 | + 'acronym' => array('title' => true), |
|
140 | 140 | 'code' => true, |
141 | 141 | 'em' => true, |
142 | 142 | 'strong' => true, |
143 | 143 | ); |
144 | - $allowed_tags['a'] = array( 'href' => true, 'title' => true ); |
|
144 | + $allowed_tags['a'] = array('href' => true, 'title' => true); |
|
145 | 145 | |
146 | 146 | // Name is marked up inside <a> tags. Don't allow these. |
147 | 147 | // Author is too, but some plugins have used <a> here (omitting Author URI). |
148 | - $plugin_data['Name'] = wp_kses( $plugin_data['Name'], $allowed_tags_in_links ); |
|
149 | - $plugin_data['Author'] = wp_kses( $plugin_data['Author'], $allowed_tags ); |
|
148 | + $plugin_data['Name'] = wp_kses($plugin_data['Name'], $allowed_tags_in_links); |
|
149 | + $plugin_data['Author'] = wp_kses($plugin_data['Author'], $allowed_tags); |
|
150 | 150 | |
151 | - $plugin_data['Description'] = wp_kses( $plugin_data['Description'], $allowed_tags ); |
|
152 | - $plugin_data['Version'] = wp_kses( $plugin_data['Version'], $allowed_tags ); |
|
151 | + $plugin_data['Description'] = wp_kses($plugin_data['Description'], $allowed_tags); |
|
152 | + $plugin_data['Version'] = wp_kses($plugin_data['Version'], $allowed_tags); |
|
153 | 153 | |
154 | - $plugin_data['PluginURI'] = esc_url( $plugin_data['PluginURI'] ); |
|
155 | - $plugin_data['AuthorURI'] = esc_url( $plugin_data['AuthorURI'] ); |
|
154 | + $plugin_data['PluginURI'] = esc_url($plugin_data['PluginURI']); |
|
155 | + $plugin_data['AuthorURI'] = esc_url($plugin_data['AuthorURI']); |
|
156 | 156 | |
157 | 157 | $plugin_data['Title'] = $plugin_data['Name']; |
158 | 158 | $plugin_data['AuthorName'] = $plugin_data['Author']; |
159 | 159 | |
160 | 160 | // Apply markup |
161 | - if ( $markup ) { |
|
162 | - if ( $plugin_data['PluginURI'] && $plugin_data['Name'] ) |
|
163 | - $plugin_data['Title'] = '<a href="' . $plugin_data['PluginURI'] . '">' . $plugin_data['Name'] . '</a>'; |
|
161 | + if ($markup) { |
|
162 | + if ($plugin_data['PluginURI'] && $plugin_data['Name']) |
|
163 | + $plugin_data['Title'] = '<a href="'.$plugin_data['PluginURI'].'">'.$plugin_data['Name'].'</a>'; |
|
164 | 164 | |
165 | - if ( $plugin_data['AuthorURI'] && $plugin_data['Author'] ) |
|
166 | - $plugin_data['Author'] = '<a href="' . $plugin_data['AuthorURI'] . '">' . $plugin_data['Author'] . '</a>'; |
|
165 | + if ($plugin_data['AuthorURI'] && $plugin_data['Author']) |
|
166 | + $plugin_data['Author'] = '<a href="'.$plugin_data['AuthorURI'].'">'.$plugin_data['Author'].'</a>'; |
|
167 | 167 | |
168 | - $plugin_data['Description'] = wptexturize( $plugin_data['Description'] ); |
|
168 | + $plugin_data['Description'] = wptexturize($plugin_data['Description']); |
|
169 | 169 | |
170 | - if ( $plugin_data['Author'] ) |
|
171 | - $plugin_data['Description'] .= ' <cite>' . sprintf( __('By %s.'), $plugin_data['Author'] ) . '</cite>'; |
|
170 | + if ($plugin_data['Author']) |
|
171 | + $plugin_data['Description'] .= ' <cite>'.sprintf(__('By %s.'), $plugin_data['Author']).'</cite>'; |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | return $plugin_data; |
@@ -183,31 +183,31 @@ discard block |
||
183 | 183 | * @return array List of files relative to the plugin root. |
184 | 184 | */ |
185 | 185 | function get_plugin_files($plugin) { |
186 | - $plugin_file = WP_PLUGIN_DIR . '/' . $plugin; |
|
186 | + $plugin_file = WP_PLUGIN_DIR.'/'.$plugin; |
|
187 | 187 | $dir = dirname($plugin_file); |
188 | 188 | $plugin_files = array($plugin); |
189 | - if ( is_dir($dir) && $dir != WP_PLUGIN_DIR ) { |
|
190 | - $plugins_dir = @ opendir( $dir ); |
|
191 | - if ( $plugins_dir ) { |
|
192 | - while (($file = readdir( $plugins_dir ) ) !== false ) { |
|
193 | - if ( substr($file, 0, 1) == '.' ) |
|
189 | + if (is_dir($dir) && $dir != WP_PLUGIN_DIR) { |
|
190 | + $plugins_dir = @ opendir($dir); |
|
191 | + if ($plugins_dir) { |
|
192 | + while (($file = readdir($plugins_dir)) !== false) { |
|
193 | + if (substr($file, 0, 1) == '.') |
|
194 | 194 | continue; |
195 | - if ( is_dir( $dir . '/' . $file ) ) { |
|
196 | - $plugins_subdir = @ opendir( $dir . '/' . $file ); |
|
197 | - if ( $plugins_subdir ) { |
|
198 | - while (($subfile = readdir( $plugins_subdir ) ) !== false ) { |
|
199 | - if ( substr($subfile, 0, 1) == '.' ) |
|
195 | + if (is_dir($dir.'/'.$file)) { |
|
196 | + $plugins_subdir = @ opendir($dir.'/'.$file); |
|
197 | + if ($plugins_subdir) { |
|
198 | + while (($subfile = readdir($plugins_subdir)) !== false) { |
|
199 | + if (substr($subfile, 0, 1) == '.') |
|
200 | 200 | continue; |
201 | 201 | $plugin_files[] = plugin_basename("$dir/$file/$subfile"); |
202 | 202 | } |
203 | - @closedir( $plugins_subdir ); |
|
203 | + @closedir($plugins_subdir); |
|
204 | 204 | } |
205 | 205 | } else { |
206 | - if ( plugin_basename("$dir/$file") != $plugin ) |
|
206 | + if (plugin_basename("$dir/$file") != $plugin) |
|
207 | 207 | $plugin_files[] = plugin_basename("$dir/$file"); |
208 | 208 | } |
209 | 209 | } |
210 | - @closedir( $plugins_dir ); |
|
210 | + @closedir($plugins_dir); |
|
211 | 211 | } |
212 | 212 | } |
213 | 213 | |
@@ -236,61 +236,61 @@ discard block |
||
236 | 236 | */ |
237 | 237 | function get_plugins($plugin_folder = '') { |
238 | 238 | |
239 | - if ( ! $cache_plugins = wp_cache_get('plugins', 'plugins') ) |
|
239 | + if ( ! $cache_plugins = wp_cache_get('plugins', 'plugins')) |
|
240 | 240 | $cache_plugins = array(); |
241 | 241 | |
242 | - if ( isset($cache_plugins[ $plugin_folder ]) ) |
|
243 | - return $cache_plugins[ $plugin_folder ]; |
|
242 | + if (isset($cache_plugins[$plugin_folder])) |
|
243 | + return $cache_plugins[$plugin_folder]; |
|
244 | 244 | |
245 | - $wp_plugins = array (); |
|
245 | + $wp_plugins = array(); |
|
246 | 246 | $plugin_root = WP_PLUGIN_DIR; |
247 | - if ( !empty($plugin_folder) ) |
|
247 | + if ( ! empty($plugin_folder)) |
|
248 | 248 | $plugin_root .= $plugin_folder; |
249 | 249 | |
250 | 250 | // Files in wp-content/plugins directory |
251 | - $plugins_dir = @ opendir( $plugin_root); |
|
251 | + $plugins_dir = @ opendir($plugin_root); |
|
252 | 252 | $plugin_files = array(); |
253 | - if ( $plugins_dir ) { |
|
254 | - while (($file = readdir( $plugins_dir ) ) !== false ) { |
|
255 | - if ( substr($file, 0, 1) == '.' ) |
|
253 | + if ($plugins_dir) { |
|
254 | + while (($file = readdir($plugins_dir)) !== false) { |
|
255 | + if (substr($file, 0, 1) == '.') |
|
256 | 256 | continue; |
257 | - if ( is_dir( $plugin_root.'/'.$file ) ) { |
|
258 | - $plugins_subdir = @ opendir( $plugin_root.'/'.$file ); |
|
259 | - if ( $plugins_subdir ) { |
|
260 | - while (($subfile = readdir( $plugins_subdir ) ) !== false ) { |
|
261 | - if ( substr($subfile, 0, 1) == '.' ) |
|
257 | + if (is_dir($plugin_root.'/'.$file)) { |
|
258 | + $plugins_subdir = @ opendir($plugin_root.'/'.$file); |
|
259 | + if ($plugins_subdir) { |
|
260 | + while (($subfile = readdir($plugins_subdir)) !== false) { |
|
261 | + if (substr($subfile, 0, 1) == '.') |
|
262 | 262 | continue; |
263 | - if ( substr($subfile, -4) == '.php' ) |
|
263 | + if (substr($subfile, -4) == '.php') |
|
264 | 264 | $plugin_files[] = "$file/$subfile"; |
265 | 265 | } |
266 | - closedir( $plugins_subdir ); |
|
266 | + closedir($plugins_subdir); |
|
267 | 267 | } |
268 | 268 | } else { |
269 | - if ( substr($file, -4) == '.php' ) |
|
269 | + if (substr($file, -4) == '.php') |
|
270 | 270 | $plugin_files[] = $file; |
271 | 271 | } |
272 | 272 | } |
273 | - closedir( $plugins_dir ); |
|
273 | + closedir($plugins_dir); |
|
274 | 274 | } |
275 | 275 | |
276 | - if ( empty($plugin_files) ) |
|
276 | + if (empty($plugin_files)) |
|
277 | 277 | return $wp_plugins; |
278 | 278 | |
279 | - foreach ( $plugin_files as $plugin_file ) { |
|
280 | - if ( !is_readable( "$plugin_root/$plugin_file" ) ) |
|
279 | + foreach ($plugin_files as $plugin_file) { |
|
280 | + if ( ! is_readable("$plugin_root/$plugin_file")) |
|
281 | 281 | continue; |
282 | 282 | |
283 | - $plugin_data = get_plugin_data( "$plugin_root/$plugin_file", false, false ); //Do not apply markup/translate as it'll be cached. |
|
283 | + $plugin_data = get_plugin_data("$plugin_root/$plugin_file", false, false); //Do not apply markup/translate as it'll be cached. |
|
284 | 284 | |
285 | - if ( empty ( $plugin_data['Name'] ) ) |
|
285 | + if (empty ($plugin_data['Name'])) |
|
286 | 286 | continue; |
287 | 287 | |
288 | - $wp_plugins[plugin_basename( $plugin_file )] = $plugin_data; |
|
288 | + $wp_plugins[plugin_basename($plugin_file)] = $plugin_data; |
|
289 | 289 | } |
290 | 290 | |
291 | - uasort( $wp_plugins, '_sort_uname_callback' ); |
|
291 | + uasort($wp_plugins, '_sort_uname_callback'); |
|
292 | 292 | |
293 | - $cache_plugins[ $plugin_folder ] = $wp_plugins; |
|
293 | + $cache_plugins[$plugin_folder] = $wp_plugins; |
|
294 | 294 | wp_cache_set('plugins', $cache_plugins, 'plugins'); |
295 | 295 | |
296 | 296 | return $wp_plugins; |
@@ -309,38 +309,38 @@ discard block |
||
309 | 309 | // Files in wp-content/mu-plugins directory |
310 | 310 | $plugin_files = array(); |
311 | 311 | |
312 | - if ( ! is_dir( WPMU_PLUGIN_DIR ) ) |
|
312 | + if ( ! is_dir(WPMU_PLUGIN_DIR)) |
|
313 | 313 | return $wp_plugins; |
314 | - if ( $plugins_dir = @ opendir( WPMU_PLUGIN_DIR ) ) { |
|
315 | - while ( ( $file = readdir( $plugins_dir ) ) !== false ) { |
|
316 | - if ( substr( $file, -4 ) == '.php' ) |
|
314 | + if ($plugins_dir = @ opendir(WPMU_PLUGIN_DIR)) { |
|
315 | + while (($file = readdir($plugins_dir)) !== false) { |
|
316 | + if (substr($file, -4) == '.php') |
|
317 | 317 | $plugin_files[] = $file; |
318 | 318 | } |
319 | 319 | } else { |
320 | 320 | return $wp_plugins; |
321 | 321 | } |
322 | 322 | |
323 | - @closedir( $plugins_dir ); |
|
323 | + @closedir($plugins_dir); |
|
324 | 324 | |
325 | - if ( empty($plugin_files) ) |
|
325 | + if (empty($plugin_files)) |
|
326 | 326 | return $wp_plugins; |
327 | 327 | |
328 | - foreach ( $plugin_files as $plugin_file ) { |
|
329 | - if ( !is_readable( WPMU_PLUGIN_DIR . "/$plugin_file" ) ) |
|
328 | + foreach ($plugin_files as $plugin_file) { |
|
329 | + if ( ! is_readable(WPMU_PLUGIN_DIR."/$plugin_file")) |
|
330 | 330 | continue; |
331 | 331 | |
332 | - $plugin_data = get_plugin_data( WPMU_PLUGIN_DIR . "/$plugin_file", false, false ); //Do not apply markup/translate as it'll be cached. |
|
332 | + $plugin_data = get_plugin_data(WPMU_PLUGIN_DIR."/$plugin_file", false, false); //Do not apply markup/translate as it'll be cached. |
|
333 | 333 | |
334 | - if ( empty ( $plugin_data['Name'] ) ) |
|
334 | + if (empty ($plugin_data['Name'])) |
|
335 | 335 | $plugin_data['Name'] = $plugin_file; |
336 | 336 | |
337 | - $wp_plugins[ $plugin_file ] = $plugin_data; |
|
337 | + $wp_plugins[$plugin_file] = $plugin_data; |
|
338 | 338 | } |
339 | 339 | |
340 | - if ( isset( $wp_plugins['index.php'] ) && filesize( WPMU_PLUGIN_DIR . '/index.php') <= 30 ) // silence is golden |
|
341 | - unset( $wp_plugins['index.php'] ); |
|
340 | + if (isset($wp_plugins['index.php']) && filesize(WPMU_PLUGIN_DIR.'/index.php') <= 30) // silence is golden |
|
341 | + unset($wp_plugins['index.php']); |
|
342 | 342 | |
343 | - uasort( $wp_plugins, '_sort_uname_callback' ); |
|
343 | + uasort($wp_plugins, '_sort_uname_callback'); |
|
344 | 344 | |
345 | 345 | return $wp_plugins; |
346 | 346 | } |
@@ -351,8 +351,8 @@ discard block |
||
351 | 351 | * @since 3.1.0 |
352 | 352 | * @access private |
353 | 353 | */ |
354 | -function _sort_uname_callback( $a, $b ) { |
|
355 | - return strnatcasecmp( $a['Name'], $b['Name'] ); |
|
354 | +function _sort_uname_callback($a, $b) { |
|
355 | + return strnatcasecmp($a['Name'], $b['Name']); |
|
356 | 356 | } |
357 | 357 | |
358 | 358 | /** |
@@ -368,30 +368,30 @@ discard block |
||
368 | 368 | $_dropins = _get_dropins(); |
369 | 369 | |
370 | 370 | // These exist in the wp-content directory |
371 | - if ( $plugins_dir = @ opendir( WP_CONTENT_DIR ) ) { |
|
372 | - while ( ( $file = readdir( $plugins_dir ) ) !== false ) { |
|
373 | - if ( isset( $_dropins[ $file ] ) ) |
|
371 | + if ($plugins_dir = @ opendir(WP_CONTENT_DIR)) { |
|
372 | + while (($file = readdir($plugins_dir)) !== false) { |
|
373 | + if (isset($_dropins[$file])) |
|
374 | 374 | $plugin_files[] = $file; |
375 | 375 | } |
376 | 376 | } else { |
377 | 377 | return $dropins; |
378 | 378 | } |
379 | 379 | |
380 | - @closedir( $plugins_dir ); |
|
380 | + @closedir($plugins_dir); |
|
381 | 381 | |
382 | - if ( empty($plugin_files) ) |
|
382 | + if (empty($plugin_files)) |
|
383 | 383 | return $dropins; |
384 | 384 | |
385 | - foreach ( $plugin_files as $plugin_file ) { |
|
386 | - if ( !is_readable( WP_CONTENT_DIR . "/$plugin_file" ) ) |
|
385 | + foreach ($plugin_files as $plugin_file) { |
|
386 | + if ( ! is_readable(WP_CONTENT_DIR."/$plugin_file")) |
|
387 | 387 | continue; |
388 | - $plugin_data = get_plugin_data( WP_CONTENT_DIR . "/$plugin_file", false, false ); //Do not apply markup/translate as it'll be cached. |
|
389 | - if ( empty( $plugin_data['Name'] ) ) |
|
388 | + $plugin_data = get_plugin_data(WP_CONTENT_DIR."/$plugin_file", false, false); //Do not apply markup/translate as it'll be cached. |
|
389 | + if (empty($plugin_data['Name'])) |
|
390 | 390 | $plugin_data['Name'] = $plugin_file; |
391 | - $dropins[ $plugin_file ] = $plugin_data; |
|
391 | + $dropins[$plugin_file] = $plugin_data; |
|
392 | 392 | } |
393 | 393 | |
394 | - uksort( $dropins, 'strnatcasecmp' ); |
|
394 | + uksort($dropins, 'strnatcasecmp'); |
|
395 | 395 | |
396 | 396 | return $dropins; |
397 | 397 | } |
@@ -408,19 +408,19 @@ discard block |
||
408 | 408 | */ |
409 | 409 | function _get_dropins() { |
410 | 410 | $dropins = array( |
411 | - 'advanced-cache.php' => array( __( 'Advanced caching plugin.' ), 'WP_CACHE' ), // WP_CACHE |
|
412 | - 'db.php' => array( __( 'Custom database class.' ), true ), // auto on load |
|
413 | - 'db-error.php' => array( __( 'Custom database error message.' ), true ), // auto on error |
|
414 | - 'install.php' => array( __( 'Custom install script.' ), true ), // auto on install |
|
415 | - 'maintenance.php' => array( __( 'Custom maintenance message.' ), true ), // auto on maintenance |
|
416 | - 'object-cache.php' => array( __( 'External object cache.' ), true ), // auto on load |
|
411 | + 'advanced-cache.php' => array(__('Advanced caching plugin.'), 'WP_CACHE'), // WP_CACHE |
|
412 | + 'db.php' => array(__('Custom database class.'), true), // auto on load |
|
413 | + 'db-error.php' => array(__('Custom database error message.'), true), // auto on error |
|
414 | + 'install.php' => array(__('Custom install script.'), true), // auto on install |
|
415 | + 'maintenance.php' => array(__('Custom maintenance message.'), true), // auto on maintenance |
|
416 | + 'object-cache.php' => array(__('External object cache.'), true), // auto on load |
|
417 | 417 | ); |
418 | 418 | |
419 | - if ( is_multisite() ) { |
|
420 | - $dropins['sunrise.php' ] = array( __( 'Executed before Multisite is loaded.' ), 'SUNRISE' ); // SUNRISE |
|
421 | - $dropins['blog-deleted.php' ] = array( __( 'Custom site deleted message.' ), true ); // auto on deleted blog |
|
422 | - $dropins['blog-inactive.php' ] = array( __( 'Custom site inactive message.' ), true ); // auto on inactive blog |
|
423 | - $dropins['blog-suspended.php'] = array( __( 'Custom site suspended message.' ), true ); // auto on archived or spammed blog |
|
419 | + if (is_multisite()) { |
|
420 | + $dropins['sunrise.php'] = array(__('Executed before Multisite is loaded.'), 'SUNRISE'); // SUNRISE |
|
421 | + $dropins['blog-deleted.php'] = array(__('Custom site deleted message.'), true); // auto on deleted blog |
|
422 | + $dropins['blog-inactive.php'] = array(__('Custom site inactive message.'), true); // auto on inactive blog |
|
423 | + $dropins['blog-suspended.php'] = array(__('Custom site suspended message.'), true); // auto on archived or spammed blog |
|
424 | 424 | } |
425 | 425 | |
426 | 426 | return $dropins; |
@@ -439,8 +439,8 @@ discard block |
||
439 | 439 | * @param string $plugin Base plugin path from plugins directory. |
440 | 440 | * @return bool True, if in the active plugins list. False, not in the list. |
441 | 441 | */ |
442 | -function is_plugin_active( $plugin ) { |
|
443 | - return in_array( $plugin, (array) get_option( 'active_plugins', array() ) ) || is_plugin_active_for_network( $plugin ); |
|
442 | +function is_plugin_active($plugin) { |
|
443 | + return in_array($plugin, (array) get_option('active_plugins', array())) || is_plugin_active_for_network($plugin); |
|
444 | 444 | } |
445 | 445 | |
446 | 446 | /** |
@@ -454,8 +454,8 @@ discard block |
||
454 | 454 | * @param string $plugin Base plugin path from plugins directory. |
455 | 455 | * @return bool True if inactive. False if active. |
456 | 456 | */ |
457 | -function is_plugin_inactive( $plugin ) { |
|
458 | - return ! is_plugin_active( $plugin ); |
|
457 | +function is_plugin_inactive($plugin) { |
|
458 | + return ! is_plugin_active($plugin); |
|
459 | 459 | } |
460 | 460 | |
461 | 461 | /** |
@@ -471,12 +471,12 @@ discard block |
||
471 | 471 | * @param string $plugin Base plugin path from plugins directory. |
472 | 472 | * @return bool True, if active for the network, otherwise false. |
473 | 473 | */ |
474 | -function is_plugin_active_for_network( $plugin ) { |
|
475 | - if ( !is_multisite() ) |
|
474 | +function is_plugin_active_for_network($plugin) { |
|
475 | + if ( ! is_multisite()) |
|
476 | 476 | return false; |
477 | 477 | |
478 | - $plugins = get_site_option( 'active_sitewide_plugins'); |
|
479 | - if ( isset($plugins[$plugin]) ) |
|
478 | + $plugins = get_site_option('active_sitewide_plugins'); |
|
479 | + if (isset($plugins[$plugin])) |
|
480 | 480 | return true; |
481 | 481 | |
482 | 482 | return false; |
@@ -494,9 +494,9 @@ discard block |
||
494 | 494 | * @param string $plugin Plugin to check |
495 | 495 | * @return bool True if plugin is network only, false otherwise. |
496 | 496 | */ |
497 | -function is_network_only_plugin( $plugin ) { |
|
498 | - $plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin ); |
|
499 | - if ( $plugin_data ) |
|
497 | +function is_network_only_plugin($plugin) { |
|
498 | + $plugin_data = get_plugin_data(WP_PLUGIN_DIR.'/'.$plugin); |
|
499 | + if ($plugin_data) |
|
500 | 500 | return $plugin_data['Network']; |
501 | 501 | return false; |
502 | 502 | } |
@@ -528,31 +528,31 @@ discard block |
||
528 | 528 | * @param bool $silent Optional. Whether to prevent calling activation hooks. Default false. |
529 | 529 | * @return WP_Error|null WP_Error on invalid file or null on success. |
530 | 530 | */ |
531 | -function activate_plugin( $plugin, $redirect = '', $network_wide = false, $silent = false ) { |
|
532 | - $plugin = plugin_basename( trim( $plugin ) ); |
|
531 | +function activate_plugin($plugin, $redirect = '', $network_wide = false, $silent = false) { |
|
532 | + $plugin = plugin_basename(trim($plugin)); |
|
533 | 533 | |
534 | - if ( is_multisite() && ( $network_wide || is_network_only_plugin($plugin) ) ) { |
|
534 | + if (is_multisite() && ($network_wide || is_network_only_plugin($plugin))) { |
|
535 | 535 | $network_wide = true; |
536 | - $current = get_site_option( 'active_sitewide_plugins', array() ); |
|
536 | + $current = get_site_option('active_sitewide_plugins', array()); |
|
537 | 537 | $_GET['networkwide'] = 1; // Back compat for plugins looking for this value. |
538 | 538 | } else { |
539 | - $current = get_option( 'active_plugins', array() ); |
|
539 | + $current = get_option('active_plugins', array()); |
|
540 | 540 | } |
541 | 541 | |
542 | 542 | $valid = validate_plugin($plugin); |
543 | - if ( is_wp_error($valid) ) |
|
543 | + if (is_wp_error($valid)) |
|
544 | 544 | return $valid; |
545 | 545 | |
546 | - if ( ( $network_wide && ! isset( $current[ $plugin ] ) ) || ( ! $network_wide && ! in_array( $plugin, $current ) ) ) { |
|
547 | - if ( !empty($redirect) ) |
|
548 | - wp_redirect(add_query_arg('_error_nonce', wp_create_nonce('plugin-activation-error_' . $plugin), $redirect)); // we'll override this later if the plugin can be included without fatal error |
|
546 | + if (($network_wide && ! isset($current[$plugin])) || ( ! $network_wide && ! in_array($plugin, $current))) { |
|
547 | + if ( ! empty($redirect)) |
|
548 | + wp_redirect(add_query_arg('_error_nonce', wp_create_nonce('plugin-activation-error_'.$plugin), $redirect)); // we'll override this later if the plugin can be included without fatal error |
|
549 | 549 | ob_start(); |
550 | - wp_register_plugin_realpath( WP_PLUGIN_DIR . '/' . $plugin ); |
|
550 | + wp_register_plugin_realpath(WP_PLUGIN_DIR.'/'.$plugin); |
|
551 | 551 | $_wp_plugin_file = $plugin; |
552 | - include_once( WP_PLUGIN_DIR . '/' . $plugin ); |
|
552 | + include_once(WP_PLUGIN_DIR.'/'.$plugin); |
|
553 | 553 | $plugin = $_wp_plugin_file; // Avoid stomping of the $plugin variable in a plugin. |
554 | 554 | |
555 | - if ( ! $silent ) { |
|
555 | + if ( ! $silent) { |
|
556 | 556 | /** |
557 | 557 | * Fires before a plugin is activated. |
558 | 558 | * |
@@ -565,7 +565,7 @@ discard block |
||
565 | 565 | * @param bool $network_wide Whether to enable the plugin for all sites in the network |
566 | 566 | * or just the current site. Multisite only. Default is false. |
567 | 567 | */ |
568 | - do_action( 'activate_plugin', $plugin, $network_wide ); |
|
568 | + do_action('activate_plugin', $plugin, $network_wide); |
|
569 | 569 | |
570 | 570 | /** |
571 | 571 | * Fires as a specific plugin is being activated. |
@@ -582,21 +582,21 @@ discard block |
||
582 | 582 | * @param bool $network_wide Whether to enable the plugin for all sites in the network |
583 | 583 | * or just the current site. Multisite only. Default is false. |
584 | 584 | */ |
585 | - do_action( 'activate_' . $plugin, $network_wide ); |
|
585 | + do_action('activate_'.$plugin, $network_wide); |
|
586 | 586 | } |
587 | 587 | |
588 | - if ( $network_wide ) { |
|
589 | - $current = get_site_option( 'active_sitewide_plugins', array() ); |
|
588 | + if ($network_wide) { |
|
589 | + $current = get_site_option('active_sitewide_plugins', array()); |
|
590 | 590 | $current[$plugin] = time(); |
591 | - update_site_option( 'active_sitewide_plugins', $current ); |
|
591 | + update_site_option('active_sitewide_plugins', $current); |
|
592 | 592 | } else { |
593 | - $current = get_option( 'active_plugins', array() ); |
|
593 | + $current = get_option('active_plugins', array()); |
|
594 | 594 | $current[] = $plugin; |
595 | 595 | sort($current); |
596 | 596 | update_option('active_plugins', $current); |
597 | 597 | } |
598 | 598 | |
599 | - if ( ! $silent ) { |
|
599 | + if ( ! $silent) { |
|
600 | 600 | /** |
601 | 601 | * Fires after a plugin has been activated. |
602 | 602 | * |
@@ -609,10 +609,10 @@ discard block |
||
609 | 609 | * @param bool $network_wide Whether to enable the plugin for all sites in the network |
610 | 610 | * or just the current site. Multisite only. Default is false. |
611 | 611 | */ |
612 | - do_action( 'activated_plugin', $plugin, $network_wide ); |
|
612 | + do_action('activated_plugin', $plugin, $network_wide); |
|
613 | 613 | } |
614 | 614 | |
615 | - if ( ob_get_length() > 0 ) { |
|
615 | + if (ob_get_length() > 0) { |
|
616 | 616 | $output = ob_get_clean(); |
617 | 617 | return new WP_Error('unexpected_output', __('The plugin generated unexpected output.'), $output); |
618 | 618 | } |
@@ -635,20 +635,20 @@ discard block |
||
635 | 635 | * @param mixed $network_wide Whether to deactivate the plugin for all sites in the network. |
636 | 636 | * A value of null (the default) will deactivate plugins for both the site and the network. |
637 | 637 | */ |
638 | -function deactivate_plugins( $plugins, $silent = false, $network_wide = null ) { |
|
639 | - if ( is_multisite() ) |
|
640 | - $network_current = get_site_option( 'active_sitewide_plugins', array() ); |
|
641 | - $current = get_option( 'active_plugins', array() ); |
|
638 | +function deactivate_plugins($plugins, $silent = false, $network_wide = null) { |
|
639 | + if (is_multisite()) |
|
640 | + $network_current = get_site_option('active_sitewide_plugins', array()); |
|
641 | + $current = get_option('active_plugins', array()); |
|
642 | 642 | $do_blog = $do_network = false; |
643 | 643 | |
644 | - foreach ( (array) $plugins as $plugin ) { |
|
645 | - $plugin = plugin_basename( trim( $plugin ) ); |
|
646 | - if ( ! is_plugin_active($plugin) ) |
|
644 | + foreach ((array) $plugins as $plugin) { |
|
645 | + $plugin = plugin_basename(trim($plugin)); |
|
646 | + if ( ! is_plugin_active($plugin)) |
|
647 | 647 | continue; |
648 | 648 | |
649 | - $network_deactivating = false !== $network_wide && is_plugin_active_for_network( $plugin ); |
|
649 | + $network_deactivating = false !== $network_wide && is_plugin_active_for_network($plugin); |
|
650 | 650 | |
651 | - if ( ! $silent ) { |
|
651 | + if ( ! $silent) { |
|
652 | 652 | /** |
653 | 653 | * Fires before a plugin is deactivated. |
654 | 654 | * |
@@ -661,27 +661,27 @@ discard block |
||
661 | 661 | * @param bool $network_deactivating Whether the plugin is deactivated for all sites in the network |
662 | 662 | * or just the current site. Multisite only. Default is false. |
663 | 663 | */ |
664 | - do_action( 'deactivate_plugin', $plugin, $network_deactivating ); |
|
664 | + do_action('deactivate_plugin', $plugin, $network_deactivating); |
|
665 | 665 | } |
666 | 666 | |
667 | - if ( false !== $network_wide ) { |
|
668 | - if ( is_plugin_active_for_network( $plugin ) ) { |
|
667 | + if (false !== $network_wide) { |
|
668 | + if (is_plugin_active_for_network($plugin)) { |
|
669 | 669 | $do_network = true; |
670 | - unset( $network_current[ $plugin ] ); |
|
671 | - } elseif ( $network_wide ) { |
|
670 | + unset($network_current[$plugin]); |
|
671 | + } elseif ($network_wide) { |
|
672 | 672 | continue; |
673 | 673 | } |
674 | 674 | } |
675 | 675 | |
676 | - if ( true !== $network_wide ) { |
|
677 | - $key = array_search( $plugin, $current ); |
|
678 | - if ( false !== $key ) { |
|
676 | + if (true !== $network_wide) { |
|
677 | + $key = array_search($plugin, $current); |
|
678 | + if (false !== $key) { |
|
679 | 679 | $do_blog = true; |
680 | - unset( $current[ $key ] ); |
|
680 | + unset($current[$key]); |
|
681 | 681 | } |
682 | 682 | } |
683 | 683 | |
684 | - if ( ! $silent ) { |
|
684 | + if ( ! $silent) { |
|
685 | 685 | /** |
686 | 686 | * Fires as a specific plugin is being deactivated. |
687 | 687 | * |
@@ -697,7 +697,7 @@ discard block |
||
697 | 697 | * @param bool $network_deactivating Whether the plugin is deactivated for all sites in the network |
698 | 698 | * or just the current site. Multisite only. Default is false. |
699 | 699 | */ |
700 | - do_action( 'deactivate_' . $plugin, $network_deactivating ); |
|
700 | + do_action('deactivate_'.$plugin, $network_deactivating); |
|
701 | 701 | |
702 | 702 | /** |
703 | 703 | * Fires after a plugin is deactivated. |
@@ -711,14 +711,14 @@ discard block |
||
711 | 711 | * @param bool $network_deactivating Whether the plugin is deactivated for all sites in the network |
712 | 712 | * or just the current site. Multisite only. Default false. |
713 | 713 | */ |
714 | - do_action( 'deactivated_plugin', $plugin, $network_deactivating ); |
|
714 | + do_action('deactivated_plugin', $plugin, $network_deactivating); |
|
715 | 715 | } |
716 | 716 | } |
717 | 717 | |
718 | - if ( $do_blog ) |
|
718 | + if ($do_blog) |
|
719 | 719 | update_option('active_plugins', $current); |
720 | - if ( $do_network ) |
|
721 | - update_site_option( 'active_sitewide_plugins', $network_current ); |
|
720 | + if ($do_network) |
|
721 | + update_site_option('active_sitewide_plugins', $network_current); |
|
722 | 722 | } |
723 | 723 | |
724 | 724 | /** |
@@ -737,20 +737,20 @@ discard block |
||
737 | 737 | * @param bool $silent Prevent calling activation hooks. Default is false. |
738 | 738 | * @return bool|WP_Error True when finished or WP_Error if there were errors during a plugin activation. |
739 | 739 | */ |
740 | -function activate_plugins( $plugins, $redirect = '', $network_wide = false, $silent = false ) { |
|
741 | - if ( !is_array($plugins) ) |
|
740 | +function activate_plugins($plugins, $redirect = '', $network_wide = false, $silent = false) { |
|
741 | + if ( ! is_array($plugins)) |
|
742 | 742 | $plugins = array($plugins); |
743 | 743 | |
744 | 744 | $errors = array(); |
745 | - foreach ( $plugins as $plugin ) { |
|
746 | - if ( !empty($redirect) ) |
|
745 | + foreach ($plugins as $plugin) { |
|
746 | + if ( ! empty($redirect)) |
|
747 | 747 | $redirect = add_query_arg('plugin', $plugin, $redirect); |
748 | 748 | $result = activate_plugin($plugin, $redirect, $network_wide, $silent); |
749 | - if ( is_wp_error($result) ) |
|
749 | + if (is_wp_error($result)) |
|
750 | 750 | $errors[$plugin] = $result; |
751 | 751 | } |
752 | 752 | |
753 | - if ( !empty($errors) ) |
|
753 | + if ( ! empty($errors)) |
|
754 | 754 | return new WP_Error('plugins_invalid', __('One of the plugins is invalid.'), $errors); |
755 | 755 | |
756 | 756 | return true; |
@@ -768,64 +768,64 @@ discard block |
||
768 | 768 | * @return bool|null|WP_Error True on success, false is $plugins is empty, WP_Error on failure. |
769 | 769 | * Null if filesystem credentials are required to proceed. |
770 | 770 | */ |
771 | -function delete_plugins( $plugins, $deprecated = '' ) { |
|
771 | +function delete_plugins($plugins, $deprecated = '') { |
|
772 | 772 | global $wp_filesystem; |
773 | 773 | |
774 | - if ( empty($plugins) ) |
|
774 | + if (empty($plugins)) |
|
775 | 775 | return false; |
776 | 776 | |
777 | 777 | $checked = array(); |
778 | - foreach ( $plugins as $plugin ) |
|
779 | - $checked[] = 'checked[]=' . $plugin; |
|
778 | + foreach ($plugins as $plugin) |
|
779 | + $checked[] = 'checked[]='.$plugin; |
|
780 | 780 | |
781 | 781 | ob_start(); |
782 | - $url = wp_nonce_url('plugins.php?action=delete-selected&verify-delete=1&' . implode('&', $checked), 'bulk-plugins'); |
|
783 | - if ( false === ($credentials = request_filesystem_credentials($url)) ) { |
|
782 | + $url = wp_nonce_url('plugins.php?action=delete-selected&verify-delete=1&'.implode('&', $checked), 'bulk-plugins'); |
|
783 | + if (false === ($credentials = request_filesystem_credentials($url))) { |
|
784 | 784 | $data = ob_get_clean(); |
785 | 785 | |
786 | - if ( ! empty($data) ){ |
|
787 | - include_once( ABSPATH . 'wp-admin/admin-header.php'); |
|
786 | + if ( ! empty($data)) { |
|
787 | + include_once(ABSPATH.'wp-admin/admin-header.php'); |
|
788 | 788 | echo $data; |
789 | - include( ABSPATH . 'wp-admin/admin-footer.php'); |
|
789 | + include(ABSPATH.'wp-admin/admin-footer.php'); |
|
790 | 790 | exit; |
791 | 791 | } |
792 | 792 | return; |
793 | 793 | } |
794 | 794 | |
795 | - if ( ! WP_Filesystem($credentials) ) { |
|
795 | + if ( ! WP_Filesystem($credentials)) { |
|
796 | 796 | request_filesystem_credentials($url, '', true); //Failed to connect, Error and request again |
797 | 797 | $data = ob_get_clean(); |
798 | 798 | |
799 | - if ( ! empty($data) ){ |
|
800 | - include_once( ABSPATH . 'wp-admin/admin-header.php'); |
|
799 | + if ( ! empty($data)) { |
|
800 | + include_once(ABSPATH.'wp-admin/admin-header.php'); |
|
801 | 801 | echo $data; |
802 | - include( ABSPATH . 'wp-admin/admin-footer.php'); |
|
802 | + include(ABSPATH.'wp-admin/admin-footer.php'); |
|
803 | 803 | exit; |
804 | 804 | } |
805 | 805 | return; |
806 | 806 | } |
807 | 807 | |
808 | - if ( ! is_object($wp_filesystem) ) |
|
808 | + if ( ! is_object($wp_filesystem)) |
|
809 | 809 | return new WP_Error('fs_unavailable', __('Could not access filesystem.')); |
810 | 810 | |
811 | - if ( is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code() ) |
|
811 | + if (is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code()) |
|
812 | 812 | return new WP_Error('fs_error', __('Filesystem error.'), $wp_filesystem->errors); |
813 | 813 | |
814 | 814 | // Get the base plugin folder. |
815 | 815 | $plugins_dir = $wp_filesystem->wp_plugins_dir(); |
816 | - if ( empty( $plugins_dir ) ) { |
|
817 | - return new WP_Error( 'fs_no_plugins_dir', __( 'Unable to locate WordPress Plugin directory.' ) ); |
|
816 | + if (empty($plugins_dir)) { |
|
817 | + return new WP_Error('fs_no_plugins_dir', __('Unable to locate WordPress Plugin directory.')); |
|
818 | 818 | } |
819 | 819 | |
820 | - $plugins_dir = trailingslashit( $plugins_dir ); |
|
820 | + $plugins_dir = trailingslashit($plugins_dir); |
|
821 | 821 | |
822 | - $plugin_translations = wp_get_installed_translations( 'plugins' ); |
|
822 | + $plugin_translations = wp_get_installed_translations('plugins'); |
|
823 | 823 | |
824 | 824 | $errors = array(); |
825 | 825 | |
826 | - foreach ( $plugins as $plugin_file ) { |
|
826 | + foreach ($plugins as $plugin_file) { |
|
827 | 827 | // Run Uninstall hook. |
828 | - if ( is_uninstallable_plugin( $plugin_file ) ) { |
|
828 | + if (is_uninstallable_plugin($plugin_file)) { |
|
829 | 829 | uninstall_plugin($plugin_file); |
830 | 830 | } |
831 | 831 | |
@@ -836,15 +836,15 @@ discard block |
||
836 | 836 | * |
837 | 837 | * @param string $plugin_file Plugin file name. |
838 | 838 | */ |
839 | - do_action( 'delete_plugin', $plugin_file ); |
|
839 | + do_action('delete_plugin', $plugin_file); |
|
840 | 840 | |
841 | - $this_plugin_dir = trailingslashit( dirname( $plugins_dir . $plugin_file ) ); |
|
841 | + $this_plugin_dir = trailingslashit(dirname($plugins_dir.$plugin_file)); |
|
842 | 842 | |
843 | 843 | // If plugin is in its own directory, recursively delete the directory. |
844 | - if ( strpos( $plugin_file, '/' ) && $this_plugin_dir != $plugins_dir ) { //base check on if plugin includes directory separator AND that it's not the root plugin folder |
|
845 | - $deleted = $wp_filesystem->delete( $this_plugin_dir, true ); |
|
844 | + if (strpos($plugin_file, '/') && $this_plugin_dir != $plugins_dir) { //base check on if plugin includes directory separator AND that it's not the root plugin folder |
|
845 | + $deleted = $wp_filesystem->delete($this_plugin_dir, true); |
|
846 | 846 | } else { |
847 | - $deleted = $wp_filesystem->delete( $plugins_dir . $plugin_file ); |
|
847 | + $deleted = $wp_filesystem->delete($plugins_dir.$plugin_file); |
|
848 | 848 | } |
849 | 849 | |
850 | 850 | /** |
@@ -855,39 +855,39 @@ discard block |
||
855 | 855 | * @param string $plugin_file Plugin file name. |
856 | 856 | * @param bool $deleted Whether the plugin deletion was successful. |
857 | 857 | */ |
858 | - do_action( 'deleted_plugin', $plugin_file, $deleted ); |
|
858 | + do_action('deleted_plugin', $plugin_file, $deleted); |
|
859 | 859 | |
860 | - if ( ! $deleted ) { |
|
860 | + if ( ! $deleted) { |
|
861 | 861 | $errors[] = $plugin_file; |
862 | 862 | continue; |
863 | 863 | } |
864 | 864 | |
865 | 865 | // Remove language files, silently. |
866 | - $plugin_slug = dirname( $plugin_file ); |
|
867 | - if ( '.' !== $plugin_slug && ! empty( $plugin_translations[ $plugin_slug ] ) ) { |
|
868 | - $translations = $plugin_translations[ $plugin_slug ]; |
|
866 | + $plugin_slug = dirname($plugin_file); |
|
867 | + if ('.' !== $plugin_slug && ! empty($plugin_translations[$plugin_slug])) { |
|
868 | + $translations = $plugin_translations[$plugin_slug]; |
|
869 | 869 | |
870 | - foreach ( $translations as $translation => $data ) { |
|
871 | - $wp_filesystem->delete( WP_LANG_DIR . '/plugins/' . $plugin_slug . '-' . $translation . '.po' ); |
|
872 | - $wp_filesystem->delete( WP_LANG_DIR . '/plugins/' . $plugin_slug . '-' . $translation . '.mo' ); |
|
870 | + foreach ($translations as $translation => $data) { |
|
871 | + $wp_filesystem->delete(WP_LANG_DIR.'/plugins/'.$plugin_slug.'-'.$translation.'.po'); |
|
872 | + $wp_filesystem->delete(WP_LANG_DIR.'/plugins/'.$plugin_slug.'-'.$translation.'.mo'); |
|
873 | 873 | } |
874 | 874 | } |
875 | 875 | } |
876 | 876 | |
877 | 877 | // Remove deleted plugins from the plugin updates list. |
878 | - if ( $current = get_site_transient('update_plugins') ) { |
|
878 | + if ($current = get_site_transient('update_plugins')) { |
|
879 | 879 | // Don't remove the plugins that weren't deleted. |
880 | - $deleted = array_diff( $plugins, $errors ); |
|
880 | + $deleted = array_diff($plugins, $errors); |
|
881 | 881 | |
882 | - foreach ( $deleted as $plugin_file ) { |
|
883 | - unset( $current->response[ $plugin_file ] ); |
|
882 | + foreach ($deleted as $plugin_file) { |
|
883 | + unset($current->response[$plugin_file]); |
|
884 | 884 | } |
885 | 885 | |
886 | - set_site_transient( 'update_plugins', $current ); |
|
886 | + set_site_transient('update_plugins', $current); |
|
887 | 887 | } |
888 | 888 | |
889 | - if ( ! empty($errors) ) |
|
890 | - return new WP_Error('could_not_remove_plugin', sprintf(__('Could not fully remove the plugin(s) %s.'), implode(', ', $errors)) ); |
|
889 | + if ( ! empty($errors)) |
|
890 | + return new WP_Error('could_not_remove_plugin', sprintf(__('Could not fully remove the plugin(s) %s.'), implode(', ', $errors))); |
|
891 | 891 | |
892 | 892 | return true; |
893 | 893 | } |
@@ -902,29 +902,29 @@ discard block |
||
902 | 902 | * @return array invalid plugins, plugin as key, error as value |
903 | 903 | */ |
904 | 904 | function validate_active_plugins() { |
905 | - $plugins = get_option( 'active_plugins', array() ); |
|
905 | + $plugins = get_option('active_plugins', array()); |
|
906 | 906 | // Validate vartype: array. |
907 | - if ( ! is_array( $plugins ) ) { |
|
908 | - update_option( 'active_plugins', array() ); |
|
907 | + if ( ! is_array($plugins)) { |
|
908 | + update_option('active_plugins', array()); |
|
909 | 909 | $plugins = array(); |
910 | 910 | } |
911 | 911 | |
912 | - if ( is_multisite() && current_user_can( 'manage_network_plugins' ) ) { |
|
913 | - $network_plugins = (array) get_site_option( 'active_sitewide_plugins', array() ); |
|
914 | - $plugins = array_merge( $plugins, array_keys( $network_plugins ) ); |
|
912 | + if (is_multisite() && current_user_can('manage_network_plugins')) { |
|
913 | + $network_plugins = (array) get_site_option('active_sitewide_plugins', array()); |
|
914 | + $plugins = array_merge($plugins, array_keys($network_plugins)); |
|
915 | 915 | } |
916 | 916 | |
917 | - if ( empty( $plugins ) ) |
|
917 | + if (empty($plugins)) |
|
918 | 918 | return array(); |
919 | 919 | |
920 | 920 | $invalid = array(); |
921 | 921 | |
922 | 922 | // Invalid plugins get deactivated. |
923 | - foreach ( $plugins as $plugin ) { |
|
924 | - $result = validate_plugin( $plugin ); |
|
925 | - if ( is_wp_error( $result ) ) { |
|
923 | + foreach ($plugins as $plugin) { |
|
924 | + $result = validate_plugin($plugin); |
|
925 | + if (is_wp_error($result)) { |
|
926 | 926 | $invalid[$plugin] = $result; |
927 | - deactivate_plugins( $plugin, true ); |
|
927 | + deactivate_plugins($plugin, true); |
|
928 | 928 | } |
929 | 929 | } |
930 | 930 | return $invalid; |
@@ -941,13 +941,13 @@ discard block |
||
941 | 941 | * @return WP_Error|int 0 on success, WP_Error on failure. |
942 | 942 | */ |
943 | 943 | function validate_plugin($plugin) { |
944 | - if ( validate_file($plugin) ) |
|
944 | + if (validate_file($plugin)) |
|
945 | 945 | return new WP_Error('plugin_invalid', __('Invalid plugin path.')); |
946 | - if ( ! file_exists(WP_PLUGIN_DIR . '/' . $plugin) ) |
|
946 | + if ( ! file_exists(WP_PLUGIN_DIR.'/'.$plugin)) |
|
947 | 947 | return new WP_Error('plugin_not_found', __('Plugin file does not exist.')); |
948 | 948 | |
949 | 949 | $installed_plugins = get_plugins(); |
950 | - if ( ! isset($installed_plugins[$plugin]) ) |
|
950 | + if ( ! isset($installed_plugins[$plugin])) |
|
951 | 951 | return new WP_Error('no_plugin_header', __('The plugin does not have a valid header.')); |
952 | 952 | return 0; |
953 | 953 | } |
@@ -964,7 +964,7 @@ discard block |
||
964 | 964 | $file = plugin_basename($plugin); |
965 | 965 | |
966 | 966 | $uninstallable_plugins = (array) get_option('uninstall_plugins'); |
967 | - if ( isset( $uninstallable_plugins[$file] ) || file_exists( WP_PLUGIN_DIR . '/' . dirname($file) . '/uninstall.php' ) ) |
|
967 | + if (isset($uninstallable_plugins[$file]) || file_exists(WP_PLUGIN_DIR.'/'.dirname($file).'/uninstall.php')) |
|
968 | 968 | return true; |
969 | 969 | |
970 | 970 | return false; |
@@ -993,32 +993,32 @@ discard block |
||
993 | 993 | * @param string $plugin Relative plugin path from plugin directory. |
994 | 994 | * @param array $uninstallable_plugins Uninstallable plugins. |
995 | 995 | */ |
996 | - do_action( 'pre_uninstall_plugin', $plugin, $uninstallable_plugins ); |
|
996 | + do_action('pre_uninstall_plugin', $plugin, $uninstallable_plugins); |
|
997 | 997 | |
998 | - if ( file_exists( WP_PLUGIN_DIR . '/' . dirname($file) . '/uninstall.php' ) ) { |
|
999 | - if ( isset( $uninstallable_plugins[$file] ) ) { |
|
998 | + if (file_exists(WP_PLUGIN_DIR.'/'.dirname($file).'/uninstall.php')) { |
|
999 | + if (isset($uninstallable_plugins[$file])) { |
|
1000 | 1000 | unset($uninstallable_plugins[$file]); |
1001 | 1001 | update_option('uninstall_plugins', $uninstallable_plugins); |
1002 | 1002 | } |
1003 | 1003 | unset($uninstallable_plugins); |
1004 | 1004 | |
1005 | 1005 | define('WP_UNINSTALL_PLUGIN', $file); |
1006 | - wp_register_plugin_realpath( WP_PLUGIN_DIR . '/' . dirname( $file ) ); |
|
1007 | - include( WP_PLUGIN_DIR . '/' . dirname($file) . '/uninstall.php' ); |
|
1006 | + wp_register_plugin_realpath(WP_PLUGIN_DIR.'/'.dirname($file)); |
|
1007 | + include(WP_PLUGIN_DIR.'/'.dirname($file).'/uninstall.php'); |
|
1008 | 1008 | |
1009 | 1009 | return true; |
1010 | 1010 | } |
1011 | 1011 | |
1012 | - if ( isset( $uninstallable_plugins[$file] ) ) { |
|
1012 | + if (isset($uninstallable_plugins[$file])) { |
|
1013 | 1013 | $callable = $uninstallable_plugins[$file]; |
1014 | 1014 | unset($uninstallable_plugins[$file]); |
1015 | 1015 | update_option('uninstall_plugins', $uninstallable_plugins); |
1016 | 1016 | unset($uninstallable_plugins); |
1017 | 1017 | |
1018 | - wp_register_plugin_realpath( WP_PLUGIN_DIR . '/' . $file ); |
|
1019 | - include( WP_PLUGIN_DIR . '/' . $file ); |
|
1018 | + wp_register_plugin_realpath(WP_PLUGIN_DIR.'/'.$file); |
|
1019 | + include(WP_PLUGIN_DIR.'/'.$file); |
|
1020 | 1020 | |
1021 | - add_action( 'uninstall_' . $file, $callable ); |
|
1021 | + add_action('uninstall_'.$file, $callable); |
|
1022 | 1022 | |
1023 | 1023 | /** |
1024 | 1024 | * Fires in uninstall_plugin() once the plugin has been uninstalled. |
@@ -1028,7 +1028,7 @@ discard block |
||
1028 | 1028 | * |
1029 | 1029 | * @since 2.7.0 |
1030 | 1030 | */ |
1031 | - do_action( 'uninstall_' . $file ); |
|
1031 | + do_action('uninstall_'.$file); |
|
1032 | 1032 | } |
1033 | 1033 | } |
1034 | 1034 | |
@@ -1064,35 +1064,35 @@ discard block |
||
1064 | 1064 | * @param int $position The position in the menu order this one should appear. |
1065 | 1065 | * @return string The resulting page's hook_suffix. |
1066 | 1066 | */ |
1067 | -function add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $icon_url = '', $position = null ) { |
|
1067 | +function add_menu_page($page_title, $menu_title, $capability, $menu_slug, $function = '', $icon_url = '', $position = null) { |
|
1068 | 1068 | global $menu, $admin_page_hooks, $_registered_pages, $_parent_pages; |
1069 | 1069 | |
1070 | - $menu_slug = plugin_basename( $menu_slug ); |
|
1070 | + $menu_slug = plugin_basename($menu_slug); |
|
1071 | 1071 | |
1072 | - $admin_page_hooks[$menu_slug] = sanitize_title( $menu_title ); |
|
1072 | + $admin_page_hooks[$menu_slug] = sanitize_title($menu_title); |
|
1073 | 1073 | |
1074 | - $hookname = get_plugin_page_hookname( $menu_slug, '' ); |
|
1074 | + $hookname = get_plugin_page_hookname($menu_slug, ''); |
|
1075 | 1075 | |
1076 | - if ( !empty( $function ) && !empty( $hookname ) && current_user_can( $capability ) ) |
|
1077 | - add_action( $hookname, $function ); |
|
1076 | + if ( ! empty($function) && ! empty($hookname) && current_user_can($capability)) |
|
1077 | + add_action($hookname, $function); |
|
1078 | 1078 | |
1079 | - if ( empty($icon_url) ) { |
|
1079 | + if (empty($icon_url)) { |
|
1080 | 1080 | $icon_url = 'dashicons-admin-generic'; |
1081 | 1081 | $icon_class = 'menu-icon-generic '; |
1082 | 1082 | } else { |
1083 | - $icon_url = set_url_scheme( $icon_url ); |
|
1083 | + $icon_url = set_url_scheme($icon_url); |
|
1084 | 1084 | $icon_class = ''; |
1085 | 1085 | } |
1086 | 1086 | |
1087 | - $new_menu = array( $menu_title, $capability, $menu_slug, $page_title, 'menu-top ' . $icon_class . $hookname, $hookname, $icon_url ); |
|
1087 | + $new_menu = array($menu_title, $capability, $menu_slug, $page_title, 'menu-top '.$icon_class.$hookname, $hookname, $icon_url); |
|
1088 | 1088 | |
1089 | - if ( null === $position ) { |
|
1089 | + if (null === $position) { |
|
1090 | 1090 | $menu[] = $new_menu; |
1091 | - } elseif ( isset( $menu[ "$position" ] ) ) { |
|
1092 | - $position = $position + substr( base_convert( md5( $menu_slug . $menu_title ), 16, 10 ) , -5 ) * 0.00001; |
|
1093 | - $menu[ "$position" ] = $new_menu; |
|
1091 | + } elseif (isset($menu["$position"])) { |
|
1092 | + $position = $position + substr(base_convert(md5($menu_slug.$menu_title), 16, 10), -5) * 0.00001; |
|
1093 | + $menu["$position"] = $new_menu; |
|
1094 | 1094 | } else { |
1095 | - $menu[ $position ] = $new_menu; |
|
1095 | + $menu[$position] = $new_menu; |
|
1096 | 1096 | } |
1097 | 1097 | |
1098 | 1098 | $_registered_pages[$hookname] = true; |
@@ -1127,17 +1127,17 @@ discard block |
||
1127 | 1127 | * @param callable $function The function to be called to output the content for this page. |
1128 | 1128 | * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required. |
1129 | 1129 | */ |
1130 | -function add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { |
|
1130 | +function add_submenu_page($parent_slug, $page_title, $menu_title, $capability, $menu_slug, $function = '') { |
|
1131 | 1131 | global $submenu, $menu, $_wp_real_parent_file, $_wp_submenu_nopriv, |
1132 | 1132 | $_registered_pages, $_parent_pages; |
1133 | 1133 | |
1134 | - $menu_slug = plugin_basename( $menu_slug ); |
|
1135 | - $parent_slug = plugin_basename( $parent_slug); |
|
1134 | + $menu_slug = plugin_basename($menu_slug); |
|
1135 | + $parent_slug = plugin_basename($parent_slug); |
|
1136 | 1136 | |
1137 | - if ( isset( $_wp_real_parent_file[$parent_slug] ) ) |
|
1137 | + if (isset($_wp_real_parent_file[$parent_slug])) |
|
1138 | 1138 | $parent_slug = $_wp_real_parent_file[$parent_slug]; |
1139 | 1139 | |
1140 | - if ( !current_user_can( $capability ) ) { |
|
1140 | + if ( ! current_user_can($capability)) { |
|
1141 | 1141 | $_wp_submenu_nopriv[$parent_slug][$menu_slug] = true; |
1142 | 1142 | return false; |
1143 | 1143 | } |
@@ -1148,18 +1148,18 @@ discard block |
||
1148 | 1148 | * parent file someone is trying to link back to the parent manually. In |
1149 | 1149 | * this case, don't automatically add a link back to avoid duplication. |
1150 | 1150 | */ |
1151 | - if (!isset( $submenu[$parent_slug] ) && $menu_slug != $parent_slug ) { |
|
1152 | - foreach ( (array)$menu as $parent_menu ) { |
|
1153 | - if ( $parent_menu[2] == $parent_slug && current_user_can( $parent_menu[1] ) ) |
|
1154 | - $submenu[$parent_slug][] = array_slice( $parent_menu, 0, 4 ); |
|
1151 | + if ( ! isset($submenu[$parent_slug]) && $menu_slug != $parent_slug) { |
|
1152 | + foreach ((array) $menu as $parent_menu) { |
|
1153 | + if ($parent_menu[2] == $parent_slug && current_user_can($parent_menu[1])) |
|
1154 | + $submenu[$parent_slug][] = array_slice($parent_menu, 0, 4); |
|
1155 | 1155 | } |
1156 | 1156 | } |
1157 | 1157 | |
1158 | - $submenu[$parent_slug][] = array ( $menu_title, $capability, $menu_slug, $page_title ); |
|
1158 | + $submenu[$parent_slug][] = array($menu_title, $capability, $menu_slug, $page_title); |
|
1159 | 1159 | |
1160 | - $hookname = get_plugin_page_hookname( $menu_slug, $parent_slug); |
|
1161 | - if (!empty ( $function ) && !empty ( $hookname )) |
|
1162 | - add_action( $hookname, $function ); |
|
1160 | + $hookname = get_plugin_page_hookname($menu_slug, $parent_slug); |
|
1161 | + if ( ! empty ($function) && ! empty ($hookname)) |
|
1162 | + add_action($hookname, $function); |
|
1163 | 1163 | |
1164 | 1164 | $_registered_pages[$hookname] = true; |
1165 | 1165 | |
@@ -1167,8 +1167,8 @@ discard block |
||
1167 | 1167 | * Backward-compatibility for plugins using add_management page. |
1168 | 1168 | * See wp-admin/admin.php for redirect from edit.php to tools.php |
1169 | 1169 | */ |
1170 | - if ( 'tools.php' == $parent_slug ) |
|
1171 | - $_registered_pages[get_plugin_page_hookname( $menu_slug, 'edit.php')] = true; |
|
1170 | + if ('tools.php' == $parent_slug) |
|
1171 | + $_registered_pages[get_plugin_page_hookname($menu_slug, 'edit.php')] = true; |
|
1172 | 1172 | |
1173 | 1173 | // No parent as top level. |
1174 | 1174 | $_parent_pages[$menu_slug] = $parent_slug; |
@@ -1192,8 +1192,8 @@ discard block |
||
1192 | 1192 | * @param callable $function The function to be called to output the content for this page. |
1193 | 1193 | * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required. |
1194 | 1194 | */ |
1195 | -function add_management_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { |
|
1196 | - return add_submenu_page( 'tools.php', $page_title, $menu_title, $capability, $menu_slug, $function ); |
|
1195 | +function add_management_page($page_title, $menu_title, $capability, $menu_slug, $function = '') { |
|
1196 | + return add_submenu_page('tools.php', $page_title, $menu_title, $capability, $menu_slug, $function); |
|
1197 | 1197 | } |
1198 | 1198 | |
1199 | 1199 | /** |
@@ -1212,8 +1212,8 @@ discard block |
||
1212 | 1212 | * @param callable $function The function to be called to output the content for this page. |
1213 | 1213 | * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required. |
1214 | 1214 | */ |
1215 | -function add_options_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { |
|
1216 | - return add_submenu_page( 'options-general.php', $page_title, $menu_title, $capability, $menu_slug, $function ); |
|
1215 | +function add_options_page($page_title, $menu_title, $capability, $menu_slug, $function = '') { |
|
1216 | + return add_submenu_page('options-general.php', $page_title, $menu_title, $capability, $menu_slug, $function); |
|
1217 | 1217 | } |
1218 | 1218 | |
1219 | 1219 | /** |
@@ -1232,8 +1232,8 @@ discard block |
||
1232 | 1232 | * @param callable $function The function to be called to output the content for this page. |
1233 | 1233 | * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required. |
1234 | 1234 | */ |
1235 | -function add_theme_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { |
|
1236 | - return add_submenu_page( 'themes.php', $page_title, $menu_title, $capability, $menu_slug, $function ); |
|
1235 | +function add_theme_page($page_title, $menu_title, $capability, $menu_slug, $function = '') { |
|
1236 | + return add_submenu_page('themes.php', $page_title, $menu_title, $capability, $menu_slug, $function); |
|
1237 | 1237 | } |
1238 | 1238 | |
1239 | 1239 | /** |
@@ -1252,8 +1252,8 @@ discard block |
||
1252 | 1252 | * @param callable $function The function to be called to output the content for this page. |
1253 | 1253 | * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required. |
1254 | 1254 | */ |
1255 | -function add_plugins_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { |
|
1256 | - return add_submenu_page( 'plugins.php', $page_title, $menu_title, $capability, $menu_slug, $function ); |
|
1255 | +function add_plugins_page($page_title, $menu_title, $capability, $menu_slug, $function = '') { |
|
1256 | + return add_submenu_page('plugins.php', $page_title, $menu_title, $capability, $menu_slug, $function); |
|
1257 | 1257 | } |
1258 | 1258 | |
1259 | 1259 | /** |
@@ -1272,12 +1272,12 @@ discard block |
||
1272 | 1272 | * @param callable $function The function to be called to output the content for this page. |
1273 | 1273 | * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required. |
1274 | 1274 | */ |
1275 | -function add_users_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { |
|
1276 | - if ( current_user_can('edit_users') ) |
|
1275 | +function add_users_page($page_title, $menu_title, $capability, $menu_slug, $function = '') { |
|
1276 | + if (current_user_can('edit_users')) |
|
1277 | 1277 | $parent = 'users.php'; |
1278 | 1278 | else |
1279 | 1279 | $parent = 'profile.php'; |
1280 | - return add_submenu_page( $parent, $page_title, $menu_title, $capability, $menu_slug, $function ); |
|
1280 | + return add_submenu_page($parent, $page_title, $menu_title, $capability, $menu_slug, $function); |
|
1281 | 1281 | } |
1282 | 1282 | /** |
1283 | 1283 | * Add submenu page to the Dashboard main menu. |
@@ -1295,8 +1295,8 @@ discard block |
||
1295 | 1295 | * @param callable $function The function to be called to output the content for this page. |
1296 | 1296 | * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required. |
1297 | 1297 | */ |
1298 | -function add_dashboard_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { |
|
1299 | - return add_submenu_page( 'index.php', $page_title, $menu_title, $capability, $menu_slug, $function ); |
|
1298 | +function add_dashboard_page($page_title, $menu_title, $capability, $menu_slug, $function = '') { |
|
1299 | + return add_submenu_page('index.php', $page_title, $menu_title, $capability, $menu_slug, $function); |
|
1300 | 1300 | } |
1301 | 1301 | |
1302 | 1302 | /** |
@@ -1315,8 +1315,8 @@ discard block |
||
1315 | 1315 | * @param callable $function The function to be called to output the content for this page. |
1316 | 1316 | * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required. |
1317 | 1317 | */ |
1318 | -function add_posts_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { |
|
1319 | - return add_submenu_page( 'edit.php', $page_title, $menu_title, $capability, $menu_slug, $function ); |
|
1318 | +function add_posts_page($page_title, $menu_title, $capability, $menu_slug, $function = '') { |
|
1319 | + return add_submenu_page('edit.php', $page_title, $menu_title, $capability, $menu_slug, $function); |
|
1320 | 1320 | } |
1321 | 1321 | |
1322 | 1322 | /** |
@@ -1335,8 +1335,8 @@ discard block |
||
1335 | 1335 | * @param callable $function The function to be called to output the content for this page. |
1336 | 1336 | * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required. |
1337 | 1337 | */ |
1338 | -function add_media_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { |
|
1339 | - return add_submenu_page( 'upload.php', $page_title, $menu_title, $capability, $menu_slug, $function ); |
|
1338 | +function add_media_page($page_title, $menu_title, $capability, $menu_slug, $function = '') { |
|
1339 | + return add_submenu_page('upload.php', $page_title, $menu_title, $capability, $menu_slug, $function); |
|
1340 | 1340 | } |
1341 | 1341 | |
1342 | 1342 | /** |
@@ -1355,8 +1355,8 @@ discard block |
||
1355 | 1355 | * @param callable $function The function to be called to output the content for this page. |
1356 | 1356 | * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required. |
1357 | 1357 | */ |
1358 | -function add_links_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { |
|
1359 | - return add_submenu_page( 'link-manager.php', $page_title, $menu_title, $capability, $menu_slug, $function ); |
|
1358 | +function add_links_page($page_title, $menu_title, $capability, $menu_slug, $function = '') { |
|
1359 | + return add_submenu_page('link-manager.php', $page_title, $menu_title, $capability, $menu_slug, $function); |
|
1360 | 1360 | } |
1361 | 1361 | |
1362 | 1362 | /** |
@@ -1375,8 +1375,8 @@ discard block |
||
1375 | 1375 | * @param callable $function The function to be called to output the content for this page. |
1376 | 1376 | * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required. |
1377 | 1377 | */ |
1378 | -function add_pages_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { |
|
1379 | - return add_submenu_page( 'edit.php?post_type=page', $page_title, $menu_title, $capability, $menu_slug, $function ); |
|
1378 | +function add_pages_page($page_title, $menu_title, $capability, $menu_slug, $function = '') { |
|
1379 | + return add_submenu_page('edit.php?post_type=page', $page_title, $menu_title, $capability, $menu_slug, $function); |
|
1380 | 1380 | } |
1381 | 1381 | |
1382 | 1382 | /** |
@@ -1395,8 +1395,8 @@ discard block |
||
1395 | 1395 | * @param callable $function The function to be called to output the content for this page. |
1396 | 1396 | * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required. |
1397 | 1397 | */ |
1398 | -function add_comments_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { |
|
1399 | - return add_submenu_page( 'edit-comments.php', $page_title, $menu_title, $capability, $menu_slug, $function ); |
|
1398 | +function add_comments_page($page_title, $menu_title, $capability, $menu_slug, $function = '') { |
|
1399 | + return add_submenu_page('edit-comments.php', $page_title, $menu_title, $capability, $menu_slug, $function); |
|
1400 | 1400 | } |
1401 | 1401 | |
1402 | 1402 | /** |
@@ -1409,12 +1409,12 @@ discard block |
||
1409 | 1409 | * @param string $menu_slug The slug of the menu. |
1410 | 1410 | * @return array|bool The removed menu on success, false if not found. |
1411 | 1411 | */ |
1412 | -function remove_menu_page( $menu_slug ) { |
|
1412 | +function remove_menu_page($menu_slug) { |
|
1413 | 1413 | global $menu; |
1414 | 1414 | |
1415 | - foreach ( $menu as $i => $item ) { |
|
1416 | - if ( $menu_slug == $item[2] ) { |
|
1417 | - unset( $menu[$i] ); |
|
1415 | + foreach ($menu as $i => $item) { |
|
1416 | + if ($menu_slug == $item[2]) { |
|
1417 | + unset($menu[$i]); |
|
1418 | 1418 | return $item; |
1419 | 1419 | } |
1420 | 1420 | } |
@@ -1433,15 +1433,15 @@ discard block |
||
1433 | 1433 | * @param string $submenu_slug The slug of the submenu. |
1434 | 1434 | * @return array|bool The removed submenu on success, false if not found. |
1435 | 1435 | */ |
1436 | -function remove_submenu_page( $menu_slug, $submenu_slug ) { |
|
1436 | +function remove_submenu_page($menu_slug, $submenu_slug) { |
|
1437 | 1437 | global $submenu; |
1438 | 1438 | |
1439 | - if ( !isset( $submenu[$menu_slug] ) ) |
|
1439 | + if ( ! isset($submenu[$menu_slug])) |
|
1440 | 1440 | return false; |
1441 | 1441 | |
1442 | - foreach ( $submenu[$menu_slug] as $i => $item ) { |
|
1443 | - if ( $submenu_slug == $item[2] ) { |
|
1444 | - unset( $submenu[$menu_slug][$i] ); |
|
1442 | + foreach ($submenu[$menu_slug] as $i => $item) { |
|
1443 | + if ($submenu_slug == $item[2]) { |
|
1444 | + unset($submenu[$menu_slug][$i]); |
|
1445 | 1445 | return $item; |
1446 | 1446 | } |
1447 | 1447 | } |
@@ -1465,12 +1465,12 @@ discard block |
||
1465 | 1465 | function menu_page_url($menu_slug, $echo = true) { |
1466 | 1466 | global $_parent_pages; |
1467 | 1467 | |
1468 | - if ( isset( $_parent_pages[$menu_slug] ) ) { |
|
1468 | + if (isset($_parent_pages[$menu_slug])) { |
|
1469 | 1469 | $parent_slug = $_parent_pages[$menu_slug]; |
1470 | - if ( $parent_slug && ! isset( $_parent_pages[$parent_slug] ) ) { |
|
1471 | - $url = admin_url( add_query_arg( 'page', $menu_slug, $parent_slug ) ); |
|
1470 | + if ($parent_slug && ! isset($_parent_pages[$parent_slug])) { |
|
1471 | + $url = admin_url(add_query_arg('page', $menu_slug, $parent_slug)); |
|
1472 | 1472 | } else { |
1473 | - $url = admin_url( 'admin.php?page=' . $menu_slug ); |
|
1473 | + $url = admin_url('admin.php?page='.$menu_slug); |
|
1474 | 1474 | } |
1475 | 1475 | } else { |
1476 | 1476 | $url = ''; |
@@ -1478,7 +1478,7 @@ discard block |
||
1478 | 1478 | |
1479 | 1479 | $url = esc_url($url); |
1480 | 1480 | |
1481 | - if ( $echo ) |
|
1481 | + if ($echo) |
|
1482 | 1482 | echo $url; |
1483 | 1483 | |
1484 | 1484 | return $url; |
@@ -1499,58 +1499,58 @@ discard block |
||
1499 | 1499 | * @global array $_wp_menu_nopriv |
1500 | 1500 | * @global array $_wp_submenu_nopriv |
1501 | 1501 | */ |
1502 | -function get_admin_page_parent( $parent = '' ) { |
|
1502 | +function get_admin_page_parent($parent = '') { |
|
1503 | 1503 | global $parent_file, $menu, $submenu, $pagenow, $typenow, |
1504 | 1504 | $plugin_page, $_wp_real_parent_file, $_wp_menu_nopriv, $_wp_submenu_nopriv; |
1505 | 1505 | |
1506 | - if ( !empty ( $parent ) && 'admin.php' != $parent ) { |
|
1507 | - if ( isset( $_wp_real_parent_file[$parent] ) ) |
|
1506 | + if ( ! empty ($parent) && 'admin.php' != $parent) { |
|
1507 | + if (isset($_wp_real_parent_file[$parent])) |
|
1508 | 1508 | $parent = $_wp_real_parent_file[$parent]; |
1509 | 1509 | return $parent; |
1510 | 1510 | } |
1511 | 1511 | |
1512 | - if ( $pagenow == 'admin.php' && isset( $plugin_page ) ) { |
|
1513 | - foreach ( (array)$menu as $parent_menu ) { |
|
1514 | - if ( $parent_menu[2] == $plugin_page ) { |
|
1512 | + if ($pagenow == 'admin.php' && isset($plugin_page)) { |
|
1513 | + foreach ((array) $menu as $parent_menu) { |
|
1514 | + if ($parent_menu[2] == $plugin_page) { |
|
1515 | 1515 | $parent_file = $plugin_page; |
1516 | - if ( isset( $_wp_real_parent_file[$parent_file] ) ) |
|
1516 | + if (isset($_wp_real_parent_file[$parent_file])) |
|
1517 | 1517 | $parent_file = $_wp_real_parent_file[$parent_file]; |
1518 | 1518 | return $parent_file; |
1519 | 1519 | } |
1520 | 1520 | } |
1521 | - if ( isset( $_wp_menu_nopriv[$plugin_page] ) ) { |
|
1521 | + if (isset($_wp_menu_nopriv[$plugin_page])) { |
|
1522 | 1522 | $parent_file = $plugin_page; |
1523 | - if ( isset( $_wp_real_parent_file[$parent_file] ) ) |
|
1523 | + if (isset($_wp_real_parent_file[$parent_file])) |
|
1524 | 1524 | $parent_file = $_wp_real_parent_file[$parent_file]; |
1525 | 1525 | return $parent_file; |
1526 | 1526 | } |
1527 | 1527 | } |
1528 | 1528 | |
1529 | - if ( isset( $plugin_page ) && isset( $_wp_submenu_nopriv[$pagenow][$plugin_page] ) ) { |
|
1529 | + if (isset($plugin_page) && isset($_wp_submenu_nopriv[$pagenow][$plugin_page])) { |
|
1530 | 1530 | $parent_file = $pagenow; |
1531 | - if ( isset( $_wp_real_parent_file[$parent_file] ) ) |
|
1531 | + if (isset($_wp_real_parent_file[$parent_file])) |
|
1532 | 1532 | $parent_file = $_wp_real_parent_file[$parent_file]; |
1533 | 1533 | return $parent_file; |
1534 | 1534 | } |
1535 | 1535 | |
1536 | - foreach (array_keys( (array)$submenu ) as $parent) { |
|
1537 | - foreach ( $submenu[$parent] as $submenu_array ) { |
|
1538 | - if ( isset( $_wp_real_parent_file[$parent] ) ) |
|
1536 | + foreach (array_keys((array) $submenu) as $parent) { |
|
1537 | + foreach ($submenu[$parent] as $submenu_array) { |
|
1538 | + if (isset($_wp_real_parent_file[$parent])) |
|
1539 | 1539 | $parent = $_wp_real_parent_file[$parent]; |
1540 | - if ( !empty($typenow) && ($submenu_array[2] == "$pagenow?post_type=$typenow") ) { |
|
1540 | + if ( ! empty($typenow) && ($submenu_array[2] == "$pagenow?post_type=$typenow")) { |
|
1541 | 1541 | $parent_file = $parent; |
1542 | 1542 | return $parent; |
1543 | - } elseif ( $submenu_array[2] == $pagenow && empty($typenow) && ( empty($parent_file) || false === strpos($parent_file, '?') ) ) { |
|
1543 | + } elseif ($submenu_array[2] == $pagenow && empty($typenow) && (empty($parent_file) || false === strpos($parent_file, '?'))) { |
|
1544 | 1544 | $parent_file = $parent; |
1545 | 1545 | return $parent; |
1546 | - } elseif ( isset( $plugin_page ) && ($plugin_page == $submenu_array[2] ) ) { |
|
1546 | + } elseif (isset($plugin_page) && ($plugin_page == $submenu_array[2])) { |
|
1547 | 1547 | $parent_file = $parent; |
1548 | 1548 | return $parent; |
1549 | 1549 | } |
1550 | 1550 | } |
1551 | 1551 | } |
1552 | 1552 | |
1553 | - if ( empty($parent_file) ) |
|
1553 | + if (empty($parent_file)) |
|
1554 | 1554 | $parent_file = ''; |
1555 | 1555 | return ''; |
1556 | 1556 | } |
@@ -1567,20 +1567,20 @@ discard block |
||
1567 | 1567 | function get_admin_page_title() { |
1568 | 1568 | global $title, $menu, $submenu, $pagenow, $plugin_page, $typenow; |
1569 | 1569 | |
1570 | - if ( ! empty ( $title ) ) |
|
1570 | + if ( ! empty ($title)) |
|
1571 | 1571 | return $title; |
1572 | 1572 | |
1573 | - $hook = get_plugin_page_hook( $plugin_page, $pagenow ); |
|
1573 | + $hook = get_plugin_page_hook($plugin_page, $pagenow); |
|
1574 | 1574 | |
1575 | 1575 | $parent = $parent1 = get_admin_page_parent(); |
1576 | 1576 | |
1577 | - if ( empty ( $parent) ) { |
|
1578 | - foreach ( (array)$menu as $menu_array ) { |
|
1579 | - if ( isset( $menu_array[3] ) ) { |
|
1580 | - if ( $menu_array[2] == $pagenow ) { |
|
1577 | + if (empty ($parent)) { |
|
1578 | + foreach ((array) $menu as $menu_array) { |
|
1579 | + if (isset($menu_array[3])) { |
|
1580 | + if ($menu_array[2] == $pagenow) { |
|
1581 | 1581 | $title = $menu_array[3]; |
1582 | 1582 | return $menu_array[3]; |
1583 | - } elseif ( isset( $plugin_page ) && ($plugin_page == $menu_array[2] ) && ($hook == $menu_array[3] ) ) { |
|
1583 | + } elseif (isset($plugin_page) && ($plugin_page == $menu_array[2]) && ($hook == $menu_array[3])) { |
|
1584 | 1584 | $title = $menu_array[3]; |
1585 | 1585 | return $menu_array[3]; |
1586 | 1586 | } |
@@ -1590,26 +1590,26 @@ discard block |
||
1590 | 1590 | } |
1591 | 1591 | } |
1592 | 1592 | } else { |
1593 | - foreach ( array_keys( $submenu ) as $parent ) { |
|
1594 | - foreach ( $submenu[$parent] as $submenu_array ) { |
|
1595 | - if ( isset( $plugin_page ) && |
|
1596 | - ( $plugin_page == $submenu_array[2] ) && |
|
1593 | + foreach (array_keys($submenu) as $parent) { |
|
1594 | + foreach ($submenu[$parent] as $submenu_array) { |
|
1595 | + if (isset($plugin_page) && |
|
1596 | + ($plugin_page == $submenu_array[2]) && |
|
1597 | 1597 | ( |
1598 | - ( $parent == $pagenow ) || |
|
1599 | - ( $parent == $plugin_page ) || |
|
1600 | - ( $plugin_page == $hook ) || |
|
1601 | - ( $pagenow == 'admin.php' && $parent1 != $submenu_array[2] ) || |
|
1602 | - ( !empty($typenow) && $parent == $pagenow . '?post_type=' . $typenow) |
|
1598 | + ($parent == $pagenow) || |
|
1599 | + ($parent == $plugin_page) || |
|
1600 | + ($plugin_page == $hook) || |
|
1601 | + ($pagenow == 'admin.php' && $parent1 != $submenu_array[2]) || |
|
1602 | + ( ! empty($typenow) && $parent == $pagenow.'?post_type='.$typenow) |
|
1603 | 1603 | ) |
1604 | 1604 | ) { |
1605 | 1605 | $title = $submenu_array[3]; |
1606 | 1606 | return $submenu_array[3]; |
1607 | 1607 | } |
1608 | 1608 | |
1609 | - if ( $submenu_array[2] != $pagenow || isset( $_GET['page'] ) ) // not the current page |
|
1609 | + if ($submenu_array[2] != $pagenow || isset($_GET['page'])) // not the current page |
|
1610 | 1610 | continue; |
1611 | 1611 | |
1612 | - if ( isset( $submenu_array[3] ) ) { |
|
1612 | + if (isset($submenu_array[3])) { |
|
1613 | 1613 | $title = $submenu_array[3]; |
1614 | 1614 | return $submenu_array[3]; |
1615 | 1615 | } else { |
@@ -1618,12 +1618,12 @@ discard block |
||
1618 | 1618 | } |
1619 | 1619 | } |
1620 | 1620 | } |
1621 | - if ( empty ( $title ) ) { |
|
1622 | - foreach ( $menu as $menu_array ) { |
|
1623 | - if ( isset( $plugin_page ) && |
|
1624 | - ( $plugin_page == $menu_array[2] ) && |
|
1625 | - ( $pagenow == 'admin.php' ) && |
|
1626 | - ( $parent1 == $menu_array[2] ) ) |
|
1621 | + if (empty ($title)) { |
|
1622 | + foreach ($menu as $menu_array) { |
|
1623 | + if (isset($plugin_page) && |
|
1624 | + ($plugin_page == $menu_array[2]) && |
|
1625 | + ($pagenow == 'admin.php') && |
|
1626 | + ($parent1 == $menu_array[2])) |
|
1627 | 1627 | { |
1628 | 1628 | $title = $menu_array[3]; |
1629 | 1629 | return $menu_array[3]; |
@@ -1642,9 +1642,9 @@ discard block |
||
1642 | 1642 | * @param string $parent_page |
1643 | 1643 | * @return string|null |
1644 | 1644 | */ |
1645 | -function get_plugin_page_hook( $plugin_page, $parent_page ) { |
|
1646 | - $hook = get_plugin_page_hookname( $plugin_page, $parent_page ); |
|
1647 | - if ( has_action($hook) ) |
|
1645 | +function get_plugin_page_hook($plugin_page, $parent_page) { |
|
1646 | + $hook = get_plugin_page_hookname($plugin_page, $parent_page); |
|
1647 | + if (has_action($hook)) |
|
1648 | 1648 | return $hook; |
1649 | 1649 | else |
1650 | 1650 | return null; |
@@ -1656,25 +1656,25 @@ discard block |
||
1656 | 1656 | * @param string $plugin_page |
1657 | 1657 | * @param string $parent_page |
1658 | 1658 | */ |
1659 | -function get_plugin_page_hookname( $plugin_page, $parent_page ) { |
|
1659 | +function get_plugin_page_hookname($plugin_page, $parent_page) { |
|
1660 | 1660 | global $admin_page_hooks; |
1661 | 1661 | |
1662 | - $parent = get_admin_page_parent( $parent_page ); |
|
1662 | + $parent = get_admin_page_parent($parent_page); |
|
1663 | 1663 | |
1664 | 1664 | $page_type = 'admin'; |
1665 | - if ( empty ( $parent_page ) || 'admin.php' == $parent_page || isset( $admin_page_hooks[$plugin_page] ) ) { |
|
1666 | - if ( isset( $admin_page_hooks[$plugin_page] ) ) { |
|
1665 | + if (empty ($parent_page) || 'admin.php' == $parent_page || isset($admin_page_hooks[$plugin_page])) { |
|
1666 | + if (isset($admin_page_hooks[$plugin_page])) { |
|
1667 | 1667 | $page_type = 'toplevel'; |
1668 | - } elseif ( isset( $admin_page_hooks[$parent] )) { |
|
1668 | + } elseif (isset($admin_page_hooks[$parent])) { |
|
1669 | 1669 | $page_type = $admin_page_hooks[$parent]; |
1670 | 1670 | } |
1671 | - } elseif ( isset( $admin_page_hooks[$parent] ) ) { |
|
1671 | + } elseif (isset($admin_page_hooks[$parent])) { |
|
1672 | 1672 | $page_type = $admin_page_hooks[$parent]; |
1673 | 1673 | } |
1674 | 1674 | |
1675 | - $plugin_name = preg_replace( '!\.php!', '', $plugin_page ); |
|
1675 | + $plugin_name = preg_replace('!\.php!', '', $plugin_page); |
|
1676 | 1676 | |
1677 | - return $page_type . '_page_' . $plugin_name; |
|
1677 | + return $page_type.'_page_'.$plugin_name; |
|
1678 | 1678 | } |
1679 | 1679 | |
1680 | 1680 | /** |
@@ -1693,49 +1693,49 @@ discard block |
||
1693 | 1693 | |
1694 | 1694 | $parent = get_admin_page_parent(); |
1695 | 1695 | |
1696 | - if ( !isset( $plugin_page ) && isset( $_wp_submenu_nopriv[$parent][$pagenow] ) ) |
|
1696 | + if ( ! isset($plugin_page) && isset($_wp_submenu_nopriv[$parent][$pagenow])) |
|
1697 | 1697 | return false; |
1698 | 1698 | |
1699 | - if ( isset( $plugin_page ) ) { |
|
1700 | - if ( isset( $_wp_submenu_nopriv[$parent][$plugin_page] ) ) |
|
1699 | + if (isset($plugin_page)) { |
|
1700 | + if (isset($_wp_submenu_nopriv[$parent][$plugin_page])) |
|
1701 | 1701 | return false; |
1702 | 1702 | |
1703 | 1703 | $hookname = get_plugin_page_hookname($plugin_page, $parent); |
1704 | 1704 | |
1705 | - if ( !isset($_registered_pages[$hookname]) ) |
|
1705 | + if ( ! isset($_registered_pages[$hookname])) |
|
1706 | 1706 | return false; |
1707 | 1707 | } |
1708 | 1708 | |
1709 | - if ( empty( $parent) ) { |
|
1710 | - if ( isset( $_wp_menu_nopriv[$pagenow] ) ) |
|
1709 | + if (empty($parent)) { |
|
1710 | + if (isset($_wp_menu_nopriv[$pagenow])) |
|
1711 | 1711 | return false; |
1712 | - if ( isset( $_wp_submenu_nopriv[$pagenow][$pagenow] ) ) |
|
1712 | + if (isset($_wp_submenu_nopriv[$pagenow][$pagenow])) |
|
1713 | 1713 | return false; |
1714 | - if ( isset( $plugin_page ) && isset( $_wp_submenu_nopriv[$pagenow][$plugin_page] ) ) |
|
1714 | + if (isset($plugin_page) && isset($_wp_submenu_nopriv[$pagenow][$plugin_page])) |
|
1715 | 1715 | return false; |
1716 | - if ( isset( $plugin_page ) && isset( $_wp_menu_nopriv[$plugin_page] ) ) |
|
1716 | + if (isset($plugin_page) && isset($_wp_menu_nopriv[$plugin_page])) |
|
1717 | 1717 | return false; |
1718 | - foreach (array_keys( $_wp_submenu_nopriv ) as $key ) { |
|
1719 | - if ( isset( $_wp_submenu_nopriv[$key][$pagenow] ) ) |
|
1718 | + foreach (array_keys($_wp_submenu_nopriv) as $key) { |
|
1719 | + if (isset($_wp_submenu_nopriv[$key][$pagenow])) |
|
1720 | 1720 | return false; |
1721 | - if ( isset( $plugin_page ) && isset( $_wp_submenu_nopriv[$key][$plugin_page] ) ) |
|
1721 | + if (isset($plugin_page) && isset($_wp_submenu_nopriv[$key][$plugin_page])) |
|
1722 | 1722 | return false; |
1723 | 1723 | } |
1724 | 1724 | return true; |
1725 | 1725 | } |
1726 | 1726 | |
1727 | - if ( isset( $plugin_page ) && ( $plugin_page == $parent ) && isset( $_wp_menu_nopriv[$plugin_page] ) ) |
|
1727 | + if (isset($plugin_page) && ($plugin_page == $parent) && isset($_wp_menu_nopriv[$plugin_page])) |
|
1728 | 1728 | return false; |
1729 | 1729 | |
1730 | - if ( isset( $submenu[$parent] ) ) { |
|
1731 | - foreach ( $submenu[$parent] as $submenu_array ) { |
|
1732 | - if ( isset( $plugin_page ) && ( $submenu_array[2] == $plugin_page ) ) { |
|
1733 | - if ( current_user_can( $submenu_array[1] )) |
|
1730 | + if (isset($submenu[$parent])) { |
|
1731 | + foreach ($submenu[$parent] as $submenu_array) { |
|
1732 | + if (isset($plugin_page) && ($submenu_array[2] == $plugin_page)) { |
|
1733 | + if (current_user_can($submenu_array[1])) |
|
1734 | 1734 | return true; |
1735 | 1735 | else |
1736 | 1736 | return false; |
1737 | - } elseif ( $submenu_array[2] == $pagenow ) { |
|
1738 | - if ( current_user_can( $submenu_array[1] )) |
|
1737 | + } elseif ($submenu_array[2] == $pagenow) { |
|
1738 | + if (current_user_can($submenu_array[1])) |
|
1739 | 1739 | return true; |
1740 | 1740 | else |
1741 | 1741 | return false; |
@@ -1743,9 +1743,9 @@ discard block |
||
1743 | 1743 | } |
1744 | 1744 | } |
1745 | 1745 | |
1746 | - foreach ( $menu as $menu_array ) { |
|
1747 | - if ( $menu_array[2] == $parent) { |
|
1748 | - if ( current_user_can( $menu_array[1] )) |
|
1746 | + foreach ($menu as $menu_array) { |
|
1747 | + if ($menu_array[2] == $parent) { |
|
1748 | + if (current_user_can($menu_array[1])) |
|
1749 | 1749 | return true; |
1750 | 1750 | else |
1751 | 1751 | return false; |
@@ -1769,22 +1769,22 @@ discard block |
||
1769 | 1769 | * @param string $option_name The name of an option to sanitize and save. |
1770 | 1770 | * @param callable $sanitize_callback A callback function that sanitizes the option's value. |
1771 | 1771 | */ |
1772 | -function register_setting( $option_group, $option_name, $sanitize_callback = '' ) { |
|
1772 | +function register_setting($option_group, $option_name, $sanitize_callback = '') { |
|
1773 | 1773 | global $new_whitelist_options; |
1774 | 1774 | |
1775 | - if ( 'misc' == $option_group ) { |
|
1776 | - _deprecated_argument( __FUNCTION__, '3.0', sprintf( __( 'The "%s" options group has been removed. Use another settings group.' ), 'misc' ) ); |
|
1775 | + if ('misc' == $option_group) { |
|
1776 | + _deprecated_argument(__FUNCTION__, '3.0', sprintf(__('The "%s" options group has been removed. Use another settings group.'), 'misc')); |
|
1777 | 1777 | $option_group = 'general'; |
1778 | 1778 | } |
1779 | 1779 | |
1780 | - if ( 'privacy' == $option_group ) { |
|
1781 | - _deprecated_argument( __FUNCTION__, '3.5', sprintf( __( 'The "%s" options group has been removed. Use another settings group.' ), 'privacy' ) ); |
|
1780 | + if ('privacy' == $option_group) { |
|
1781 | + _deprecated_argument(__FUNCTION__, '3.5', sprintf(__('The "%s" options group has been removed. Use another settings group.'), 'privacy')); |
|
1782 | 1782 | $option_group = 'reading'; |
1783 | 1783 | } |
1784 | 1784 | |
1785 | - $new_whitelist_options[ $option_group ][] = $option_name; |
|
1786 | - if ( $sanitize_callback != '' ) |
|
1787 | - add_filter( "sanitize_option_{$option_name}", $sanitize_callback ); |
|
1785 | + $new_whitelist_options[$option_group][] = $option_name; |
|
1786 | + if ($sanitize_callback != '') |
|
1787 | + add_filter("sanitize_option_{$option_name}", $sanitize_callback); |
|
1788 | 1788 | } |
1789 | 1789 | |
1790 | 1790 | /** |
@@ -1798,24 +1798,24 @@ discard block |
||
1798 | 1798 | * @param string $option_name |
1799 | 1799 | * @param callable $sanitize_callback |
1800 | 1800 | */ |
1801 | -function unregister_setting( $option_group, $option_name, $sanitize_callback = '' ) { |
|
1801 | +function unregister_setting($option_group, $option_name, $sanitize_callback = '') { |
|
1802 | 1802 | global $new_whitelist_options; |
1803 | 1803 | |
1804 | - if ( 'misc' == $option_group ) { |
|
1805 | - _deprecated_argument( __FUNCTION__, '3.0', sprintf( __( 'The "%s" options group has been removed. Use another settings group.' ), 'misc' ) ); |
|
1804 | + if ('misc' == $option_group) { |
|
1805 | + _deprecated_argument(__FUNCTION__, '3.0', sprintf(__('The "%s" options group has been removed. Use another settings group.'), 'misc')); |
|
1806 | 1806 | $option_group = 'general'; |
1807 | 1807 | } |
1808 | 1808 | |
1809 | - if ( 'privacy' == $option_group ) { |
|
1810 | - _deprecated_argument( __FUNCTION__, '3.5', sprintf( __( 'The "%s" options group has been removed. Use another settings group.' ), 'privacy' ) ); |
|
1809 | + if ('privacy' == $option_group) { |
|
1810 | + _deprecated_argument(__FUNCTION__, '3.5', sprintf(__('The "%s" options group has been removed. Use another settings group.'), 'privacy')); |
|
1811 | 1811 | $option_group = 'reading'; |
1812 | 1812 | } |
1813 | 1813 | |
1814 | - $pos = array_search( $option_name, (array) $new_whitelist_options[ $option_group ] ); |
|
1815 | - if ( $pos !== false ) |
|
1816 | - unset( $new_whitelist_options[ $option_group ][ $pos ] ); |
|
1817 | - if ( $sanitize_callback != '' ) |
|
1818 | - remove_filter( "sanitize_option_{$option_name}", $sanitize_callback ); |
|
1814 | + $pos = array_search($option_name, (array) $new_whitelist_options[$option_group]); |
|
1815 | + if ($pos !== false) |
|
1816 | + unset($new_whitelist_options[$option_group][$pos]); |
|
1817 | + if ($sanitize_callback != '') |
|
1818 | + remove_filter("sanitize_option_{$option_name}", $sanitize_callback); |
|
1819 | 1819 | } |
1820 | 1820 | |
1821 | 1821 | /** |
@@ -1828,11 +1828,11 @@ discard block |
||
1828 | 1828 | * @param array $options |
1829 | 1829 | * @return array |
1830 | 1830 | */ |
1831 | -function option_update_filter( $options ) { |
|
1831 | +function option_update_filter($options) { |
|
1832 | 1832 | global $new_whitelist_options; |
1833 | 1833 | |
1834 | - if ( is_array( $new_whitelist_options ) ) |
|
1835 | - $options = add_option_whitelist( $new_whitelist_options, $options ); |
|
1834 | + if (is_array($new_whitelist_options)) |
|
1835 | + $options = add_option_whitelist($new_whitelist_options, $options); |
|
1836 | 1836 | |
1837 | 1837 | return $options; |
1838 | 1838 | } |
@@ -1848,21 +1848,21 @@ discard block |
||
1848 | 1848 | * @param string|array $options |
1849 | 1849 | * @return array |
1850 | 1850 | */ |
1851 | -function add_option_whitelist( $new_options, $options = '' ) { |
|
1852 | - if ( $options == '' ) |
|
1851 | +function add_option_whitelist($new_options, $options = '') { |
|
1852 | + if ($options == '') |
|
1853 | 1853 | global $whitelist_options; |
1854 | 1854 | else |
1855 | 1855 | $whitelist_options = $options; |
1856 | 1856 | |
1857 | - foreach ( $new_options as $page => $keys ) { |
|
1858 | - foreach ( $keys as $key ) { |
|
1859 | - if ( !isset($whitelist_options[ $page ]) || !is_array($whitelist_options[ $page ]) ) { |
|
1860 | - $whitelist_options[ $page ] = array(); |
|
1861 | - $whitelist_options[ $page ][] = $key; |
|
1857 | + foreach ($new_options as $page => $keys) { |
|
1858 | + foreach ($keys as $key) { |
|
1859 | + if ( ! isset($whitelist_options[$page]) || ! is_array($whitelist_options[$page])) { |
|
1860 | + $whitelist_options[$page] = array(); |
|
1861 | + $whitelist_options[$page][] = $key; |
|
1862 | 1862 | } else { |
1863 | - $pos = array_search( $key, $whitelist_options[ $page ] ); |
|
1864 | - if ( $pos === false ) |
|
1865 | - $whitelist_options[ $page ][] = $key; |
|
1863 | + $pos = array_search($key, $whitelist_options[$page]); |
|
1864 | + if ($pos === false) |
|
1865 | + $whitelist_options[$page][] = $key; |
|
1866 | 1866 | } |
1867 | 1867 | } |
1868 | 1868 | } |
@@ -1881,18 +1881,18 @@ discard block |
||
1881 | 1881 | * @param string|array $options |
1882 | 1882 | * @return array |
1883 | 1883 | */ |
1884 | -function remove_option_whitelist( $del_options, $options = '' ) { |
|
1885 | - if ( $options == '' ) |
|
1884 | +function remove_option_whitelist($del_options, $options = '') { |
|
1885 | + if ($options == '') |
|
1886 | 1886 | global $whitelist_options; |
1887 | 1887 | else |
1888 | 1888 | $whitelist_options = $options; |
1889 | 1889 | |
1890 | - foreach ( $del_options as $page => $keys ) { |
|
1891 | - foreach ( $keys as $key ) { |
|
1892 | - if ( isset($whitelist_options[ $page ]) && is_array($whitelist_options[ $page ]) ) { |
|
1893 | - $pos = array_search( $key, $whitelist_options[ $page ] ); |
|
1894 | - if ( $pos !== false ) |
|
1895 | - unset( $whitelist_options[ $page ][ $pos ] ); |
|
1890 | + foreach ($del_options as $page => $keys) { |
|
1891 | + foreach ($keys as $key) { |
|
1892 | + if (isset($whitelist_options[$page]) && is_array($whitelist_options[$page])) { |
|
1893 | + $pos = array_search($key, $whitelist_options[$page]); |
|
1894 | + if ($pos !== false) |
|
1895 | + unset($whitelist_options[$page][$pos]); |
|
1896 | 1896 | } |
1897 | 1897 | } |
1898 | 1898 | } |
@@ -1908,7 +1908,7 @@ discard block |
||
1908 | 1908 | * @param string $option_group A settings group name. This should match the group name used in register_setting(). |
1909 | 1909 | */ |
1910 | 1910 | function settings_fields($option_group) { |
1911 | - echo "<input type='hidden' name='option_page' value='" . esc_attr($option_group) . "' />"; |
|
1911 | + echo "<input type='hidden' name='option_page' value='".esc_attr($option_group)."' />"; |
|
1912 | 1912 | echo '<input type="hidden" name="action" value="update" />'; |
1913 | 1913 | wp_nonce_field("$option_group-options"); |
1914 | 1914 | } |
@@ -1920,16 +1920,16 @@ discard block |
||
1920 | 1920 | * |
1921 | 1921 | * @param bool $clear_update_cache Whether to clear the Plugin updates cache |
1922 | 1922 | */ |
1923 | -function wp_clean_plugins_cache( $clear_update_cache = true ) { |
|
1924 | - if ( $clear_update_cache ) |
|
1925 | - delete_site_transient( 'update_plugins' ); |
|
1926 | - wp_cache_delete( 'plugins', 'plugins' ); |
|
1923 | +function wp_clean_plugins_cache($clear_update_cache = true) { |
|
1924 | + if ($clear_update_cache) |
|
1925 | + delete_site_transient('update_plugins'); |
|
1926 | + wp_cache_delete('plugins', 'plugins'); |
|
1927 | 1927 | } |
1928 | 1928 | |
1929 | 1929 | /** |
1930 | 1930 | * @param string $plugin |
1931 | 1931 | */ |
1932 | -function plugin_sandbox_scrape( $plugin ) { |
|
1933 | - wp_register_plugin_realpath( WP_PLUGIN_DIR . '/' . $plugin ); |
|
1934 | - include( WP_PLUGIN_DIR . '/' . $plugin ); |
|
1932 | +function plugin_sandbox_scrape($plugin) { |
|
1933 | + wp_register_plugin_realpath(WP_PLUGIN_DIR.'/'.$plugin); |
|
1934 | + include(WP_PLUGIN_DIR.'/'.$plugin); |
|
1935 | 1935 | } |
@@ -128,8 +128,9 @@ discard block |
||
128 | 128 | $textdomain = 'default'; |
129 | 129 | } |
130 | 130 | if ( $textdomain ) { |
131 | - foreach ( array( 'Name', 'PluginURI', 'Description', 'Author', 'AuthorURI', 'Version' ) as $field ) |
|
132 | - $plugin_data[ $field ] = translate( $plugin_data[ $field ], $textdomain ); |
|
131 | + foreach ( array( 'Name', 'PluginURI', 'Description', 'Author', 'AuthorURI', 'Version' ) as $field ) { |
|
132 | + $plugin_data[ $field ] = translate( $plugin_data[ $field ], $textdomain ); |
|
133 | + } |
|
133 | 134 | } |
134 | 135 | } |
135 | 136 | |
@@ -159,16 +160,19 @@ discard block |
||
159 | 160 | |
160 | 161 | // Apply markup |
161 | 162 | if ( $markup ) { |
162 | - if ( $plugin_data['PluginURI'] && $plugin_data['Name'] ) |
|
163 | - $plugin_data['Title'] = '<a href="' . $plugin_data['PluginURI'] . '">' . $plugin_data['Name'] . '</a>'; |
|
163 | + if ( $plugin_data['PluginURI'] && $plugin_data['Name'] ) { |
|
164 | + $plugin_data['Title'] = '<a href="' . $plugin_data['PluginURI'] . '">' . $plugin_data['Name'] . '</a>'; |
|
165 | + } |
|
164 | 166 | |
165 | - if ( $plugin_data['AuthorURI'] && $plugin_data['Author'] ) |
|
166 | - $plugin_data['Author'] = '<a href="' . $plugin_data['AuthorURI'] . '">' . $plugin_data['Author'] . '</a>'; |
|
167 | + if ( $plugin_data['AuthorURI'] && $plugin_data['Author'] ) { |
|
168 | + $plugin_data['Author'] = '<a href="' . $plugin_data['AuthorURI'] . '">' . $plugin_data['Author'] . '</a>'; |
|
169 | + } |
|
167 | 170 | |
168 | 171 | $plugin_data['Description'] = wptexturize( $plugin_data['Description'] ); |
169 | 172 | |
170 | - if ( $plugin_data['Author'] ) |
|
171 | - $plugin_data['Description'] .= ' <cite>' . sprintf( __('By %s.'), $plugin_data['Author'] ) . '</cite>'; |
|
173 | + if ( $plugin_data['Author'] ) { |
|
174 | + $plugin_data['Description'] .= ' <cite>' . sprintf( __('By %s.'), $plugin_data['Author'] ) . '</cite>'; |
|
175 | + } |
|
172 | 176 | } |
173 | 177 | |
174 | 178 | return $plugin_data; |
@@ -190,21 +194,24 @@ discard block |
||
190 | 194 | $plugins_dir = @ opendir( $dir ); |
191 | 195 | if ( $plugins_dir ) { |
192 | 196 | while (($file = readdir( $plugins_dir ) ) !== false ) { |
193 | - if ( substr($file, 0, 1) == '.' ) |
|
194 | - continue; |
|
197 | + if ( substr($file, 0, 1) == '.' ) { |
|
198 | + continue; |
|
199 | + } |
|
195 | 200 | if ( is_dir( $dir . '/' . $file ) ) { |
196 | 201 | $plugins_subdir = @ opendir( $dir . '/' . $file ); |
197 | 202 | if ( $plugins_subdir ) { |
198 | 203 | while (($subfile = readdir( $plugins_subdir ) ) !== false ) { |
199 | - if ( substr($subfile, 0, 1) == '.' ) |
|
200 | - continue; |
|
204 | + if ( substr($subfile, 0, 1) == '.' ) { |
|
205 | + continue; |
|
206 | + } |
|
201 | 207 | $plugin_files[] = plugin_basename("$dir/$file/$subfile"); |
202 | 208 | } |
203 | 209 | @closedir( $plugins_subdir ); |
204 | 210 | } |
205 | 211 | } else { |
206 | - if ( plugin_basename("$dir/$file") != $plugin ) |
|
207 | - $plugin_files[] = plugin_basename("$dir/$file"); |
|
212 | + if ( plugin_basename("$dir/$file") != $plugin ) { |
|
213 | + $plugin_files[] = plugin_basename("$dir/$file"); |
|
214 | + } |
|
208 | 215 | } |
209 | 216 | } |
210 | 217 | @closedir( $plugins_dir ); |
@@ -236,54 +243,64 @@ discard block |
||
236 | 243 | */ |
237 | 244 | function get_plugins($plugin_folder = '') { |
238 | 245 | |
239 | - if ( ! $cache_plugins = wp_cache_get('plugins', 'plugins') ) |
|
240 | - $cache_plugins = array(); |
|
246 | + if ( ! $cache_plugins = wp_cache_get('plugins', 'plugins') ) { |
|
247 | + $cache_plugins = array(); |
|
248 | + } |
|
241 | 249 | |
242 | - if ( isset($cache_plugins[ $plugin_folder ]) ) |
|
243 | - return $cache_plugins[ $plugin_folder ]; |
|
250 | + if ( isset($cache_plugins[ $plugin_folder ]) ) { |
|
251 | + return $cache_plugins[ $plugin_folder ]; |
|
252 | + } |
|
244 | 253 | |
245 | 254 | $wp_plugins = array (); |
246 | 255 | $plugin_root = WP_PLUGIN_DIR; |
247 | - if ( !empty($plugin_folder) ) |
|
248 | - $plugin_root .= $plugin_folder; |
|
256 | + if ( !empty($plugin_folder) ) { |
|
257 | + $plugin_root .= $plugin_folder; |
|
258 | + } |
|
249 | 259 | |
250 | 260 | // Files in wp-content/plugins directory |
251 | 261 | $plugins_dir = @ opendir( $plugin_root); |
252 | 262 | $plugin_files = array(); |
253 | 263 | if ( $plugins_dir ) { |
254 | 264 | while (($file = readdir( $plugins_dir ) ) !== false ) { |
255 | - if ( substr($file, 0, 1) == '.' ) |
|
256 | - continue; |
|
265 | + if ( substr($file, 0, 1) == '.' ) { |
|
266 | + continue; |
|
267 | + } |
|
257 | 268 | if ( is_dir( $plugin_root.'/'.$file ) ) { |
258 | 269 | $plugins_subdir = @ opendir( $plugin_root.'/'.$file ); |
259 | 270 | if ( $plugins_subdir ) { |
260 | 271 | while (($subfile = readdir( $plugins_subdir ) ) !== false ) { |
261 | - if ( substr($subfile, 0, 1) == '.' ) |
|
262 | - continue; |
|
263 | - if ( substr($subfile, -4) == '.php' ) |
|
264 | - $plugin_files[] = "$file/$subfile"; |
|
272 | + if ( substr($subfile, 0, 1) == '.' ) { |
|
273 | + continue; |
|
274 | + } |
|
275 | + if ( substr($subfile, -4) == '.php' ) { |
|
276 | + $plugin_files[] = "$file/$subfile"; |
|
277 | + } |
|
265 | 278 | } |
266 | 279 | closedir( $plugins_subdir ); |
267 | 280 | } |
268 | 281 | } else { |
269 | - if ( substr($file, -4) == '.php' ) |
|
270 | - $plugin_files[] = $file; |
|
282 | + if ( substr($file, -4) == '.php' ) { |
|
283 | + $plugin_files[] = $file; |
|
284 | + } |
|
271 | 285 | } |
272 | 286 | } |
273 | 287 | closedir( $plugins_dir ); |
274 | 288 | } |
275 | 289 | |
276 | - if ( empty($plugin_files) ) |
|
277 | - return $wp_plugins; |
|
290 | + if ( empty($plugin_files) ) { |
|
291 | + return $wp_plugins; |
|
292 | + } |
|
278 | 293 | |
279 | 294 | foreach ( $plugin_files as $plugin_file ) { |
280 | - if ( !is_readable( "$plugin_root/$plugin_file" ) ) |
|
281 | - continue; |
|
295 | + if ( !is_readable( "$plugin_root/$plugin_file" ) ) { |
|
296 | + continue; |
|
297 | + } |
|
282 | 298 | |
283 | 299 | $plugin_data = get_plugin_data( "$plugin_root/$plugin_file", false, false ); //Do not apply markup/translate as it'll be cached. |
284 | 300 | |
285 | - if ( empty ( $plugin_data['Name'] ) ) |
|
286 | - continue; |
|
301 | + if ( empty ( $plugin_data['Name'] ) ) { |
|
302 | + continue; |
|
303 | + } |
|
287 | 304 | |
288 | 305 | $wp_plugins[plugin_basename( $plugin_file )] = $plugin_data; |
289 | 306 | } |
@@ -309,12 +326,14 @@ discard block |
||
309 | 326 | // Files in wp-content/mu-plugins directory |
310 | 327 | $plugin_files = array(); |
311 | 328 | |
312 | - if ( ! is_dir( WPMU_PLUGIN_DIR ) ) |
|
313 | - return $wp_plugins; |
|
329 | + if ( ! is_dir( WPMU_PLUGIN_DIR ) ) { |
|
330 | + return $wp_plugins; |
|
331 | + } |
|
314 | 332 | if ( $plugins_dir = @ opendir( WPMU_PLUGIN_DIR ) ) { |
315 | 333 | while ( ( $file = readdir( $plugins_dir ) ) !== false ) { |
316 | - if ( substr( $file, -4 ) == '.php' ) |
|
317 | - $plugin_files[] = $file; |
|
334 | + if ( substr( $file, -4 ) == '.php' ) { |
|
335 | + $plugin_files[] = $file; |
|
336 | + } |
|
318 | 337 | } |
319 | 338 | } else { |
320 | 339 | return $wp_plugins; |
@@ -322,23 +341,28 @@ discard block |
||
322 | 341 | |
323 | 342 | @closedir( $plugins_dir ); |
324 | 343 | |
325 | - if ( empty($plugin_files) ) |
|
326 | - return $wp_plugins; |
|
344 | + if ( empty($plugin_files) ) { |
|
345 | + return $wp_plugins; |
|
346 | + } |
|
327 | 347 | |
328 | 348 | foreach ( $plugin_files as $plugin_file ) { |
329 | - if ( !is_readable( WPMU_PLUGIN_DIR . "/$plugin_file" ) ) |
|
330 | - continue; |
|
349 | + if ( !is_readable( WPMU_PLUGIN_DIR . "/$plugin_file" ) ) { |
|
350 | + continue; |
|
351 | + } |
|
331 | 352 | |
332 | 353 | $plugin_data = get_plugin_data( WPMU_PLUGIN_DIR . "/$plugin_file", false, false ); //Do not apply markup/translate as it'll be cached. |
333 | 354 | |
334 | - if ( empty ( $plugin_data['Name'] ) ) |
|
335 | - $plugin_data['Name'] = $plugin_file; |
|
355 | + if ( empty ( $plugin_data['Name'] ) ) { |
|
356 | + $plugin_data['Name'] = $plugin_file; |
|
357 | + } |
|
336 | 358 | |
337 | 359 | $wp_plugins[ $plugin_file ] = $plugin_data; |
338 | 360 | } |
339 | 361 | |
340 | - if ( isset( $wp_plugins['index.php'] ) && filesize( WPMU_PLUGIN_DIR . '/index.php') <= 30 ) // silence is golden |
|
362 | + if ( isset( $wp_plugins['index.php'] ) && filesize( WPMU_PLUGIN_DIR . '/index.php') <= 30 ) { |
|
363 | + // silence is golden |
|
341 | 364 | unset( $wp_plugins['index.php'] ); |
365 | + } |
|
342 | 366 | |
343 | 367 | uasort( $wp_plugins, '_sort_uname_callback' ); |
344 | 368 | |
@@ -370,8 +394,9 @@ discard block |
||
370 | 394 | // These exist in the wp-content directory |
371 | 395 | if ( $plugins_dir = @ opendir( WP_CONTENT_DIR ) ) { |
372 | 396 | while ( ( $file = readdir( $plugins_dir ) ) !== false ) { |
373 | - if ( isset( $_dropins[ $file ] ) ) |
|
374 | - $plugin_files[] = $file; |
|
397 | + if ( isset( $_dropins[ $file ] ) ) { |
|
398 | + $plugin_files[] = $file; |
|
399 | + } |
|
375 | 400 | } |
376 | 401 | } else { |
377 | 402 | return $dropins; |
@@ -379,15 +404,18 @@ discard block |
||
379 | 404 | |
380 | 405 | @closedir( $plugins_dir ); |
381 | 406 | |
382 | - if ( empty($plugin_files) ) |
|
383 | - return $dropins; |
|
407 | + if ( empty($plugin_files) ) { |
|
408 | + return $dropins; |
|
409 | + } |
|
384 | 410 | |
385 | 411 | foreach ( $plugin_files as $plugin_file ) { |
386 | - if ( !is_readable( WP_CONTENT_DIR . "/$plugin_file" ) ) |
|
387 | - continue; |
|
412 | + if ( !is_readable( WP_CONTENT_DIR . "/$plugin_file" ) ) { |
|
413 | + continue; |
|
414 | + } |
|
388 | 415 | $plugin_data = get_plugin_data( WP_CONTENT_DIR . "/$plugin_file", false, false ); //Do not apply markup/translate as it'll be cached. |
389 | - if ( empty( $plugin_data['Name'] ) ) |
|
390 | - $plugin_data['Name'] = $plugin_file; |
|
416 | + if ( empty( $plugin_data['Name'] ) ) { |
|
417 | + $plugin_data['Name'] = $plugin_file; |
|
418 | + } |
|
391 | 419 | $dropins[ $plugin_file ] = $plugin_data; |
392 | 420 | } |
393 | 421 | |
@@ -472,12 +500,14 @@ discard block |
||
472 | 500 | * @return bool True, if active for the network, otherwise false. |
473 | 501 | */ |
474 | 502 | function is_plugin_active_for_network( $plugin ) { |
475 | - if ( !is_multisite() ) |
|
476 | - return false; |
|
503 | + if ( !is_multisite() ) { |
|
504 | + return false; |
|
505 | + } |
|
477 | 506 | |
478 | 507 | $plugins = get_site_option( 'active_sitewide_plugins'); |
479 | - if ( isset($plugins[$plugin]) ) |
|
480 | - return true; |
|
508 | + if ( isset($plugins[$plugin]) ) { |
|
509 | + return true; |
|
510 | + } |
|
481 | 511 | |
482 | 512 | return false; |
483 | 513 | } |
@@ -496,8 +526,9 @@ discard block |
||
496 | 526 | */ |
497 | 527 | function is_network_only_plugin( $plugin ) { |
498 | 528 | $plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin ); |
499 | - if ( $plugin_data ) |
|
500 | - return $plugin_data['Network']; |
|
529 | + if ( $plugin_data ) { |
|
530 | + return $plugin_data['Network']; |
|
531 | + } |
|
501 | 532 | return false; |
502 | 533 | } |
503 | 534 | |
@@ -540,12 +571,15 @@ discard block |
||
540 | 571 | } |
541 | 572 | |
542 | 573 | $valid = validate_plugin($plugin); |
543 | - if ( is_wp_error($valid) ) |
|
544 | - return $valid; |
|
574 | + if ( is_wp_error($valid) ) { |
|
575 | + return $valid; |
|
576 | + } |
|
545 | 577 | |
546 | 578 | if ( ( $network_wide && ! isset( $current[ $plugin ] ) ) || ( ! $network_wide && ! in_array( $plugin, $current ) ) ) { |
547 | - if ( !empty($redirect) ) |
|
548 | - wp_redirect(add_query_arg('_error_nonce', wp_create_nonce('plugin-activation-error_' . $plugin), $redirect)); // we'll override this later if the plugin can be included without fatal error |
|
579 | + if ( !empty($redirect) ) { |
|
580 | + wp_redirect(add_query_arg('_error_nonce', wp_create_nonce('plugin-activation-error_' . $plugin), $redirect)); |
|
581 | + } |
|
582 | + // we'll override this later if the plugin can be included without fatal error |
|
549 | 583 | ob_start(); |
550 | 584 | wp_register_plugin_realpath( WP_PLUGIN_DIR . '/' . $plugin ); |
551 | 585 | $_wp_plugin_file = $plugin; |
@@ -636,15 +670,17 @@ discard block |
||
636 | 670 | * A value of null (the default) will deactivate plugins for both the site and the network. |
637 | 671 | */ |
638 | 672 | function deactivate_plugins( $plugins, $silent = false, $network_wide = null ) { |
639 | - if ( is_multisite() ) |
|
640 | - $network_current = get_site_option( 'active_sitewide_plugins', array() ); |
|
673 | + if ( is_multisite() ) { |
|
674 | + $network_current = get_site_option( 'active_sitewide_plugins', array() ); |
|
675 | + } |
|
641 | 676 | $current = get_option( 'active_plugins', array() ); |
642 | 677 | $do_blog = $do_network = false; |
643 | 678 | |
644 | 679 | foreach ( (array) $plugins as $plugin ) { |
645 | 680 | $plugin = plugin_basename( trim( $plugin ) ); |
646 | - if ( ! is_plugin_active($plugin) ) |
|
647 | - continue; |
|
681 | + if ( ! is_plugin_active($plugin) ) { |
|
682 | + continue; |
|
683 | + } |
|
648 | 684 | |
649 | 685 | $network_deactivating = false !== $network_wide && is_plugin_active_for_network( $plugin ); |
650 | 686 | |
@@ -715,11 +751,13 @@ discard block |
||
715 | 751 | } |
716 | 752 | } |
717 | 753 | |
718 | - if ( $do_blog ) |
|
719 | - update_option('active_plugins', $current); |
|
720 | - if ( $do_network ) |
|
721 | - update_site_option( 'active_sitewide_plugins', $network_current ); |
|
722 | -} |
|
754 | + if ( $do_blog ) { |
|
755 | + update_option('active_plugins', $current); |
|
756 | + } |
|
757 | + if ( $do_network ) { |
|
758 | + update_site_option( 'active_sitewide_plugins', $network_current ); |
|
759 | + } |
|
760 | + } |
|
723 | 761 | |
724 | 762 | /** |
725 | 763 | * Activate multiple plugins. |
@@ -738,20 +776,24 @@ discard block |
||
738 | 776 | * @return bool|WP_Error True when finished or WP_Error if there were errors during a plugin activation. |
739 | 777 | */ |
740 | 778 | function activate_plugins( $plugins, $redirect = '', $network_wide = false, $silent = false ) { |
741 | - if ( !is_array($plugins) ) |
|
742 | - $plugins = array($plugins); |
|
779 | + if ( !is_array($plugins) ) { |
|
780 | + $plugins = array($plugins); |
|
781 | + } |
|
743 | 782 | |
744 | 783 | $errors = array(); |
745 | 784 | foreach ( $plugins as $plugin ) { |
746 | - if ( !empty($redirect) ) |
|
747 | - $redirect = add_query_arg('plugin', $plugin, $redirect); |
|
785 | + if ( !empty($redirect) ) { |
|
786 | + $redirect = add_query_arg('plugin', $plugin, $redirect); |
|
787 | + } |
|
748 | 788 | $result = activate_plugin($plugin, $redirect, $network_wide, $silent); |
749 | - if ( is_wp_error($result) ) |
|
750 | - $errors[$plugin] = $result; |
|
789 | + if ( is_wp_error($result) ) { |
|
790 | + $errors[$plugin] = $result; |
|
791 | + } |
|
751 | 792 | } |
752 | 793 | |
753 | - if ( !empty($errors) ) |
|
754 | - return new WP_Error('plugins_invalid', __('One of the plugins is invalid.'), $errors); |
|
794 | + if ( !empty($errors) ) { |
|
795 | + return new WP_Error('plugins_invalid', __('One of the plugins is invalid.'), $errors); |
|
796 | + } |
|
755 | 797 | |
756 | 798 | return true; |
757 | 799 | } |
@@ -771,12 +813,14 @@ discard block |
||
771 | 813 | function delete_plugins( $plugins, $deprecated = '' ) { |
772 | 814 | global $wp_filesystem; |
773 | 815 | |
774 | - if ( empty($plugins) ) |
|
775 | - return false; |
|
816 | + if ( empty($plugins) ) { |
|
817 | + return false; |
|
818 | + } |
|
776 | 819 | |
777 | 820 | $checked = array(); |
778 | - foreach ( $plugins as $plugin ) |
|
779 | - $checked[] = 'checked[]=' . $plugin; |
|
821 | + foreach ( $plugins as $plugin ) { |
|
822 | + $checked[] = 'checked[]=' . $plugin; |
|
823 | + } |
|
780 | 824 | |
781 | 825 | ob_start(); |
782 | 826 | $url = wp_nonce_url('plugins.php?action=delete-selected&verify-delete=1&' . implode('&', $checked), 'bulk-plugins'); |
@@ -805,11 +849,13 @@ discard block |
||
805 | 849 | return; |
806 | 850 | } |
807 | 851 | |
808 | - if ( ! is_object($wp_filesystem) ) |
|
809 | - return new WP_Error('fs_unavailable', __('Could not access filesystem.')); |
|
852 | + if ( ! is_object($wp_filesystem) ) { |
|
853 | + return new WP_Error('fs_unavailable', __('Could not access filesystem.')); |
|
854 | + } |
|
810 | 855 | |
811 | - if ( is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code() ) |
|
812 | - return new WP_Error('fs_error', __('Filesystem error.'), $wp_filesystem->errors); |
|
856 | + if ( is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code() ) { |
|
857 | + return new WP_Error('fs_error', __('Filesystem error.'), $wp_filesystem->errors); |
|
858 | + } |
|
813 | 859 | |
814 | 860 | // Get the base plugin folder. |
815 | 861 | $plugins_dir = $wp_filesystem->wp_plugins_dir(); |
@@ -886,8 +932,9 @@ discard block |
||
886 | 932 | set_site_transient( 'update_plugins', $current ); |
887 | 933 | } |
888 | 934 | |
889 | - if ( ! empty($errors) ) |
|
890 | - return new WP_Error('could_not_remove_plugin', sprintf(__('Could not fully remove the plugin(s) %s.'), implode(', ', $errors)) ); |
|
935 | + if ( ! empty($errors) ) { |
|
936 | + return new WP_Error('could_not_remove_plugin', sprintf(__('Could not fully remove the plugin(s) %s.'), implode(', ', $errors)) ); |
|
937 | + } |
|
891 | 938 | |
892 | 939 | return true; |
893 | 940 | } |
@@ -914,8 +961,9 @@ discard block |
||
914 | 961 | $plugins = array_merge( $plugins, array_keys( $network_plugins ) ); |
915 | 962 | } |
916 | 963 | |
917 | - if ( empty( $plugins ) ) |
|
918 | - return array(); |
|
964 | + if ( empty( $plugins ) ) { |
|
965 | + return array(); |
|
966 | + } |
|
919 | 967 | |
920 | 968 | $invalid = array(); |
921 | 969 | |
@@ -941,14 +989,17 @@ discard block |
||
941 | 989 | * @return WP_Error|int 0 on success, WP_Error on failure. |
942 | 990 | */ |
943 | 991 | function validate_plugin($plugin) { |
944 | - if ( validate_file($plugin) ) |
|
945 | - return new WP_Error('plugin_invalid', __('Invalid plugin path.')); |
|
946 | - if ( ! file_exists(WP_PLUGIN_DIR . '/' . $plugin) ) |
|
947 | - return new WP_Error('plugin_not_found', __('Plugin file does not exist.')); |
|
992 | + if ( validate_file($plugin) ) { |
|
993 | + return new WP_Error('plugin_invalid', __('Invalid plugin path.')); |
|
994 | + } |
|
995 | + if ( ! file_exists(WP_PLUGIN_DIR . '/' . $plugin) ) { |
|
996 | + return new WP_Error('plugin_not_found', __('Plugin file does not exist.')); |
|
997 | + } |
|
948 | 998 | |
949 | 999 | $installed_plugins = get_plugins(); |
950 | - if ( ! isset($installed_plugins[$plugin]) ) |
|
951 | - return new WP_Error('no_plugin_header', __('The plugin does not have a valid header.')); |
|
1000 | + if ( ! isset($installed_plugins[$plugin]) ) { |
|
1001 | + return new WP_Error('no_plugin_header', __('The plugin does not have a valid header.')); |
|
1002 | + } |
|
952 | 1003 | return 0; |
953 | 1004 | } |
954 | 1005 | |
@@ -964,8 +1015,9 @@ discard block |
||
964 | 1015 | $file = plugin_basename($plugin); |
965 | 1016 | |
966 | 1017 | $uninstallable_plugins = (array) get_option('uninstall_plugins'); |
967 | - if ( isset( $uninstallable_plugins[$file] ) || file_exists( WP_PLUGIN_DIR . '/' . dirname($file) . '/uninstall.php' ) ) |
|
968 | - return true; |
|
1018 | + if ( isset( $uninstallable_plugins[$file] ) || file_exists( WP_PLUGIN_DIR . '/' . dirname($file) . '/uninstall.php' ) ) { |
|
1019 | + return true; |
|
1020 | + } |
|
969 | 1021 | |
970 | 1022 | return false; |
971 | 1023 | } |
@@ -1073,8 +1125,9 @@ discard block |
||
1073 | 1125 | |
1074 | 1126 | $hookname = get_plugin_page_hookname( $menu_slug, '' ); |
1075 | 1127 | |
1076 | - if ( !empty( $function ) && !empty( $hookname ) && current_user_can( $capability ) ) |
|
1077 | - add_action( $hookname, $function ); |
|
1128 | + if ( !empty( $function ) && !empty( $hookname ) && current_user_can( $capability ) ) { |
|
1129 | + add_action( $hookname, $function ); |
|
1130 | + } |
|
1078 | 1131 | |
1079 | 1132 | if ( empty($icon_url) ) { |
1080 | 1133 | $icon_url = 'dashicons-admin-generic'; |
@@ -1134,8 +1187,9 @@ discard block |
||
1134 | 1187 | $menu_slug = plugin_basename( $menu_slug ); |
1135 | 1188 | $parent_slug = plugin_basename( $parent_slug); |
1136 | 1189 | |
1137 | - if ( isset( $_wp_real_parent_file[$parent_slug] ) ) |
|
1138 | - $parent_slug = $_wp_real_parent_file[$parent_slug]; |
|
1190 | + if ( isset( $_wp_real_parent_file[$parent_slug] ) ) { |
|
1191 | + $parent_slug = $_wp_real_parent_file[$parent_slug]; |
|
1192 | + } |
|
1139 | 1193 | |
1140 | 1194 | if ( !current_user_can( $capability ) ) { |
1141 | 1195 | $_wp_submenu_nopriv[$parent_slug][$menu_slug] = true; |
@@ -1150,16 +1204,18 @@ discard block |
||
1150 | 1204 | */ |
1151 | 1205 | if (!isset( $submenu[$parent_slug] ) && $menu_slug != $parent_slug ) { |
1152 | 1206 | foreach ( (array)$menu as $parent_menu ) { |
1153 | - if ( $parent_menu[2] == $parent_slug && current_user_can( $parent_menu[1] ) ) |
|
1154 | - $submenu[$parent_slug][] = array_slice( $parent_menu, 0, 4 ); |
|
1207 | + if ( $parent_menu[2] == $parent_slug && current_user_can( $parent_menu[1] ) ) { |
|
1208 | + $submenu[$parent_slug][] = array_slice( $parent_menu, 0, 4 ); |
|
1209 | + } |
|
1155 | 1210 | } |
1156 | 1211 | } |
1157 | 1212 | |
1158 | 1213 | $submenu[$parent_slug][] = array ( $menu_title, $capability, $menu_slug, $page_title ); |
1159 | 1214 | |
1160 | 1215 | $hookname = get_plugin_page_hookname( $menu_slug, $parent_slug); |
1161 | - if (!empty ( $function ) && !empty ( $hookname )) |
|
1162 | - add_action( $hookname, $function ); |
|
1216 | + if (!empty ( $function ) && !empty ( $hookname )) { |
|
1217 | + add_action( $hookname, $function ); |
|
1218 | + } |
|
1163 | 1219 | |
1164 | 1220 | $_registered_pages[$hookname] = true; |
1165 | 1221 | |
@@ -1167,8 +1223,9 @@ discard block |
||
1167 | 1223 | * Backward-compatibility for plugins using add_management page. |
1168 | 1224 | * See wp-admin/admin.php for redirect from edit.php to tools.php |
1169 | 1225 | */ |
1170 | - if ( 'tools.php' == $parent_slug ) |
|
1171 | - $_registered_pages[get_plugin_page_hookname( $menu_slug, 'edit.php')] = true; |
|
1226 | + if ( 'tools.php' == $parent_slug ) { |
|
1227 | + $_registered_pages[get_plugin_page_hookname( $menu_slug, 'edit.php')] = true; |
|
1228 | + } |
|
1172 | 1229 | |
1173 | 1230 | // No parent as top level. |
1174 | 1231 | $_parent_pages[$menu_slug] = $parent_slug; |
@@ -1273,10 +1330,11 @@ discard block |
||
1273 | 1330 | * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required. |
1274 | 1331 | */ |
1275 | 1332 | function add_users_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { |
1276 | - if ( current_user_can('edit_users') ) |
|
1277 | - $parent = 'users.php'; |
|
1278 | - else |
|
1279 | - $parent = 'profile.php'; |
|
1333 | + if ( current_user_can('edit_users') ) { |
|
1334 | + $parent = 'users.php'; |
|
1335 | + } else { |
|
1336 | + $parent = 'profile.php'; |
|
1337 | + } |
|
1280 | 1338 | return add_submenu_page( $parent, $page_title, $menu_title, $capability, $menu_slug, $function ); |
1281 | 1339 | } |
1282 | 1340 | /** |
@@ -1436,8 +1494,9 @@ discard block |
||
1436 | 1494 | function remove_submenu_page( $menu_slug, $submenu_slug ) { |
1437 | 1495 | global $submenu; |
1438 | 1496 | |
1439 | - if ( !isset( $submenu[$menu_slug] ) ) |
|
1440 | - return false; |
|
1497 | + if ( !isset( $submenu[$menu_slug] ) ) { |
|
1498 | + return false; |
|
1499 | + } |
|
1441 | 1500 | |
1442 | 1501 | foreach ( $submenu[$menu_slug] as $i => $item ) { |
1443 | 1502 | if ( $submenu_slug == $item[2] ) { |
@@ -1478,8 +1537,9 @@ discard block |
||
1478 | 1537 | |
1479 | 1538 | $url = esc_url($url); |
1480 | 1539 | |
1481 | - if ( $echo ) |
|
1482 | - echo $url; |
|
1540 | + if ( $echo ) { |
|
1541 | + echo $url; |
|
1542 | + } |
|
1483 | 1543 | |
1484 | 1544 | return $url; |
1485 | 1545 | } |
@@ -1504,8 +1564,9 @@ discard block |
||
1504 | 1564 | $plugin_page, $_wp_real_parent_file, $_wp_menu_nopriv, $_wp_submenu_nopriv; |
1505 | 1565 | |
1506 | 1566 | if ( !empty ( $parent ) && 'admin.php' != $parent ) { |
1507 | - if ( isset( $_wp_real_parent_file[$parent] ) ) |
|
1508 | - $parent = $_wp_real_parent_file[$parent]; |
|
1567 | + if ( isset( $_wp_real_parent_file[$parent] ) ) { |
|
1568 | + $parent = $_wp_real_parent_file[$parent]; |
|
1569 | + } |
|
1509 | 1570 | return $parent; |
1510 | 1571 | } |
1511 | 1572 | |
@@ -1513,30 +1574,34 @@ discard block |
||
1513 | 1574 | foreach ( (array)$menu as $parent_menu ) { |
1514 | 1575 | if ( $parent_menu[2] == $plugin_page ) { |
1515 | 1576 | $parent_file = $plugin_page; |
1516 | - if ( isset( $_wp_real_parent_file[$parent_file] ) ) |
|
1517 | - $parent_file = $_wp_real_parent_file[$parent_file]; |
|
1577 | + if ( isset( $_wp_real_parent_file[$parent_file] ) ) { |
|
1578 | + $parent_file = $_wp_real_parent_file[$parent_file]; |
|
1579 | + } |
|
1518 | 1580 | return $parent_file; |
1519 | 1581 | } |
1520 | 1582 | } |
1521 | 1583 | if ( isset( $_wp_menu_nopriv[$plugin_page] ) ) { |
1522 | 1584 | $parent_file = $plugin_page; |
1523 | - if ( isset( $_wp_real_parent_file[$parent_file] ) ) |
|
1524 | - $parent_file = $_wp_real_parent_file[$parent_file]; |
|
1585 | + if ( isset( $_wp_real_parent_file[$parent_file] ) ) { |
|
1586 | + $parent_file = $_wp_real_parent_file[$parent_file]; |
|
1587 | + } |
|
1525 | 1588 | return $parent_file; |
1526 | 1589 | } |
1527 | 1590 | } |
1528 | 1591 | |
1529 | 1592 | if ( isset( $plugin_page ) && isset( $_wp_submenu_nopriv[$pagenow][$plugin_page] ) ) { |
1530 | 1593 | $parent_file = $pagenow; |
1531 | - if ( isset( $_wp_real_parent_file[$parent_file] ) ) |
|
1532 | - $parent_file = $_wp_real_parent_file[$parent_file]; |
|
1594 | + if ( isset( $_wp_real_parent_file[$parent_file] ) ) { |
|
1595 | + $parent_file = $_wp_real_parent_file[$parent_file]; |
|
1596 | + } |
|
1533 | 1597 | return $parent_file; |
1534 | 1598 | } |
1535 | 1599 | |
1536 | 1600 | foreach (array_keys( (array)$submenu ) as $parent) { |
1537 | 1601 | foreach ( $submenu[$parent] as $submenu_array ) { |
1538 | - if ( isset( $_wp_real_parent_file[$parent] ) ) |
|
1539 | - $parent = $_wp_real_parent_file[$parent]; |
|
1602 | + if ( isset( $_wp_real_parent_file[$parent] ) ) { |
|
1603 | + $parent = $_wp_real_parent_file[$parent]; |
|
1604 | + } |
|
1540 | 1605 | if ( !empty($typenow) && ($submenu_array[2] == "$pagenow?post_type=$typenow") ) { |
1541 | 1606 | $parent_file = $parent; |
1542 | 1607 | return $parent; |
@@ -1550,8 +1615,9 @@ discard block |
||
1550 | 1615 | } |
1551 | 1616 | } |
1552 | 1617 | |
1553 | - if ( empty($parent_file) ) |
|
1554 | - $parent_file = ''; |
|
1618 | + if ( empty($parent_file) ) { |
|
1619 | + $parent_file = ''; |
|
1620 | + } |
|
1555 | 1621 | return ''; |
1556 | 1622 | } |
1557 | 1623 | |
@@ -1567,8 +1633,9 @@ discard block |
||
1567 | 1633 | function get_admin_page_title() { |
1568 | 1634 | global $title, $menu, $submenu, $pagenow, $plugin_page, $typenow; |
1569 | 1635 | |
1570 | - if ( ! empty ( $title ) ) |
|
1571 | - return $title; |
|
1636 | + if ( ! empty ( $title ) ) { |
|
1637 | + return $title; |
|
1638 | + } |
|
1572 | 1639 | |
1573 | 1640 | $hook = get_plugin_page_hook( $plugin_page, $pagenow ); |
1574 | 1641 | |
@@ -1606,8 +1673,10 @@ discard block |
||
1606 | 1673 | return $submenu_array[3]; |
1607 | 1674 | } |
1608 | 1675 | |
1609 | - if ( $submenu_array[2] != $pagenow || isset( $_GET['page'] ) ) // not the current page |
|
1676 | + if ( $submenu_array[2] != $pagenow || isset( $_GET['page'] ) ) { |
|
1677 | + // not the current page |
|
1610 | 1678 | continue; |
1679 | + } |
|
1611 | 1680 | |
1612 | 1681 | if ( isset( $submenu_array[3] ) ) { |
1613 | 1682 | $title = $submenu_array[3]; |
@@ -1644,11 +1713,12 @@ discard block |
||
1644 | 1713 | */ |
1645 | 1714 | function get_plugin_page_hook( $plugin_page, $parent_page ) { |
1646 | 1715 | $hook = get_plugin_page_hookname( $plugin_page, $parent_page ); |
1647 | - if ( has_action($hook) ) |
|
1648 | - return $hook; |
|
1649 | - else |
|
1650 | - return null; |
|
1651 | -} |
|
1716 | + if ( has_action($hook) ) { |
|
1717 | + return $hook; |
|
1718 | + } else { |
|
1719 | + return null; |
|
1720 | + } |
|
1721 | + } |
|
1652 | 1722 | |
1653 | 1723 | /** |
1654 | 1724 | * |
@@ -1693,62 +1763,75 @@ discard block |
||
1693 | 1763 | |
1694 | 1764 | $parent = get_admin_page_parent(); |
1695 | 1765 | |
1696 | - if ( !isset( $plugin_page ) && isset( $_wp_submenu_nopriv[$parent][$pagenow] ) ) |
|
1697 | - return false; |
|
1766 | + if ( !isset( $plugin_page ) && isset( $_wp_submenu_nopriv[$parent][$pagenow] ) ) { |
|
1767 | + return false; |
|
1768 | + } |
|
1698 | 1769 | |
1699 | 1770 | if ( isset( $plugin_page ) ) { |
1700 | - if ( isset( $_wp_submenu_nopriv[$parent][$plugin_page] ) ) |
|
1701 | - return false; |
|
1771 | + if ( isset( $_wp_submenu_nopriv[$parent][$plugin_page] ) ) { |
|
1772 | + return false; |
|
1773 | + } |
|
1702 | 1774 | |
1703 | 1775 | $hookname = get_plugin_page_hookname($plugin_page, $parent); |
1704 | 1776 | |
1705 | - if ( !isset($_registered_pages[$hookname]) ) |
|
1706 | - return false; |
|
1777 | + if ( !isset($_registered_pages[$hookname]) ) { |
|
1778 | + return false; |
|
1779 | + } |
|
1707 | 1780 | } |
1708 | 1781 | |
1709 | 1782 | if ( empty( $parent) ) { |
1710 | - if ( isset( $_wp_menu_nopriv[$pagenow] ) ) |
|
1711 | - return false; |
|
1712 | - if ( isset( $_wp_submenu_nopriv[$pagenow][$pagenow] ) ) |
|
1713 | - return false; |
|
1714 | - if ( isset( $plugin_page ) && isset( $_wp_submenu_nopriv[$pagenow][$plugin_page] ) ) |
|
1715 | - return false; |
|
1716 | - if ( isset( $plugin_page ) && isset( $_wp_menu_nopriv[$plugin_page] ) ) |
|
1717 | - return false; |
|
1783 | + if ( isset( $_wp_menu_nopriv[$pagenow] ) ) { |
|
1784 | + return false; |
|
1785 | + } |
|
1786 | + if ( isset( $_wp_submenu_nopriv[$pagenow][$pagenow] ) ) { |
|
1787 | + return false; |
|
1788 | + } |
|
1789 | + if ( isset( $plugin_page ) && isset( $_wp_submenu_nopriv[$pagenow][$plugin_page] ) ) { |
|
1790 | + return false; |
|
1791 | + } |
|
1792 | + if ( isset( $plugin_page ) && isset( $_wp_menu_nopriv[$plugin_page] ) ) { |
|
1793 | + return false; |
|
1794 | + } |
|
1718 | 1795 | foreach (array_keys( $_wp_submenu_nopriv ) as $key ) { |
1719 | - if ( isset( $_wp_submenu_nopriv[$key][$pagenow] ) ) |
|
1720 | - return false; |
|
1721 | - if ( isset( $plugin_page ) && isset( $_wp_submenu_nopriv[$key][$plugin_page] ) ) |
|
1722 | - return false; |
|
1796 | + if ( isset( $_wp_submenu_nopriv[$key][$pagenow] ) ) { |
|
1797 | + return false; |
|
1798 | + } |
|
1799 | + if ( isset( $plugin_page ) && isset( $_wp_submenu_nopriv[$key][$plugin_page] ) ) { |
|
1800 | + return false; |
|
1801 | + } |
|
1723 | 1802 | } |
1724 | 1803 | return true; |
1725 | 1804 | } |
1726 | 1805 | |
1727 | - if ( isset( $plugin_page ) && ( $plugin_page == $parent ) && isset( $_wp_menu_nopriv[$plugin_page] ) ) |
|
1728 | - return false; |
|
1806 | + if ( isset( $plugin_page ) && ( $plugin_page == $parent ) && isset( $_wp_menu_nopriv[$plugin_page] ) ) { |
|
1807 | + return false; |
|
1808 | + } |
|
1729 | 1809 | |
1730 | 1810 | if ( isset( $submenu[$parent] ) ) { |
1731 | 1811 | foreach ( $submenu[$parent] as $submenu_array ) { |
1732 | 1812 | if ( isset( $plugin_page ) && ( $submenu_array[2] == $plugin_page ) ) { |
1733 | - if ( current_user_can( $submenu_array[1] )) |
|
1734 | - return true; |
|
1735 | - else |
|
1736 | - return false; |
|
1813 | + if ( current_user_can( $submenu_array[1] )) { |
|
1814 | + return true; |
|
1815 | + } else { |
|
1816 | + return false; |
|
1817 | + } |
|
1737 | 1818 | } elseif ( $submenu_array[2] == $pagenow ) { |
1738 | - if ( current_user_can( $submenu_array[1] )) |
|
1739 | - return true; |
|
1740 | - else |
|
1741 | - return false; |
|
1819 | + if ( current_user_can( $submenu_array[1] )) { |
|
1820 | + return true; |
|
1821 | + } else { |
|
1822 | + return false; |
|
1823 | + } |
|
1742 | 1824 | } |
1743 | 1825 | } |
1744 | 1826 | } |
1745 | 1827 | |
1746 | 1828 | foreach ( $menu as $menu_array ) { |
1747 | 1829 | if ( $menu_array[2] == $parent) { |
1748 | - if ( current_user_can( $menu_array[1] )) |
|
1749 | - return true; |
|
1750 | - else |
|
1751 | - return false; |
|
1830 | + if ( current_user_can( $menu_array[1] )) { |
|
1831 | + return true; |
|
1832 | + } else { |
|
1833 | + return false; |
|
1834 | + } |
|
1752 | 1835 | } |
1753 | 1836 | } |
1754 | 1837 | |
@@ -1783,9 +1866,10 @@ discard block |
||
1783 | 1866 | } |
1784 | 1867 | |
1785 | 1868 | $new_whitelist_options[ $option_group ][] = $option_name; |
1786 | - if ( $sanitize_callback != '' ) |
|
1787 | - add_filter( "sanitize_option_{$option_name}", $sanitize_callback ); |
|
1788 | -} |
|
1869 | + if ( $sanitize_callback != '' ) { |
|
1870 | + add_filter( "sanitize_option_{$option_name}", $sanitize_callback ); |
|
1871 | + } |
|
1872 | + } |
|
1789 | 1873 | |
1790 | 1874 | /** |
1791 | 1875 | * Unregister a setting |
@@ -1812,11 +1896,13 @@ discard block |
||
1812 | 1896 | } |
1813 | 1897 | |
1814 | 1898 | $pos = array_search( $option_name, (array) $new_whitelist_options[ $option_group ] ); |
1815 | - if ( $pos !== false ) |
|
1816 | - unset( $new_whitelist_options[ $option_group ][ $pos ] ); |
|
1817 | - if ( $sanitize_callback != '' ) |
|
1818 | - remove_filter( "sanitize_option_{$option_name}", $sanitize_callback ); |
|
1819 | -} |
|
1899 | + if ( $pos !== false ) { |
|
1900 | + unset( $new_whitelist_options[ $option_group ][ $pos ] ); |
|
1901 | + } |
|
1902 | + if ( $sanitize_callback != '' ) { |
|
1903 | + remove_filter( "sanitize_option_{$option_name}", $sanitize_callback ); |
|
1904 | + } |
|
1905 | + } |
|
1820 | 1906 | |
1821 | 1907 | /** |
1822 | 1908 | * Refreshes the value of the options whitelist available via the 'whitelist_options' filter. |
@@ -1831,8 +1917,9 @@ discard block |
||
1831 | 1917 | function option_update_filter( $options ) { |
1832 | 1918 | global $new_whitelist_options; |
1833 | 1919 | |
1834 | - if ( is_array( $new_whitelist_options ) ) |
|
1835 | - $options = add_option_whitelist( $new_whitelist_options, $options ); |
|
1920 | + if ( is_array( $new_whitelist_options ) ) { |
|
1921 | + $options = add_option_whitelist( $new_whitelist_options, $options ); |
|
1922 | + } |
|
1836 | 1923 | |
1837 | 1924 | return $options; |
1838 | 1925 | } |
@@ -1849,10 +1936,11 @@ discard block |
||
1849 | 1936 | * @return array |
1850 | 1937 | */ |
1851 | 1938 | function add_option_whitelist( $new_options, $options = '' ) { |
1852 | - if ( $options == '' ) |
|
1853 | - global $whitelist_options; |
|
1854 | - else |
|
1855 | - $whitelist_options = $options; |
|
1939 | + if ( $options == '' ) { |
|
1940 | + global $whitelist_options; |
|
1941 | + } else { |
|
1942 | + $whitelist_options = $options; |
|
1943 | + } |
|
1856 | 1944 | |
1857 | 1945 | foreach ( $new_options as $page => $keys ) { |
1858 | 1946 | foreach ( $keys as $key ) { |
@@ -1861,8 +1949,9 @@ discard block |
||
1861 | 1949 | $whitelist_options[ $page ][] = $key; |
1862 | 1950 | } else { |
1863 | 1951 | $pos = array_search( $key, $whitelist_options[ $page ] ); |
1864 | - if ( $pos === false ) |
|
1865 | - $whitelist_options[ $page ][] = $key; |
|
1952 | + if ( $pos === false ) { |
|
1953 | + $whitelist_options[ $page ][] = $key; |
|
1954 | + } |
|
1866 | 1955 | } |
1867 | 1956 | } |
1868 | 1957 | } |
@@ -1882,17 +1971,19 @@ discard block |
||
1882 | 1971 | * @return array |
1883 | 1972 | */ |
1884 | 1973 | function remove_option_whitelist( $del_options, $options = '' ) { |
1885 | - if ( $options == '' ) |
|
1886 | - global $whitelist_options; |
|
1887 | - else |
|
1888 | - $whitelist_options = $options; |
|
1974 | + if ( $options == '' ) { |
|
1975 | + global $whitelist_options; |
|
1976 | + } else { |
|
1977 | + $whitelist_options = $options; |
|
1978 | + } |
|
1889 | 1979 | |
1890 | 1980 | foreach ( $del_options as $page => $keys ) { |
1891 | 1981 | foreach ( $keys as $key ) { |
1892 | 1982 | if ( isset($whitelist_options[ $page ]) && is_array($whitelist_options[ $page ]) ) { |
1893 | 1983 | $pos = array_search( $key, $whitelist_options[ $page ] ); |
1894 | - if ( $pos !== false ) |
|
1895 | - unset( $whitelist_options[ $page ][ $pos ] ); |
|
1984 | + if ( $pos !== false ) { |
|
1985 | + unset( $whitelist_options[ $page ][ $pos ] ); |
|
1986 | + } |
|
1896 | 1987 | } |
1897 | 1988 | } |
1898 | 1989 | } |
@@ -1921,8 +2012,9 @@ discard block |
||
1921 | 2012 | * @param bool $clear_update_cache Whether to clear the Plugin updates cache |
1922 | 2013 | */ |
1923 | 2014 | function wp_clean_plugins_cache( $clear_update_cache = true ) { |
1924 | - if ( $clear_update_cache ) |
|
1925 | - delete_site_transient( 'update_plugins' ); |
|
2015 | + if ( $clear_update_cache ) { |
|
2016 | + delete_site_transient( 'update_plugins' ); |
|
2017 | + } |
|
1926 | 2018 | wp_cache_delete( 'plugins', 'plugins' ); |
1927 | 2019 | } |
1928 | 2020 |
@@ -20,10 +20,6 @@ discard block |
||
20 | 20 | * |
21 | 21 | * @param string $cap Capability name. |
22 | 22 | * @param int $user_id User ID. |
23 | - * @param int $object_id Optional. ID of the specific object to check against if `$cap` is a "meta" cap. |
|
24 | - * "Meta" capabilities, e.g. 'edit_post', 'edit_user', etc., are capabilities used |
|
25 | - * by map_meta_cap() to map to other "primitive" capabilities, e.g. 'edit_posts', |
|
26 | - * 'edit_others_posts', etc. The parameter is accessed via func_get_args(). |
|
27 | 23 | * @return array Actual capabilities for meta capability. |
28 | 24 | */ |
29 | 25 | function map_meta_cap( $cap, $user_id ) { |
@@ -416,11 +412,6 @@ discard block |
||
416 | 412 | * @see map_meta_cap() |
417 | 413 | * |
418 | 414 | * @param string $capability Capability name. |
419 | - * @param int $object_id Optional. ID of the specific object to check against if `$capability` is a "meta" cap. |
|
420 | - * "Meta" capabilities, e.g. 'edit_post', 'edit_user', etc., are capabilities used |
|
421 | - * by map_meta_cap() to map to other "primitive" capabilities, e.g. 'edit_posts', |
|
422 | - * 'edit_others_posts', etc. Accessed via func_get_args() and passed to WP_User::has_cap(), |
|
423 | - * then map_meta_cap(). |
|
424 | 415 | * @return bool Whether the current user has the given capability. If `$capability` is a meta cap and `$object_id` is |
425 | 416 | * passed, whether the current user has the given meta capability for the given object. |
426 | 417 | */ |
@@ -1,10 +1,10 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Core User Role & Capabilities API |
|
4 | - * |
|
5 | - * @package WordPress |
|
6 | - * @subpackage Users |
|
7 | - */ |
|
3 | + * Core User Role & Capabilities API |
|
4 | + * |
|
5 | + * @package WordPress |
|
6 | + * @subpackage Users |
|
7 | + */ |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Map meta capabilities to primitive capabilities. |
@@ -31,224 +31,224 @@ discard block |
||
31 | 31 | $caps = array(); |
32 | 32 | |
33 | 33 | switch ( $cap ) { |
34 | - case 'remove_user': |
|
35 | - $caps[] = 'remove_users'; |
|
36 | - break; |
|
37 | - case 'promote_user': |
|
38 | - case 'add_users': |
|
39 | - $caps[] = 'promote_users'; |
|
40 | - break; |
|
41 | - case 'edit_user': |
|
42 | - case 'edit_users': |
|
43 | - // Allow user to edit itself |
|
44 | - if ( 'edit_user' == $cap && isset( $args[0] ) && $user_id == $args[0] ) |
|
34 | + case 'remove_user': |
|
35 | + $caps[] = 'remove_users'; |
|
45 | 36 | break; |
46 | - |
|
47 | - // In multisite the user must have manage_network_users caps. If editing a super admin, the user must be a super admin. |
|
48 | - if ( is_multisite() && ( ( ! is_super_admin( $user_id ) && 'edit_user' === $cap && is_super_admin( $args[0] ) ) || ! user_can( $user_id, 'manage_network_users' ) ) ) { |
|
49 | - $caps[] = 'do_not_allow'; |
|
50 | - } else { |
|
51 | - $caps[] = 'edit_users'; // edit_user maps to edit_users. |
|
52 | - } |
|
53 | - break; |
|
54 | - case 'delete_post': |
|
55 | - case 'delete_page': |
|
56 | - $post = get_post( $args[0] ); |
|
57 | - if ( ! $post ) { |
|
58 | - $caps[] = 'do_not_allow'; |
|
37 | + case 'promote_user': |
|
38 | + case 'add_users': |
|
39 | + $caps[] = 'promote_users'; |
|
59 | 40 | break; |
60 | - } |
|
41 | + case 'edit_user': |
|
42 | + case 'edit_users': |
|
43 | + // Allow user to edit itself |
|
44 | + if ( 'edit_user' == $cap && isset( $args[0] ) && $user_id == $args[0] ) |
|
45 | + break; |
|
61 | 46 | |
62 | - if ( 'revision' == $post->post_type ) { |
|
63 | - $post = get_post( $post->post_parent ); |
|
47 | + // In multisite the user must have manage_network_users caps. If editing a super admin, the user must be a super admin. |
|
48 | + if ( is_multisite() && ( ( ! is_super_admin( $user_id ) && 'edit_user' === $cap && is_super_admin( $args[0] ) ) || ! user_can( $user_id, 'manage_network_users' ) ) ) { |
|
49 | + $caps[] = 'do_not_allow'; |
|
50 | + } else { |
|
51 | + $caps[] = 'edit_users'; // edit_user maps to edit_users. |
|
52 | + } |
|
53 | + break; |
|
54 | + case 'delete_post': |
|
55 | + case 'delete_page': |
|
56 | + $post = get_post( $args[0] ); |
|
64 | 57 | if ( ! $post ) { |
65 | 58 | $caps[] = 'do_not_allow'; |
66 | 59 | break; |
67 | 60 | } |
68 | - } |
|
69 | 61 | |
70 | - $post_type = get_post_type_object( $post->post_type ); |
|
71 | - if ( ! $post_type ) { |
|
72 | - /* translators: 1: post type, 2: capability name */ |
|
73 | - _doing_it_wrong( __FUNCTION__, sprintf( __( 'The post type %1$s is not registered, so it may not be reliable to check the capability "%2$s" against a post of that type.' ), $post->post_type, $cap ), '4.4.0' ); |
|
74 | - $caps[] = 'edit_others_posts'; |
|
75 | - break; |
|
76 | - } |
|
62 | + if ( 'revision' == $post->post_type ) { |
|
63 | + $post = get_post( $post->post_parent ); |
|
64 | + if ( ! $post ) { |
|
65 | + $caps[] = 'do_not_allow'; |
|
66 | + break; |
|
67 | + } |
|
68 | + } |
|
77 | 69 | |
78 | - if ( ! $post_type->map_meta_cap ) { |
|
79 | - $caps[] = $post_type->cap->$cap; |
|
80 | - // Prior to 3.1 we would re-call map_meta_cap here. |
|
81 | - if ( 'delete_post' == $cap ) |
|
82 | - $cap = $post_type->cap->$cap; |
|
83 | - break; |
|
84 | - } |
|
70 | + $post_type = get_post_type_object( $post->post_type ); |
|
71 | + if ( ! $post_type ) { |
|
72 | + /* translators: 1: post type, 2: capability name */ |
|
73 | + _doing_it_wrong( __FUNCTION__, sprintf( __( 'The post type %1$s is not registered, so it may not be reliable to check the capability "%2$s" against a post of that type.' ), $post->post_type, $cap ), '4.4.0' ); |
|
74 | + $caps[] = 'edit_others_posts'; |
|
75 | + break; |
|
76 | + } |
|
85 | 77 | |
86 | - // If the post author is set and the user is the author... |
|
87 | - if ( $post->post_author && $user_id == $post->post_author ) { |
|
88 | - // If the post is published or scheduled... |
|
89 | - if ( in_array( $post->post_status, array( 'publish', 'future' ), true ) ) { |
|
90 | - $caps[] = $post_type->cap->delete_published_posts; |
|
91 | - } elseif ( 'trash' == $post->post_status ) { |
|
92 | - $status = get_post_meta( $post->ID, '_wp_trash_meta_status', true ); |
|
93 | - if ( in_array( $status, array( 'publish', 'future' ), true ) ) { |
|
78 | + if ( ! $post_type->map_meta_cap ) { |
|
79 | + $caps[] = $post_type->cap->$cap; |
|
80 | + // Prior to 3.1 we would re-call map_meta_cap here. |
|
81 | + if ( 'delete_post' == $cap ) |
|
82 | + $cap = $post_type->cap->$cap; |
|
83 | + break; |
|
84 | + } |
|
85 | + |
|
86 | + // If the post author is set and the user is the author... |
|
87 | + if ( $post->post_author && $user_id == $post->post_author ) { |
|
88 | + // If the post is published or scheduled... |
|
89 | + if ( in_array( $post->post_status, array( 'publish', 'future' ), true ) ) { |
|
94 | 90 | $caps[] = $post_type->cap->delete_published_posts; |
91 | + } elseif ( 'trash' == $post->post_status ) { |
|
92 | + $status = get_post_meta( $post->ID, '_wp_trash_meta_status', true ); |
|
93 | + if ( in_array( $status, array( 'publish', 'future' ), true ) ) { |
|
94 | + $caps[] = $post_type->cap->delete_published_posts; |
|
95 | + } else { |
|
96 | + $caps[] = $post_type->cap->delete_posts; |
|
97 | + } |
|
95 | 98 | } else { |
99 | + // If the post is draft... |
|
96 | 100 | $caps[] = $post_type->cap->delete_posts; |
97 | 101 | } |
98 | 102 | } else { |
99 | - // If the post is draft... |
|
100 | - $caps[] = $post_type->cap->delete_posts; |
|
101 | - } |
|
102 | - } else { |
|
103 | - // The user is trying to edit someone else's post. |
|
104 | - $caps[] = $post_type->cap->delete_others_posts; |
|
105 | - // The post is published or scheduled, extra cap required. |
|
106 | - if ( in_array( $post->post_status, array( 'publish', 'future' ), true ) ) { |
|
107 | - $caps[] = $post_type->cap->delete_published_posts; |
|
108 | - } elseif ( 'private' == $post->post_status ) { |
|
109 | - $caps[] = $post_type->cap->delete_private_posts; |
|
103 | + // The user is trying to edit someone else's post. |
|
104 | + $caps[] = $post_type->cap->delete_others_posts; |
|
105 | + // The post is published or scheduled, extra cap required. |
|
106 | + if ( in_array( $post->post_status, array( 'publish', 'future' ), true ) ) { |
|
107 | + $caps[] = $post_type->cap->delete_published_posts; |
|
108 | + } elseif ( 'private' == $post->post_status ) { |
|
109 | + $caps[] = $post_type->cap->delete_private_posts; |
|
110 | + } |
|
110 | 111 | } |
111 | - } |
|
112 | - break; |
|
113 | - // edit_post breaks down to edit_posts, edit_published_posts, or |
|
114 | - // edit_others_posts |
|
115 | - case 'edit_post': |
|
116 | - case 'edit_page': |
|
117 | - $post = get_post( $args[0] ); |
|
118 | - if ( ! $post ) { |
|
119 | - $caps[] = 'do_not_allow'; |
|
120 | 112 | break; |
121 | - } |
|
122 | - |
|
123 | - if ( 'revision' == $post->post_type ) { |
|
124 | - $post = get_post( $post->post_parent ); |
|
113 | + // edit_post breaks down to edit_posts, edit_published_posts, or |
|
114 | + // edit_others_posts |
|
115 | + case 'edit_post': |
|
116 | + case 'edit_page': |
|
117 | + $post = get_post( $args[0] ); |
|
125 | 118 | if ( ! $post ) { |
126 | 119 | $caps[] = 'do_not_allow'; |
127 | 120 | break; |
128 | 121 | } |
129 | - } |
|
130 | 122 | |
131 | - $post_type = get_post_type_object( $post->post_type ); |
|
132 | - if ( ! $post_type ) { |
|
133 | - /* translators: 1: post type, 2: capability name */ |
|
134 | - _doing_it_wrong( __FUNCTION__, sprintf( __( 'The post type %1$s is not registered, so it may not be reliable to check the capability "%2$s" against a post of that type.' ), $post->post_type, $cap ), '4.4.0' ); |
|
135 | - $caps[] = 'edit_others_posts'; |
|
136 | - break; |
|
137 | - } |
|
123 | + if ( 'revision' == $post->post_type ) { |
|
124 | + $post = get_post( $post->post_parent ); |
|
125 | + if ( ! $post ) { |
|
126 | + $caps[] = 'do_not_allow'; |
|
127 | + break; |
|
128 | + } |
|
129 | + } |
|
138 | 130 | |
139 | - if ( ! $post_type->map_meta_cap ) { |
|
140 | - $caps[] = $post_type->cap->$cap; |
|
141 | - // Prior to 3.1 we would re-call map_meta_cap here. |
|
142 | - if ( 'edit_post' == $cap ) |
|
143 | - $cap = $post_type->cap->$cap; |
|
144 | - break; |
|
145 | - } |
|
131 | + $post_type = get_post_type_object( $post->post_type ); |
|
132 | + if ( ! $post_type ) { |
|
133 | + /* translators: 1: post type, 2: capability name */ |
|
134 | + _doing_it_wrong( __FUNCTION__, sprintf( __( 'The post type %1$s is not registered, so it may not be reliable to check the capability "%2$s" against a post of that type.' ), $post->post_type, $cap ), '4.4.0' ); |
|
135 | + $caps[] = 'edit_others_posts'; |
|
136 | + break; |
|
137 | + } |
|
146 | 138 | |
147 | - // If the post author is set and the user is the author... |
|
148 | - if ( $post->post_author && $user_id == $post->post_author ) { |
|
149 | - // If the post is published or scheduled... |
|
150 | - if ( in_array( $post->post_status, array( 'publish', 'future' ), true ) ) { |
|
151 | - $caps[] = $post_type->cap->edit_published_posts; |
|
152 | - } elseif ( 'trash' == $post->post_status ) { |
|
153 | - $status = get_post_meta( $post->ID, '_wp_trash_meta_status', true ); |
|
154 | - if ( in_array( $status, array( 'publish', 'future' ), true ) ) { |
|
139 | + if ( ! $post_type->map_meta_cap ) { |
|
140 | + $caps[] = $post_type->cap->$cap; |
|
141 | + // Prior to 3.1 we would re-call map_meta_cap here. |
|
142 | + if ( 'edit_post' == $cap ) |
|
143 | + $cap = $post_type->cap->$cap; |
|
144 | + break; |
|
145 | + } |
|
146 | + |
|
147 | + // If the post author is set and the user is the author... |
|
148 | + if ( $post->post_author && $user_id == $post->post_author ) { |
|
149 | + // If the post is published or scheduled... |
|
150 | + if ( in_array( $post->post_status, array( 'publish', 'future' ), true ) ) { |
|
155 | 151 | $caps[] = $post_type->cap->edit_published_posts; |
152 | + } elseif ( 'trash' == $post->post_status ) { |
|
153 | + $status = get_post_meta( $post->ID, '_wp_trash_meta_status', true ); |
|
154 | + if ( in_array( $status, array( 'publish', 'future' ), true ) ) { |
|
155 | + $caps[] = $post_type->cap->edit_published_posts; |
|
156 | + } else { |
|
157 | + $caps[] = $post_type->cap->edit_posts; |
|
158 | + } |
|
156 | 159 | } else { |
160 | + // If the post is draft... |
|
157 | 161 | $caps[] = $post_type->cap->edit_posts; |
158 | 162 | } |
159 | 163 | } else { |
160 | - // If the post is draft... |
|
161 | - $caps[] = $post_type->cap->edit_posts; |
|
162 | - } |
|
163 | - } else { |
|
164 | - // The user is trying to edit someone else's post. |
|
165 | - $caps[] = $post_type->cap->edit_others_posts; |
|
166 | - // The post is published or scheduled, extra cap required. |
|
167 | - if ( in_array( $post->post_status, array( 'publish', 'future' ), true ) ) { |
|
168 | - $caps[] = $post_type->cap->edit_published_posts; |
|
169 | - } elseif ( 'private' == $post->post_status ) { |
|
170 | - $caps[] = $post_type->cap->edit_private_posts; |
|
164 | + // The user is trying to edit someone else's post. |
|
165 | + $caps[] = $post_type->cap->edit_others_posts; |
|
166 | + // The post is published or scheduled, extra cap required. |
|
167 | + if ( in_array( $post->post_status, array( 'publish', 'future' ), true ) ) { |
|
168 | + $caps[] = $post_type->cap->edit_published_posts; |
|
169 | + } elseif ( 'private' == $post->post_status ) { |
|
170 | + $caps[] = $post_type->cap->edit_private_posts; |
|
171 | + } |
|
171 | 172 | } |
172 | - } |
|
173 | - break; |
|
174 | - case 'read_post': |
|
175 | - case 'read_page': |
|
176 | - $post = get_post( $args[0] ); |
|
177 | - if ( ! $post ) { |
|
178 | - $caps[] = 'do_not_allow'; |
|
179 | 173 | break; |
180 | - } |
|
181 | - |
|
182 | - if ( 'revision' == $post->post_type ) { |
|
183 | - $post = get_post( $post->post_parent ); |
|
174 | + case 'read_post': |
|
175 | + case 'read_page': |
|
176 | + $post = get_post( $args[0] ); |
|
184 | 177 | if ( ! $post ) { |
185 | 178 | $caps[] = 'do_not_allow'; |
186 | 179 | break; |
187 | 180 | } |
188 | - } |
|
189 | 181 | |
190 | - $post_type = get_post_type_object( $post->post_type ); |
|
191 | - if ( ! $post_type ) { |
|
192 | - /* translators: 1: post type, 2: capability name */ |
|
193 | - _doing_it_wrong( __FUNCTION__, sprintf( __( 'The post type %1$s is not registered, so it may not be reliable to check the capability "%2$s" against a post of that type.' ), $post->post_type, $cap ), '4.4.0' ); |
|
194 | - $caps[] = 'edit_others_posts'; |
|
195 | - break; |
|
196 | - } |
|
182 | + if ( 'revision' == $post->post_type ) { |
|
183 | + $post = get_post( $post->post_parent ); |
|
184 | + if ( ! $post ) { |
|
185 | + $caps[] = 'do_not_allow'; |
|
186 | + break; |
|
187 | + } |
|
188 | + } |
|
197 | 189 | |
198 | - if ( ! $post_type->map_meta_cap ) { |
|
199 | - $caps[] = $post_type->cap->$cap; |
|
200 | - // Prior to 3.1 we would re-call map_meta_cap here. |
|
201 | - if ( 'read_post' == $cap ) |
|
202 | - $cap = $post_type->cap->$cap; |
|
203 | - break; |
|
204 | - } |
|
190 | + $post_type = get_post_type_object( $post->post_type ); |
|
191 | + if ( ! $post_type ) { |
|
192 | + /* translators: 1: post type, 2: capability name */ |
|
193 | + _doing_it_wrong( __FUNCTION__, sprintf( __( 'The post type %1$s is not registered, so it may not be reliable to check the capability "%2$s" against a post of that type.' ), $post->post_type, $cap ), '4.4.0' ); |
|
194 | + $caps[] = 'edit_others_posts'; |
|
195 | + break; |
|
196 | + } |
|
205 | 197 | |
206 | - $status_obj = get_post_status_object( $post->post_status ); |
|
207 | - if ( $status_obj->public ) { |
|
208 | - $caps[] = $post_type->cap->read; |
|
209 | - break; |
|
210 | - } |
|
198 | + if ( ! $post_type->map_meta_cap ) { |
|
199 | + $caps[] = $post_type->cap->$cap; |
|
200 | + // Prior to 3.1 we would re-call map_meta_cap here. |
|
201 | + if ( 'read_post' == $cap ) |
|
202 | + $cap = $post_type->cap->$cap; |
|
203 | + break; |
|
204 | + } |
|
211 | 205 | |
212 | - if ( $post->post_author && $user_id == $post->post_author ) { |
|
213 | - $caps[] = $post_type->cap->read; |
|
214 | - } elseif ( $status_obj->private ) { |
|
215 | - $caps[] = $post_type->cap->read_private_posts; |
|
216 | - } else { |
|
217 | - $caps = map_meta_cap( 'edit_post', $user_id, $post->ID ); |
|
218 | - } |
|
219 | - break; |
|
220 | - case 'publish_post': |
|
221 | - $post = get_post( $args[0] ); |
|
222 | - if ( ! $post ) { |
|
223 | - $caps[] = 'do_not_allow'; |
|
224 | - break; |
|
225 | - } |
|
206 | + $status_obj = get_post_status_object( $post->post_status ); |
|
207 | + if ( $status_obj->public ) { |
|
208 | + $caps[] = $post_type->cap->read; |
|
209 | + break; |
|
210 | + } |
|
226 | 211 | |
227 | - $post_type = get_post_type_object( $post->post_type ); |
|
228 | - if ( ! $post_type ) { |
|
229 | - /* translators: 1: post type, 2: capability name */ |
|
230 | - _doing_it_wrong( __FUNCTION__, sprintf( __( 'The post type %1$s is not registered, so it may not be reliable to check the capability "%2$s" against a post of that type.' ), $post->post_type, $cap ), '4.4.0' ); |
|
231 | - $caps[] = 'edit_others_posts'; |
|
212 | + if ( $post->post_author && $user_id == $post->post_author ) { |
|
213 | + $caps[] = $post_type->cap->read; |
|
214 | + } elseif ( $status_obj->private ) { |
|
215 | + $caps[] = $post_type->cap->read_private_posts; |
|
216 | + } else { |
|
217 | + $caps = map_meta_cap( 'edit_post', $user_id, $post->ID ); |
|
218 | + } |
|
232 | 219 | break; |
233 | - } |
|
220 | + case 'publish_post': |
|
221 | + $post = get_post( $args[0] ); |
|
222 | + if ( ! $post ) { |
|
223 | + $caps[] = 'do_not_allow'; |
|
224 | + break; |
|
225 | + } |
|
234 | 226 | |
235 | - $caps[] = $post_type->cap->publish_posts; |
|
236 | - break; |
|
237 | - case 'edit_post_meta': |
|
238 | - case 'delete_post_meta': |
|
239 | - case 'add_post_meta': |
|
240 | - $post = get_post( $args[0] ); |
|
241 | - if ( ! $post ) { |
|
242 | - $caps[] = 'do_not_allow'; |
|
227 | + $post_type = get_post_type_object( $post->post_type ); |
|
228 | + if ( ! $post_type ) { |
|
229 | + /* translators: 1: post type, 2: capability name */ |
|
230 | + _doing_it_wrong( __FUNCTION__, sprintf( __( 'The post type %1$s is not registered, so it may not be reliable to check the capability "%2$s" against a post of that type.' ), $post->post_type, $cap ), '4.4.0' ); |
|
231 | + $caps[] = 'edit_others_posts'; |
|
232 | + break; |
|
233 | + } |
|
234 | + |
|
235 | + $caps[] = $post_type->cap->publish_posts; |
|
243 | 236 | break; |
244 | - } |
|
237 | + case 'edit_post_meta': |
|
238 | + case 'delete_post_meta': |
|
239 | + case 'add_post_meta': |
|
240 | + $post = get_post( $args[0] ); |
|
241 | + if ( ! $post ) { |
|
242 | + $caps[] = 'do_not_allow'; |
|
243 | + break; |
|
244 | + } |
|
245 | 245 | |
246 | - $caps = map_meta_cap( 'edit_post', $user_id, $post->ID ); |
|
246 | + $caps = map_meta_cap( 'edit_post', $user_id, $post->ID ); |
|
247 | 247 | |
248 | - $meta_key = isset( $args[ 1 ] ) ? $args[ 1 ] : false; |
|
248 | + $meta_key = isset( $args[ 1 ] ) ? $args[ 1 ] : false; |
|
249 | 249 | |
250 | - if ( $meta_key && has_filter( "auth_post_meta_{$meta_key}" ) ) { |
|
251 | - /** |
|
250 | + if ( $meta_key && has_filter( "auth_post_meta_{$meta_key}" ) ) { |
|
251 | + /** |
|
252 | 252 | * Filter whether the user is allowed to add post meta to a post. |
253 | 253 | * |
254 | 254 | * The dynamic portion of the hook name, `$meta_key`, refers to the |
@@ -263,130 +263,130 @@ discard block |
||
263 | 263 | * @param string $cap Capability name. |
264 | 264 | * @param array $caps User capabilities. |
265 | 265 | */ |
266 | - $allowed = apply_filters( "auth_post_meta_{$meta_key}", false, $meta_key, $post->ID, $user_id, $cap, $caps ); |
|
267 | - if ( ! $allowed ) |
|
266 | + $allowed = apply_filters( "auth_post_meta_{$meta_key}", false, $meta_key, $post->ID, $user_id, $cap, $caps ); |
|
267 | + if ( ! $allowed ) |
|
268 | + $caps[] = $cap; |
|
269 | + } elseif ( $meta_key && is_protected_meta( $meta_key, 'post' ) ) { |
|
268 | 270 | $caps[] = $cap; |
269 | - } elseif ( $meta_key && is_protected_meta( $meta_key, 'post' ) ) { |
|
270 | - $caps[] = $cap; |
|
271 | - } |
|
272 | - break; |
|
273 | - case 'edit_comment': |
|
274 | - $comment = get_comment( $args[0] ); |
|
275 | - if ( ! $comment ) { |
|
276 | - $caps[] = 'do_not_allow'; |
|
271 | + } |
|
277 | 272 | break; |
278 | - } |
|
273 | + case 'edit_comment': |
|
274 | + $comment = get_comment( $args[0] ); |
|
275 | + if ( ! $comment ) { |
|
276 | + $caps[] = 'do_not_allow'; |
|
277 | + break; |
|
278 | + } |
|
279 | 279 | |
280 | - $post = get_post( $comment->comment_post_ID ); |
|
280 | + $post = get_post( $comment->comment_post_ID ); |
|
281 | 281 | |
282 | - /* |
|
282 | + /* |
|
283 | 283 | * If the post doesn't exist, we have an orphaned comment. |
284 | 284 | * Fall back to the edit_posts capability, instead. |
285 | 285 | */ |
286 | - if ( $post ) { |
|
287 | - $caps = map_meta_cap( 'edit_post', $user_id, $post->ID ); |
|
288 | - } else { |
|
289 | - $caps = map_meta_cap( 'edit_posts', $user_id ); |
|
290 | - } |
|
291 | - break; |
|
292 | - case 'unfiltered_upload': |
|
293 | - if ( defined('ALLOW_UNFILTERED_UPLOADS') && ALLOW_UNFILTERED_UPLOADS && ( !is_multisite() || is_super_admin( $user_id ) ) ) |
|
294 | - $caps[] = $cap; |
|
295 | - else |
|
296 | - $caps[] = 'do_not_allow'; |
|
297 | - break; |
|
298 | - case 'unfiltered_html' : |
|
299 | - // Disallow unfiltered_html for all users, even admins and super admins. |
|
300 | - if ( defined( 'DISALLOW_UNFILTERED_HTML' ) && DISALLOW_UNFILTERED_HTML ) |
|
301 | - $caps[] = 'do_not_allow'; |
|
302 | - elseif ( is_multisite() && ! is_super_admin( $user_id ) ) |
|
303 | - $caps[] = 'do_not_allow'; |
|
304 | - else |
|
305 | - $caps[] = $cap; |
|
306 | - break; |
|
307 | - case 'edit_files': |
|
308 | - case 'edit_plugins': |
|
309 | - case 'edit_themes': |
|
310 | - // Disallow the file editors. |
|
311 | - if ( defined( 'DISALLOW_FILE_EDIT' ) && DISALLOW_FILE_EDIT ) |
|
312 | - $caps[] = 'do_not_allow'; |
|
313 | - elseif ( defined( 'DISALLOW_FILE_MODS' ) && DISALLOW_FILE_MODS ) |
|
314 | - $caps[] = 'do_not_allow'; |
|
315 | - elseif ( is_multisite() && ! is_super_admin( $user_id ) ) |
|
316 | - $caps[] = 'do_not_allow'; |
|
317 | - else |
|
318 | - $caps[] = $cap; |
|
319 | - break; |
|
320 | - case 'update_plugins': |
|
321 | - case 'delete_plugins': |
|
322 | - case 'install_plugins': |
|
323 | - case 'upload_plugins': |
|
324 | - case 'update_themes': |
|
325 | - case 'delete_themes': |
|
326 | - case 'install_themes': |
|
327 | - case 'upload_themes': |
|
328 | - case 'update_core': |
|
329 | - // Disallow anything that creates, deletes, or updates core, plugin, or theme files. |
|
330 | - // Files in uploads are excepted. |
|
331 | - if ( defined( 'DISALLOW_FILE_MODS' ) && DISALLOW_FILE_MODS ) { |
|
332 | - $caps[] = 'do_not_allow'; |
|
333 | - } elseif ( is_multisite() && ! is_super_admin( $user_id ) ) { |
|
334 | - $caps[] = 'do_not_allow'; |
|
335 | - } elseif ( 'upload_themes' === $cap ) { |
|
336 | - $caps[] = 'install_themes'; |
|
337 | - } elseif ( 'upload_plugins' === $cap ) { |
|
338 | - $caps[] = 'install_plugins'; |
|
339 | - } else { |
|
340 | - $caps[] = $cap; |
|
341 | - } |
|
342 | - break; |
|
343 | - case 'activate_plugins': |
|
344 | - $caps[] = $cap; |
|
345 | - if ( is_multisite() ) { |
|
346 | - // update_, install_, and delete_ are handled above with is_super_admin(). |
|
347 | - $menu_perms = get_site_option( 'menu_items', array() ); |
|
348 | - if ( empty( $menu_perms['plugins'] ) ) |
|
349 | - $caps[] = 'manage_network_plugins'; |
|
350 | - } |
|
351 | - break; |
|
352 | - case 'delete_user': |
|
353 | - case 'delete_users': |
|
354 | - // If multisite only super admins can delete users. |
|
355 | - if ( is_multisite() && ! is_super_admin( $user_id ) ) |
|
356 | - $caps[] = 'do_not_allow'; |
|
357 | - else |
|
358 | - $caps[] = 'delete_users'; // delete_user maps to delete_users. |
|
359 | - break; |
|
360 | - case 'create_users': |
|
361 | - if ( !is_multisite() ) |
|
362 | - $caps[] = $cap; |
|
363 | - elseif ( is_super_admin( $user_id ) || get_site_option( 'add_new_users' ) ) |
|
364 | - $caps[] = $cap; |
|
365 | - else |
|
366 | - $caps[] = 'do_not_allow'; |
|
367 | - break; |
|
368 | - case 'manage_links' : |
|
369 | - if ( get_option( 'link_manager_enabled' ) ) |
|
286 | + if ( $post ) { |
|
287 | + $caps = map_meta_cap( 'edit_post', $user_id, $post->ID ); |
|
288 | + } else { |
|
289 | + $caps = map_meta_cap( 'edit_posts', $user_id ); |
|
290 | + } |
|
291 | + break; |
|
292 | + case 'unfiltered_upload': |
|
293 | + if ( defined('ALLOW_UNFILTERED_UPLOADS') && ALLOW_UNFILTERED_UPLOADS && ( !is_multisite() || is_super_admin( $user_id ) ) ) |
|
294 | + $caps[] = $cap; |
|
295 | + else |
|
296 | + $caps[] = 'do_not_allow'; |
|
297 | + break; |
|
298 | + case 'unfiltered_html' : |
|
299 | + // Disallow unfiltered_html for all users, even admins and super admins. |
|
300 | + if ( defined( 'DISALLOW_UNFILTERED_HTML' ) && DISALLOW_UNFILTERED_HTML ) |
|
301 | + $caps[] = 'do_not_allow'; |
|
302 | + elseif ( is_multisite() && ! is_super_admin( $user_id ) ) |
|
303 | + $caps[] = 'do_not_allow'; |
|
304 | + else |
|
305 | + $caps[] = $cap; |
|
306 | + break; |
|
307 | + case 'edit_files': |
|
308 | + case 'edit_plugins': |
|
309 | + case 'edit_themes': |
|
310 | + // Disallow the file editors. |
|
311 | + if ( defined( 'DISALLOW_FILE_EDIT' ) && DISALLOW_FILE_EDIT ) |
|
312 | + $caps[] = 'do_not_allow'; |
|
313 | + elseif ( defined( 'DISALLOW_FILE_MODS' ) && DISALLOW_FILE_MODS ) |
|
314 | + $caps[] = 'do_not_allow'; |
|
315 | + elseif ( is_multisite() && ! is_super_admin( $user_id ) ) |
|
316 | + $caps[] = 'do_not_allow'; |
|
317 | + else |
|
318 | + $caps[] = $cap; |
|
319 | + break; |
|
320 | + case 'update_plugins': |
|
321 | + case 'delete_plugins': |
|
322 | + case 'install_plugins': |
|
323 | + case 'upload_plugins': |
|
324 | + case 'update_themes': |
|
325 | + case 'delete_themes': |
|
326 | + case 'install_themes': |
|
327 | + case 'upload_themes': |
|
328 | + case 'update_core': |
|
329 | + // Disallow anything that creates, deletes, or updates core, plugin, or theme files. |
|
330 | + // Files in uploads are excepted. |
|
331 | + if ( defined( 'DISALLOW_FILE_MODS' ) && DISALLOW_FILE_MODS ) { |
|
332 | + $caps[] = 'do_not_allow'; |
|
333 | + } elseif ( is_multisite() && ! is_super_admin( $user_id ) ) { |
|
334 | + $caps[] = 'do_not_allow'; |
|
335 | + } elseif ( 'upload_themes' === $cap ) { |
|
336 | + $caps[] = 'install_themes'; |
|
337 | + } elseif ( 'upload_plugins' === $cap ) { |
|
338 | + $caps[] = 'install_plugins'; |
|
339 | + } else { |
|
340 | + $caps[] = $cap; |
|
341 | + } |
|
342 | + break; |
|
343 | + case 'activate_plugins': |
|
370 | 344 | $caps[] = $cap; |
371 | - else |
|
372 | - $caps[] = 'do_not_allow'; |
|
373 | - break; |
|
374 | - case 'customize' : |
|
375 | - $caps[] = 'edit_theme_options'; |
|
376 | - break; |
|
377 | - case 'delete_site': |
|
378 | - $caps[] = 'manage_options'; |
|
379 | - break; |
|
380 | - default: |
|
381 | - // Handle meta capabilities for custom post types. |
|
382 | - global $post_type_meta_caps; |
|
383 | - if ( isset( $post_type_meta_caps[ $cap ] ) ) { |
|
384 | - $args = array_merge( array( $post_type_meta_caps[ $cap ], $user_id ), $args ); |
|
385 | - return call_user_func_array( 'map_meta_cap', $args ); |
|
386 | - } |
|
345 | + if ( is_multisite() ) { |
|
346 | + // update_, install_, and delete_ are handled above with is_super_admin(). |
|
347 | + $menu_perms = get_site_option( 'menu_items', array() ); |
|
348 | + if ( empty( $menu_perms['plugins'] ) ) |
|
349 | + $caps[] = 'manage_network_plugins'; |
|
350 | + } |
|
351 | + break; |
|
352 | + case 'delete_user': |
|
353 | + case 'delete_users': |
|
354 | + // If multisite only super admins can delete users. |
|
355 | + if ( is_multisite() && ! is_super_admin( $user_id ) ) |
|
356 | + $caps[] = 'do_not_allow'; |
|
357 | + else |
|
358 | + $caps[] = 'delete_users'; // delete_user maps to delete_users. |
|
359 | + break; |
|
360 | + case 'create_users': |
|
361 | + if ( !is_multisite() ) |
|
362 | + $caps[] = $cap; |
|
363 | + elseif ( is_super_admin( $user_id ) || get_site_option( 'add_new_users' ) ) |
|
364 | + $caps[] = $cap; |
|
365 | + else |
|
366 | + $caps[] = 'do_not_allow'; |
|
367 | + break; |
|
368 | + case 'manage_links' : |
|
369 | + if ( get_option( 'link_manager_enabled' ) ) |
|
370 | + $caps[] = $cap; |
|
371 | + else |
|
372 | + $caps[] = 'do_not_allow'; |
|
373 | + break; |
|
374 | + case 'customize' : |
|
375 | + $caps[] = 'edit_theme_options'; |
|
376 | + break; |
|
377 | + case 'delete_site': |
|
378 | + $caps[] = 'manage_options'; |
|
379 | + break; |
|
380 | + default: |
|
381 | + // Handle meta capabilities for custom post types. |
|
382 | + global $post_type_meta_caps; |
|
383 | + if ( isset( $post_type_meta_caps[ $cap ] ) ) { |
|
384 | + $args = array_merge( array( $post_type_meta_caps[ $cap ], $user_id ), $args ); |
|
385 | + return call_user_func_array( 'map_meta_cap', $args ); |
|
386 | + } |
|
387 | 387 | |
388 | - // If no meta caps match, return the original cap. |
|
389 | - $caps[] = $cap; |
|
388 | + // If no meta caps match, return the original cap. |
|
389 | + $caps[] = $cap; |
|
390 | 390 | } |
391 | 391 | |
392 | 392 | /** |
@@ -26,11 +26,11 @@ discard block |
||
26 | 26 | * 'edit_others_posts', etc. The parameter is accessed via func_get_args(). |
27 | 27 | * @return array Actual capabilities for meta capability. |
28 | 28 | */ |
29 | -function map_meta_cap( $cap, $user_id ) { |
|
30 | - $args = array_slice( func_get_args(), 2 ); |
|
29 | +function map_meta_cap($cap, $user_id) { |
|
30 | + $args = array_slice(func_get_args(), 2); |
|
31 | 31 | $caps = array(); |
32 | 32 | |
33 | - switch ( $cap ) { |
|
33 | + switch ($cap) { |
|
34 | 34 | case 'remove_user': |
35 | 35 | $caps[] = 'remove_users'; |
36 | 36 | break; |
@@ -41,11 +41,11 @@ discard block |
||
41 | 41 | case 'edit_user': |
42 | 42 | case 'edit_users': |
43 | 43 | // Allow user to edit itself |
44 | - if ( 'edit_user' == $cap && isset( $args[0] ) && $user_id == $args[0] ) |
|
44 | + if ('edit_user' == $cap && isset($args[0]) && $user_id == $args[0]) |
|
45 | 45 | break; |
46 | 46 | |
47 | 47 | // In multisite the user must have manage_network_users caps. If editing a super admin, the user must be a super admin. |
48 | - if ( is_multisite() && ( ( ! is_super_admin( $user_id ) && 'edit_user' === $cap && is_super_admin( $args[0] ) ) || ! user_can( $user_id, 'manage_network_users' ) ) ) { |
|
48 | + if (is_multisite() && (( ! is_super_admin($user_id) && 'edit_user' === $cap && is_super_admin($args[0])) || ! user_can($user_id, 'manage_network_users'))) { |
|
49 | 49 | $caps[] = 'do_not_allow'; |
50 | 50 | } else { |
51 | 51 | $caps[] = 'edit_users'; // edit_user maps to edit_users. |
@@ -53,44 +53,44 @@ discard block |
||
53 | 53 | break; |
54 | 54 | case 'delete_post': |
55 | 55 | case 'delete_page': |
56 | - $post = get_post( $args[0] ); |
|
57 | - if ( ! $post ) { |
|
56 | + $post = get_post($args[0]); |
|
57 | + if ( ! $post) { |
|
58 | 58 | $caps[] = 'do_not_allow'; |
59 | 59 | break; |
60 | 60 | } |
61 | 61 | |
62 | - if ( 'revision' == $post->post_type ) { |
|
63 | - $post = get_post( $post->post_parent ); |
|
64 | - if ( ! $post ) { |
|
62 | + if ('revision' == $post->post_type) { |
|
63 | + $post = get_post($post->post_parent); |
|
64 | + if ( ! $post) { |
|
65 | 65 | $caps[] = 'do_not_allow'; |
66 | 66 | break; |
67 | 67 | } |
68 | 68 | } |
69 | 69 | |
70 | - $post_type = get_post_type_object( $post->post_type ); |
|
71 | - if ( ! $post_type ) { |
|
70 | + $post_type = get_post_type_object($post->post_type); |
|
71 | + if ( ! $post_type) { |
|
72 | 72 | /* translators: 1: post type, 2: capability name */ |
73 | - _doing_it_wrong( __FUNCTION__, sprintf( __( 'The post type %1$s is not registered, so it may not be reliable to check the capability "%2$s" against a post of that type.' ), $post->post_type, $cap ), '4.4.0' ); |
|
73 | + _doing_it_wrong(__FUNCTION__, sprintf(__('The post type %1$s is not registered, so it may not be reliable to check the capability "%2$s" against a post of that type.'), $post->post_type, $cap), '4.4.0'); |
|
74 | 74 | $caps[] = 'edit_others_posts'; |
75 | 75 | break; |
76 | 76 | } |
77 | 77 | |
78 | - if ( ! $post_type->map_meta_cap ) { |
|
78 | + if ( ! $post_type->map_meta_cap) { |
|
79 | 79 | $caps[] = $post_type->cap->$cap; |
80 | 80 | // Prior to 3.1 we would re-call map_meta_cap here. |
81 | - if ( 'delete_post' == $cap ) |
|
81 | + if ('delete_post' == $cap) |
|
82 | 82 | $cap = $post_type->cap->$cap; |
83 | 83 | break; |
84 | 84 | } |
85 | 85 | |
86 | 86 | // If the post author is set and the user is the author... |
87 | - if ( $post->post_author && $user_id == $post->post_author ) { |
|
87 | + if ($post->post_author && $user_id == $post->post_author) { |
|
88 | 88 | // If the post is published or scheduled... |
89 | - if ( in_array( $post->post_status, array( 'publish', 'future' ), true ) ) { |
|
89 | + if (in_array($post->post_status, array('publish', 'future'), true)) { |
|
90 | 90 | $caps[] = $post_type->cap->delete_published_posts; |
91 | - } elseif ( 'trash' == $post->post_status ) { |
|
92 | - $status = get_post_meta( $post->ID, '_wp_trash_meta_status', true ); |
|
93 | - if ( in_array( $status, array( 'publish', 'future' ), true ) ) { |
|
91 | + } elseif ('trash' == $post->post_status) { |
|
92 | + $status = get_post_meta($post->ID, '_wp_trash_meta_status', true); |
|
93 | + if (in_array($status, array('publish', 'future'), true)) { |
|
94 | 94 | $caps[] = $post_type->cap->delete_published_posts; |
95 | 95 | } else { |
96 | 96 | $caps[] = $post_type->cap->delete_posts; |
@@ -103,9 +103,9 @@ discard block |
||
103 | 103 | // The user is trying to edit someone else's post. |
104 | 104 | $caps[] = $post_type->cap->delete_others_posts; |
105 | 105 | // The post is published or scheduled, extra cap required. |
106 | - if ( in_array( $post->post_status, array( 'publish', 'future' ), true ) ) { |
|
106 | + if (in_array($post->post_status, array('publish', 'future'), true)) { |
|
107 | 107 | $caps[] = $post_type->cap->delete_published_posts; |
108 | - } elseif ( 'private' == $post->post_status ) { |
|
108 | + } elseif ('private' == $post->post_status) { |
|
109 | 109 | $caps[] = $post_type->cap->delete_private_posts; |
110 | 110 | } |
111 | 111 | } |
@@ -114,44 +114,44 @@ discard block |
||
114 | 114 | // edit_others_posts |
115 | 115 | case 'edit_post': |
116 | 116 | case 'edit_page': |
117 | - $post = get_post( $args[0] ); |
|
118 | - if ( ! $post ) { |
|
117 | + $post = get_post($args[0]); |
|
118 | + if ( ! $post) { |
|
119 | 119 | $caps[] = 'do_not_allow'; |
120 | 120 | break; |
121 | 121 | } |
122 | 122 | |
123 | - if ( 'revision' == $post->post_type ) { |
|
124 | - $post = get_post( $post->post_parent ); |
|
125 | - if ( ! $post ) { |
|
123 | + if ('revision' == $post->post_type) { |
|
124 | + $post = get_post($post->post_parent); |
|
125 | + if ( ! $post) { |
|
126 | 126 | $caps[] = 'do_not_allow'; |
127 | 127 | break; |
128 | 128 | } |
129 | 129 | } |
130 | 130 | |
131 | - $post_type = get_post_type_object( $post->post_type ); |
|
132 | - if ( ! $post_type ) { |
|
131 | + $post_type = get_post_type_object($post->post_type); |
|
132 | + if ( ! $post_type) { |
|
133 | 133 | /* translators: 1: post type, 2: capability name */ |
134 | - _doing_it_wrong( __FUNCTION__, sprintf( __( 'The post type %1$s is not registered, so it may not be reliable to check the capability "%2$s" against a post of that type.' ), $post->post_type, $cap ), '4.4.0' ); |
|
134 | + _doing_it_wrong(__FUNCTION__, sprintf(__('The post type %1$s is not registered, so it may not be reliable to check the capability "%2$s" against a post of that type.'), $post->post_type, $cap), '4.4.0'); |
|
135 | 135 | $caps[] = 'edit_others_posts'; |
136 | 136 | break; |
137 | 137 | } |
138 | 138 | |
139 | - if ( ! $post_type->map_meta_cap ) { |
|
139 | + if ( ! $post_type->map_meta_cap) { |
|
140 | 140 | $caps[] = $post_type->cap->$cap; |
141 | 141 | // Prior to 3.1 we would re-call map_meta_cap here. |
142 | - if ( 'edit_post' == $cap ) |
|
142 | + if ('edit_post' == $cap) |
|
143 | 143 | $cap = $post_type->cap->$cap; |
144 | 144 | break; |
145 | 145 | } |
146 | 146 | |
147 | 147 | // If the post author is set and the user is the author... |
148 | - if ( $post->post_author && $user_id == $post->post_author ) { |
|
148 | + if ($post->post_author && $user_id == $post->post_author) { |
|
149 | 149 | // If the post is published or scheduled... |
150 | - if ( in_array( $post->post_status, array( 'publish', 'future' ), true ) ) { |
|
150 | + if (in_array($post->post_status, array('publish', 'future'), true)) { |
|
151 | 151 | $caps[] = $post_type->cap->edit_published_posts; |
152 | - } elseif ( 'trash' == $post->post_status ) { |
|
153 | - $status = get_post_meta( $post->ID, '_wp_trash_meta_status', true ); |
|
154 | - if ( in_array( $status, array( 'publish', 'future' ), true ) ) { |
|
152 | + } elseif ('trash' == $post->post_status) { |
|
153 | + $status = get_post_meta($post->ID, '_wp_trash_meta_status', true); |
|
154 | + if (in_array($status, array('publish', 'future'), true)) { |
|
155 | 155 | $caps[] = $post_type->cap->edit_published_posts; |
156 | 156 | } else { |
157 | 157 | $caps[] = $post_type->cap->edit_posts; |
@@ -164,70 +164,70 @@ discard block |
||
164 | 164 | // The user is trying to edit someone else's post. |
165 | 165 | $caps[] = $post_type->cap->edit_others_posts; |
166 | 166 | // The post is published or scheduled, extra cap required. |
167 | - if ( in_array( $post->post_status, array( 'publish', 'future' ), true ) ) { |
|
167 | + if (in_array($post->post_status, array('publish', 'future'), true)) { |
|
168 | 168 | $caps[] = $post_type->cap->edit_published_posts; |
169 | - } elseif ( 'private' == $post->post_status ) { |
|
169 | + } elseif ('private' == $post->post_status) { |
|
170 | 170 | $caps[] = $post_type->cap->edit_private_posts; |
171 | 171 | } |
172 | 172 | } |
173 | 173 | break; |
174 | 174 | case 'read_post': |
175 | 175 | case 'read_page': |
176 | - $post = get_post( $args[0] ); |
|
177 | - if ( ! $post ) { |
|
176 | + $post = get_post($args[0]); |
|
177 | + if ( ! $post) { |
|
178 | 178 | $caps[] = 'do_not_allow'; |
179 | 179 | break; |
180 | 180 | } |
181 | 181 | |
182 | - if ( 'revision' == $post->post_type ) { |
|
183 | - $post = get_post( $post->post_parent ); |
|
184 | - if ( ! $post ) { |
|
182 | + if ('revision' == $post->post_type) { |
|
183 | + $post = get_post($post->post_parent); |
|
184 | + if ( ! $post) { |
|
185 | 185 | $caps[] = 'do_not_allow'; |
186 | 186 | break; |
187 | 187 | } |
188 | 188 | } |
189 | 189 | |
190 | - $post_type = get_post_type_object( $post->post_type ); |
|
191 | - if ( ! $post_type ) { |
|
190 | + $post_type = get_post_type_object($post->post_type); |
|
191 | + if ( ! $post_type) { |
|
192 | 192 | /* translators: 1: post type, 2: capability name */ |
193 | - _doing_it_wrong( __FUNCTION__, sprintf( __( 'The post type %1$s is not registered, so it may not be reliable to check the capability "%2$s" against a post of that type.' ), $post->post_type, $cap ), '4.4.0' ); |
|
193 | + _doing_it_wrong(__FUNCTION__, sprintf(__('The post type %1$s is not registered, so it may not be reliable to check the capability "%2$s" against a post of that type.'), $post->post_type, $cap), '4.4.0'); |
|
194 | 194 | $caps[] = 'edit_others_posts'; |
195 | 195 | break; |
196 | 196 | } |
197 | 197 | |
198 | - if ( ! $post_type->map_meta_cap ) { |
|
198 | + if ( ! $post_type->map_meta_cap) { |
|
199 | 199 | $caps[] = $post_type->cap->$cap; |
200 | 200 | // Prior to 3.1 we would re-call map_meta_cap here. |
201 | - if ( 'read_post' == $cap ) |
|
201 | + if ('read_post' == $cap) |
|
202 | 202 | $cap = $post_type->cap->$cap; |
203 | 203 | break; |
204 | 204 | } |
205 | 205 | |
206 | - $status_obj = get_post_status_object( $post->post_status ); |
|
207 | - if ( $status_obj->public ) { |
|
206 | + $status_obj = get_post_status_object($post->post_status); |
|
207 | + if ($status_obj->public) { |
|
208 | 208 | $caps[] = $post_type->cap->read; |
209 | 209 | break; |
210 | 210 | } |
211 | 211 | |
212 | - if ( $post->post_author && $user_id == $post->post_author ) { |
|
212 | + if ($post->post_author && $user_id == $post->post_author) { |
|
213 | 213 | $caps[] = $post_type->cap->read; |
214 | - } elseif ( $status_obj->private ) { |
|
214 | + } elseif ($status_obj->private) { |
|
215 | 215 | $caps[] = $post_type->cap->read_private_posts; |
216 | 216 | } else { |
217 | - $caps = map_meta_cap( 'edit_post', $user_id, $post->ID ); |
|
217 | + $caps = map_meta_cap('edit_post', $user_id, $post->ID); |
|
218 | 218 | } |
219 | 219 | break; |
220 | 220 | case 'publish_post': |
221 | - $post = get_post( $args[0] ); |
|
222 | - if ( ! $post ) { |
|
221 | + $post = get_post($args[0]); |
|
222 | + if ( ! $post) { |
|
223 | 223 | $caps[] = 'do_not_allow'; |
224 | 224 | break; |
225 | 225 | } |
226 | 226 | |
227 | - $post_type = get_post_type_object( $post->post_type ); |
|
228 | - if ( ! $post_type ) { |
|
227 | + $post_type = get_post_type_object($post->post_type); |
|
228 | + if ( ! $post_type) { |
|
229 | 229 | /* translators: 1: post type, 2: capability name */ |
230 | - _doing_it_wrong( __FUNCTION__, sprintf( __( 'The post type %1$s is not registered, so it may not be reliable to check the capability "%2$s" against a post of that type.' ), $post->post_type, $cap ), '4.4.0' ); |
|
230 | + _doing_it_wrong(__FUNCTION__, sprintf(__('The post type %1$s is not registered, so it may not be reliable to check the capability "%2$s" against a post of that type.'), $post->post_type, $cap), '4.4.0'); |
|
231 | 231 | $caps[] = 'edit_others_posts'; |
232 | 232 | break; |
233 | 233 | } |
@@ -237,17 +237,17 @@ discard block |
||
237 | 237 | case 'edit_post_meta': |
238 | 238 | case 'delete_post_meta': |
239 | 239 | case 'add_post_meta': |
240 | - $post = get_post( $args[0] ); |
|
241 | - if ( ! $post ) { |
|
240 | + $post = get_post($args[0]); |
|
241 | + if ( ! $post) { |
|
242 | 242 | $caps[] = 'do_not_allow'; |
243 | 243 | break; |
244 | 244 | } |
245 | 245 | |
246 | - $caps = map_meta_cap( 'edit_post', $user_id, $post->ID ); |
|
246 | + $caps = map_meta_cap('edit_post', $user_id, $post->ID); |
|
247 | 247 | |
248 | - $meta_key = isset( $args[ 1 ] ) ? $args[ 1 ] : false; |
|
248 | + $meta_key = isset($args[1]) ? $args[1] : false; |
|
249 | 249 | |
250 | - if ( $meta_key && has_filter( "auth_post_meta_{$meta_key}" ) ) { |
|
250 | + if ($meta_key && has_filter("auth_post_meta_{$meta_key}")) { |
|
251 | 251 | /** |
252 | 252 | * Filter whether the user is allowed to add post meta to a post. |
253 | 253 | * |
@@ -263,43 +263,43 @@ discard block |
||
263 | 263 | * @param string $cap Capability name. |
264 | 264 | * @param array $caps User capabilities. |
265 | 265 | */ |
266 | - $allowed = apply_filters( "auth_post_meta_{$meta_key}", false, $meta_key, $post->ID, $user_id, $cap, $caps ); |
|
267 | - if ( ! $allowed ) |
|
266 | + $allowed = apply_filters("auth_post_meta_{$meta_key}", false, $meta_key, $post->ID, $user_id, $cap, $caps); |
|
267 | + if ( ! $allowed) |
|
268 | 268 | $caps[] = $cap; |
269 | - } elseif ( $meta_key && is_protected_meta( $meta_key, 'post' ) ) { |
|
269 | + } elseif ($meta_key && is_protected_meta($meta_key, 'post')) { |
|
270 | 270 | $caps[] = $cap; |
271 | 271 | } |
272 | 272 | break; |
273 | 273 | case 'edit_comment': |
274 | - $comment = get_comment( $args[0] ); |
|
275 | - if ( ! $comment ) { |
|
274 | + $comment = get_comment($args[0]); |
|
275 | + if ( ! $comment) { |
|
276 | 276 | $caps[] = 'do_not_allow'; |
277 | 277 | break; |
278 | 278 | } |
279 | 279 | |
280 | - $post = get_post( $comment->comment_post_ID ); |
|
280 | + $post = get_post($comment->comment_post_ID); |
|
281 | 281 | |
282 | 282 | /* |
283 | 283 | * If the post doesn't exist, we have an orphaned comment. |
284 | 284 | * Fall back to the edit_posts capability, instead. |
285 | 285 | */ |
286 | - if ( $post ) { |
|
287 | - $caps = map_meta_cap( 'edit_post', $user_id, $post->ID ); |
|
286 | + if ($post) { |
|
287 | + $caps = map_meta_cap('edit_post', $user_id, $post->ID); |
|
288 | 288 | } else { |
289 | - $caps = map_meta_cap( 'edit_posts', $user_id ); |
|
289 | + $caps = map_meta_cap('edit_posts', $user_id); |
|
290 | 290 | } |
291 | 291 | break; |
292 | 292 | case 'unfiltered_upload': |
293 | - if ( defined('ALLOW_UNFILTERED_UPLOADS') && ALLOW_UNFILTERED_UPLOADS && ( !is_multisite() || is_super_admin( $user_id ) ) ) |
|
293 | + if (defined('ALLOW_UNFILTERED_UPLOADS') && ALLOW_UNFILTERED_UPLOADS && ( ! is_multisite() || is_super_admin($user_id))) |
|
294 | 294 | $caps[] = $cap; |
295 | 295 | else |
296 | 296 | $caps[] = 'do_not_allow'; |
297 | 297 | break; |
298 | 298 | case 'unfiltered_html' : |
299 | 299 | // Disallow unfiltered_html for all users, even admins and super admins. |
300 | - if ( defined( 'DISALLOW_UNFILTERED_HTML' ) && DISALLOW_UNFILTERED_HTML ) |
|
300 | + if (defined('DISALLOW_UNFILTERED_HTML') && DISALLOW_UNFILTERED_HTML) |
|
301 | 301 | $caps[] = 'do_not_allow'; |
302 | - elseif ( is_multisite() && ! is_super_admin( $user_id ) ) |
|
302 | + elseif (is_multisite() && ! is_super_admin($user_id)) |
|
303 | 303 | $caps[] = 'do_not_allow'; |
304 | 304 | else |
305 | 305 | $caps[] = $cap; |
@@ -308,11 +308,11 @@ discard block |
||
308 | 308 | case 'edit_plugins': |
309 | 309 | case 'edit_themes': |
310 | 310 | // Disallow the file editors. |
311 | - if ( defined( 'DISALLOW_FILE_EDIT' ) && DISALLOW_FILE_EDIT ) |
|
311 | + if (defined('DISALLOW_FILE_EDIT') && DISALLOW_FILE_EDIT) |
|
312 | 312 | $caps[] = 'do_not_allow'; |
313 | - elseif ( defined( 'DISALLOW_FILE_MODS' ) && DISALLOW_FILE_MODS ) |
|
313 | + elseif (defined('DISALLOW_FILE_MODS') && DISALLOW_FILE_MODS) |
|
314 | 314 | $caps[] = 'do_not_allow'; |
315 | - elseif ( is_multisite() && ! is_super_admin( $user_id ) ) |
|
315 | + elseif (is_multisite() && ! is_super_admin($user_id)) |
|
316 | 316 | $caps[] = 'do_not_allow'; |
317 | 317 | else |
318 | 318 | $caps[] = $cap; |
@@ -328,13 +328,13 @@ discard block |
||
328 | 328 | case 'update_core': |
329 | 329 | // Disallow anything that creates, deletes, or updates core, plugin, or theme files. |
330 | 330 | // Files in uploads are excepted. |
331 | - if ( defined( 'DISALLOW_FILE_MODS' ) && DISALLOW_FILE_MODS ) { |
|
331 | + if (defined('DISALLOW_FILE_MODS') && DISALLOW_FILE_MODS) { |
|
332 | 332 | $caps[] = 'do_not_allow'; |
333 | - } elseif ( is_multisite() && ! is_super_admin( $user_id ) ) { |
|
333 | + } elseif (is_multisite() && ! is_super_admin($user_id)) { |
|
334 | 334 | $caps[] = 'do_not_allow'; |
335 | - } elseif ( 'upload_themes' === $cap ) { |
|
335 | + } elseif ('upload_themes' === $cap) { |
|
336 | 336 | $caps[] = 'install_themes'; |
337 | - } elseif ( 'upload_plugins' === $cap ) { |
|
337 | + } elseif ('upload_plugins' === $cap) { |
|
338 | 338 | $caps[] = 'install_plugins'; |
339 | 339 | } else { |
340 | 340 | $caps[] = $cap; |
@@ -342,31 +342,31 @@ discard block |
||
342 | 342 | break; |
343 | 343 | case 'activate_plugins': |
344 | 344 | $caps[] = $cap; |
345 | - if ( is_multisite() ) { |
|
345 | + if (is_multisite()) { |
|
346 | 346 | // update_, install_, and delete_ are handled above with is_super_admin(). |
347 | - $menu_perms = get_site_option( 'menu_items', array() ); |
|
348 | - if ( empty( $menu_perms['plugins'] ) ) |
|
347 | + $menu_perms = get_site_option('menu_items', array()); |
|
348 | + if (empty($menu_perms['plugins'])) |
|
349 | 349 | $caps[] = 'manage_network_plugins'; |
350 | 350 | } |
351 | 351 | break; |
352 | 352 | case 'delete_user': |
353 | 353 | case 'delete_users': |
354 | 354 | // If multisite only super admins can delete users. |
355 | - if ( is_multisite() && ! is_super_admin( $user_id ) ) |
|
355 | + if (is_multisite() && ! is_super_admin($user_id)) |
|
356 | 356 | $caps[] = 'do_not_allow'; |
357 | 357 | else |
358 | 358 | $caps[] = 'delete_users'; // delete_user maps to delete_users. |
359 | 359 | break; |
360 | 360 | case 'create_users': |
361 | - if ( !is_multisite() ) |
|
361 | + if ( ! is_multisite()) |
|
362 | 362 | $caps[] = $cap; |
363 | - elseif ( is_super_admin( $user_id ) || get_site_option( 'add_new_users' ) ) |
|
363 | + elseif (is_super_admin($user_id) || get_site_option('add_new_users')) |
|
364 | 364 | $caps[] = $cap; |
365 | 365 | else |
366 | 366 | $caps[] = 'do_not_allow'; |
367 | 367 | break; |
368 | 368 | case 'manage_links' : |
369 | - if ( get_option( 'link_manager_enabled' ) ) |
|
369 | + if (get_option('link_manager_enabled')) |
|
370 | 370 | $caps[] = $cap; |
371 | 371 | else |
372 | 372 | $caps[] = 'do_not_allow'; |
@@ -380,9 +380,9 @@ discard block |
||
380 | 380 | default: |
381 | 381 | // Handle meta capabilities for custom post types. |
382 | 382 | global $post_type_meta_caps; |
383 | - if ( isset( $post_type_meta_caps[ $cap ] ) ) { |
|
384 | - $args = array_merge( array( $post_type_meta_caps[ $cap ], $user_id ), $args ); |
|
385 | - return call_user_func_array( 'map_meta_cap', $args ); |
|
383 | + if (isset($post_type_meta_caps[$cap])) { |
|
384 | + $args = array_merge(array($post_type_meta_caps[$cap], $user_id), $args); |
|
385 | + return call_user_func_array('map_meta_cap', $args); |
|
386 | 386 | } |
387 | 387 | |
388 | 388 | // If no meta caps match, return the original cap. |
@@ -399,7 +399,7 @@ discard block |
||
399 | 399 | * @param int $user_id The user ID. |
400 | 400 | * @param array $args Adds the context to the cap. Typically the object ID. |
401 | 401 | */ |
402 | - return apply_filters( 'map_meta_cap', $caps, $cap, $user_id, $args ); |
|
402 | + return apply_filters('map_meta_cap', $caps, $cap, $user_id, $args); |
|
403 | 403 | } |
404 | 404 | |
405 | 405 | /** |
@@ -424,16 +424,16 @@ discard block |
||
424 | 424 | * @return bool Whether the current user has the given capability. If `$capability` is a meta cap and `$object_id` is |
425 | 425 | * passed, whether the current user has the given meta capability for the given object. |
426 | 426 | */ |
427 | -function current_user_can( $capability ) { |
|
427 | +function current_user_can($capability) { |
|
428 | 428 | $current_user = wp_get_current_user(); |
429 | 429 | |
430 | - if ( empty( $current_user ) ) |
|
430 | + if (empty($current_user)) |
|
431 | 431 | return false; |
432 | 432 | |
433 | - $args = array_slice( func_get_args(), 1 ); |
|
434 | - $args = array_merge( array( $capability ), $args ); |
|
433 | + $args = array_slice(func_get_args(), 1); |
|
434 | + $args = array_merge(array($capability), $args); |
|
435 | 435 | |
436 | - return call_user_func_array( array( $current_user, 'has_cap' ), $args ); |
|
436 | + return call_user_func_array(array($current_user, 'has_cap'), $args); |
|
437 | 437 | } |
438 | 438 | |
439 | 439 | /** |
@@ -445,24 +445,24 @@ discard block |
||
445 | 445 | * @param string $capability Capability or role name. |
446 | 446 | * @return bool |
447 | 447 | */ |
448 | -function current_user_can_for_blog( $blog_id, $capability ) { |
|
449 | - $switched = is_multisite() ? switch_to_blog( $blog_id ) : false; |
|
448 | +function current_user_can_for_blog($blog_id, $capability) { |
|
449 | + $switched = is_multisite() ? switch_to_blog($blog_id) : false; |
|
450 | 450 | |
451 | 451 | $current_user = wp_get_current_user(); |
452 | 452 | |
453 | - if ( empty( $current_user ) ) { |
|
454 | - if ( $switched ) { |
|
453 | + if (empty($current_user)) { |
|
454 | + if ($switched) { |
|
455 | 455 | restore_current_blog(); |
456 | 456 | } |
457 | 457 | return false; |
458 | 458 | } |
459 | 459 | |
460 | - $args = array_slice( func_get_args(), 2 ); |
|
461 | - $args = array_merge( array( $capability ), $args ); |
|
460 | + $args = array_slice(func_get_args(), 2); |
|
461 | + $args = array_merge(array($capability), $args); |
|
462 | 462 | |
463 | - $can = call_user_func_array( array( $current_user, 'has_cap' ), $args ); |
|
463 | + $can = call_user_func_array(array($current_user, 'has_cap'), $args); |
|
464 | 464 | |
465 | - if ( $switched ) { |
|
465 | + if ($switched) { |
|
466 | 466 | restore_current_blog(); |
467 | 467 | } |
468 | 468 | |
@@ -478,19 +478,19 @@ discard block |
||
478 | 478 | * @param string $capability Capability or role name. |
479 | 479 | * @return bool |
480 | 480 | */ |
481 | -function author_can( $post, $capability ) { |
|
482 | - if ( !$post = get_post($post) ) |
|
481 | +function author_can($post, $capability) { |
|
482 | + if ( ! $post = get_post($post)) |
|
483 | 483 | return false; |
484 | 484 | |
485 | - $author = get_userdata( $post->post_author ); |
|
485 | + $author = get_userdata($post->post_author); |
|
486 | 486 | |
487 | - if ( ! $author ) |
|
487 | + if ( ! $author) |
|
488 | 488 | return false; |
489 | 489 | |
490 | - $args = array_slice( func_get_args(), 2 ); |
|
491 | - $args = array_merge( array( $capability ), $args ); |
|
490 | + $args = array_slice(func_get_args(), 2); |
|
491 | + $args = array_merge(array($capability), $args); |
|
492 | 492 | |
493 | - return call_user_func_array( array( $author, 'has_cap' ), $args ); |
|
493 | + return call_user_func_array(array($author, 'has_cap'), $args); |
|
494 | 494 | } |
495 | 495 | |
496 | 496 | /** |
@@ -502,17 +502,17 @@ discard block |
||
502 | 502 | * @param string $capability Capability or role name. |
503 | 503 | * @return bool |
504 | 504 | */ |
505 | -function user_can( $user, $capability ) { |
|
506 | - if ( ! is_object( $user ) ) |
|
507 | - $user = get_userdata( $user ); |
|
505 | +function user_can($user, $capability) { |
|
506 | + if ( ! is_object($user)) |
|
507 | + $user = get_userdata($user); |
|
508 | 508 | |
509 | - if ( ! $user || ! $user->exists() ) |
|
509 | + if ( ! $user || ! $user->exists()) |
|
510 | 510 | return false; |
511 | 511 | |
512 | - $args = array_slice( func_get_args(), 2 ); |
|
513 | - $args = array_merge( array( $capability ), $args ); |
|
512 | + $args = array_slice(func_get_args(), 2); |
|
513 | + $args = array_merge(array($capability), $args); |
|
514 | 514 | |
515 | - return call_user_func_array( array( $user, 'has_cap' ), $args ); |
|
515 | + return call_user_func_array(array($user, 'has_cap'), $args); |
|
516 | 516 | } |
517 | 517 | |
518 | 518 | /** |
@@ -527,7 +527,7 @@ discard block |
||
527 | 527 | function wp_roles() { |
528 | 528 | global $wp_roles; |
529 | 529 | |
530 | - if ( ! isset( $wp_roles ) ) { |
|
530 | + if ( ! isset($wp_roles)) { |
|
531 | 531 | $wp_roles = new WP_Roles(); |
532 | 532 | } |
533 | 533 | return $wp_roles; |
@@ -541,8 +541,8 @@ discard block |
||
541 | 541 | * @param string $role Role name. |
542 | 542 | * @return WP_Role|null WP_Role object if found, null if the role does not exist. |
543 | 543 | */ |
544 | -function get_role( $role ) { |
|
545 | - return wp_roles()->get_role( $role ); |
|
544 | +function get_role($role) { |
|
545 | + return wp_roles()->get_role($role); |
|
546 | 546 | } |
547 | 547 | |
548 | 548 | /** |
@@ -555,11 +555,11 @@ discard block |
||
555 | 555 | * @param array $capabilities List of capabilities, e.g. array( 'edit_posts' => true, 'delete_posts' => false ); |
556 | 556 | * @return WP_Role|null WP_Role object if role is added, null if already exists. |
557 | 557 | */ |
558 | -function add_role( $role, $display_name, $capabilities = array() ) { |
|
559 | - if ( empty( $role ) ) { |
|
558 | +function add_role($role, $display_name, $capabilities = array()) { |
|
559 | + if (empty($role)) { |
|
560 | 560 | return; |
561 | 561 | } |
562 | - return wp_roles()->add_role( $role, $display_name, $capabilities ); |
|
562 | + return wp_roles()->add_role($role, $display_name, $capabilities); |
|
563 | 563 | } |
564 | 564 | |
565 | 565 | /** |
@@ -569,8 +569,8 @@ discard block |
||
569 | 569 | * |
570 | 570 | * @param string $role Role name. |
571 | 571 | */ |
572 | -function remove_role( $role ) { |
|
573 | - wp_roles()->remove_role( $role ); |
|
572 | +function remove_role($role) { |
|
573 | + wp_roles()->remove_role($role); |
|
574 | 574 | } |
575 | 575 | |
576 | 576 | /** |
@@ -585,10 +585,10 @@ discard block |
||
585 | 585 | function get_super_admins() { |
586 | 586 | global $super_admins; |
587 | 587 | |
588 | - if ( isset($super_admins) ) |
|
588 | + if (isset($super_admins)) |
|
589 | 589 | return $super_admins; |
590 | 590 | else |
591 | - return get_site_option( 'site_admins', array('admin') ); |
|
591 | + return get_site_option('site_admins', array('admin')); |
|
592 | 592 | } |
593 | 593 | |
594 | 594 | /** |
@@ -599,21 +599,21 @@ discard block |
||
599 | 599 | * @param int $user_id (Optional) The ID of a user. Defaults to the current user. |
600 | 600 | * @return bool True if the user is a site admin. |
601 | 601 | */ |
602 | -function is_super_admin( $user_id = false ) { |
|
603 | - if ( ! $user_id || $user_id == get_current_user_id() ) |
|
602 | +function is_super_admin($user_id = false) { |
|
603 | + if ( ! $user_id || $user_id == get_current_user_id()) |
|
604 | 604 | $user = wp_get_current_user(); |
605 | 605 | else |
606 | - $user = get_userdata( $user_id ); |
|
606 | + $user = get_userdata($user_id); |
|
607 | 607 | |
608 | - if ( ! $user || ! $user->exists() ) |
|
608 | + if ( ! $user || ! $user->exists()) |
|
609 | 609 | return false; |
610 | 610 | |
611 | - if ( is_multisite() ) { |
|
611 | + if (is_multisite()) { |
|
612 | 612 | $super_admins = get_super_admins(); |
613 | - if ( is_array( $super_admins ) && in_array( $user->user_login, $super_admins ) ) |
|
613 | + if (is_array($super_admins) && in_array($user->user_login, $super_admins)) |
|
614 | 614 | return true; |
615 | 615 | } else { |
616 | - if ( $user->has_cap('delete_users') ) |
|
616 | + if ($user->has_cap('delete_users')) |
|
617 | 617 | return true; |
618 | 618 | } |
619 | 619 |
@@ -41,8 +41,9 @@ discard block |
||
41 | 41 | case 'edit_user': |
42 | 42 | case 'edit_users': |
43 | 43 | // Allow user to edit itself |
44 | - if ( 'edit_user' == $cap && isset( $args[0] ) && $user_id == $args[0] ) |
|
45 | - break; |
|
44 | + if ( 'edit_user' == $cap && isset( $args[0] ) && $user_id == $args[0] ) { |
|
45 | + break; |
|
46 | + } |
|
46 | 47 | |
47 | 48 | // In multisite the user must have manage_network_users caps. If editing a super admin, the user must be a super admin. |
48 | 49 | if ( is_multisite() && ( ( ! is_super_admin( $user_id ) && 'edit_user' === $cap && is_super_admin( $args[0] ) ) || ! user_can( $user_id, 'manage_network_users' ) ) ) { |
@@ -78,8 +79,9 @@ discard block |
||
78 | 79 | if ( ! $post_type->map_meta_cap ) { |
79 | 80 | $caps[] = $post_type->cap->$cap; |
80 | 81 | // Prior to 3.1 we would re-call map_meta_cap here. |
81 | - if ( 'delete_post' == $cap ) |
|
82 | - $cap = $post_type->cap->$cap; |
|
82 | + if ( 'delete_post' == $cap ) { |
|
83 | + $cap = $post_type->cap->$cap; |
|
84 | + } |
|
83 | 85 | break; |
84 | 86 | } |
85 | 87 | |
@@ -139,8 +141,9 @@ discard block |
||
139 | 141 | if ( ! $post_type->map_meta_cap ) { |
140 | 142 | $caps[] = $post_type->cap->$cap; |
141 | 143 | // Prior to 3.1 we would re-call map_meta_cap here. |
142 | - if ( 'edit_post' == $cap ) |
|
143 | - $cap = $post_type->cap->$cap; |
|
144 | + if ( 'edit_post' == $cap ) { |
|
145 | + $cap = $post_type->cap->$cap; |
|
146 | + } |
|
144 | 147 | break; |
145 | 148 | } |
146 | 149 | |
@@ -198,8 +201,9 @@ discard block |
||
198 | 201 | if ( ! $post_type->map_meta_cap ) { |
199 | 202 | $caps[] = $post_type->cap->$cap; |
200 | 203 | // Prior to 3.1 we would re-call map_meta_cap here. |
201 | - if ( 'read_post' == $cap ) |
|
202 | - $cap = $post_type->cap->$cap; |
|
204 | + if ( 'read_post' == $cap ) { |
|
205 | + $cap = $post_type->cap->$cap; |
|
206 | + } |
|
203 | 207 | break; |
204 | 208 | } |
205 | 209 | |
@@ -264,8 +268,9 @@ discard block |
||
264 | 268 | * @param array $caps User capabilities. |
265 | 269 | */ |
266 | 270 | $allowed = apply_filters( "auth_post_meta_{$meta_key}", false, $meta_key, $post->ID, $user_id, $cap, $caps ); |
267 | - if ( ! $allowed ) |
|
268 | - $caps[] = $cap; |
|
271 | + if ( ! $allowed ) { |
|
272 | + $caps[] = $cap; |
|
273 | + } |
|
269 | 274 | } elseif ( $meta_key && is_protected_meta( $meta_key, 'post' ) ) { |
270 | 275 | $caps[] = $cap; |
271 | 276 | } |
@@ -290,32 +295,35 @@ discard block |
||
290 | 295 | } |
291 | 296 | break; |
292 | 297 | case 'unfiltered_upload': |
293 | - if ( defined('ALLOW_UNFILTERED_UPLOADS') && ALLOW_UNFILTERED_UPLOADS && ( !is_multisite() || is_super_admin( $user_id ) ) ) |
|
294 | - $caps[] = $cap; |
|
295 | - else |
|
296 | - $caps[] = 'do_not_allow'; |
|
298 | + if ( defined('ALLOW_UNFILTERED_UPLOADS') && ALLOW_UNFILTERED_UPLOADS && ( !is_multisite() || is_super_admin( $user_id ) ) ) { |
|
299 | + $caps[] = $cap; |
|
300 | + } else { |
|
301 | + $caps[] = 'do_not_allow'; |
|
302 | + } |
|
297 | 303 | break; |
298 | 304 | case 'unfiltered_html' : |
299 | 305 | // Disallow unfiltered_html for all users, even admins and super admins. |
300 | - if ( defined( 'DISALLOW_UNFILTERED_HTML' ) && DISALLOW_UNFILTERED_HTML ) |
|
301 | - $caps[] = 'do_not_allow'; |
|
302 | - elseif ( is_multisite() && ! is_super_admin( $user_id ) ) |
|
303 | - $caps[] = 'do_not_allow'; |
|
304 | - else |
|
305 | - $caps[] = $cap; |
|
306 | + if ( defined( 'DISALLOW_UNFILTERED_HTML' ) && DISALLOW_UNFILTERED_HTML ) { |
|
307 | + $caps[] = 'do_not_allow'; |
|
308 | + } elseif ( is_multisite() && ! is_super_admin( $user_id ) ) { |
|
309 | + $caps[] = 'do_not_allow'; |
|
310 | + } else { |
|
311 | + $caps[] = $cap; |
|
312 | + } |
|
306 | 313 | break; |
307 | 314 | case 'edit_files': |
308 | 315 | case 'edit_plugins': |
309 | 316 | case 'edit_themes': |
310 | 317 | // Disallow the file editors. |
311 | - if ( defined( 'DISALLOW_FILE_EDIT' ) && DISALLOW_FILE_EDIT ) |
|
312 | - $caps[] = 'do_not_allow'; |
|
313 | - elseif ( defined( 'DISALLOW_FILE_MODS' ) && DISALLOW_FILE_MODS ) |
|
314 | - $caps[] = 'do_not_allow'; |
|
315 | - elseif ( is_multisite() && ! is_super_admin( $user_id ) ) |
|
316 | - $caps[] = 'do_not_allow'; |
|
317 | - else |
|
318 | - $caps[] = $cap; |
|
318 | + if ( defined( 'DISALLOW_FILE_EDIT' ) && DISALLOW_FILE_EDIT ) { |
|
319 | + $caps[] = 'do_not_allow'; |
|
320 | + } elseif ( defined( 'DISALLOW_FILE_MODS' ) && DISALLOW_FILE_MODS ) { |
|
321 | + $caps[] = 'do_not_allow'; |
|
322 | + } elseif ( is_multisite() && ! is_super_admin( $user_id ) ) { |
|
323 | + $caps[] = 'do_not_allow'; |
|
324 | + } else { |
|
325 | + $caps[] = $cap; |
|
326 | + } |
|
319 | 327 | break; |
320 | 328 | case 'update_plugins': |
321 | 329 | case 'delete_plugins': |
@@ -345,31 +353,36 @@ discard block |
||
345 | 353 | if ( is_multisite() ) { |
346 | 354 | // update_, install_, and delete_ are handled above with is_super_admin(). |
347 | 355 | $menu_perms = get_site_option( 'menu_items', array() ); |
348 | - if ( empty( $menu_perms['plugins'] ) ) |
|
349 | - $caps[] = 'manage_network_plugins'; |
|
356 | + if ( empty( $menu_perms['plugins'] ) ) { |
|
357 | + $caps[] = 'manage_network_plugins'; |
|
358 | + } |
|
350 | 359 | } |
351 | 360 | break; |
352 | 361 | case 'delete_user': |
353 | 362 | case 'delete_users': |
354 | 363 | // If multisite only super admins can delete users. |
355 | - if ( is_multisite() && ! is_super_admin( $user_id ) ) |
|
356 | - $caps[] = 'do_not_allow'; |
|
357 | - else |
|
358 | - $caps[] = 'delete_users'; // delete_user maps to delete_users. |
|
364 | + if ( is_multisite() && ! is_super_admin( $user_id ) ) { |
|
365 | + $caps[] = 'do_not_allow'; |
|
366 | + } else { |
|
367 | + $caps[] = 'delete_users'; |
|
368 | + } |
|
369 | + // delete_user maps to delete_users. |
|
359 | 370 | break; |
360 | 371 | case 'create_users': |
361 | - if ( !is_multisite() ) |
|
362 | - $caps[] = $cap; |
|
363 | - elseif ( is_super_admin( $user_id ) || get_site_option( 'add_new_users' ) ) |
|
364 | - $caps[] = $cap; |
|
365 | - else |
|
366 | - $caps[] = 'do_not_allow'; |
|
372 | + if ( !is_multisite() ) { |
|
373 | + $caps[] = $cap; |
|
374 | + } elseif ( is_super_admin( $user_id ) || get_site_option( 'add_new_users' ) ) { |
|
375 | + $caps[] = $cap; |
|
376 | + } else { |
|
377 | + $caps[] = 'do_not_allow'; |
|
378 | + } |
|
367 | 379 | break; |
368 | 380 | case 'manage_links' : |
369 | - if ( get_option( 'link_manager_enabled' ) ) |
|
370 | - $caps[] = $cap; |
|
371 | - else |
|
372 | - $caps[] = 'do_not_allow'; |
|
381 | + if ( get_option( 'link_manager_enabled' ) ) { |
|
382 | + $caps[] = $cap; |
|
383 | + } else { |
|
384 | + $caps[] = 'do_not_allow'; |
|
385 | + } |
|
373 | 386 | break; |
374 | 387 | case 'customize' : |
375 | 388 | $caps[] = 'edit_theme_options'; |
@@ -427,8 +440,9 @@ discard block |
||
427 | 440 | function current_user_can( $capability ) { |
428 | 441 | $current_user = wp_get_current_user(); |
429 | 442 | |
430 | - if ( empty( $current_user ) ) |
|
431 | - return false; |
|
443 | + if ( empty( $current_user ) ) { |
|
444 | + return false; |
|
445 | + } |
|
432 | 446 | |
433 | 447 | $args = array_slice( func_get_args(), 1 ); |
434 | 448 | $args = array_merge( array( $capability ), $args ); |
@@ -479,13 +493,15 @@ discard block |
||
479 | 493 | * @return bool |
480 | 494 | */ |
481 | 495 | function author_can( $post, $capability ) { |
482 | - if ( !$post = get_post($post) ) |
|
483 | - return false; |
|
496 | + if ( !$post = get_post($post) ) { |
|
497 | + return false; |
|
498 | + } |
|
484 | 499 | |
485 | 500 | $author = get_userdata( $post->post_author ); |
486 | 501 | |
487 | - if ( ! $author ) |
|
488 | - return false; |
|
502 | + if ( ! $author ) { |
|
503 | + return false; |
|
504 | + } |
|
489 | 505 | |
490 | 506 | $args = array_slice( func_get_args(), 2 ); |
491 | 507 | $args = array_merge( array( $capability ), $args ); |
@@ -503,11 +519,13 @@ discard block |
||
503 | 519 | * @return bool |
504 | 520 | */ |
505 | 521 | function user_can( $user, $capability ) { |
506 | - if ( ! is_object( $user ) ) |
|
507 | - $user = get_userdata( $user ); |
|
522 | + if ( ! is_object( $user ) ) { |
|
523 | + $user = get_userdata( $user ); |
|
524 | + } |
|
508 | 525 | |
509 | - if ( ! $user || ! $user->exists() ) |
|
510 | - return false; |
|
526 | + if ( ! $user || ! $user->exists() ) { |
|
527 | + return false; |
|
528 | + } |
|
511 | 529 | |
512 | 530 | $args = array_slice( func_get_args(), 2 ); |
513 | 531 | $args = array_merge( array( $capability ), $args ); |
@@ -585,11 +603,12 @@ discard block |
||
585 | 603 | function get_super_admins() { |
586 | 604 | global $super_admins; |
587 | 605 | |
588 | - if ( isset($super_admins) ) |
|
589 | - return $super_admins; |
|
590 | - else |
|
591 | - return get_site_option( 'site_admins', array('admin') ); |
|
592 | -} |
|
606 | + if ( isset($super_admins) ) { |
|
607 | + return $super_admins; |
|
608 | + } else { |
|
609 | + return get_site_option( 'site_admins', array('admin') ); |
|
610 | + } |
|
611 | + } |
|
593 | 612 | |
594 | 613 | /** |
595 | 614 | * Determine if user is a site admin. |
@@ -600,21 +619,25 @@ discard block |
||
600 | 619 | * @return bool True if the user is a site admin. |
601 | 620 | */ |
602 | 621 | function is_super_admin( $user_id = false ) { |
603 | - if ( ! $user_id || $user_id == get_current_user_id() ) |
|
604 | - $user = wp_get_current_user(); |
|
605 | - else |
|
606 | - $user = get_userdata( $user_id ); |
|
622 | + if ( ! $user_id || $user_id == get_current_user_id() ) { |
|
623 | + $user = wp_get_current_user(); |
|
624 | + } else { |
|
625 | + $user = get_userdata( $user_id ); |
|
626 | + } |
|
607 | 627 | |
608 | - if ( ! $user || ! $user->exists() ) |
|
609 | - return false; |
|
628 | + if ( ! $user || ! $user->exists() ) { |
|
629 | + return false; |
|
630 | + } |
|
610 | 631 | |
611 | 632 | if ( is_multisite() ) { |
612 | 633 | $super_admins = get_super_admins(); |
613 | - if ( is_array( $super_admins ) && in_array( $user->user_login, $super_admins ) ) |
|
614 | - return true; |
|
634 | + if ( is_array( $super_admins ) && in_array( $user->user_login, $super_admins ) ) { |
|
635 | + return true; |
|
636 | + } |
|
615 | 637 | } else { |
616 | - if ( $user->has_cap('delete_users') ) |
|
617 | - return true; |
|
638 | + if ( $user->has_cap('delete_users') ) { |
|
639 | + return true; |
|
640 | + } |
|
618 | 641 | } |
619 | 642 | |
620 | 643 | return false; |
@@ -209,7 +209,7 @@ |
||
209 | 209 | * @since 4.1.0 |
210 | 210 | * @access public |
211 | 211 | * |
212 | - * @return true Always true. |
|
212 | + * @return boolean Always true. |
|
213 | 213 | */ |
214 | 214 | public function active_callback() { |
215 | 215 | return true; |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if ( ! class_exists( 'SimplePie', false ) ) |
|
4 | - require_once( ABSPATH . WPINC . '/class-simplepie.php' ); |
|
3 | +if ( ! class_exists('SimplePie', false)) |
|
4 | + require_once(ABSPATH.WPINC.'/class-simplepie.php'); |
|
5 | 5 | |
6 | 6 | class WP_Feed_Cache extends SimplePie_Cache { |
7 | 7 | /** |
@@ -33,8 +33,8 @@ discard block |
||
33 | 33 | * @param string $extension 'spi' or 'spc'. |
34 | 34 | */ |
35 | 35 | public function __construct($location, $filename, $extension) { |
36 | - $this->name = 'feed_' . $filename; |
|
37 | - $this->mod_name = 'feed_mod_' . $filename; |
|
36 | + $this->name = 'feed_'.$filename; |
|
37 | + $this->mod_name = 'feed_mod_'.$filename; |
|
38 | 38 | |
39 | 39 | $lifetime = $this->lifetime; |
40 | 40 | /** |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | * @param int $lifetime Cache duration in seconds. Default is 43200 seconds (12 hours). |
46 | 46 | * @param string $filename Unique identifier for the cache object. |
47 | 47 | */ |
48 | - $this->lifetime = apply_filters( 'wp_feed_cache_transient_lifetime', $lifetime, $filename); |
|
48 | + $this->lifetime = apply_filters('wp_feed_cache_transient_lifetime', $lifetime, $filename); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | /** |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | * @return true Always true. |
56 | 56 | */ |
57 | 57 | public function save($data) { |
58 | - if ( $data instanceof SimplePie ) { |
|
58 | + if ($data instanceof SimplePie) { |
|
59 | 59 | $data = $data->data; |
60 | 60 | } |
61 | 61 | |
@@ -106,27 +106,27 @@ discard block |
||
106 | 106 | |
107 | 107 | $this->method = SIMPLEPIE_FILE_SOURCE_REMOTE; |
108 | 108 | |
109 | - if ( preg_match('/^http(s)?:\/\//i', $url) ) { |
|
109 | + if (preg_match('/^http(s)?:\/\//i', $url)) { |
|
110 | 110 | $args = array( |
111 | 111 | 'timeout' => $this->timeout, |
112 | 112 | 'redirection' => $this->redirects, |
113 | 113 | ); |
114 | 114 | |
115 | - if ( !empty($this->headers) ) |
|
115 | + if ( ! empty($this->headers)) |
|
116 | 116 | $args['headers'] = $this->headers; |
117 | 117 | |
118 | - if ( SIMPLEPIE_USERAGENT != $this->useragent ) //Use default WP user agent unless custom has been specified |
|
118 | + if (SIMPLEPIE_USERAGENT != $this->useragent) //Use default WP user agent unless custom has been specified |
|
119 | 119 | $args['user-agent'] = $this->useragent; |
120 | 120 | |
121 | 121 | $res = wp_safe_remote_request($url, $args); |
122 | 122 | |
123 | - if ( is_wp_error($res) ) { |
|
124 | - $this->error = 'WP HTTP Error: ' . $res->get_error_message(); |
|
123 | + if (is_wp_error($res)) { |
|
124 | + $this->error = 'WP HTTP Error: '.$res->get_error_message(); |
|
125 | 125 | $this->success = false; |
126 | 126 | } else { |
127 | - $this->headers = wp_remote_retrieve_headers( $res ); |
|
128 | - $this->body = wp_remote_retrieve_body( $res ); |
|
129 | - $this->status_code = wp_remote_retrieve_response_code( $res ); |
|
127 | + $this->headers = wp_remote_retrieve_headers($res); |
|
128 | + $this->body = wp_remote_retrieve_body($res); |
|
129 | + $this->status_code = wp_remote_retrieve_response_code($res); |
|
130 | 130 | } |
131 | 131 | } else { |
132 | 132 | $this->error = ''; |
@@ -145,27 +145,27 @@ discard block |
||
145 | 145 | * @since 3.5.0 |
146 | 146 | */ |
147 | 147 | class WP_SimplePie_Sanitize_KSES extends SimplePie_Sanitize { |
148 | - public function sanitize( $data, $type, $base = '' ) { |
|
149 | - $data = trim( $data ); |
|
150 | - if ( $type & SIMPLEPIE_CONSTRUCT_MAYBE_HTML ) { |
|
151 | - if (preg_match('/(&(#(x[0-9a-fA-F]+|[0-9]+)|[a-zA-Z0-9]+)|<\/[A-Za-z][^\x09\x0A\x0B\x0C\x0D\x20\x2F\x3E]*' . SIMPLEPIE_PCRE_HTML_ATTRIBUTE . '>)/', $data)) { |
|
148 | + public function sanitize($data, $type, $base = '') { |
|
149 | + $data = trim($data); |
|
150 | + if ($type & SIMPLEPIE_CONSTRUCT_MAYBE_HTML) { |
|
151 | + if (preg_match('/(&(#(x[0-9a-fA-F]+|[0-9]+)|[a-zA-Z0-9]+)|<\/[A-Za-z][^\x09\x0A\x0B\x0C\x0D\x20\x2F\x3E]*'.SIMPLEPIE_PCRE_HTML_ATTRIBUTE.'>)/', $data)) { |
|
152 | 152 | $type |= SIMPLEPIE_CONSTRUCT_HTML; |
153 | 153 | } |
154 | 154 | else { |
155 | 155 | $type |= SIMPLEPIE_CONSTRUCT_TEXT; |
156 | 156 | } |
157 | 157 | } |
158 | - if ( $type & SIMPLEPIE_CONSTRUCT_BASE64 ) { |
|
159 | - $data = base64_decode( $data ); |
|
158 | + if ($type & SIMPLEPIE_CONSTRUCT_BASE64) { |
|
159 | + $data = base64_decode($data); |
|
160 | 160 | } |
161 | - if ( $type & ( SIMPLEPIE_CONSTRUCT_HTML | SIMPLEPIE_CONSTRUCT_XHTML ) ) { |
|
162 | - $data = wp_kses_post( $data ); |
|
163 | - if ( $this->output_encoding !== 'UTF-8' ) { |
|
164 | - $data = $this->registry->call( 'Misc', 'change_encoding', array( $data, 'UTF-8', $this->output_encoding ) ); |
|
161 | + if ($type & (SIMPLEPIE_CONSTRUCT_HTML | SIMPLEPIE_CONSTRUCT_XHTML)) { |
|
162 | + $data = wp_kses_post($data); |
|
163 | + if ($this->output_encoding !== 'UTF-8') { |
|
164 | + $data = $this->registry->call('Misc', 'change_encoding', array($data, 'UTF-8', $this->output_encoding)); |
|
165 | 165 | } |
166 | 166 | return $data; |
167 | 167 | } else { |
168 | - return parent::sanitize( $data, $type, $base ); |
|
168 | + return parent::sanitize($data, $type, $base); |
|
169 | 169 | } |
170 | 170 | } |
171 | 171 | } |
@@ -1,7 +1,8 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if ( ! class_exists( 'SimplePie', false ) ) |
|
3 | +if ( ! class_exists( 'SimplePie', false ) ) { |
|
4 | 4 | require_once( ABSPATH . WPINC . '/class-simplepie.php' ); |
5 | +} |
|
5 | 6 | |
6 | 7 | class WP_Feed_Cache extends SimplePie_Cache { |
7 | 8 | /** |
@@ -112,11 +113,14 @@ discard block |
||
112 | 113 | 'redirection' => $this->redirects, |
113 | 114 | ); |
114 | 115 | |
115 | - if ( !empty($this->headers) ) |
|
116 | - $args['headers'] = $this->headers; |
|
116 | + if ( !empty($this->headers) ) { |
|
117 | + $args['headers'] = $this->headers; |
|
118 | + } |
|
117 | 119 | |
118 | - if ( SIMPLEPIE_USERAGENT != $this->useragent ) //Use default WP user agent unless custom has been specified |
|
120 | + if ( SIMPLEPIE_USERAGENT != $this->useragent ) { |
|
121 | + //Use default WP user agent unless custom has been specified |
|
119 | 122 | $args['user-agent'] = $this->useragent; |
123 | + } |
|
120 | 124 | |
121 | 125 | $res = wp_safe_remote_request($url, $args); |
122 | 126 | |
@@ -150,8 +154,7 @@ discard block |
||
150 | 154 | if ( $type & SIMPLEPIE_CONSTRUCT_MAYBE_HTML ) { |
151 | 155 | if (preg_match('/(&(#(x[0-9a-fA-F]+|[0-9]+)|[a-zA-Z0-9]+)|<\/[A-Za-z][^\x09\x0A\x0B\x0C\x0D\x20\x2F\x3E]*' . SIMPLEPIE_PCRE_HTML_ATTRIBUTE . '>)/', $data)) { |
152 | 156 | $type |= SIMPLEPIE_CONSTRUCT_HTML; |
153 | - } |
|
154 | - else { |
|
157 | + } else { |
|
155 | 158 | $type |= SIMPLEPIE_CONSTRUCT_TEXT; |
156 | 159 | } |
157 | 160 | } |
@@ -522,7 +522,7 @@ discard block |
||
522 | 522 | * @since 2.7.0 |
523 | 523 | * |
524 | 524 | * @param string $strResponse The full response string |
525 | - * @return array Array with 'headers' and 'body' keys. |
|
525 | + * @return string Array with 'headers' and 'body' keys. |
|
526 | 526 | */ |
527 | 527 | public static function processResponse($strResponse) { |
528 | 528 | $res = explode("\r\n\r\n", $strResponse, 2); |
@@ -542,7 +542,7 @@ discard block |
||
542 | 542 | * |
543 | 543 | * @param string|array $headers |
544 | 544 | * @param string $url The URL that was requested |
545 | - * @return array Processed string headers. If duplicate headers are encountered, |
|
545 | + * @return string Processed string headers. If duplicate headers are encountered, |
|
546 | 546 | * Then a numbered array is returned as the value of that header-key. |
547 | 547 | */ |
548 | 548 | public static function processHeaders( $headers, $url = '' ) { |
@@ -1,11 +1,11 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * HTTP API: WP_Http class |
|
4 | - * |
|
5 | - * @package WordPress |
|
6 | - * @subpackage HTTP |
|
7 | - * @since 2.7.0 |
|
8 | - */ |
|
3 | + * HTTP API: WP_Http class |
|
4 | + * |
|
5 | + * @package WordPress |
|
6 | + * @subpackage HTTP |
|
7 | + * @since 2.7.0 |
|
8 | + */ |
|
9 | 9 | |
10 | 10 | /** |
11 | 11 | * Core class used for managing HTTP transports and making HTTP requests. |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | * @return array|WP_Error Array containing 'headers', 'body', 'response', 'cookies', 'filename'. |
141 | 141 | * A WP_Error instance upon error. |
142 | 142 | */ |
143 | - public function request( $url, $args = array() ) { |
|
143 | + public function request($url, $args = array()) { |
|
144 | 144 | global $wp_version; |
145 | 145 | |
146 | 146 | $defaults = array( |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | * @param int $timeout_value Time in seconds until a request times out. |
154 | 154 | * Default 5. |
155 | 155 | */ |
156 | - 'timeout' => apply_filters( 'http_request_timeout', 5 ), |
|
156 | + 'timeout' => apply_filters('http_request_timeout', 5), |
|
157 | 157 | /** |
158 | 158 | * Filter the number of redirects allowed during an HTTP request. |
159 | 159 | * |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | * |
162 | 162 | * @param int $redirect_count Number of redirects allowed. Default 5. |
163 | 163 | */ |
164 | - 'redirection' => apply_filters( 'http_request_redirection_count', 5 ), |
|
164 | + 'redirection' => apply_filters('http_request_redirection_count', 5), |
|
165 | 165 | /** |
166 | 166 | * Filter the version of the HTTP protocol used in a request. |
167 | 167 | * |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | * @param string $version Version of HTTP used. Accepts '1.0' and '1.1'. |
171 | 171 | * Default '1.0'. |
172 | 172 | */ |
173 | - 'httpversion' => apply_filters( 'http_request_version', '1.0' ), |
|
173 | + 'httpversion' => apply_filters('http_request_version', '1.0'), |
|
174 | 174 | /** |
175 | 175 | * Filter the user agent value sent with an HTTP request. |
176 | 176 | * |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | * |
179 | 179 | * @param string $user_agent WordPress user agent string. |
180 | 180 | */ |
181 | - 'user-agent' => apply_filters( 'http_headers_useragent', 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ) ), |
|
181 | + 'user-agent' => apply_filters('http_headers_useragent', 'WordPress/'.$wp_version.'; '.get_bloginfo('url')), |
|
182 | 182 | /** |
183 | 183 | * Filter whether to pass URLs through wp_http_validate_url() in an HTTP request. |
184 | 184 | * |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | * @param bool $pass_url Whether to pass URLs through wp_http_validate_url(). |
188 | 188 | * Default false. |
189 | 189 | */ |
190 | - 'reject_unsafe_urls' => apply_filters( 'http_request_reject_unsafe_urls', false ), |
|
190 | + 'reject_unsafe_urls' => apply_filters('http_request_reject_unsafe_urls', false), |
|
191 | 191 | 'blocking' => true, |
192 | 192 | 'headers' => array(), |
193 | 193 | 'cookies' => array(), |
@@ -195,20 +195,20 @@ discard block |
||
195 | 195 | 'compress' => false, |
196 | 196 | 'decompress' => true, |
197 | 197 | 'sslverify' => true, |
198 | - 'sslcertificates' => ABSPATH . WPINC . '/certificates/ca-bundle.crt', |
|
198 | + 'sslcertificates' => ABSPATH.WPINC.'/certificates/ca-bundle.crt', |
|
199 | 199 | 'stream' => false, |
200 | 200 | 'filename' => null, |
201 | 201 | 'limit_response_size' => null, |
202 | 202 | ); |
203 | 203 | |
204 | 204 | // Pre-parse for the HEAD checks. |
205 | - $args = wp_parse_args( $args ); |
|
205 | + $args = wp_parse_args($args); |
|
206 | 206 | |
207 | 207 | // By default, Head requests do not cause redirections. |
208 | - if ( isset($args['method']) && 'HEAD' == $args['method'] ) |
|
208 | + if (isset($args['method']) && 'HEAD' == $args['method']) |
|
209 | 209 | $defaults['redirection'] = 0; |
210 | 210 | |
211 | - $r = wp_parse_args( $args, $defaults ); |
|
211 | + $r = wp_parse_args($args, $defaults); |
|
212 | 212 | /** |
213 | 213 | * Filter the arguments used in an HTTP request. |
214 | 214 | * |
@@ -217,10 +217,10 @@ discard block |
||
217 | 217 | * @param array $r An array of HTTP request arguments. |
218 | 218 | * @param string $url The request URL. |
219 | 219 | */ |
220 | - $r = apply_filters( 'http_request_args', $r, $url ); |
|
220 | + $r = apply_filters('http_request_args', $r, $url); |
|
221 | 221 | |
222 | 222 | // The transports decrement this, store a copy of the original value for loop purposes. |
223 | - if ( ! isset( $r['_redirection'] ) ) |
|
223 | + if ( ! isset($r['_redirection'])) |
|
224 | 224 | $r['_redirection'] = $r['redirection']; |
225 | 225 | |
226 | 226 | /** |
@@ -241,26 +241,26 @@ discard block |
||
241 | 241 | * @param array $r HTTP request arguments. |
242 | 242 | * @param string $url The request URL. |
243 | 243 | */ |
244 | - $pre = apply_filters( 'pre_http_request', false, $r, $url ); |
|
244 | + $pre = apply_filters('pre_http_request', false, $r, $url); |
|
245 | 245 | |
246 | - if ( false !== $pre ) |
|
246 | + if (false !== $pre) |
|
247 | 247 | return $pre; |
248 | 248 | |
249 | - if ( function_exists( 'wp_kses_bad_protocol' ) ) { |
|
250 | - if ( $r['reject_unsafe_urls'] ) |
|
251 | - $url = wp_http_validate_url( $url ); |
|
252 | - if ( $url ) { |
|
253 | - $url = wp_kses_bad_protocol( $url, array( 'http', 'https', 'ssl' ) ); |
|
249 | + if (function_exists('wp_kses_bad_protocol')) { |
|
250 | + if ($r['reject_unsafe_urls']) |
|
251 | + $url = wp_http_validate_url($url); |
|
252 | + if ($url) { |
|
253 | + $url = wp_kses_bad_protocol($url, array('http', 'https', 'ssl')); |
|
254 | 254 | } |
255 | 255 | } |
256 | 256 | |
257 | - $arrURL = @parse_url( $url ); |
|
257 | + $arrURL = @parse_url($url); |
|
258 | 258 | |
259 | - if ( empty( $url ) || empty( $arrURL['scheme'] ) ) |
|
259 | + if (empty($url) || empty($arrURL['scheme'])) |
|
260 | 260 | return new WP_Error('http_request_failed', __('A valid URL was not provided.')); |
261 | 261 | |
262 | - if ( $this->block_request( $url ) ) |
|
263 | - return new WP_Error( 'http_request_failed', __( 'User has blocked requests through HTTP.' ) ); |
|
262 | + if ($this->block_request($url)) |
|
263 | + return new WP_Error('http_request_failed', __('User has blocked requests through HTTP.')); |
|
264 | 264 | |
265 | 265 | /* |
266 | 266 | * Determine if this is a https call and pass that on to the transport functions |
@@ -269,88 +269,88 @@ discard block |
||
269 | 269 | $r['ssl'] = $arrURL['scheme'] == 'https' || $arrURL['scheme'] == 'ssl'; |
270 | 270 | |
271 | 271 | // Determine if this request is to OUR install of WordPress. |
272 | - $homeURL = parse_url( get_bloginfo( 'url' ) ); |
|
273 | - $r['local'] = 'localhost' == $arrURL['host'] || ( isset( $homeURL['host'] ) && $homeURL['host'] == $arrURL['host'] ); |
|
274 | - unset( $homeURL ); |
|
272 | + $homeURL = parse_url(get_bloginfo('url')); |
|
273 | + $r['local'] = 'localhost' == $arrURL['host'] || (isset($homeURL['host']) && $homeURL['host'] == $arrURL['host']); |
|
274 | + unset($homeURL); |
|
275 | 275 | |
276 | 276 | /* |
277 | 277 | * If we are streaming to a file but no filename was given drop it in the WP temp dir |
278 | 278 | * and pick its name using the basename of the $url. |
279 | 279 | */ |
280 | - if ( $r['stream'] && empty( $r['filename'] ) ) { |
|
281 | - $r['filename'] = get_temp_dir() . wp_unique_filename( get_temp_dir(), basename( $url ) ); |
|
280 | + if ($r['stream'] && empty($r['filename'])) { |
|
281 | + $r['filename'] = get_temp_dir().wp_unique_filename(get_temp_dir(), basename($url)); |
|
282 | 282 | } |
283 | 283 | |
284 | 284 | /* |
285 | 285 | * Force some settings if we are streaming to a file and check for existence and perms |
286 | 286 | * of destination directory. |
287 | 287 | */ |
288 | - if ( $r['stream'] ) { |
|
288 | + if ($r['stream']) { |
|
289 | 289 | $r['blocking'] = true; |
290 | - if ( ! wp_is_writable( dirname( $r['filename'] ) ) ) |
|
291 | - return new WP_Error( 'http_request_failed', __( 'Destination directory for file streaming does not exist or is not writable.' ) ); |
|
290 | + if ( ! wp_is_writable(dirname($r['filename']))) |
|
291 | + return new WP_Error('http_request_failed', __('Destination directory for file streaming does not exist or is not writable.')); |
|
292 | 292 | } |
293 | 293 | |
294 | - if ( is_null( $r['headers'] ) ) |
|
294 | + if (is_null($r['headers'])) |
|
295 | 295 | $r['headers'] = array(); |
296 | 296 | |
297 | - if ( ! is_array( $r['headers'] ) ) { |
|
298 | - $processedHeaders = self::processHeaders( $r['headers'], $url ); |
|
297 | + if ( ! is_array($r['headers'])) { |
|
298 | + $processedHeaders = self::processHeaders($r['headers'], $url); |
|
299 | 299 | $r['headers'] = $processedHeaders['headers']; |
300 | 300 | } |
301 | 301 | |
302 | - if ( isset( $r['headers']['User-Agent'] ) ) { |
|
302 | + if (isset($r['headers']['User-Agent'])) { |
|
303 | 303 | $r['user-agent'] = $r['headers']['User-Agent']; |
304 | - unset( $r['headers']['User-Agent'] ); |
|
304 | + unset($r['headers']['User-Agent']); |
|
305 | 305 | } |
306 | 306 | |
307 | - if ( isset( $r['headers']['user-agent'] ) ) { |
|
307 | + if (isset($r['headers']['user-agent'])) { |
|
308 | 308 | $r['user-agent'] = $r['headers']['user-agent']; |
309 | - unset( $r['headers']['user-agent'] ); |
|
309 | + unset($r['headers']['user-agent']); |
|
310 | 310 | } |
311 | 311 | |
312 | - if ( '1.1' == $r['httpversion'] && !isset( $r['headers']['connection'] ) ) { |
|
312 | + if ('1.1' == $r['httpversion'] && ! isset($r['headers']['connection'])) { |
|
313 | 313 | $r['headers']['connection'] = 'close'; |
314 | 314 | } |
315 | 315 | |
316 | 316 | // Construct Cookie: header if any cookies are set. |
317 | - self::buildCookieHeader( $r ); |
|
317 | + self::buildCookieHeader($r); |
|
318 | 318 | |
319 | 319 | // Avoid issues where mbstring.func_overload is enabled. |
320 | 320 | mbstring_binary_safe_encoding(); |
321 | 321 | |
322 | - if ( ! isset( $r['headers']['Accept-Encoding'] ) ) { |
|
323 | - if ( $encoding = WP_Http_Encoding::accept_encoding( $url, $r ) ) |
|
322 | + if ( ! isset($r['headers']['Accept-Encoding'])) { |
|
323 | + if ($encoding = WP_Http_Encoding::accept_encoding($url, $r)) |
|
324 | 324 | $r['headers']['Accept-Encoding'] = $encoding; |
325 | 325 | } |
326 | 326 | |
327 | - if ( ( ! is_null( $r['body'] ) && '' != $r['body'] ) || 'POST' == $r['method'] || 'PUT' == $r['method'] ) { |
|
328 | - if ( is_array( $r['body'] ) || is_object( $r['body'] ) ) { |
|
329 | - $r['body'] = http_build_query( $r['body'], null, '&' ); |
|
327 | + if (( ! is_null($r['body']) && '' != $r['body']) || 'POST' == $r['method'] || 'PUT' == $r['method']) { |
|
328 | + if (is_array($r['body']) || is_object($r['body'])) { |
|
329 | + $r['body'] = http_build_query($r['body'], null, '&'); |
|
330 | 330 | |
331 | - if ( ! isset( $r['headers']['Content-Type'] ) ) |
|
332 | - $r['headers']['Content-Type'] = 'application/x-www-form-urlencoded; charset=' . get_option( 'blog_charset' ); |
|
331 | + if ( ! isset($r['headers']['Content-Type'])) |
|
332 | + $r['headers']['Content-Type'] = 'application/x-www-form-urlencoded; charset='.get_option('blog_charset'); |
|
333 | 333 | } |
334 | 334 | |
335 | - if ( '' === $r['body'] ) |
|
335 | + if ('' === $r['body']) |
|
336 | 336 | $r['body'] = null; |
337 | 337 | |
338 | - if ( ! isset( $r['headers']['Content-Length'] ) && ! isset( $r['headers']['content-length'] ) ) |
|
339 | - $r['headers']['Content-Length'] = strlen( $r['body'] ); |
|
338 | + if ( ! isset($r['headers']['Content-Length']) && ! isset($r['headers']['content-length'])) |
|
339 | + $r['headers']['Content-Length'] = strlen($r['body']); |
|
340 | 340 | } |
341 | 341 | |
342 | - $response = $this->_dispatch_request( $url, $r ); |
|
342 | + $response = $this->_dispatch_request($url, $r); |
|
343 | 343 | |
344 | 344 | reset_mbstring_encoding(); |
345 | 345 | |
346 | - if ( is_wp_error( $response ) ) |
|
346 | + if (is_wp_error($response)) |
|
347 | 347 | return $response; |
348 | 348 | |
349 | 349 | // Append cookies that were used in this request to the response |
350 | - if ( ! empty( $r['cookies'] ) ) { |
|
351 | - $cookies_set = wp_list_pluck( $response['cookies'], 'name' ); |
|
352 | - foreach ( $r['cookies'] as $cookie ) { |
|
353 | - if ( ! in_array( $cookie->name, $cookies_set ) && $cookie->test( $url ) ) { |
|
350 | + if ( ! empty($r['cookies'])) { |
|
351 | + $cookies_set = wp_list_pluck($response['cookies'], 'name'); |
|
352 | + foreach ($r['cookies'] as $cookie) { |
|
353 | + if ( ! in_array($cookie->name, $cookies_set) && $cookie->test($url)) { |
|
354 | 354 | $response['cookies'][] = $cookie; |
355 | 355 | } |
356 | 356 | } |
@@ -370,8 +370,8 @@ discard block |
||
370 | 370 | * |
371 | 371 | * @return string|false Class name for the first transport that claims to support the request. False if no transport claims to support the request. |
372 | 372 | */ |
373 | - public function _get_first_available_transport( $args, $url = null ) { |
|
374 | - $transports = array( 'curl', 'streams' ); |
|
373 | + public function _get_first_available_transport($args, $url = null) { |
|
374 | + $transports = array('curl', 'streams'); |
|
375 | 375 | |
376 | 376 | /** |
377 | 377 | * Filter which HTTP transports are available and in what order. |
@@ -383,17 +383,17 @@ discard block |
||
383 | 383 | * @param array $args HTTP request arguments. |
384 | 384 | * @param string $url The URL to request. |
385 | 385 | */ |
386 | - $request_order = apply_filters( 'http_api_transports', $transports, $args, $url ); |
|
386 | + $request_order = apply_filters('http_api_transports', $transports, $args, $url); |
|
387 | 387 | |
388 | 388 | // Loop over each transport on each HTTP request looking for one which will serve this request's needs. |
389 | - foreach ( $request_order as $transport ) { |
|
390 | - if ( in_array( $transport, $transports ) ) { |
|
391 | - $transport = ucfirst( $transport ); |
|
389 | + foreach ($request_order as $transport) { |
|
390 | + if (in_array($transport, $transports)) { |
|
391 | + $transport = ucfirst($transport); |
|
392 | 392 | } |
393 | - $class = 'WP_Http_' . $transport; |
|
393 | + $class = 'WP_Http_'.$transport; |
|
394 | 394 | |
395 | 395 | // Check to see if this transport is a possibility, calls the transport statically. |
396 | - if ( !call_user_func( array( $class, 'test' ), $args, $url ) ) |
|
396 | + if ( ! call_user_func(array($class, 'test'), $args, $url)) |
|
397 | 397 | continue; |
398 | 398 | |
399 | 399 | return $class; |
@@ -419,18 +419,18 @@ discard block |
||
419 | 419 | * @param array $args Request arguments |
420 | 420 | * @return array|WP_Error Array containing 'headers', 'body', 'response', 'cookies', 'filename'. A WP_Error instance upon error |
421 | 421 | */ |
422 | - private function _dispatch_request( $url, $args ) { |
|
422 | + private function _dispatch_request($url, $args) { |
|
423 | 423 | static $transports = array(); |
424 | 424 | |
425 | - $class = $this->_get_first_available_transport( $args, $url ); |
|
426 | - if ( !$class ) |
|
427 | - return new WP_Error( 'http_failure', __( 'There are no HTTP transports available which can complete the requested request.' ) ); |
|
425 | + $class = $this->_get_first_available_transport($args, $url); |
|
426 | + if ( ! $class) |
|
427 | + return new WP_Error('http_failure', __('There are no HTTP transports available which can complete the requested request.')); |
|
428 | 428 | |
429 | 429 | // Transport claims to support request, instantiate it and give it a whirl. |
430 | - if ( empty( $transports[$class] ) ) |
|
430 | + if (empty($transports[$class])) |
|
431 | 431 | $transports[$class] = new $class; |
432 | 432 | |
433 | - $response = $transports[$class]->request( $url, $args ); |
|
433 | + $response = $transports[$class]->request($url, $args); |
|
434 | 434 | |
435 | 435 | /** |
436 | 436 | * Fires after an HTTP API response is received and before the response is returned. |
@@ -443,9 +443,9 @@ discard block |
||
443 | 443 | * @param array $args HTTP request arguments. |
444 | 444 | * @param string $url The request URL. |
445 | 445 | */ |
446 | - do_action( 'http_api_debug', $response, 'response', $class, $args, $url ); |
|
446 | + do_action('http_api_debug', $response, 'response', $class, $args, $url); |
|
447 | 447 | |
448 | - if ( is_wp_error( $response ) ) |
|
448 | + if (is_wp_error($response)) |
|
449 | 449 | return $response; |
450 | 450 | |
451 | 451 | /** |
@@ -457,7 +457,7 @@ discard block |
||
457 | 457 | * @param array $args HTTP request arguments. |
458 | 458 | * @param string $url The request URL. |
459 | 459 | */ |
460 | - return apply_filters( 'http_response', $response, $args, $url ); |
|
460 | + return apply_filters('http_response', $response, $args, $url); |
|
461 | 461 | } |
462 | 462 | |
463 | 463 | /** |
@@ -474,7 +474,7 @@ discard block |
||
474 | 474 | */ |
475 | 475 | public function post($url, $args = array()) { |
476 | 476 | $defaults = array('method' => 'POST'); |
477 | - $r = wp_parse_args( $args, $defaults ); |
|
477 | + $r = wp_parse_args($args, $defaults); |
|
478 | 478 | return $this->request($url, $r); |
479 | 479 | } |
480 | 480 | |
@@ -492,7 +492,7 @@ discard block |
||
492 | 492 | */ |
493 | 493 | public function get($url, $args = array()) { |
494 | 494 | $defaults = array('method' => 'GET'); |
495 | - $r = wp_parse_args( $args, $defaults ); |
|
495 | + $r = wp_parse_args($args, $defaults); |
|
496 | 496 | return $this->request($url, $r); |
497 | 497 | } |
498 | 498 | |
@@ -510,7 +510,7 @@ discard block |
||
510 | 510 | */ |
511 | 511 | public function head($url, $args = array()) { |
512 | 512 | $defaults = array('method' => 'HEAD'); |
513 | - $r = wp_parse_args( $args, $defaults ); |
|
513 | + $r = wp_parse_args($args, $defaults); |
|
514 | 514 | return $this->request($url, $r); |
515 | 515 | } |
516 | 516 | |
@@ -545,9 +545,9 @@ discard block |
||
545 | 545 | * @return array Processed string headers. If duplicate headers are encountered, |
546 | 546 | * Then a numbered array is returned as the value of that header-key. |
547 | 547 | */ |
548 | - public static function processHeaders( $headers, $url = '' ) { |
|
548 | + public static function processHeaders($headers, $url = '') { |
|
549 | 549 | // Split headers, one per array element. |
550 | - if ( is_string($headers) ) { |
|
550 | + if (is_string($headers)) { |
|
551 | 551 | // Tolerate line terminator: CRLF = LF (RFC 2616 19.3). |
552 | 552 | $headers = str_replace("\r\n", "\n", $headers); |
553 | 553 | /* |
@@ -565,8 +565,8 @@ discard block |
||
565 | 565 | * If a redirection has taken place, The headers for each page request may have been passed. |
566 | 566 | * In this case, determine the final HTTP header and parse from there. |
567 | 567 | */ |
568 | - for ( $i = count($headers)-1; $i >= 0; $i-- ) { |
|
569 | - if ( !empty($headers[$i]) && false === strpos($headers[$i], ':') ) { |
|
568 | + for ($i = count($headers) - 1; $i >= 0; $i--) { |
|
569 | + if ( ! empty($headers[$i]) && false === strpos($headers[$i], ':')) { |
|
570 | 570 | $headers = array_splice($headers, $i); |
571 | 571 | break; |
572 | 572 | } |
@@ -574,35 +574,35 @@ discard block |
||
574 | 574 | |
575 | 575 | $cookies = array(); |
576 | 576 | $newheaders = array(); |
577 | - foreach ( (array) $headers as $tempheader ) { |
|
578 | - if ( empty($tempheader) ) |
|
577 | + foreach ((array) $headers as $tempheader) { |
|
578 | + if (empty($tempheader)) |
|
579 | 579 | continue; |
580 | 580 | |
581 | - if ( false === strpos($tempheader, ':') ) { |
|
581 | + if (false === strpos($tempheader, ':')) { |
|
582 | 582 | $stack = explode(' ', $tempheader, 3); |
583 | 583 | $stack[] = ''; |
584 | - list( , $response['code'], $response['message']) = $stack; |
|
584 | + list(, $response['code'], $response['message']) = $stack; |
|
585 | 585 | continue; |
586 | 586 | } |
587 | 587 | |
588 | 588 | list($key, $value) = explode(':', $tempheader, 2); |
589 | 589 | |
590 | - $key = strtolower( $key ); |
|
591 | - $value = trim( $value ); |
|
590 | + $key = strtolower($key); |
|
591 | + $value = trim($value); |
|
592 | 592 | |
593 | - if ( isset( $newheaders[ $key ] ) ) { |
|
594 | - if ( ! is_array( $newheaders[ $key ] ) ) |
|
595 | - $newheaders[$key] = array( $newheaders[ $key ] ); |
|
596 | - $newheaders[ $key ][] = $value; |
|
593 | + if (isset($newheaders[$key])) { |
|
594 | + if ( ! is_array($newheaders[$key])) |
|
595 | + $newheaders[$key] = array($newheaders[$key]); |
|
596 | + $newheaders[$key][] = $value; |
|
597 | 597 | } else { |
598 | - $newheaders[ $key ] = $value; |
|
598 | + $newheaders[$key] = $value; |
|
599 | 599 | } |
600 | - if ( 'set-cookie' == $key ) |
|
601 | - $cookies[] = new WP_Http_Cookie( $value, $url ); |
|
600 | + if ('set-cookie' == $key) |
|
601 | + $cookies[] = new WP_Http_Cookie($value, $url); |
|
602 | 602 | } |
603 | 603 | |
604 | 604 | // Cast the Response Code to an int |
605 | - $response['code'] = intval( $response['code'] ); |
|
605 | + $response['code'] = intval($response['code']); |
|
606 | 606 | |
607 | 607 | return array('response' => $response, 'headers' => $newheaders, 'cookies' => $cookies); |
608 | 608 | } |
@@ -620,20 +620,20 @@ discard block |
||
620 | 620 | * |
621 | 621 | * @param array $r Full array of args passed into ::request() |
622 | 622 | */ |
623 | - public static function buildCookieHeader( &$r ) { |
|
624 | - if ( ! empty($r['cookies']) ) { |
|
623 | + public static function buildCookieHeader(&$r) { |
|
624 | + if ( ! empty($r['cookies'])) { |
|
625 | 625 | // Upgrade any name => value cookie pairs to WP_HTTP_Cookie instances. |
626 | - foreach ( $r['cookies'] as $name => $value ) { |
|
627 | - if ( ! is_object( $value ) ) |
|
628 | - $r['cookies'][ $name ] = new WP_Http_Cookie( array( 'name' => $name, 'value' => $value ) ); |
|
626 | + foreach ($r['cookies'] as $name => $value) { |
|
627 | + if ( ! is_object($value)) |
|
628 | + $r['cookies'][$name] = new WP_Http_Cookie(array('name' => $name, 'value' => $value)); |
|
629 | 629 | } |
630 | 630 | |
631 | 631 | $cookies_header = ''; |
632 | - foreach ( (array) $r['cookies'] as $cookie ) { |
|
633 | - $cookies_header .= $cookie->getHeaderValue() . '; '; |
|
632 | + foreach ((array) $r['cookies'] as $cookie) { |
|
633 | + $cookies_header .= $cookie->getHeaderValue().'; '; |
|
634 | 634 | } |
635 | 635 | |
636 | - $cookies_header = substr( $cookies_header, 0, -2 ); |
|
636 | + $cookies_header = substr($cookies_header, 0, -2); |
|
637 | 637 | $r['headers']['cookie'] = $cookies_header; |
638 | 638 | } |
639 | 639 | } |
@@ -652,9 +652,9 @@ discard block |
||
652 | 652 | * @param string $body Body content |
653 | 653 | * @return string Chunked decoded body on success or raw body on failure. |
654 | 654 | */ |
655 | - public static function chunkTransferDecode( $body ) { |
|
655 | + public static function chunkTransferDecode($body) { |
|
656 | 656 | // The body is not chunked encoded or is malformed. |
657 | - if ( ! preg_match( '/^([0-9a-f]+)[^\r\n]*\r\n/i', trim( $body ) ) ) |
|
657 | + if ( ! preg_match('/^([0-9a-f]+)[^\r\n]*\r\n/i', trim($body))) |
|
658 | 658 | return $body; |
659 | 659 | |
660 | 660 | $parsed_body = ''; |
@@ -662,22 +662,22 @@ discard block |
||
662 | 662 | // We'll be altering $body, so need a backup in case of error. |
663 | 663 | $body_original = $body; |
664 | 664 | |
665 | - while ( true ) { |
|
666 | - $has_chunk = (bool) preg_match( '/^([0-9a-f]+)[^\r\n]*\r\n/i', $body, $match ); |
|
667 | - if ( ! $has_chunk || empty( $match[1] ) ) |
|
665 | + while (true) { |
|
666 | + $has_chunk = (bool) preg_match('/^([0-9a-f]+)[^\r\n]*\r\n/i', $body, $match); |
|
667 | + if ( ! $has_chunk || empty($match[1])) |
|
668 | 668 | return $body_original; |
669 | 669 | |
670 | - $length = hexdec( $match[1] ); |
|
671 | - $chunk_length = strlen( $match[0] ); |
|
670 | + $length = hexdec($match[1]); |
|
671 | + $chunk_length = strlen($match[0]); |
|
672 | 672 | |
673 | 673 | // Parse out the chunk of data. |
674 | - $parsed_body .= substr( $body, $chunk_length, $length ); |
|
674 | + $parsed_body .= substr($body, $chunk_length, $length); |
|
675 | 675 | |
676 | 676 | // Remove the chunk from the raw data. |
677 | - $body = substr( $body, $length + $chunk_length ); |
|
677 | + $body = substr($body, $length + $chunk_length); |
|
678 | 678 | |
679 | 679 | // End of the document. |
680 | - if ( '0' === trim( $body ) ) |
|
680 | + if ('0' === trim($body)) |
|
681 | 681 | return $parsed_body; |
682 | 682 | } |
683 | 683 | } |
@@ -706,17 +706,17 @@ discard block |
||
706 | 706 | */ |
707 | 707 | public function block_request($uri) { |
708 | 708 | // We don't need to block requests, because nothing is blocked. |
709 | - if ( ! defined( 'WP_HTTP_BLOCK_EXTERNAL' ) || ! WP_HTTP_BLOCK_EXTERNAL ) |
|
709 | + if ( ! defined('WP_HTTP_BLOCK_EXTERNAL') || ! WP_HTTP_BLOCK_EXTERNAL) |
|
710 | 710 | return false; |
711 | 711 | |
712 | 712 | $check = parse_url($uri); |
713 | - if ( ! $check ) |
|
713 | + if ( ! $check) |
|
714 | 714 | return true; |
715 | 715 | |
716 | - $home = parse_url( get_option('siteurl') ); |
|
716 | + $home = parse_url(get_option('siteurl')); |
|
717 | 717 | |
718 | 718 | // Don't block requests back to ourselves by default. |
719 | - if ( 'localhost' == $check['host'] || ( isset( $home['host'] ) && $home['host'] == $check['host'] ) ) { |
|
719 | + if ('localhost' == $check['host'] || (isset($home['host']) && $home['host'] == $check['host'])) { |
|
720 | 720 | /** |
721 | 721 | * Filter whether to block local requests through the proxy. |
722 | 722 | * |
@@ -725,29 +725,29 @@ discard block |
||
725 | 725 | * @param bool $block Whether to block local requests through proxy. |
726 | 726 | * Default false. |
727 | 727 | */ |
728 | - return apply_filters( 'block_local_requests', false ); |
|
728 | + return apply_filters('block_local_requests', false); |
|
729 | 729 | } |
730 | 730 | |
731 | - if ( !defined('WP_ACCESSIBLE_HOSTS') ) |
|
731 | + if ( ! defined('WP_ACCESSIBLE_HOSTS')) |
|
732 | 732 | return true; |
733 | 733 | |
734 | 734 | static $accessible_hosts = null; |
735 | 735 | static $wildcard_regex = array(); |
736 | - if ( null === $accessible_hosts ) { |
|
736 | + if (null === $accessible_hosts) { |
|
737 | 737 | $accessible_hosts = preg_split('|,\s*|', WP_ACCESSIBLE_HOSTS); |
738 | 738 | |
739 | - if ( false !== strpos(WP_ACCESSIBLE_HOSTS, '*') ) { |
|
739 | + if (false !== strpos(WP_ACCESSIBLE_HOSTS, '*')) { |
|
740 | 740 | $wildcard_regex = array(); |
741 | - foreach ( $accessible_hosts as $host ) |
|
742 | - $wildcard_regex[] = str_replace( '\*', '.+', preg_quote( $host, '/' ) ); |
|
743 | - $wildcard_regex = '/^(' . implode('|', $wildcard_regex) . ')$/i'; |
|
741 | + foreach ($accessible_hosts as $host) |
|
742 | + $wildcard_regex[] = str_replace('\*', '.+', preg_quote($host, '/')); |
|
743 | + $wildcard_regex = '/^('.implode('|', $wildcard_regex).')$/i'; |
|
744 | 744 | } |
745 | 745 | } |
746 | 746 | |
747 | - if ( !empty($wildcard_regex) ) |
|
748 | - return !preg_match($wildcard_regex, $check['host']); |
|
747 | + if ( ! empty($wildcard_regex)) |
|
748 | + return ! preg_match($wildcard_regex, $check['host']); |
|
749 | 749 | else |
750 | - return !in_array( $check['host'], $accessible_hosts ); //Inverse logic, If it's in the array, then we can't access it. |
|
750 | + return ! in_array($check['host'], $accessible_hosts); //Inverse logic, If it's in the array, then we can't access it. |
|
751 | 751 | |
752 | 752 | } |
753 | 753 | |
@@ -762,9 +762,9 @@ discard block |
||
762 | 762 | * @return bool|array False on failure; Array of URL components on success; |
763 | 763 | * See parse_url()'s return values. |
764 | 764 | */ |
765 | - protected static function parse_url( $url ) { |
|
766 | - _deprecated_function( __METHOD__, '4.4.0', 'wp_parse_url()' ); |
|
767 | - return wp_parse_url( $url ); |
|
765 | + protected static function parse_url($url) { |
|
766 | + _deprecated_function(__METHOD__, '4.4.0', 'wp_parse_url()'); |
|
767 | + return wp_parse_url($url); |
|
768 | 768 | } |
769 | 769 | |
770 | 770 | /** |
@@ -781,65 +781,65 @@ discard block |
||
781 | 781 | * @param string $url The URL which $maybe_relative_path is relative to |
782 | 782 | * @return string An Absolute URL, in a failure condition where the URL cannot be parsed, the relative URL will be returned. |
783 | 783 | */ |
784 | - public static function make_absolute_url( $maybe_relative_path, $url ) { |
|
785 | - if ( empty( $url ) ) |
|
784 | + public static function make_absolute_url($maybe_relative_path, $url) { |
|
785 | + if (empty($url)) |
|
786 | 786 | return $maybe_relative_path; |
787 | 787 | |
788 | - if ( ! $url_parts = wp_parse_url( $url ) ) { |
|
788 | + if ( ! $url_parts = wp_parse_url($url)) { |
|
789 | 789 | return $maybe_relative_path; |
790 | 790 | } |
791 | 791 | |
792 | - if ( ! $relative_url_parts = wp_parse_url( $maybe_relative_path ) ) { |
|
792 | + if ( ! $relative_url_parts = wp_parse_url($maybe_relative_path)) { |
|
793 | 793 | return $maybe_relative_path; |
794 | 794 | } |
795 | 795 | |
796 | 796 | // Check for a scheme on the 'relative' url |
797 | - if ( ! empty( $relative_url_parts['scheme'] ) ) { |
|
797 | + if ( ! empty($relative_url_parts['scheme'])) { |
|
798 | 798 | return $maybe_relative_path; |
799 | 799 | } |
800 | 800 | |
801 | - $absolute_path = $url_parts['scheme'] . '://'; |
|
801 | + $absolute_path = $url_parts['scheme'].'://'; |
|
802 | 802 | |
803 | 803 | // Schemeless URL's will make it this far, so we check for a host in the relative url and convert it to a protocol-url |
804 | - if ( isset( $relative_url_parts['host'] ) ) { |
|
804 | + if (isset($relative_url_parts['host'])) { |
|
805 | 805 | $absolute_path .= $relative_url_parts['host']; |
806 | - if ( isset( $relative_url_parts['port'] ) ) |
|
807 | - $absolute_path .= ':' . $relative_url_parts['port']; |
|
806 | + if (isset($relative_url_parts['port'])) |
|
807 | + $absolute_path .= ':'.$relative_url_parts['port']; |
|
808 | 808 | } else { |
809 | 809 | $absolute_path .= $url_parts['host']; |
810 | - if ( isset( $url_parts['port'] ) ) |
|
811 | - $absolute_path .= ':' . $url_parts['port']; |
|
810 | + if (isset($url_parts['port'])) |
|
811 | + $absolute_path .= ':'.$url_parts['port']; |
|
812 | 812 | } |
813 | 813 | |
814 | 814 | // Start off with the Absolute URL path. |
815 | - $path = ! empty( $url_parts['path'] ) ? $url_parts['path'] : '/'; |
|
815 | + $path = ! empty($url_parts['path']) ? $url_parts['path'] : '/'; |
|
816 | 816 | |
817 | 817 | // If it's a root-relative path, then great. |
818 | - if ( ! empty( $relative_url_parts['path'] ) && '/' == $relative_url_parts['path'][0] ) { |
|
818 | + if ( ! empty($relative_url_parts['path']) && '/' == $relative_url_parts['path'][0]) { |
|
819 | 819 | $path = $relative_url_parts['path']; |
820 | 820 | |
821 | 821 | // Else it's a relative path. |
822 | - } elseif ( ! empty( $relative_url_parts['path'] ) ) { |
|
822 | + } elseif ( ! empty($relative_url_parts['path'])) { |
|
823 | 823 | // Strip off any file components from the absolute path. |
824 | - $path = substr( $path, 0, strrpos( $path, '/' ) + 1 ); |
|
824 | + $path = substr($path, 0, strrpos($path, '/') + 1); |
|
825 | 825 | |
826 | 826 | // Build the new path. |
827 | 827 | $path .= $relative_url_parts['path']; |
828 | 828 | |
829 | 829 | // Strip all /path/../ out of the path. |
830 | - while ( strpos( $path, '../' ) > 1 ) { |
|
831 | - $path = preg_replace( '![^/]+/\.\./!', '', $path ); |
|
830 | + while (strpos($path, '../') > 1) { |
|
831 | + $path = preg_replace('![^/]+/\.\./!', '', $path); |
|
832 | 832 | } |
833 | 833 | |
834 | 834 | // Strip any final leading ../ from the path. |
835 | - $path = preg_replace( '!^/(\.\./)+!', '', $path ); |
|
835 | + $path = preg_replace('!^/(\.\./)+!', '', $path); |
|
836 | 836 | } |
837 | 837 | |
838 | 838 | // Add the Query string. |
839 | - if ( ! empty( $relative_url_parts['query'] ) ) |
|
840 | - $path .= '?' . $relative_url_parts['query']; |
|
839 | + if ( ! empty($relative_url_parts['query'])) |
|
840 | + $path .= '?'.$relative_url_parts['query']; |
|
841 | 841 | |
842 | - return $absolute_path . '/' . ltrim( $path, '/' ); |
|
842 | + return $absolute_path.'/'.ltrim($path, '/'); |
|
843 | 843 | } |
844 | 844 | |
845 | 845 | /** |
@@ -854,42 +854,42 @@ discard block |
||
854 | 854 | * @param array $response The Response of the HTTP request. |
855 | 855 | * @return false|object False if no redirect is present, a WP_HTTP or WP_Error result otherwise. |
856 | 856 | */ |
857 | - public static function handle_redirects( $url, $args, $response ) { |
|
857 | + public static function handle_redirects($url, $args, $response) { |
|
858 | 858 | // If no redirects are present, or, redirects were not requested, perform no action. |
859 | - if ( ! isset( $response['headers']['location'] ) || 0 === $args['_redirection'] ) |
|
859 | + if ( ! isset($response['headers']['location']) || 0 === $args['_redirection']) |
|
860 | 860 | return false; |
861 | 861 | |
862 | 862 | // Only perform redirections on redirection http codes. |
863 | - if ( $response['response']['code'] > 399 || $response['response']['code'] < 300 ) |
|
863 | + if ($response['response']['code'] > 399 || $response['response']['code'] < 300) |
|
864 | 864 | return false; |
865 | 865 | |
866 | 866 | // Don't redirect if we've run out of redirects. |
867 | - if ( $args['redirection']-- <= 0 ) |
|
868 | - return new WP_Error( 'http_request_failed', __('Too many redirects.') ); |
|
867 | + if ($args['redirection']-- <= 0) |
|
868 | + return new WP_Error('http_request_failed', __('Too many redirects.')); |
|
869 | 869 | |
870 | 870 | $redirect_location = $response['headers']['location']; |
871 | 871 | |
872 | 872 | // If there were multiple Location headers, use the last header specified. |
873 | - if ( is_array( $redirect_location ) ) |
|
874 | - $redirect_location = array_pop( $redirect_location ); |
|
873 | + if (is_array($redirect_location)) |
|
874 | + $redirect_location = array_pop($redirect_location); |
|
875 | 875 | |
876 | - $redirect_location = WP_Http::make_absolute_url( $redirect_location, $url ); |
|
876 | + $redirect_location = WP_Http::make_absolute_url($redirect_location, $url); |
|
877 | 877 | |
878 | 878 | // POST requests should not POST to a redirected location. |
879 | - if ( 'POST' == $args['method'] ) { |
|
880 | - if ( in_array( $response['response']['code'], array( 302, 303 ) ) ) |
|
879 | + if ('POST' == $args['method']) { |
|
880 | + if (in_array($response['response']['code'], array(302, 303))) |
|
881 | 881 | $args['method'] = 'GET'; |
882 | 882 | } |
883 | 883 | |
884 | 884 | // Include valid cookies in the redirect process. |
885 | - if ( ! empty( $response['cookies'] ) ) { |
|
886 | - foreach ( $response['cookies'] as $cookie ) { |
|
887 | - if ( $cookie->test( $redirect_location ) ) |
|
885 | + if ( ! empty($response['cookies'])) { |
|
886 | + foreach ($response['cookies'] as $cookie) { |
|
887 | + if ($cookie->test($redirect_location)) |
|
888 | 888 | $args['cookies'][] = $cookie; |
889 | 889 | } |
890 | 890 | } |
891 | 891 | |
892 | - return wp_remote_request( $redirect_location, $args ); |
|
892 | + return wp_remote_request($redirect_location, $args); |
|
893 | 893 | } |
894 | 894 | |
895 | 895 | /** |
@@ -908,11 +908,11 @@ discard block |
||
908 | 908 | * @param string $maybe_ip A suspected IP address |
909 | 909 | * @return integer|bool Upon success, '4' or '6' to represent a IPv4 or IPv6 address, false upon failure |
910 | 910 | */ |
911 | - public static function is_ip_address( $maybe_ip ) { |
|
912 | - if ( preg_match( '/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $maybe_ip ) ) |
|
911 | + public static function is_ip_address($maybe_ip) { |
|
912 | + if (preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $maybe_ip)) |
|
913 | 913 | return 4; |
914 | 914 | |
915 | - if ( false !== strpos( $maybe_ip, ':' ) && preg_match( '/^(((?=.*(::))(?!.*\3.+\3))\3?|([\dA-F]{1,4}(\3|:\b|$)|\2))(?4){5}((?4){2}|(((2[0-4]|1\d|[1-9])?\d|25[0-5])\.?\b){4})$/i', trim( $maybe_ip, ' []' ) ) ) |
|
915 | + if (false !== strpos($maybe_ip, ':') && preg_match('/^(((?=.*(::))(?!.*\3.+\3))\3?|([\dA-F]{1,4}(\3|:\b|$)|\2))(?4){5}((?4){2}|(((2[0-4]|1\d|[1-9])?\d|25[0-5])\.?\b){4})$/i', trim($maybe_ip, ' []'))) |
|
916 | 916 | return 6; |
917 | 917 | |
918 | 918 | return false; |
@@ -205,8 +205,9 @@ discard block |
||
205 | 205 | $args = wp_parse_args( $args ); |
206 | 206 | |
207 | 207 | // By default, Head requests do not cause redirections. |
208 | - if ( isset($args['method']) && 'HEAD' == $args['method'] ) |
|
209 | - $defaults['redirection'] = 0; |
|
208 | + if ( isset($args['method']) && 'HEAD' == $args['method'] ) { |
|
209 | + $defaults['redirection'] = 0; |
|
210 | + } |
|
210 | 211 | |
211 | 212 | $r = wp_parse_args( $args, $defaults ); |
212 | 213 | /** |
@@ -220,8 +221,9 @@ discard block |
||
220 | 221 | $r = apply_filters( 'http_request_args', $r, $url ); |
221 | 222 | |
222 | 223 | // The transports decrement this, store a copy of the original value for loop purposes. |
223 | - if ( ! isset( $r['_redirection'] ) ) |
|
224 | - $r['_redirection'] = $r['redirection']; |
|
224 | + if ( ! isset( $r['_redirection'] ) ) { |
|
225 | + $r['_redirection'] = $r['redirection']; |
|
226 | + } |
|
225 | 227 | |
226 | 228 | /** |
227 | 229 | * Filter whether to preempt an HTTP request's return value. |
@@ -243,12 +245,14 @@ discard block |
||
243 | 245 | */ |
244 | 246 | $pre = apply_filters( 'pre_http_request', false, $r, $url ); |
245 | 247 | |
246 | - if ( false !== $pre ) |
|
247 | - return $pre; |
|
248 | + if ( false !== $pre ) { |
|
249 | + return $pre; |
|
250 | + } |
|
248 | 251 | |
249 | 252 | if ( function_exists( 'wp_kses_bad_protocol' ) ) { |
250 | - if ( $r['reject_unsafe_urls'] ) |
|
251 | - $url = wp_http_validate_url( $url ); |
|
253 | + if ( $r['reject_unsafe_urls'] ) { |
|
254 | + $url = wp_http_validate_url( $url ); |
|
255 | + } |
|
252 | 256 | if ( $url ) { |
253 | 257 | $url = wp_kses_bad_protocol( $url, array( 'http', 'https', 'ssl' ) ); |
254 | 258 | } |
@@ -256,11 +260,13 @@ discard block |
||
256 | 260 | |
257 | 261 | $arrURL = @parse_url( $url ); |
258 | 262 | |
259 | - if ( empty( $url ) || empty( $arrURL['scheme'] ) ) |
|
260 | - return new WP_Error('http_request_failed', __('A valid URL was not provided.')); |
|
263 | + if ( empty( $url ) || empty( $arrURL['scheme'] ) ) { |
|
264 | + return new WP_Error('http_request_failed', __('A valid URL was not provided.')); |
|
265 | + } |
|
261 | 266 | |
262 | - if ( $this->block_request( $url ) ) |
|
263 | - return new WP_Error( 'http_request_failed', __( 'User has blocked requests through HTTP.' ) ); |
|
267 | + if ( $this->block_request( $url ) ) { |
|
268 | + return new WP_Error( 'http_request_failed', __( 'User has blocked requests through HTTP.' ) ); |
|
269 | + } |
|
264 | 270 | |
265 | 271 | /* |
266 | 272 | * Determine if this is a https call and pass that on to the transport functions |
@@ -287,12 +293,14 @@ discard block |
||
287 | 293 | */ |
288 | 294 | if ( $r['stream'] ) { |
289 | 295 | $r['blocking'] = true; |
290 | - if ( ! wp_is_writable( dirname( $r['filename'] ) ) ) |
|
291 | - return new WP_Error( 'http_request_failed', __( 'Destination directory for file streaming does not exist or is not writable.' ) ); |
|
296 | + if ( ! wp_is_writable( dirname( $r['filename'] ) ) ) { |
|
297 | + return new WP_Error( 'http_request_failed', __( 'Destination directory for file streaming does not exist or is not writable.' ) ); |
|
298 | + } |
|
292 | 299 | } |
293 | 300 | |
294 | - if ( is_null( $r['headers'] ) ) |
|
295 | - $r['headers'] = array(); |
|
301 | + if ( is_null( $r['headers'] ) ) { |
|
302 | + $r['headers'] = array(); |
|
303 | + } |
|
296 | 304 | |
297 | 305 | if ( ! is_array( $r['headers'] ) ) { |
298 | 306 | $processedHeaders = self::processHeaders( $r['headers'], $url ); |
@@ -320,31 +328,36 @@ discard block |
||
320 | 328 | mbstring_binary_safe_encoding(); |
321 | 329 | |
322 | 330 | if ( ! isset( $r['headers']['Accept-Encoding'] ) ) { |
323 | - if ( $encoding = WP_Http_Encoding::accept_encoding( $url, $r ) ) |
|
324 | - $r['headers']['Accept-Encoding'] = $encoding; |
|
331 | + if ( $encoding = WP_Http_Encoding::accept_encoding( $url, $r ) ) { |
|
332 | + $r['headers']['Accept-Encoding'] = $encoding; |
|
333 | + } |
|
325 | 334 | } |
326 | 335 | |
327 | 336 | if ( ( ! is_null( $r['body'] ) && '' != $r['body'] ) || 'POST' == $r['method'] || 'PUT' == $r['method'] ) { |
328 | 337 | if ( is_array( $r['body'] ) || is_object( $r['body'] ) ) { |
329 | 338 | $r['body'] = http_build_query( $r['body'], null, '&' ); |
330 | 339 | |
331 | - if ( ! isset( $r['headers']['Content-Type'] ) ) |
|
332 | - $r['headers']['Content-Type'] = 'application/x-www-form-urlencoded; charset=' . get_option( 'blog_charset' ); |
|
340 | + if ( ! isset( $r['headers']['Content-Type'] ) ) { |
|
341 | + $r['headers']['Content-Type'] = 'application/x-www-form-urlencoded; charset=' . get_option( 'blog_charset' ); |
|
342 | + } |
|
333 | 343 | } |
334 | 344 | |
335 | - if ( '' === $r['body'] ) |
|
336 | - $r['body'] = null; |
|
345 | + if ( '' === $r['body'] ) { |
|
346 | + $r['body'] = null; |
|
347 | + } |
|
337 | 348 | |
338 | - if ( ! isset( $r['headers']['Content-Length'] ) && ! isset( $r['headers']['content-length'] ) ) |
|
339 | - $r['headers']['Content-Length'] = strlen( $r['body'] ); |
|
349 | + if ( ! isset( $r['headers']['Content-Length'] ) && ! isset( $r['headers']['content-length'] ) ) { |
|
350 | + $r['headers']['Content-Length'] = strlen( $r['body'] ); |
|
351 | + } |
|
340 | 352 | } |
341 | 353 | |
342 | 354 | $response = $this->_dispatch_request( $url, $r ); |
343 | 355 | |
344 | 356 | reset_mbstring_encoding(); |
345 | 357 | |
346 | - if ( is_wp_error( $response ) ) |
|
347 | - return $response; |
|
358 | + if ( is_wp_error( $response ) ) { |
|
359 | + return $response; |
|
360 | + } |
|
348 | 361 | |
349 | 362 | // Append cookies that were used in this request to the response |
350 | 363 | if ( ! empty( $r['cookies'] ) ) { |
@@ -393,8 +406,9 @@ discard block |
||
393 | 406 | $class = 'WP_Http_' . $transport; |
394 | 407 | |
395 | 408 | // Check to see if this transport is a possibility, calls the transport statically. |
396 | - if ( !call_user_func( array( $class, 'test' ), $args, $url ) ) |
|
397 | - continue; |
|
409 | + if ( !call_user_func( array( $class, 'test' ), $args, $url ) ) { |
|
410 | + continue; |
|
411 | + } |
|
398 | 412 | |
399 | 413 | return $class; |
400 | 414 | } |
@@ -423,12 +437,14 @@ discard block |
||
423 | 437 | static $transports = array(); |
424 | 438 | |
425 | 439 | $class = $this->_get_first_available_transport( $args, $url ); |
426 | - if ( !$class ) |
|
427 | - return new WP_Error( 'http_failure', __( 'There are no HTTP transports available which can complete the requested request.' ) ); |
|
440 | + if ( !$class ) { |
|
441 | + return new WP_Error( 'http_failure', __( 'There are no HTTP transports available which can complete the requested request.' ) ); |
|
442 | + } |
|
428 | 443 | |
429 | 444 | // Transport claims to support request, instantiate it and give it a whirl. |
430 | - if ( empty( $transports[$class] ) ) |
|
431 | - $transports[$class] = new $class; |
|
445 | + if ( empty( $transports[$class] ) ) { |
|
446 | + $transports[$class] = new $class; |
|
447 | + } |
|
432 | 448 | |
433 | 449 | $response = $transports[$class]->request( $url, $args ); |
434 | 450 | |
@@ -445,8 +461,9 @@ discard block |
||
445 | 461 | */ |
446 | 462 | do_action( 'http_api_debug', $response, 'response', $class, $args, $url ); |
447 | 463 | |
448 | - if ( is_wp_error( $response ) ) |
|
449 | - return $response; |
|
464 | + if ( is_wp_error( $response ) ) { |
|
465 | + return $response; |
|
466 | + } |
|
450 | 467 | |
451 | 468 | /** |
452 | 469 | * Filter the HTTP API response immediately before the response is returned. |
@@ -575,8 +592,9 @@ discard block |
||
575 | 592 | $cookies = array(); |
576 | 593 | $newheaders = array(); |
577 | 594 | foreach ( (array) $headers as $tempheader ) { |
578 | - if ( empty($tempheader) ) |
|
579 | - continue; |
|
595 | + if ( empty($tempheader) ) { |
|
596 | + continue; |
|
597 | + } |
|
580 | 598 | |
581 | 599 | if ( false === strpos($tempheader, ':') ) { |
582 | 600 | $stack = explode(' ', $tempheader, 3); |
@@ -591,14 +609,16 @@ discard block |
||
591 | 609 | $value = trim( $value ); |
592 | 610 | |
593 | 611 | if ( isset( $newheaders[ $key ] ) ) { |
594 | - if ( ! is_array( $newheaders[ $key ] ) ) |
|
595 | - $newheaders[$key] = array( $newheaders[ $key ] ); |
|
612 | + if ( ! is_array( $newheaders[ $key ] ) ) { |
|
613 | + $newheaders[$key] = array( $newheaders[ $key ] ); |
|
614 | + } |
|
596 | 615 | $newheaders[ $key ][] = $value; |
597 | 616 | } else { |
598 | 617 | $newheaders[ $key ] = $value; |
599 | 618 | } |
600 | - if ( 'set-cookie' == $key ) |
|
601 | - $cookies[] = new WP_Http_Cookie( $value, $url ); |
|
619 | + if ( 'set-cookie' == $key ) { |
|
620 | + $cookies[] = new WP_Http_Cookie( $value, $url ); |
|
621 | + } |
|
602 | 622 | } |
603 | 623 | |
604 | 624 | // Cast the Response Code to an int |
@@ -624,8 +644,9 @@ discard block |
||
624 | 644 | if ( ! empty($r['cookies']) ) { |
625 | 645 | // Upgrade any name => value cookie pairs to WP_HTTP_Cookie instances. |
626 | 646 | foreach ( $r['cookies'] as $name => $value ) { |
627 | - if ( ! is_object( $value ) ) |
|
628 | - $r['cookies'][ $name ] = new WP_Http_Cookie( array( 'name' => $name, 'value' => $value ) ); |
|
647 | + if ( ! is_object( $value ) ) { |
|
648 | + $r['cookies'][ $name ] = new WP_Http_Cookie( array( 'name' => $name, 'value' => $value ) ); |
|
649 | + } |
|
629 | 650 | } |
630 | 651 | |
631 | 652 | $cookies_header = ''; |
@@ -654,8 +675,9 @@ discard block |
||
654 | 675 | */ |
655 | 676 | public static function chunkTransferDecode( $body ) { |
656 | 677 | // The body is not chunked encoded or is malformed. |
657 | - if ( ! preg_match( '/^([0-9a-f]+)[^\r\n]*\r\n/i', trim( $body ) ) ) |
|
658 | - return $body; |
|
678 | + if ( ! preg_match( '/^([0-9a-f]+)[^\r\n]*\r\n/i', trim( $body ) ) ) { |
|
679 | + return $body; |
|
680 | + } |
|
659 | 681 | |
660 | 682 | $parsed_body = ''; |
661 | 683 | |
@@ -664,8 +686,9 @@ discard block |
||
664 | 686 | |
665 | 687 | while ( true ) { |
666 | 688 | $has_chunk = (bool) preg_match( '/^([0-9a-f]+)[^\r\n]*\r\n/i', $body, $match ); |
667 | - if ( ! $has_chunk || empty( $match[1] ) ) |
|
668 | - return $body_original; |
|
689 | + if ( ! $has_chunk || empty( $match[1] ) ) { |
|
690 | + return $body_original; |
|
691 | + } |
|
669 | 692 | |
670 | 693 | $length = hexdec( $match[1] ); |
671 | 694 | $chunk_length = strlen( $match[0] ); |
@@ -677,8 +700,9 @@ discard block |
||
677 | 700 | $body = substr( $body, $length + $chunk_length ); |
678 | 701 | |
679 | 702 | // End of the document. |
680 | - if ( '0' === trim( $body ) ) |
|
681 | - return $parsed_body; |
|
703 | + if ( '0' === trim( $body ) ) { |
|
704 | + return $parsed_body; |
|
705 | + } |
|
682 | 706 | } |
683 | 707 | } |
684 | 708 | |
@@ -706,12 +730,14 @@ discard block |
||
706 | 730 | */ |
707 | 731 | public function block_request($uri) { |
708 | 732 | // We don't need to block requests, because nothing is blocked. |
709 | - if ( ! defined( 'WP_HTTP_BLOCK_EXTERNAL' ) || ! WP_HTTP_BLOCK_EXTERNAL ) |
|
710 | - return false; |
|
733 | + if ( ! defined( 'WP_HTTP_BLOCK_EXTERNAL' ) || ! WP_HTTP_BLOCK_EXTERNAL ) { |
|
734 | + return false; |
|
735 | + } |
|
711 | 736 | |
712 | 737 | $check = parse_url($uri); |
713 | - if ( ! $check ) |
|
714 | - return true; |
|
738 | + if ( ! $check ) { |
|
739 | + return true; |
|
740 | + } |
|
715 | 741 | |
716 | 742 | $home = parse_url( get_option('siteurl') ); |
717 | 743 | |
@@ -728,8 +754,9 @@ discard block |
||
728 | 754 | return apply_filters( 'block_local_requests', false ); |
729 | 755 | } |
730 | 756 | |
731 | - if ( !defined('WP_ACCESSIBLE_HOSTS') ) |
|
732 | - return true; |
|
757 | + if ( !defined('WP_ACCESSIBLE_HOSTS') ) { |
|
758 | + return true; |
|
759 | + } |
|
733 | 760 | |
734 | 761 | static $accessible_hosts = null; |
735 | 762 | static $wildcard_regex = array(); |
@@ -738,16 +765,19 @@ discard block |
||
738 | 765 | |
739 | 766 | if ( false !== strpos(WP_ACCESSIBLE_HOSTS, '*') ) { |
740 | 767 | $wildcard_regex = array(); |
741 | - foreach ( $accessible_hosts as $host ) |
|
742 | - $wildcard_regex[] = str_replace( '\*', '.+', preg_quote( $host, '/' ) ); |
|
768 | + foreach ( $accessible_hosts as $host ) { |
|
769 | + $wildcard_regex[] = str_replace( '\*', '.+', preg_quote( $host, '/' ) ); |
|
770 | + } |
|
743 | 771 | $wildcard_regex = '/^(' . implode('|', $wildcard_regex) . ')$/i'; |
744 | 772 | } |
745 | 773 | } |
746 | 774 | |
747 | - if ( !empty($wildcard_regex) ) |
|
748 | - return !preg_match($wildcard_regex, $check['host']); |
|
749 | - else |
|
750 | - return !in_array( $check['host'], $accessible_hosts ); //Inverse logic, If it's in the array, then we can't access it. |
|
775 | + if ( !empty($wildcard_regex) ) { |
|
776 | + return !preg_match($wildcard_regex, $check['host']); |
|
777 | + } else { |
|
778 | + return !in_array( $check['host'], $accessible_hosts ); |
|
779 | + } |
|
780 | + //Inverse logic, If it's in the array, then we can't access it. |
|
751 | 781 | |
752 | 782 | } |
753 | 783 | |
@@ -782,8 +812,9 @@ discard block |
||
782 | 812 | * @return string An Absolute URL, in a failure condition where the URL cannot be parsed, the relative URL will be returned. |
783 | 813 | */ |
784 | 814 | public static function make_absolute_url( $maybe_relative_path, $url ) { |
785 | - if ( empty( $url ) ) |
|
786 | - return $maybe_relative_path; |
|
815 | + if ( empty( $url ) ) { |
|
816 | + return $maybe_relative_path; |
|
817 | + } |
|
787 | 818 | |
788 | 819 | if ( ! $url_parts = wp_parse_url( $url ) ) { |
789 | 820 | return $maybe_relative_path; |
@@ -803,12 +834,14 @@ discard block |
||
803 | 834 | // Schemeless URL's will make it this far, so we check for a host in the relative url and convert it to a protocol-url |
804 | 835 | if ( isset( $relative_url_parts['host'] ) ) { |
805 | 836 | $absolute_path .= $relative_url_parts['host']; |
806 | - if ( isset( $relative_url_parts['port'] ) ) |
|
807 | - $absolute_path .= ':' . $relative_url_parts['port']; |
|
837 | + if ( isset( $relative_url_parts['port'] ) ) { |
|
838 | + $absolute_path .= ':' . $relative_url_parts['port']; |
|
839 | + } |
|
808 | 840 | } else { |
809 | 841 | $absolute_path .= $url_parts['host']; |
810 | - if ( isset( $url_parts['port'] ) ) |
|
811 | - $absolute_path .= ':' . $url_parts['port']; |
|
842 | + if ( isset( $url_parts['port'] ) ) { |
|
843 | + $absolute_path .= ':' . $url_parts['port']; |
|
844 | + } |
|
812 | 845 | } |
813 | 846 | |
814 | 847 | // Start off with the Absolute URL path. |
@@ -836,8 +869,9 @@ discard block |
||
836 | 869 | } |
837 | 870 | |
838 | 871 | // Add the Query string. |
839 | - if ( ! empty( $relative_url_parts['query'] ) ) |
|
840 | - $path .= '?' . $relative_url_parts['query']; |
|
872 | + if ( ! empty( $relative_url_parts['query'] ) ) { |
|
873 | + $path .= '?' . $relative_url_parts['query']; |
|
874 | + } |
|
841 | 875 | |
842 | 876 | return $absolute_path . '/' . ltrim( $path, '/' ); |
843 | 877 | } |
@@ -856,36 +890,42 @@ discard block |
||
856 | 890 | */ |
857 | 891 | public static function handle_redirects( $url, $args, $response ) { |
858 | 892 | // If no redirects are present, or, redirects were not requested, perform no action. |
859 | - if ( ! isset( $response['headers']['location'] ) || 0 === $args['_redirection'] ) |
|
860 | - return false; |
|
893 | + if ( ! isset( $response['headers']['location'] ) || 0 === $args['_redirection'] ) { |
|
894 | + return false; |
|
895 | + } |
|
861 | 896 | |
862 | 897 | // Only perform redirections on redirection http codes. |
863 | - if ( $response['response']['code'] > 399 || $response['response']['code'] < 300 ) |
|
864 | - return false; |
|
898 | + if ( $response['response']['code'] > 399 || $response['response']['code'] < 300 ) { |
|
899 | + return false; |
|
900 | + } |
|
865 | 901 | |
866 | 902 | // Don't redirect if we've run out of redirects. |
867 | - if ( $args['redirection']-- <= 0 ) |
|
868 | - return new WP_Error( 'http_request_failed', __('Too many redirects.') ); |
|
903 | + if ( $args['redirection']-- <= 0 ) { |
|
904 | + return new WP_Error( 'http_request_failed', __('Too many redirects.') ); |
|
905 | + } |
|
869 | 906 | |
870 | 907 | $redirect_location = $response['headers']['location']; |
871 | 908 | |
872 | 909 | // If there were multiple Location headers, use the last header specified. |
873 | - if ( is_array( $redirect_location ) ) |
|
874 | - $redirect_location = array_pop( $redirect_location ); |
|
910 | + if ( is_array( $redirect_location ) ) { |
|
911 | + $redirect_location = array_pop( $redirect_location ); |
|
912 | + } |
|
875 | 913 | |
876 | 914 | $redirect_location = WP_Http::make_absolute_url( $redirect_location, $url ); |
877 | 915 | |
878 | 916 | // POST requests should not POST to a redirected location. |
879 | 917 | if ( 'POST' == $args['method'] ) { |
880 | - if ( in_array( $response['response']['code'], array( 302, 303 ) ) ) |
|
881 | - $args['method'] = 'GET'; |
|
918 | + if ( in_array( $response['response']['code'], array( 302, 303 ) ) ) { |
|
919 | + $args['method'] = 'GET'; |
|
920 | + } |
|
882 | 921 | } |
883 | 922 | |
884 | 923 | // Include valid cookies in the redirect process. |
885 | 924 | if ( ! empty( $response['cookies'] ) ) { |
886 | 925 | foreach ( $response['cookies'] as $cookie ) { |
887 | - if ( $cookie->test( $redirect_location ) ) |
|
888 | - $args['cookies'][] = $cookie; |
|
926 | + if ( $cookie->test( $redirect_location ) ) { |
|
927 | + $args['cookies'][] = $cookie; |
|
928 | + } |
|
889 | 929 | } |
890 | 930 | } |
891 | 931 | |
@@ -909,11 +949,13 @@ discard block |
||
909 | 949 | * @return integer|bool Upon success, '4' or '6' to represent a IPv4 or IPv6 address, false upon failure |
910 | 950 | */ |
911 | 951 | public static function is_ip_address( $maybe_ip ) { |
912 | - if ( preg_match( '/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $maybe_ip ) ) |
|
913 | - return 4; |
|
952 | + if ( preg_match( '/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $maybe_ip ) ) { |
|
953 | + return 4; |
|
954 | + } |
|
914 | 955 | |
915 | - if ( false !== strpos( $maybe_ip, ':' ) && preg_match( '/^(((?=.*(::))(?!.*\3.+\3))\3?|([\dA-F]{1,4}(\3|:\b|$)|\2))(?4){5}((?4){2}|(((2[0-4]|1\d|[1-9])?\d|25[0-5])\.?\b){4})$/i', trim( $maybe_ip, ' []' ) ) ) |
|
916 | - return 6; |
|
956 | + if ( false !== strpos( $maybe_ip, ':' ) && preg_match( '/^(((?=.*(::))(?!.*\3.+\3))\3?|([\dA-F]{1,4}(\3|:\b|$)|\2))(?4){5}((?4){2}|(((2[0-4]|1\d|[1-9])?\d|25[0-5])\.?\b){4})$/i', trim( $maybe_ip, ' []' ) ) ) { |
|
957 | + return 6; |
|
958 | + } |
|
917 | 959 | |
918 | 960 | return false; |
919 | 961 | } |
@@ -1004,7 +1004,7 @@ |
||
1004 | 1004 | * @global wpdb $wpdb WordPress database abstraction object. |
1005 | 1005 | * |
1006 | 1006 | * @param string $string |
1007 | - * @param array $cols |
|
1007 | + * @param string[] $cols |
|
1008 | 1008 | * @return string |
1009 | 1009 | */ |
1010 | 1010 | protected function get_search_sql( $string, $cols ) { |
@@ -1,11 +1,11 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Comment API: WP_Comment_Query class |
|
4 | - * |
|
5 | - * @package WordPress |
|
6 | - * @subpackage Comments |
|
7 | - * @since 4.4.0 |
|
8 | - */ |
|
3 | + * Comment API: WP_Comment_Query class |
|
4 | + * |
|
5 | + * @package WordPress |
|
6 | + * @subpackage Comments |
|
7 | + * @since 4.4.0 |
|
8 | + */ |
|
9 | 9 | |
10 | 10 | /** |
11 | 11 | * Core class used for querying comments. |
@@ -134,9 +134,9 @@ discard block |
||
134 | 134 | * @param array $arguments Arguments to pass when calling. |
135 | 135 | * @return mixed|false Return value of the callback, false otherwise. |
136 | 136 | */ |
137 | - public function __call( $name, $arguments ) { |
|
138 | - if ( 'get_search_sql' === $name ) { |
|
139 | - return call_user_func_array( array( $this, $name ), $arguments ); |
|
137 | + public function __call($name, $arguments) { |
|
138 | + if ('get_search_sql' === $name) { |
|
139 | + return call_user_func_array(array($this, $name), $arguments); |
|
140 | 140 | } |
141 | 141 | return false; |
142 | 142 | } |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | * Default false. |
257 | 257 | * } |
258 | 258 | */ |
259 | - public function __construct( $query = '' ) { |
|
259 | + public function __construct($query = '') { |
|
260 | 260 | $this->query_var_defaults = array( |
261 | 261 | 'author_email' => '', |
262 | 262 | 'author_url' => '', |
@@ -303,8 +303,8 @@ discard block |
||
303 | 303 | 'update_comment_post_cache' => false, |
304 | 304 | ); |
305 | 305 | |
306 | - if ( ! empty( $query ) ) { |
|
307 | - $this->query( $query ); |
|
306 | + if ( ! empty($query)) { |
|
307 | + $this->query($query); |
|
308 | 308 | } |
309 | 309 | } |
310 | 310 | |
@@ -317,13 +317,13 @@ discard block |
||
317 | 317 | * |
318 | 318 | * @param string|array $query WP_Comment_Query arguments. See WP_Comment_Query::__construct() |
319 | 319 | */ |
320 | - public function parse_query( $query = '' ) { |
|
321 | - if ( empty( $query ) ) { |
|
320 | + public function parse_query($query = '') { |
|
321 | + if (empty($query)) { |
|
322 | 322 | $query = $this->query_vars; |
323 | 323 | } |
324 | 324 | |
325 | - $this->query_vars = wp_parse_args( $query, $this->query_var_defaults ); |
|
326 | - do_action_ref_array( 'parse_comment_query', array( &$this ) ); |
|
325 | + $this->query_vars = wp_parse_args($query, $this->query_var_defaults); |
|
326 | + do_action_ref_array('parse_comment_query', array(&$this)); |
|
327 | 327 | } |
328 | 328 | |
329 | 329 | /** |
@@ -340,8 +340,8 @@ discard block |
||
340 | 340 | * @param string|array $query Array or URL query string of parameters. |
341 | 341 | * @return array|int List of comments, or number of comments when 'count' is passed as a query var. |
342 | 342 | */ |
343 | - public function query( $query ) { |
|
344 | - $this->query_vars = wp_parse_args( $query ); |
|
343 | + public function query($query) { |
|
344 | + $this->query_vars = wp_parse_args($query); |
|
345 | 345 | return $this->get_comments(); |
346 | 346 | } |
347 | 347 | |
@@ -362,7 +362,7 @@ discard block |
||
362 | 362 | |
363 | 363 | // Parse meta query |
364 | 364 | $this->meta_query = new WP_Meta_Query(); |
365 | - $this->meta_query->parse_query_vars( $this->query_vars ); |
|
365 | + $this->meta_query->parse_query_vars($this->query_vars); |
|
366 | 366 | |
367 | 367 | /** |
368 | 368 | * Fires before comments are retrieved. |
@@ -371,40 +371,40 @@ discard block |
||
371 | 371 | * |
372 | 372 | * @param WP_Comment_Query &$this Current instance of WP_Comment_Query, passed by reference. |
373 | 373 | */ |
374 | - do_action_ref_array( 'pre_get_comments', array( &$this ) ); |
|
374 | + do_action_ref_array('pre_get_comments', array(&$this)); |
|
375 | 375 | |
376 | 376 | // Reparse query vars, in case they were modified in a 'pre_get_comments' callback. |
377 | - $this->meta_query->parse_query_vars( $this->query_vars ); |
|
378 | - if ( ! empty( $this->meta_query->queries ) ) { |
|
379 | - $this->meta_query_clauses = $this->meta_query->get_sql( 'comment', $wpdb->comments, 'comment_ID', $this ); |
|
377 | + $this->meta_query->parse_query_vars($this->query_vars); |
|
378 | + if ( ! empty($this->meta_query->queries)) { |
|
379 | + $this->meta_query_clauses = $this->meta_query->get_sql('comment', $wpdb->comments, 'comment_ID', $this); |
|
380 | 380 | } |
381 | 381 | |
382 | 382 | // $args can include anything. Only use the args defined in the query_var_defaults to compute the key. |
383 | - $key = md5( serialize( wp_array_slice_assoc( $this->query_vars, array_keys( $this->query_var_defaults ) ) ) ); |
|
384 | - $last_changed = wp_cache_get( 'last_changed', 'comment' ); |
|
385 | - if ( ! $last_changed ) { |
|
383 | + $key = md5(serialize(wp_array_slice_assoc($this->query_vars, array_keys($this->query_var_defaults)))); |
|
384 | + $last_changed = wp_cache_get('last_changed', 'comment'); |
|
385 | + if ( ! $last_changed) { |
|
386 | 386 | $last_changed = microtime(); |
387 | - wp_cache_set( 'last_changed', $last_changed, 'comment' ); |
|
387 | + wp_cache_set('last_changed', $last_changed, 'comment'); |
|
388 | 388 | } |
389 | 389 | $cache_key = "get_comment_ids:$key:$last_changed"; |
390 | 390 | |
391 | - $comment_ids = wp_cache_get( $cache_key, 'comment' ); |
|
392 | - if ( false === $comment_ids ) { |
|
391 | + $comment_ids = wp_cache_get($cache_key, 'comment'); |
|
392 | + if (false === $comment_ids) { |
|
393 | 393 | $comment_ids = $this->get_comment_ids(); |
394 | - wp_cache_add( $cache_key, $comment_ids, 'comment' ); |
|
394 | + wp_cache_add($cache_key, $comment_ids, 'comment'); |
|
395 | 395 | } |
396 | 396 | |
397 | 397 | // If querying for a count only, there's nothing more to do. |
398 | - if ( $this->query_vars['count'] ) { |
|
398 | + if ($this->query_vars['count']) { |
|
399 | 399 | // $comment_ids is actually a count in this case. |
400 | - return intval( $comment_ids ); |
|
400 | + return intval($comment_ids); |
|
401 | 401 | } |
402 | 402 | |
403 | - $comment_ids = array_map( 'intval', $comment_ids ); |
|
403 | + $comment_ids = array_map('intval', $comment_ids); |
|
404 | 404 | |
405 | - $this->comment_count = count( $this->comments ); |
|
405 | + $this->comment_count = count($this->comments); |
|
406 | 406 | |
407 | - if ( $comment_ids && $this->query_vars['number'] && ! $this->query_vars['no_found_rows'] ) { |
|
407 | + if ($comment_ids && $this->query_vars['number'] && ! $this->query_vars['no_found_rows']) { |
|
408 | 408 | /** |
409 | 409 | * Filter the query used to retrieve found comment count. |
410 | 410 | * |
@@ -413,35 +413,35 @@ discard block |
||
413 | 413 | * @param string $found_comments_query SQL query. Default 'SELECT FOUND_ROWS()'. |
414 | 414 | * @param WP_Comment_Query $comment_query The `WP_Comment_Query` instance. |
415 | 415 | */ |
416 | - $found_comments_query = apply_filters( 'found_comments_query', 'SELECT FOUND_ROWS()', $this ); |
|
417 | - $this->found_comments = (int) $wpdb->get_var( $found_comments_query ); |
|
416 | + $found_comments_query = apply_filters('found_comments_query', 'SELECT FOUND_ROWS()', $this); |
|
417 | + $this->found_comments = (int) $wpdb->get_var($found_comments_query); |
|
418 | 418 | |
419 | - $this->max_num_pages = ceil( $this->found_comments / $this->query_vars['number'] ); |
|
419 | + $this->max_num_pages = ceil($this->found_comments / $this->query_vars['number']); |
|
420 | 420 | } |
421 | 421 | |
422 | - if ( 'ids' == $this->query_vars['fields'] ) { |
|
422 | + if ('ids' == $this->query_vars['fields']) { |
|
423 | 423 | $this->comments = $comment_ids; |
424 | 424 | return $this->comments; |
425 | 425 | } |
426 | 426 | |
427 | - _prime_comment_caches( $comment_ids, $this->query_vars['update_comment_meta_cache'] ); |
|
427 | + _prime_comment_caches($comment_ids, $this->query_vars['update_comment_meta_cache']); |
|
428 | 428 | |
429 | 429 | // Fetch full comment objects from the primed cache. |
430 | 430 | $_comments = array(); |
431 | - foreach ( $comment_ids as $comment_id ) { |
|
432 | - if ( $_comment = get_comment( $comment_id ) ) { |
|
431 | + foreach ($comment_ids as $comment_id) { |
|
432 | + if ($_comment = get_comment($comment_id)) { |
|
433 | 433 | $_comments[] = $_comment; |
434 | 434 | } |
435 | 435 | } |
436 | 436 | |
437 | 437 | // Prime comment post caches. |
438 | - if ( $this->query_vars['update_comment_post_cache'] ) { |
|
438 | + if ($this->query_vars['update_comment_post_cache']) { |
|
439 | 439 | $comment_post_ids = array(); |
440 | - foreach ( $_comments as $_comment ) { |
|
440 | + foreach ($_comments as $_comment) { |
|
441 | 441 | $comment_post_ids[] = $_comment->comment_post_ID; |
442 | 442 | } |
443 | 443 | |
444 | - _prime_post_caches( $comment_post_ids, false, false ); |
|
444 | + _prime_post_caches($comment_post_ids, false, false); |
|
445 | 445 | } |
446 | 446 | |
447 | 447 | /** |
@@ -452,13 +452,13 @@ discard block |
||
452 | 452 | * @param array $results An array of comments. |
453 | 453 | * @param WP_Comment_Query &$this Current instance of WP_Comment_Query, passed by reference. |
454 | 454 | */ |
455 | - $_comments = apply_filters_ref_array( 'the_comments', array( $_comments, &$this ) ); |
|
455 | + $_comments = apply_filters_ref_array('the_comments', array($_comments, &$this)); |
|
456 | 456 | |
457 | 457 | // Convert to WP_Comment instances |
458 | - $comments = array_map( 'get_comment', $_comments ); |
|
458 | + $comments = array_map('get_comment', $_comments); |
|
459 | 459 | |
460 | - if ( $this->query_vars['hierarchical'] ) { |
|
461 | - $comments = $this->fill_descendants( $comments ); |
|
460 | + if ($this->query_vars['hierarchical']) { |
|
461 | + $comments = $this->fill_descendants($comments); |
|
462 | 462 | } |
463 | 463 | |
464 | 464 | $this->comments = $comments; |
@@ -482,14 +482,14 @@ discard block |
||
482 | 482 | // 'status' accepts an array or a comma-separated string. |
483 | 483 | $status_clauses = array(); |
484 | 484 | $statuses = $this->query_vars['status']; |
485 | - if ( ! is_array( $statuses ) ) { |
|
486 | - $statuses = preg_split( '/[\s,]+/', $statuses ); |
|
485 | + if ( ! is_array($statuses)) { |
|
486 | + $statuses = preg_split('/[\s,]+/', $statuses); |
|
487 | 487 | } |
488 | 488 | |
489 | 489 | // 'any' overrides other statuses. |
490 | - if ( ! in_array( 'any', $statuses ) ) { |
|
491 | - foreach ( $statuses as $status ) { |
|
492 | - switch ( $status ) { |
|
490 | + if ( ! in_array('any', $statuses)) { |
|
491 | + foreach ($statuses as $status) { |
|
492 | + switch ($status) { |
|
493 | 493 | case 'hold' : |
494 | 494 | $status_clauses[] = "comment_approved = '0'"; |
495 | 495 | break; |
@@ -504,65 +504,64 @@ discard block |
||
504 | 504 | break; |
505 | 505 | |
506 | 506 | default : |
507 | - $status_clauses[] = $wpdb->prepare( "comment_approved = %s", $status ); |
|
507 | + $status_clauses[] = $wpdb->prepare("comment_approved = %s", $status); |
|
508 | 508 | break; |
509 | 509 | } |
510 | 510 | } |
511 | 511 | |
512 | - if ( ! empty( $status_clauses ) ) { |
|
513 | - $approved_clauses[] = '( ' . implode( ' OR ', $status_clauses ) . ' )'; |
|
512 | + if ( ! empty($status_clauses)) { |
|
513 | + $approved_clauses[] = '( '.implode(' OR ', $status_clauses).' )'; |
|
514 | 514 | } |
515 | 515 | } |
516 | 516 | |
517 | 517 | // User IDs or emails whose unapproved comments are included, regardless of $status. |
518 | - if ( ! empty( $this->query_vars['include_unapproved'] ) ) { |
|
518 | + if ( ! empty($this->query_vars['include_unapproved'])) { |
|
519 | 519 | $include_unapproved = $this->query_vars['include_unapproved']; |
520 | 520 | |
521 | 521 | // Accepts arrays or comma-separated strings. |
522 | - if ( ! is_array( $include_unapproved ) ) { |
|
523 | - $include_unapproved = preg_split( '/[\s,]+/', $include_unapproved ); |
|
522 | + if ( ! is_array($include_unapproved)) { |
|
523 | + $include_unapproved = preg_split('/[\s,]+/', $include_unapproved); |
|
524 | 524 | } |
525 | 525 | |
526 | 526 | $unapproved_ids = $unapproved_emails = array(); |
527 | - foreach ( $include_unapproved as $unapproved_identifier ) { |
|
527 | + foreach ($include_unapproved as $unapproved_identifier) { |
|
528 | 528 | // Numeric values are assumed to be user ids. |
529 | - if ( is_numeric( $unapproved_identifier ) ) { |
|
530 | - $approved_clauses[] = $wpdb->prepare( "( user_id = %d AND comment_approved = '0' )", $unapproved_identifier ); |
|
529 | + if (is_numeric($unapproved_identifier)) { |
|
530 | + $approved_clauses[] = $wpdb->prepare("( user_id = %d AND comment_approved = '0' )", $unapproved_identifier); |
|
531 | 531 | |
532 | 532 | // Otherwise we match against email addresses. |
533 | 533 | } else { |
534 | - $approved_clauses[] = $wpdb->prepare( "( comment_author_email = %s AND comment_approved = '0' )", $unapproved_identifier ); |
|
534 | + $approved_clauses[] = $wpdb->prepare("( comment_author_email = %s AND comment_approved = '0' )", $unapproved_identifier); |
|
535 | 535 | } |
536 | 536 | } |
537 | 537 | } |
538 | 538 | |
539 | 539 | // Collapse comment_approved clauses into a single OR-separated clause. |
540 | - if ( ! empty( $approved_clauses ) ) { |
|
541 | - if ( 1 === count( $approved_clauses ) ) { |
|
540 | + if ( ! empty($approved_clauses)) { |
|
541 | + if (1 === count($approved_clauses)) { |
|
542 | 542 | $this->sql_clauses['where']['approved'] = $approved_clauses[0]; |
543 | 543 | } else { |
544 | - $this->sql_clauses['where']['approved'] = '( ' . implode( ' OR ', $approved_clauses ) . ' )'; |
|
544 | + $this->sql_clauses['where']['approved'] = '( '.implode(' OR ', $approved_clauses).' )'; |
|
545 | 545 | } |
546 | 546 | } |
547 | 547 | |
548 | - $order = ( 'ASC' == strtoupper( $this->query_vars['order'] ) ) ? 'ASC' : 'DESC'; |
|
548 | + $order = ('ASC' == strtoupper($this->query_vars['order'])) ? 'ASC' : 'DESC'; |
|
549 | 549 | |
550 | 550 | // Disable ORDER BY with 'none', an empty array, or boolean false. |
551 | - if ( in_array( $this->query_vars['orderby'], array( 'none', array(), false ), true ) ) { |
|
551 | + if (in_array($this->query_vars['orderby'], array('none', array(), false), true)) { |
|
552 | 552 | $orderby = ''; |
553 | - } elseif ( ! empty( $this->query_vars['orderby'] ) ) { |
|
554 | - $ordersby = is_array( $this->query_vars['orderby'] ) ? |
|
555 | - $this->query_vars['orderby'] : |
|
556 | - preg_split( '/[,\s]/', $this->query_vars['orderby'] ); |
|
553 | + } elseif ( ! empty($this->query_vars['orderby'])) { |
|
554 | + $ordersby = is_array($this->query_vars['orderby']) ? |
|
555 | + $this->query_vars['orderby'] : preg_split('/[,\s]/', $this->query_vars['orderby']); |
|
557 | 556 | |
558 | 557 | $orderby_array = array(); |
559 | 558 | $found_orderby_comment_ID = false; |
560 | - foreach ( $ordersby as $_key => $_value ) { |
|
561 | - if ( ! $_value ) { |
|
559 | + foreach ($ordersby as $_key => $_value) { |
|
560 | + if ( ! $_value) { |
|
562 | 561 | continue; |
563 | 562 | } |
564 | 563 | |
565 | - if ( is_int( $_key ) ) { |
|
564 | + if (is_int($_key)) { |
|
566 | 565 | $_orderby = $_value; |
567 | 566 | $_order = $order; |
568 | 567 | } else { |
@@ -570,45 +569,45 @@ discard block |
||
570 | 569 | $_order = $_value; |
571 | 570 | } |
572 | 571 | |
573 | - if ( ! $found_orderby_comment_ID && in_array( $_orderby, array( 'comment_ID', 'comment__in' ) ) ) { |
|
572 | + if ( ! $found_orderby_comment_ID && in_array($_orderby, array('comment_ID', 'comment__in'))) { |
|
574 | 573 | $found_orderby_comment_ID = true; |
575 | 574 | } |
576 | 575 | |
577 | - $parsed = $this->parse_orderby( $_orderby ); |
|
576 | + $parsed = $this->parse_orderby($_orderby); |
|
578 | 577 | |
579 | - if ( ! $parsed ) { |
|
578 | + if ( ! $parsed) { |
|
580 | 579 | continue; |
581 | 580 | } |
582 | 581 | |
583 | - if ( 'comment__in' === $_orderby ) { |
|
582 | + if ('comment__in' === $_orderby) { |
|
584 | 583 | $orderby_array[] = $parsed; |
585 | 584 | continue; |
586 | 585 | } |
587 | 586 | |
588 | - $orderby_array[] = $parsed . ' ' . $this->parse_order( $_order ); |
|
587 | + $orderby_array[] = $parsed.' '.$this->parse_order($_order); |
|
589 | 588 | } |
590 | 589 | |
591 | 590 | // If no valid clauses were found, order by comment_date_gmt. |
592 | - if ( empty( $orderby_array ) ) { |
|
591 | + if (empty($orderby_array)) { |
|
593 | 592 | $orderby_array[] = "$wpdb->comments.comment_date_gmt $order"; |
594 | 593 | } |
595 | 594 | |
596 | 595 | // To ensure determinate sorting, always include a comment_ID clause. |
597 | - if ( ! $found_orderby_comment_ID ) { |
|
596 | + if ( ! $found_orderby_comment_ID) { |
|
598 | 597 | $comment_ID_order = ''; |
599 | 598 | |
600 | 599 | // Inherit order from comment_date or comment_date_gmt, if available. |
601 | - foreach ( $orderby_array as $orderby_clause ) { |
|
602 | - if ( preg_match( '/comment_date(?:_gmt)*\ (ASC|DESC)/', $orderby_clause, $match ) ) { |
|
600 | + foreach ($orderby_array as $orderby_clause) { |
|
601 | + if (preg_match('/comment_date(?:_gmt)*\ (ASC|DESC)/', $orderby_clause, $match)) { |
|
603 | 602 | $comment_ID_order = $match[1]; |
604 | 603 | break; |
605 | 604 | } |
606 | 605 | } |
607 | 606 | |
608 | 607 | // If no date-related order is available, use the date from the first available clause. |
609 | - if ( ! $comment_ID_order ) { |
|
610 | - foreach ( $orderby_array as $orderby_clause ) { |
|
611 | - if ( false !== strpos( 'ASC', $orderby_clause ) ) { |
|
608 | + if ( ! $comment_ID_order) { |
|
609 | + foreach ($orderby_array as $orderby_clause) { |
|
610 | + if (false !== strpos('ASC', $orderby_clause)) { |
|
612 | 611 | $comment_ID_order = 'ASC'; |
613 | 612 | } else { |
614 | 613 | $comment_ID_order = 'DESC'; |
@@ -619,94 +618,94 @@ discard block |
||
619 | 618 | } |
620 | 619 | |
621 | 620 | // Default to DESC. |
622 | - if ( ! $comment_ID_order ) { |
|
621 | + if ( ! $comment_ID_order) { |
|
623 | 622 | $comment_ID_order = 'DESC'; |
624 | 623 | } |
625 | 624 | |
626 | 625 | $orderby_array[] = "$wpdb->comments.comment_ID $comment_ID_order"; |
627 | 626 | } |
628 | 627 | |
629 | - $orderby = implode( ', ', $orderby_array ); |
|
628 | + $orderby = implode(', ', $orderby_array); |
|
630 | 629 | } else { |
631 | 630 | $orderby = "$wpdb->comments.comment_date_gmt $order"; |
632 | 631 | } |
633 | 632 | |
634 | - $number = absint( $this->query_vars['number'] ); |
|
635 | - $offset = absint( $this->query_vars['offset'] ); |
|
633 | + $number = absint($this->query_vars['number']); |
|
634 | + $offset = absint($this->query_vars['offset']); |
|
636 | 635 | |
637 | - if ( ! empty( $number ) ) { |
|
638 | - if ( $offset ) { |
|
639 | - $limits = 'LIMIT ' . $offset . ',' . $number; |
|
636 | + if ( ! empty($number)) { |
|
637 | + if ($offset) { |
|
638 | + $limits = 'LIMIT '.$offset.','.$number; |
|
640 | 639 | } else { |
641 | - $limits = 'LIMIT ' . $number; |
|
640 | + $limits = 'LIMIT '.$number; |
|
642 | 641 | } |
643 | 642 | } |
644 | 643 | |
645 | - if ( $this->query_vars['count'] ) { |
|
644 | + if ($this->query_vars['count']) { |
|
646 | 645 | $fields = 'COUNT(*)'; |
647 | 646 | } else { |
648 | 647 | $fields = "$wpdb->comments.comment_ID"; |
649 | 648 | } |
650 | 649 | |
651 | - $post_id = absint( $this->query_vars['post_id'] ); |
|
652 | - if ( ! empty( $post_id ) ) { |
|
653 | - $this->sql_clauses['where']['post_id'] = $wpdb->prepare( 'comment_post_ID = %d', $post_id ); |
|
650 | + $post_id = absint($this->query_vars['post_id']); |
|
651 | + if ( ! empty($post_id)) { |
|
652 | + $this->sql_clauses['where']['post_id'] = $wpdb->prepare('comment_post_ID = %d', $post_id); |
|
654 | 653 | } |
655 | 654 | |
656 | 655 | // Parse comment IDs for an IN clause. |
657 | - if ( ! empty( $this->query_vars['comment__in'] ) ) { |
|
658 | - $this->sql_clauses['where']['comment__in'] = "$wpdb->comments.comment_ID IN ( " . implode( ',', wp_parse_id_list( $this->query_vars['comment__in'] ) ) . ' )'; |
|
656 | + if ( ! empty($this->query_vars['comment__in'])) { |
|
657 | + $this->sql_clauses['where']['comment__in'] = "$wpdb->comments.comment_ID IN ( ".implode(',', wp_parse_id_list($this->query_vars['comment__in'])).' )'; |
|
659 | 658 | } |
660 | 659 | |
661 | 660 | // Parse comment IDs for a NOT IN clause. |
662 | - if ( ! empty( $this->query_vars['comment__not_in'] ) ) { |
|
663 | - $this->sql_clauses['where']['comment__not_in'] = "$wpdb->comments.comment_ID NOT IN ( " . implode( ',', wp_parse_id_list( $this->query_vars['comment__not_in'] ) ) . ' )'; |
|
661 | + if ( ! empty($this->query_vars['comment__not_in'])) { |
|
662 | + $this->sql_clauses['where']['comment__not_in'] = "$wpdb->comments.comment_ID NOT IN ( ".implode(',', wp_parse_id_list($this->query_vars['comment__not_in'])).' )'; |
|
664 | 663 | } |
665 | 664 | |
666 | 665 | // Parse comment parent IDs for an IN clause. |
667 | - if ( ! empty( $this->query_vars['parent__in'] ) ) { |
|
668 | - $this->sql_clauses['where']['parent__in'] = 'comment_parent IN ( ' . implode( ',', wp_parse_id_list( $this->query_vars['parent__in'] ) ) . ' )'; |
|
666 | + if ( ! empty($this->query_vars['parent__in'])) { |
|
667 | + $this->sql_clauses['where']['parent__in'] = 'comment_parent IN ( '.implode(',', wp_parse_id_list($this->query_vars['parent__in'])).' )'; |
|
669 | 668 | } |
670 | 669 | |
671 | 670 | // Parse comment parent IDs for a NOT IN clause. |
672 | - if ( ! empty( $this->query_vars['parent__not_in'] ) ) { |
|
673 | - $this->sql_clauses['where']['parent__not_in'] = 'comment_parent NOT IN ( ' . implode( ',', wp_parse_id_list( $this->query_vars['parent__not_in'] ) ) . ' )'; |
|
671 | + if ( ! empty($this->query_vars['parent__not_in'])) { |
|
672 | + $this->sql_clauses['where']['parent__not_in'] = 'comment_parent NOT IN ( '.implode(',', wp_parse_id_list($this->query_vars['parent__not_in'])).' )'; |
|
674 | 673 | } |
675 | 674 | |
676 | 675 | // Parse comment post IDs for an IN clause. |
677 | - if ( ! empty( $this->query_vars['post__in'] ) ) { |
|
678 | - $this->sql_clauses['where']['post__in'] = 'comment_post_ID IN ( ' . implode( ',', wp_parse_id_list( $this->query_vars['post__in'] ) ) . ' )'; |
|
676 | + if ( ! empty($this->query_vars['post__in'])) { |
|
677 | + $this->sql_clauses['where']['post__in'] = 'comment_post_ID IN ( '.implode(',', wp_parse_id_list($this->query_vars['post__in'])).' )'; |
|
679 | 678 | } |
680 | 679 | |
681 | 680 | // Parse comment post IDs for a NOT IN clause. |
682 | - if ( ! empty( $this->query_vars['post__not_in'] ) ) { |
|
683 | - $this->sql_clauses['where']['post__not_in'] = 'comment_post_ID NOT IN ( ' . implode( ',', wp_parse_id_list( $this->query_vars['post__not_in'] ) ) . ' )'; |
|
681 | + if ( ! empty($this->query_vars['post__not_in'])) { |
|
682 | + $this->sql_clauses['where']['post__not_in'] = 'comment_post_ID NOT IN ( '.implode(',', wp_parse_id_list($this->query_vars['post__not_in'])).' )'; |
|
684 | 683 | } |
685 | 684 | |
686 | - if ( '' !== $this->query_vars['author_email'] ) { |
|
687 | - $this->sql_clauses['where']['author_email'] = $wpdb->prepare( 'comment_author_email = %s', $this->query_vars['author_email'] ); |
|
685 | + if ('' !== $this->query_vars['author_email']) { |
|
686 | + $this->sql_clauses['where']['author_email'] = $wpdb->prepare('comment_author_email = %s', $this->query_vars['author_email']); |
|
688 | 687 | } |
689 | 688 | |
690 | - if ( '' !== $this->query_vars['author_url'] ) { |
|
691 | - $this->sql_clauses['where']['author_url'] = $wpdb->prepare( 'comment_author_url = %s', $this->query_vars['author_url'] ); |
|
689 | + if ('' !== $this->query_vars['author_url']) { |
|
690 | + $this->sql_clauses['where']['author_url'] = $wpdb->prepare('comment_author_url = %s', $this->query_vars['author_url']); |
|
692 | 691 | } |
693 | 692 | |
694 | - if ( '' !== $this->query_vars['karma'] ) { |
|
695 | - $this->sql_clauses['where']['karma'] = $wpdb->prepare( 'comment_karma = %d', $this->query_vars['karma'] ); |
|
693 | + if ('' !== $this->query_vars['karma']) { |
|
694 | + $this->sql_clauses['where']['karma'] = $wpdb->prepare('comment_karma = %d', $this->query_vars['karma']); |
|
696 | 695 | } |
697 | 696 | |
698 | 697 | // Filtering by comment_type: 'type', 'type__in', 'type__not_in'. |
699 | 698 | $raw_types = array( |
700 | - 'IN' => array_merge( (array) $this->query_vars['type'], (array) $this->query_vars['type__in'] ), |
|
699 | + 'IN' => array_merge((array) $this->query_vars['type'], (array) $this->query_vars['type__in']), |
|
701 | 700 | 'NOT IN' => (array) $this->query_vars['type__not_in'], |
702 | 701 | ); |
703 | 702 | |
704 | 703 | $comment_types = array(); |
705 | - foreach ( $raw_types as $operator => $_raw_types ) { |
|
706 | - $_raw_types = array_unique( $_raw_types ); |
|
704 | + foreach ($raw_types as $operator => $_raw_types) { |
|
705 | + $_raw_types = array_unique($_raw_types); |
|
707 | 706 | |
708 | - foreach ( $_raw_types as $type ) { |
|
709 | - switch ( $type ) { |
|
707 | + foreach ($_raw_types as $type) { |
|
708 | + switch ($type) { |
|
710 | 709 | // An empty translates to 'all', for backward compatibility |
711 | 710 | case '': |
712 | 711 | case 'all' : |
@@ -714,134 +713,134 @@ discard block |
||
714 | 713 | |
715 | 714 | case 'comment': |
716 | 715 | case 'comments': |
717 | - $comment_types[ $operator ][] = "''"; |
|
716 | + $comment_types[$operator][] = "''"; |
|
718 | 717 | break; |
719 | 718 | |
720 | 719 | case 'pings': |
721 | - $comment_types[ $operator ][] = "'pingback'"; |
|
722 | - $comment_types[ $operator ][] = "'trackback'"; |
|
720 | + $comment_types[$operator][] = "'pingback'"; |
|
721 | + $comment_types[$operator][] = "'trackback'"; |
|
723 | 722 | break; |
724 | 723 | |
725 | 724 | default: |
726 | - $comment_types[ $operator ][] = $wpdb->prepare( '%s', $type ); |
|
725 | + $comment_types[$operator][] = $wpdb->prepare('%s', $type); |
|
727 | 726 | break; |
728 | 727 | } |
729 | 728 | } |
730 | 729 | |
731 | - if ( ! empty( $comment_types[ $operator ] ) ) { |
|
732 | - $types_sql = implode( ', ', $comment_types[ $operator ] ); |
|
733 | - $this->sql_clauses['where']['comment_type__' . strtolower( str_replace( ' ', '_', $operator ) ) ] = "comment_type $operator ($types_sql)"; |
|
730 | + if ( ! empty($comment_types[$operator])) { |
|
731 | + $types_sql = implode(', ', $comment_types[$operator]); |
|
732 | + $this->sql_clauses['where']['comment_type__'.strtolower(str_replace(' ', '_', $operator))] = "comment_type $operator ($types_sql)"; |
|
734 | 733 | } |
735 | 734 | } |
736 | 735 | |
737 | - if ( $this->query_vars['hierarchical'] && ! $this->query_vars['parent'] ) { |
|
736 | + if ($this->query_vars['hierarchical'] && ! $this->query_vars['parent']) { |
|
738 | 737 | $this->query_vars['parent'] = 0; |
739 | 738 | } |
740 | 739 | |
741 | - if ( '' !== $this->query_vars['parent'] ) { |
|
742 | - $this->sql_clauses['where']['parent'] = $wpdb->prepare( 'comment_parent = %d', $this->query_vars['parent'] ); |
|
740 | + if ('' !== $this->query_vars['parent']) { |
|
741 | + $this->sql_clauses['where']['parent'] = $wpdb->prepare('comment_parent = %d', $this->query_vars['parent']); |
|
743 | 742 | } |
744 | 743 | |
745 | - if ( is_array( $this->query_vars['user_id'] ) ) { |
|
746 | - $this->sql_clauses['where']['user_id'] = 'user_id IN (' . implode( ',', array_map( 'absint', $this->query_vars['user_id'] ) ) . ')'; |
|
747 | - } elseif ( '' !== $this->query_vars['user_id'] ) { |
|
748 | - $this->sql_clauses['where']['user_id'] = $wpdb->prepare( 'user_id = %d', $this->query_vars['user_id'] ); |
|
744 | + if (is_array($this->query_vars['user_id'])) { |
|
745 | + $this->sql_clauses['where']['user_id'] = 'user_id IN ('.implode(',', array_map('absint', $this->query_vars['user_id'])).')'; |
|
746 | + } elseif ('' !== $this->query_vars['user_id']) { |
|
747 | + $this->sql_clauses['where']['user_id'] = $wpdb->prepare('user_id = %d', $this->query_vars['user_id']); |
|
749 | 748 | } |
750 | 749 | |
751 | 750 | // Falsy search strings are ignored. |
752 | - if ( strlen( $this->query_vars['search'] ) ) { |
|
751 | + if (strlen($this->query_vars['search'])) { |
|
753 | 752 | $search_sql = $this->get_search_sql( |
754 | 753 | $this->query_vars['search'], |
755 | - array( 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_author_IP', 'comment_content' ) |
|
754 | + array('comment_author', 'comment_author_email', 'comment_author_url', 'comment_author_IP', 'comment_content') |
|
756 | 755 | ); |
757 | 756 | |
758 | 757 | // Strip leading 'AND'. |
759 | - $this->sql_clauses['where']['search'] = preg_replace( '/^\s*AND\s*/', '', $search_sql ); |
|
758 | + $this->sql_clauses['where']['search'] = preg_replace('/^\s*AND\s*/', '', $search_sql); |
|
760 | 759 | } |
761 | 760 | |
762 | 761 | // If any post-related query vars are passed, join the posts table. |
763 | 762 | $join_posts_table = false; |
764 | - $plucked = wp_array_slice_assoc( $this->query_vars, array( 'post_author', 'post_name', 'post_parent' ) ); |
|
765 | - $post_fields = array_filter( $plucked ); |
|
763 | + $plucked = wp_array_slice_assoc($this->query_vars, array('post_author', 'post_name', 'post_parent')); |
|
764 | + $post_fields = array_filter($plucked); |
|
766 | 765 | |
767 | - if ( ! empty( $post_fields ) ) { |
|
766 | + if ( ! empty($post_fields)) { |
|
768 | 767 | $join_posts_table = true; |
769 | - foreach ( $post_fields as $field_name => $field_value ) { |
|
768 | + foreach ($post_fields as $field_name => $field_value) { |
|
770 | 769 | // $field_value may be an array. |
771 | - $esses = array_fill( 0, count( (array) $field_value ), '%s' ); |
|
772 | - $this->sql_clauses['where'][ $field_name ] = $wpdb->prepare( " {$wpdb->posts}.{$field_name} IN (" . implode( ',', $esses ) . ')', $field_value ); |
|
770 | + $esses = array_fill(0, count((array) $field_value), '%s'); |
|
771 | + $this->sql_clauses['where'][$field_name] = $wpdb->prepare(" {$wpdb->posts}.{$field_name} IN (".implode(',', $esses).')', $field_value); |
|
773 | 772 | } |
774 | 773 | } |
775 | 774 | |
776 | 775 | // 'post_status' and 'post_type' are handled separately, due to the specialized behavior of 'any'. |
777 | - foreach ( array( 'post_status', 'post_type' ) as $field_name ) { |
|
776 | + foreach (array('post_status', 'post_type') as $field_name) { |
|
778 | 777 | $q_values = array(); |
779 | - if ( ! empty( $this->query_vars[ $field_name ] ) ) { |
|
780 | - $q_values = $this->query_vars[ $field_name ]; |
|
781 | - if ( ! is_array( $q_values ) ) { |
|
782 | - $q_values = explode( ',', $q_values ); |
|
778 | + if ( ! empty($this->query_vars[$field_name])) { |
|
779 | + $q_values = $this->query_vars[$field_name]; |
|
780 | + if ( ! is_array($q_values)) { |
|
781 | + $q_values = explode(',', $q_values); |
|
783 | 782 | } |
784 | 783 | |
785 | 784 | // 'any' will cause the query var to be ignored. |
786 | - if ( in_array( 'any', $q_values, true ) || empty( $q_values ) ) { |
|
785 | + if (in_array('any', $q_values, true) || empty($q_values)) { |
|
787 | 786 | continue; |
788 | 787 | } |
789 | 788 | |
790 | 789 | $join_posts_table = true; |
791 | 790 | |
792 | - $esses = array_fill( 0, count( $q_values ), '%s' ); |
|
793 | - $this->sql_clauses['where'][ $field_name ] = $wpdb->prepare( " {$wpdb->posts}.{$field_name} IN (" . implode( ',', $esses ) . ")", $q_values ); |
|
791 | + $esses = array_fill(0, count($q_values), '%s'); |
|
792 | + $this->sql_clauses['where'][$field_name] = $wpdb->prepare(" {$wpdb->posts}.{$field_name} IN (".implode(',', $esses).")", $q_values); |
|
794 | 793 | } |
795 | 794 | } |
796 | 795 | |
797 | 796 | // Comment author IDs for an IN clause. |
798 | - if ( ! empty( $this->query_vars['author__in'] ) ) { |
|
799 | - $this->sql_clauses['where']['author__in'] = 'user_id IN ( ' . implode( ',', wp_parse_id_list( $this->query_vars['author__in'] ) ) . ' )'; |
|
797 | + if ( ! empty($this->query_vars['author__in'])) { |
|
798 | + $this->sql_clauses['where']['author__in'] = 'user_id IN ( '.implode(',', wp_parse_id_list($this->query_vars['author__in'])).' )'; |
|
800 | 799 | } |
801 | 800 | |
802 | 801 | // Comment author IDs for a NOT IN clause. |
803 | - if ( ! empty( $this->query_vars['author__not_in'] ) ) { |
|
804 | - $this->sql_clauses['where']['author__not_in'] = 'user_id NOT IN ( ' . implode( ',', wp_parse_id_list( $this->query_vars['author__not_in'] ) ) . ' )'; |
|
802 | + if ( ! empty($this->query_vars['author__not_in'])) { |
|
803 | + $this->sql_clauses['where']['author__not_in'] = 'user_id NOT IN ( '.implode(',', wp_parse_id_list($this->query_vars['author__not_in'])).' )'; |
|
805 | 804 | } |
806 | 805 | |
807 | 806 | // Post author IDs for an IN clause. |
808 | - if ( ! empty( $this->query_vars['post_author__in'] ) ) { |
|
807 | + if ( ! empty($this->query_vars['post_author__in'])) { |
|
809 | 808 | $join_posts_table = true; |
810 | - $this->sql_clauses['where']['post_author__in'] = 'post_author IN ( ' . implode( ',', wp_parse_id_list( $this->query_vars['post_author__in'] ) ) . ' )'; |
|
809 | + $this->sql_clauses['where']['post_author__in'] = 'post_author IN ( '.implode(',', wp_parse_id_list($this->query_vars['post_author__in'])).' )'; |
|
811 | 810 | } |
812 | 811 | |
813 | 812 | // Post author IDs for a NOT IN clause. |
814 | - if ( ! empty( $this->query_vars['post_author__not_in'] ) ) { |
|
813 | + if ( ! empty($this->query_vars['post_author__not_in'])) { |
|
815 | 814 | $join_posts_table = true; |
816 | - $this->sql_clauses['where']['post_author__not_in'] = 'post_author NOT IN ( ' . implode( ',', wp_parse_id_list( $this->query_vars['post_author__not_in'] ) ) . ' )'; |
|
815 | + $this->sql_clauses['where']['post_author__not_in'] = 'post_author NOT IN ( '.implode(',', wp_parse_id_list($this->query_vars['post_author__not_in'])).' )'; |
|
817 | 816 | } |
818 | 817 | |
819 | 818 | $join = ''; |
820 | 819 | |
821 | - if ( $join_posts_table ) { |
|
820 | + if ($join_posts_table) { |
|
822 | 821 | $join .= "JOIN $wpdb->posts ON $wpdb->posts.ID = $wpdb->comments.comment_post_ID"; |
823 | 822 | } |
824 | 823 | |
825 | - if ( ! empty( $this->meta_query_clauses ) ) { |
|
824 | + if ( ! empty($this->meta_query_clauses)) { |
|
826 | 825 | $join .= $this->meta_query_clauses['join']; |
827 | 826 | |
828 | 827 | // Strip leading 'AND'. |
829 | - $this->sql_clauses['where']['meta_query'] = preg_replace( '/^\s*AND\s*/', '', $this->meta_query_clauses['where'] ); |
|
828 | + $this->sql_clauses['where']['meta_query'] = preg_replace('/^\s*AND\s*/', '', $this->meta_query_clauses['where']); |
|
830 | 829 | |
831 | - if ( ! $this->query_vars['count'] ) { |
|
830 | + if ( ! $this->query_vars['count']) { |
|
832 | 831 | $groupby = "{$wpdb->comments}.comment_ID"; |
833 | 832 | } |
834 | 833 | } |
835 | 834 | |
836 | 835 | $date_query = $this->query_vars['date_query']; |
837 | - if ( ! empty( $date_query ) && is_array( $date_query ) ) { |
|
838 | - $date_query_object = new WP_Date_Query( $date_query, 'comment_date' ); |
|
839 | - $this->sql_clauses['where']['date_query'] = preg_replace( '/^\s*AND\s*/', '', $date_query_object->get_sql() ); |
|
836 | + if ( ! empty($date_query) && is_array($date_query)) { |
|
837 | + $date_query_object = new WP_Date_Query($date_query, 'comment_date'); |
|
838 | + $this->sql_clauses['where']['date_query'] = preg_replace('/^\s*AND\s*/', '', $date_query_object->get_sql()); |
|
840 | 839 | } |
841 | 840 | |
842 | - $where = implode( ' AND ', $this->sql_clauses['where'] ); |
|
841 | + $where = implode(' AND ', $this->sql_clauses['where']); |
|
843 | 842 | |
844 | - $pieces = array( 'fields', 'join', 'where', 'orderby', 'limits', 'groupby' ); |
|
843 | + $pieces = array('fields', 'join', 'where', 'orderby', 'limits', 'groupby'); |
|
845 | 844 | /** |
846 | 845 | * Filter the comment query clauses. |
847 | 846 | * |
@@ -850,31 +849,31 @@ discard block |
||
850 | 849 | * @param array $pieces A compacted array of comment query clauses. |
851 | 850 | * @param WP_Comment_Query &$this Current instance of WP_Comment_Query, passed by reference. |
852 | 851 | */ |
853 | - $clauses = apply_filters_ref_array( 'comments_clauses', array( compact( $pieces ), &$this ) ); |
|
852 | + $clauses = apply_filters_ref_array('comments_clauses', array(compact($pieces), &$this)); |
|
854 | 853 | |
855 | - $fields = isset( $clauses[ 'fields' ] ) ? $clauses[ 'fields' ] : ''; |
|
856 | - $join = isset( $clauses[ 'join' ] ) ? $clauses[ 'join' ] : ''; |
|
857 | - $where = isset( $clauses[ 'where' ] ) ? $clauses[ 'where' ] : ''; |
|
858 | - $orderby = isset( $clauses[ 'orderby' ] ) ? $clauses[ 'orderby' ] : ''; |
|
859 | - $limits = isset( $clauses[ 'limits' ] ) ? $clauses[ 'limits' ] : ''; |
|
860 | - $groupby = isset( $clauses[ 'groupby' ] ) ? $clauses[ 'groupby' ] : ''; |
|
854 | + $fields = isset($clauses['fields']) ? $clauses['fields'] : ''; |
|
855 | + $join = isset($clauses['join']) ? $clauses['join'] : ''; |
|
856 | + $where = isset($clauses['where']) ? $clauses['where'] : ''; |
|
857 | + $orderby = isset($clauses['orderby']) ? $clauses['orderby'] : ''; |
|
858 | + $limits = isset($clauses['limits']) ? $clauses['limits'] : ''; |
|
859 | + $groupby = isset($clauses['groupby']) ? $clauses['groupby'] : ''; |
|
861 | 860 | |
862 | 861 | $this->filtered_where_clause = $where; |
863 | 862 | |
864 | - if ( $where ) { |
|
865 | - $where = 'WHERE ' . $where; |
|
863 | + if ($where) { |
|
864 | + $where = 'WHERE '.$where; |
|
866 | 865 | } |
867 | 866 | |
868 | - if ( $groupby ) { |
|
869 | - $groupby = 'GROUP BY ' . $groupby; |
|
867 | + if ($groupby) { |
|
868 | + $groupby = 'GROUP BY '.$groupby; |
|
870 | 869 | } |
871 | 870 | |
872 | - if ( $orderby ) { |
|
871 | + if ($orderby) { |
|
873 | 872 | $orderby = "ORDER BY $orderby"; |
874 | 873 | } |
875 | 874 | |
876 | 875 | $found_rows = ''; |
877 | - if ( ! $this->query_vars['no_found_rows'] ) { |
|
876 | + if ( ! $this->query_vars['no_found_rows']) { |
|
878 | 877 | $found_rows = 'SQL_CALC_FOUND_ROWS'; |
879 | 878 | } |
880 | 879 | |
@@ -886,11 +885,11 @@ discard block |
||
886 | 885 | |
887 | 886 | $this->request = "{$this->sql_clauses['select']} {$this->sql_clauses['from']} {$where} {$this->sql_clauses['groupby']} {$this->sql_clauses['orderby']} {$this->sql_clauses['limits']}"; |
888 | 887 | |
889 | - if ( $this->query_vars['count'] ) { |
|
890 | - return intval( $wpdb->get_var( $this->request ) ); |
|
888 | + if ($this->query_vars['count']) { |
|
889 | + return intval($wpdb->get_var($this->request)); |
|
891 | 890 | } else { |
892 | - $comment_ids = $wpdb->get_col( $this->request ); |
|
893 | - return array_map( 'intval', $comment_ids ); |
|
891 | + $comment_ids = $wpdb->get_col($this->request); |
|
892 | + return array_map('intval', $comment_ids); |
|
894 | 893 | } |
895 | 894 | } |
896 | 895 | |
@@ -905,11 +904,11 @@ discard block |
||
905 | 904 | * @param array $comments Array of top-level comments whose descendants should be filled in. |
906 | 905 | * @return array |
907 | 906 | */ |
908 | - protected function fill_descendants( $comments ) { |
|
907 | + protected function fill_descendants($comments) { |
|
909 | 908 | global $wpdb; |
910 | 909 | |
911 | 910 | $levels = array( |
912 | - 0 => wp_list_pluck( $comments, 'comment_ID' ), |
|
911 | + 0 => wp_list_pluck($comments, 'comment_ID'), |
|
913 | 912 | ); |
914 | 913 | |
915 | 914 | /* |
@@ -917,74 +916,74 @@ discard block |
||
917 | 916 | * query, minus the `parent`, `parent__in`, and `parent__not_in` sub-clauses. |
918 | 917 | */ |
919 | 918 | $_where = $this->filtered_where_clause; |
920 | - $exclude_keys = array( 'parent', 'parent__in', 'parent__not_in' ); |
|
921 | - foreach ( $exclude_keys as $exclude_key ) { |
|
922 | - if ( isset( $this->sql_clauses['where'][ $exclude_key ] ) ) { |
|
923 | - $clause = $this->sql_clauses['where'][ $exclude_key ]; |
|
919 | + $exclude_keys = array('parent', 'parent__in', 'parent__not_in'); |
|
920 | + foreach ($exclude_keys as $exclude_key) { |
|
921 | + if (isset($this->sql_clauses['where'][$exclude_key])) { |
|
922 | + $clause = $this->sql_clauses['where'][$exclude_key]; |
|
924 | 923 | |
925 | 924 | // Strip the clause as well as any adjacent ANDs. |
926 | - $pattern = '|(?:AND)?\s*' . $clause . '\s*(?:AND)?|'; |
|
927 | - $_where_parts = preg_split( $pattern, $_where ); |
|
925 | + $pattern = '|(?:AND)?\s*'.$clause.'\s*(?:AND)?|'; |
|
926 | + $_where_parts = preg_split($pattern, $_where); |
|
928 | 927 | |
929 | 928 | // Remove empties. |
930 | - $_where_parts = array_filter( array_map( 'trim', $_where_parts ) ); |
|
929 | + $_where_parts = array_filter(array_map('trim', $_where_parts)); |
|
931 | 930 | |
932 | 931 | // Reassemble with an AND. |
933 | - $_where = implode( ' AND ', $_where_parts ); |
|
932 | + $_where = implode(' AND ', $_where_parts); |
|
934 | 933 | } |
935 | 934 | } |
936 | 935 | |
937 | 936 | // Fetch an entire level of the descendant tree at a time. |
938 | 937 | $level = 0; |
939 | 938 | do { |
940 | - $parent_ids = $levels[ $level ]; |
|
941 | - if ( ! $parent_ids ) { |
|
939 | + $parent_ids = $levels[$level]; |
|
940 | + if ( ! $parent_ids) { |
|
942 | 941 | break; |
943 | 942 | } |
944 | 943 | |
945 | - $where = 'WHERE ' . $_where . ' AND comment_parent IN (' . implode( ',', array_map( 'intval', $parent_ids ) ) . ')'; |
|
946 | - $comment_ids = $wpdb->get_col( "{$this->sql_clauses['select']} {$this->sql_clauses['from']} {$where} {$this->sql_clauses['groupby']} ORDER BY comment_date_gmt ASC, comment_ID ASC" ); |
|
944 | + $where = 'WHERE '.$_where.' AND comment_parent IN ('.implode(',', array_map('intval', $parent_ids)).')'; |
|
945 | + $comment_ids = $wpdb->get_col("{$this->sql_clauses['select']} {$this->sql_clauses['from']} {$where} {$this->sql_clauses['groupby']} ORDER BY comment_date_gmt ASC, comment_ID ASC"); |
|
947 | 946 | |
948 | 947 | $level++; |
949 | - $levels[ $level ] = $comment_ids; |
|
950 | - } while ( $comment_ids ); |
|
948 | + $levels[$level] = $comment_ids; |
|
949 | + } while ($comment_ids); |
|
951 | 950 | |
952 | 951 | // Prime comment caches for non-top-level comments. |
953 | 952 | $descendant_ids = array(); |
954 | - for ( $i = 1; $i < count( $levels ); $i++ ) { |
|
955 | - $descendant_ids = array_merge( $descendant_ids, $levels[ $i ] ); |
|
953 | + for ($i = 1; $i < count($levels); $i++) { |
|
954 | + $descendant_ids = array_merge($descendant_ids, $levels[$i]); |
|
956 | 955 | } |
957 | 956 | |
958 | - _prime_comment_caches( $descendant_ids, $this->query_vars['update_comment_meta_cache'] ); |
|
957 | + _prime_comment_caches($descendant_ids, $this->query_vars['update_comment_meta_cache']); |
|
959 | 958 | |
960 | 959 | // Assemble a flat array of all comments + descendants. |
961 | 960 | $all_comments = $comments; |
962 | - foreach ( $descendant_ids as $descendant_id ) { |
|
963 | - $all_comments[] = get_comment( $descendant_id ); |
|
961 | + foreach ($descendant_ids as $descendant_id) { |
|
962 | + $all_comments[] = get_comment($descendant_id); |
|
964 | 963 | } |
965 | 964 | |
966 | 965 | // If a threaded representation was requested, build the tree. |
967 | - if ( 'threaded' === $this->query_vars['hierarchical'] ) { |
|
966 | + if ('threaded' === $this->query_vars['hierarchical']) { |
|
968 | 967 | $threaded_comments = $ref = array(); |
969 | - foreach ( $all_comments as $k => $c ) { |
|
970 | - $_c = get_comment( $c->comment_ID ); |
|
968 | + foreach ($all_comments as $k => $c) { |
|
969 | + $_c = get_comment($c->comment_ID); |
|
971 | 970 | |
972 | 971 | // If the comment isn't in the reference array, it goes in the top level of the thread. |
973 | - if ( ! isset( $ref[ $c->comment_parent ] ) ) { |
|
974 | - $threaded_comments[ $_c->comment_ID ] = $_c; |
|
975 | - $ref[ $_c->comment_ID ] = $threaded_comments[ $_c->comment_ID ]; |
|
972 | + if ( ! isset($ref[$c->comment_parent])) { |
|
973 | + $threaded_comments[$_c->comment_ID] = $_c; |
|
974 | + $ref[$_c->comment_ID] = $threaded_comments[$_c->comment_ID]; |
|
976 | 975 | |
977 | 976 | // Otherwise, set it as a child of its parent. |
978 | 977 | } else { |
979 | 978 | |
980 | - $ref[ $_c->comment_parent ]->add_child( $_c ); |
|
981 | - $ref[ $_c->comment_ID ] = $ref[ $_c->comment_parent ]->get_child( $_c->comment_ID ); |
|
979 | + $ref[$_c->comment_parent]->add_child($_c); |
|
980 | + $ref[$_c->comment_ID] = $ref[$_c->comment_parent]->get_child($_c->comment_ID); |
|
982 | 981 | } |
983 | 982 | } |
984 | 983 | |
985 | 984 | // Set the 'populated_children' flag, to ensure additional database queries aren't run. |
986 | - foreach ( $ref as $_ref ) { |
|
987 | - $_ref->populated_children( true ); |
|
985 | + foreach ($ref as $_ref) { |
|
986 | + $_ref->populated_children(true); |
|
988 | 987 | } |
989 | 988 | |
990 | 989 | $comments = $threaded_comments; |
@@ -1007,17 +1006,17 @@ discard block |
||
1007 | 1006 | * @param array $cols |
1008 | 1007 | * @return string |
1009 | 1008 | */ |
1010 | - protected function get_search_sql( $string, $cols ) { |
|
1009 | + protected function get_search_sql($string, $cols) { |
|
1011 | 1010 | global $wpdb; |
1012 | 1011 | |
1013 | - $like = '%' . $wpdb->esc_like( $string ) . '%'; |
|
1012 | + $like = '%'.$wpdb->esc_like($string).'%'; |
|
1014 | 1013 | |
1015 | 1014 | $searches = array(); |
1016 | - foreach ( $cols as $col ) { |
|
1017 | - $searches[] = $wpdb->prepare( "$col LIKE %s", $like ); |
|
1015 | + foreach ($cols as $col) { |
|
1016 | + $searches[] = $wpdb->prepare("$col LIKE %s", $like); |
|
1018 | 1017 | } |
1019 | 1018 | |
1020 | - return ' AND (' . implode(' OR ', $searches) . ')'; |
|
1019 | + return ' AND ('.implode(' OR ', $searches).')'; |
|
1021 | 1020 | } |
1022 | 1021 | |
1023 | 1022 | /** |
@@ -1031,7 +1030,7 @@ discard block |
||
1031 | 1030 | * @param string $orderby Alias for the field to order by. |
1032 | 1031 | * @return string|false Value to used in the ORDER clause. False otherwise. |
1033 | 1032 | */ |
1034 | - protected function parse_orderby( $orderby ) { |
|
1033 | + protected function parse_orderby($orderby) { |
|
1035 | 1034 | global $wpdb; |
1036 | 1035 | |
1037 | 1036 | $allowed_keys = array( |
@@ -1052,30 +1051,30 @@ discard block |
||
1052 | 1051 | 'user_id', |
1053 | 1052 | ); |
1054 | 1053 | |
1055 | - if ( ! empty( $this->query_vars['meta_key'] ) ) { |
|
1054 | + if ( ! empty($this->query_vars['meta_key'])) { |
|
1056 | 1055 | $allowed_keys[] = $this->query_vars['meta_key']; |
1057 | 1056 | $allowed_keys[] = 'meta_value'; |
1058 | 1057 | $allowed_keys[] = 'meta_value_num'; |
1059 | 1058 | } |
1060 | 1059 | |
1061 | 1060 | $meta_query_clauses = $this->meta_query->get_clauses(); |
1062 | - if ( $meta_query_clauses ) { |
|
1063 | - $allowed_keys = array_merge( $allowed_keys, array_keys( $meta_query_clauses ) ); |
|
1061 | + if ($meta_query_clauses) { |
|
1062 | + $allowed_keys = array_merge($allowed_keys, array_keys($meta_query_clauses)); |
|
1064 | 1063 | } |
1065 | 1064 | |
1066 | 1065 | $parsed = false; |
1067 | - if ( $orderby == $this->query_vars['meta_key'] || $orderby == 'meta_value' ) { |
|
1066 | + if ($orderby == $this->query_vars['meta_key'] || $orderby == 'meta_value') { |
|
1068 | 1067 | $parsed = "$wpdb->commentmeta.meta_value"; |
1069 | - } elseif ( $orderby == 'meta_value_num' ) { |
|
1068 | + } elseif ($orderby == 'meta_value_num') { |
|
1070 | 1069 | $parsed = "$wpdb->commentmeta.meta_value+0"; |
1071 | - } elseif ( $orderby == 'comment__in' ) { |
|
1072 | - $comment__in = implode( ',', array_map( 'absint', $this->query_vars['comment__in'] ) ); |
|
1070 | + } elseif ($orderby == 'comment__in') { |
|
1071 | + $comment__in = implode(',', array_map('absint', $this->query_vars['comment__in'])); |
|
1073 | 1072 | $parsed = "FIELD( {$wpdb->comments}.comment_ID, $comment__in )"; |
1074 | - } elseif ( in_array( $orderby, $allowed_keys ) ) { |
|
1073 | + } elseif (in_array($orderby, $allowed_keys)) { |
|
1075 | 1074 | |
1076 | - if ( isset( $meta_query_clauses[ $orderby ] ) ) { |
|
1077 | - $meta_clause = $meta_query_clauses[ $orderby ]; |
|
1078 | - $parsed = sprintf( "CAST(%s.meta_value AS %s)", esc_sql( $meta_clause['alias'] ), esc_sql( $meta_clause['cast'] ) ); |
|
1075 | + if (isset($meta_query_clauses[$orderby])) { |
|
1076 | + $meta_clause = $meta_query_clauses[$orderby]; |
|
1077 | + $parsed = sprintf("CAST(%s.meta_value AS %s)", esc_sql($meta_clause['alias']), esc_sql($meta_clause['cast'])); |
|
1079 | 1078 | } else { |
1080 | 1079 | $parsed = "$wpdb->comments.$orderby"; |
1081 | 1080 | } |
@@ -1093,12 +1092,12 @@ discard block |
||
1093 | 1092 | * @param string $order The 'order' query variable. |
1094 | 1093 | * @return string The sanitized 'order' query variable. |
1095 | 1094 | */ |
1096 | - protected function parse_order( $order ) { |
|
1097 | - if ( ! is_string( $order ) || empty( $order ) ) { |
|
1095 | + protected function parse_order($order) { |
|
1096 | + if ( ! is_string($order) || empty($order)) { |
|
1098 | 1097 | return 'DESC'; |
1099 | 1098 | } |
1100 | 1099 | |
1101 | - if ( 'ASC' === strtoupper( $order ) ) { |
|
1100 | + if ('ASC' === strtoupper($order)) { |
|
1102 | 1101 | return 'ASC'; |
1103 | 1102 | } else { |
1104 | 1103 | return 'DESC'; |
@@ -366,7 +366,7 @@ |
||
366 | 366 | * @access public |
367 | 367 | * |
368 | 368 | * @param string $name Property name. |
369 | - * @return bool |
|
369 | + * @return boolean|null |
|
370 | 370 | */ |
371 | 371 | public function __isset( $name ) { |
372 | 372 | if ( in_array( $name, $this->post_fields ) && 0 !== (int) $this->comment_post_ID ) { |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | * @access protected |
175 | 175 | * @var array |
176 | 176 | */ |
177 | - protected $post_fields = array( 'post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_excerpt', 'post_status', 'comment_status', 'ping_status', 'post_name', 'to_ping', 'pinged', 'post_modified', 'post_modified_gmt', 'post_content_filtered', 'post_parent', 'guid', 'menu_order', 'post_type', 'post_mime_type', 'comment_count' ); |
|
177 | + protected $post_fields = array('post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_excerpt', 'post_status', 'comment_status', 'ping_status', 'post_name', 'to_ping', 'pinged', 'post_modified', 'post_modified_gmt', 'post_content_filtered', 'post_parent', 'guid', 'menu_order', 'post_type', 'post_mime_type', 'comment_count'); |
|
178 | 178 | |
179 | 179 | /** |
180 | 180 | * Retrieves a WP_Comment instance. |
@@ -188,27 +188,27 @@ discard block |
||
188 | 188 | * @param int $id Comment ID. |
189 | 189 | * @return WP_Comment|false Comment object, otherwise false. |
190 | 190 | */ |
191 | - public static function get_instance( $id ) { |
|
191 | + public static function get_instance($id) { |
|
192 | 192 | global $wpdb; |
193 | 193 | |
194 | 194 | $comment_id = (int) $id; |
195 | - if ( ! $comment_id ) { |
|
195 | + if ( ! $comment_id) { |
|
196 | 196 | return false; |
197 | 197 | } |
198 | 198 | |
199 | - $_comment = wp_cache_get( $comment_id, 'comment' ); |
|
199 | + $_comment = wp_cache_get($comment_id, 'comment'); |
|
200 | 200 | |
201 | - if ( ! $_comment ) { |
|
202 | - $_comment = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->comments WHERE comment_ID = %d LIMIT 1", $comment_id ) ); |
|
201 | + if ( ! $_comment) { |
|
202 | + $_comment = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_ID = %d LIMIT 1", $comment_id)); |
|
203 | 203 | |
204 | - if ( ! $_comment ) { |
|
204 | + if ( ! $_comment) { |
|
205 | 205 | return false; |
206 | 206 | } |
207 | 207 | |
208 | - wp_cache_add( $_comment->comment_ID, $_comment, 'comment' ); |
|
208 | + wp_cache_add($_comment->comment_ID, $_comment, 'comment'); |
|
209 | 209 | } |
210 | 210 | |
211 | - return new WP_Comment( $_comment ); |
|
211 | + return new WP_Comment($_comment); |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | /** |
@@ -221,8 +221,8 @@ discard block |
||
221 | 221 | * |
222 | 222 | * @param WP_Comment $comment Comment object. |
223 | 223 | */ |
224 | - public function __construct( $comment ) { |
|
225 | - foreach ( get_object_vars( $comment ) as $key => $value ) { |
|
224 | + public function __construct($comment) { |
|
225 | + foreach (get_object_vars($comment) as $key => $value) { |
|
226 | 226 | $this->$key = $value; |
227 | 227 | } |
228 | 228 | } |
@@ -236,7 +236,7 @@ discard block |
||
236 | 236 | * @return array Object as array. |
237 | 237 | */ |
238 | 238 | public function to_array() { |
239 | - return get_object_vars( $this ); |
|
239 | + return get_object_vars($this); |
|
240 | 240 | } |
241 | 241 | |
242 | 242 | /** |
@@ -276,7 +276,7 @@ discard block |
||
276 | 276 | * } |
277 | 277 | * @return array Array of `WP_Comment` objects. |
278 | 278 | */ |
279 | - public function get_children( $args = array() ) { |
|
279 | + public function get_children($args = array()) { |
|
280 | 280 | $defaults = array( |
281 | 281 | 'format' => 'tree', |
282 | 282 | 'status' => 'all', |
@@ -284,26 +284,26 @@ discard block |
||
284 | 284 | 'orderby' => '', |
285 | 285 | ); |
286 | 286 | |
287 | - $_args = wp_parse_args( $args, $defaults ); |
|
287 | + $_args = wp_parse_args($args, $defaults); |
|
288 | 288 | $_args['parent'] = $this->comment_ID; |
289 | 289 | |
290 | - if ( is_null( $this->children ) ) { |
|
291 | - if ( $this->populated_children ) { |
|
290 | + if (is_null($this->children)) { |
|
291 | + if ($this->populated_children) { |
|
292 | 292 | $this->children = array(); |
293 | 293 | } else { |
294 | - $this->children = get_comments( $_args ); |
|
294 | + $this->children = get_comments($_args); |
|
295 | 295 | } |
296 | 296 | } |
297 | 297 | |
298 | - if ( 'flat' === $_args['format'] ) { |
|
298 | + if ('flat' === $_args['format']) { |
|
299 | 299 | $children = array(); |
300 | - foreach ( $this->children as $child ) { |
|
300 | + foreach ($this->children as $child) { |
|
301 | 301 | $child_args = $_args; |
302 | 302 | $child_args['format'] = 'flat'; |
303 | 303 | // get_children() resets this value automatically. |
304 | - unset( $child_args['parent'] ); |
|
304 | + unset($child_args['parent']); |
|
305 | 305 | |
306 | - $children = array_merge( $children, array( $child ), $child->get_children( $child_args ) ); |
|
306 | + $children = array_merge($children, array($child), $child->get_children($child_args)); |
|
307 | 307 | } |
308 | 308 | } else { |
309 | 309 | $children = $this->children; |
@@ -322,8 +322,8 @@ discard block |
||
322 | 322 | * |
323 | 323 | * @param WP_Comment $child Child comment. |
324 | 324 | */ |
325 | - public function add_child( WP_Comment $child ) { |
|
326 | - $this->children[ $child->comment_ID ] = $child; |
|
325 | + public function add_child(WP_Comment $child) { |
|
326 | + $this->children[$child->comment_ID] = $child; |
|
327 | 327 | } |
328 | 328 | |
329 | 329 | /** |
@@ -335,9 +335,9 @@ discard block |
||
335 | 335 | * @param int $child_id ID of the child. |
336 | 336 | * @return WP_Comment|bool Returns the comment object if found, otherwise false. |
337 | 337 | */ |
338 | - public function get_child( $child_id ) { |
|
339 | - if ( isset( $this->children[ $child_id ] ) ) { |
|
340 | - return $this->children[ $child_id ]; |
|
338 | + public function get_child($child_id) { |
|
339 | + if (isset($this->children[$child_id])) { |
|
340 | + return $this->children[$child_id]; |
|
341 | 341 | } |
342 | 342 | |
343 | 343 | return false; |
@@ -353,7 +353,7 @@ discard block |
||
353 | 353 | * |
354 | 354 | * @param bool $set Whether the comment's children have already been populated. |
355 | 355 | */ |
356 | - public function populated_children( $set ) { |
|
356 | + public function populated_children($set) { |
|
357 | 357 | $this->populated_children = (bool) $set; |
358 | 358 | } |
359 | 359 | |
@@ -368,10 +368,10 @@ discard block |
||
368 | 368 | * @param string $name Property name. |
369 | 369 | * @return bool |
370 | 370 | */ |
371 | - public function __isset( $name ) { |
|
372 | - if ( in_array( $name, $this->post_fields ) && 0 !== (int) $this->comment_post_ID ) { |
|
373 | - $post = get_post( $this->comment_post_ID ); |
|
374 | - return property_exists( $post, $name ); |
|
371 | + public function __isset($name) { |
|
372 | + if (in_array($name, $this->post_fields) && 0 !== (int) $this->comment_post_ID) { |
|
373 | + $post = get_post($this->comment_post_ID); |
|
374 | + return property_exists($post, $name); |
|
375 | 375 | } |
376 | 376 | } |
377 | 377 | |
@@ -386,9 +386,9 @@ discard block |
||
386 | 386 | * @param string $name |
387 | 387 | * @return mixed |
388 | 388 | */ |
389 | - public function __get( $name ) { |
|
390 | - if ( in_array( $name, $this->post_fields ) ) { |
|
391 | - $post = get_post( $this->comment_post_ID ); |
|
389 | + public function __get($name) { |
|
390 | + if (in_array($name, $this->post_fields)) { |
|
391 | + $post = get_post($this->comment_post_ID); |
|
392 | 392 | return $post->$name; |
393 | 393 | } |
394 | 394 | } |
@@ -480,7 +480,7 @@ |
||
480 | 480 | * |
481 | 481 | * @since 3.4.0 |
482 | 482 | * |
483 | - * @param mixed $default A default value which is used as a fallback. Default is null. |
|
483 | + * @param stdClass $default A default value which is used as a fallback. Default is null. |
|
484 | 484 | * @return mixed The default value on failure, otherwise the sanitized value. |
485 | 485 | */ |
486 | 486 | final public function post_value( $default = null ) { |
@@ -121,11 +121,11 @@ discard block |
||
121 | 121 | * theme mod or option name. |
122 | 122 | * @param array $args Setting arguments. |
123 | 123 | */ |
124 | - public function __construct( $manager, $id, $args = array() ) { |
|
125 | - $keys = array_keys( get_object_vars( $this ) ); |
|
126 | - foreach ( $keys as $key ) { |
|
127 | - if ( isset( $args[ $key ] ) ) { |
|
128 | - $this->$key = $args[ $key ]; |
|
124 | + public function __construct($manager, $id, $args = array()) { |
|
125 | + $keys = array_keys(get_object_vars($this)); |
|
126 | + foreach ($keys as $key) { |
|
127 | + if (isset($args[$key])) { |
|
128 | + $this->$key = $args[$key]; |
|
129 | 129 | } |
130 | 130 | } |
131 | 131 | |
@@ -133,29 +133,29 @@ discard block |
||
133 | 133 | $this->id = $id; |
134 | 134 | |
135 | 135 | // Parse the ID for array keys. |
136 | - $this->id_data['keys'] = preg_split( '/\[/', str_replace( ']', '', $this->id ) ); |
|
137 | - $this->id_data['base'] = array_shift( $this->id_data['keys'] ); |
|
136 | + $this->id_data['keys'] = preg_split('/\[/', str_replace(']', '', $this->id)); |
|
137 | + $this->id_data['base'] = array_shift($this->id_data['keys']); |
|
138 | 138 | |
139 | 139 | // Rebuild the ID. |
140 | - $this->id = $this->id_data[ 'base' ]; |
|
141 | - if ( ! empty( $this->id_data[ 'keys' ] ) ) { |
|
142 | - $this->id .= '[' . implode( '][', $this->id_data['keys'] ) . ']'; |
|
140 | + $this->id = $this->id_data['base']; |
|
141 | + if ( ! empty($this->id_data['keys'])) { |
|
142 | + $this->id .= '['.implode('][', $this->id_data['keys']).']'; |
|
143 | 143 | } |
144 | 144 | |
145 | - if ( $this->sanitize_callback ) { |
|
146 | - add_filter( "customize_sanitize_{$this->id}", $this->sanitize_callback, 10, 2 ); |
|
145 | + if ($this->sanitize_callback) { |
|
146 | + add_filter("customize_sanitize_{$this->id}", $this->sanitize_callback, 10, 2); |
|
147 | 147 | } |
148 | - if ( $this->sanitize_js_callback ) { |
|
149 | - add_filter( "customize_sanitize_js_{$this->id}", $this->sanitize_js_callback, 10, 2 ); |
|
148 | + if ($this->sanitize_js_callback) { |
|
149 | + add_filter("customize_sanitize_js_{$this->id}", $this->sanitize_js_callback, 10, 2); |
|
150 | 150 | } |
151 | 151 | |
152 | - if ( 'option' === $this->type || 'theme_mod' === $this->type ) { |
|
152 | + if ('option' === $this->type || 'theme_mod' === $this->type) { |
|
153 | 153 | // Other setting types can opt-in to aggregate multidimensional explicitly. |
154 | 154 | $this->aggregate_multidimensional(); |
155 | 155 | |
156 | 156 | // Allow option settings to indicate whether they should be autoloaded. |
157 | - if ( 'option' === $this->type && isset( $args['autoload'] ) ) { |
|
158 | - self::$aggregated_multidimensionals[ $this->type ][ $this->id_data['base'] ]['autoload'] = $args['autoload']; |
|
157 | + if ('option' === $this->type && isset($args['autoload'])) { |
|
158 | + self::$aggregated_multidimensionals[$this->type][$this->id_data['base']]['autoload'] = $args['autoload']; |
|
159 | 159 | } |
160 | 160 | } |
161 | 161 | } |
@@ -188,20 +188,20 @@ discard block |
||
188 | 188 | */ |
189 | 189 | protected function aggregate_multidimensional() { |
190 | 190 | $id_base = $this->id_data['base']; |
191 | - if ( ! isset( self::$aggregated_multidimensionals[ $this->type ] ) ) { |
|
192 | - self::$aggregated_multidimensionals[ $this->type ] = array(); |
|
191 | + if ( ! isset(self::$aggregated_multidimensionals[$this->type])) { |
|
192 | + self::$aggregated_multidimensionals[$this->type] = array(); |
|
193 | 193 | } |
194 | - if ( ! isset( self::$aggregated_multidimensionals[ $this->type ][ $id_base ] ) ) { |
|
195 | - self::$aggregated_multidimensionals[ $this->type ][ $id_base ] = array( |
|
194 | + if ( ! isset(self::$aggregated_multidimensionals[$this->type][$id_base])) { |
|
195 | + self::$aggregated_multidimensionals[$this->type][$id_base] = array( |
|
196 | 196 | 'previewed_instances' => array(), // Calling preview() will add the $setting to the array. |
197 | 197 | 'preview_applied_instances' => array(), // Flags for which settings have had their values applied. |
198 | - 'root_value' => $this->get_root_value( array() ), // Root value for initial state, manipulated by preview and update calls. |
|
198 | + 'root_value' => $this->get_root_value(array()), // Root value for initial state, manipulated by preview and update calls. |
|
199 | 199 | ); |
200 | 200 | } |
201 | 201 | |
202 | - if ( ! empty( $this->id_data['keys'] ) ) { |
|
202 | + if ( ! empty($this->id_data['keys'])) { |
|
203 | 203 | // Note the preview-applied flag is cleared at priority 9 to ensure it is cleared before a deferred-preview runs. |
204 | - add_action( "customize_post_value_set_{$this->id}", array( $this, '_clear_aggregated_multidimensional_preview_applied_flag' ), 9 ); |
|
204 | + add_action("customize_post_value_set_{$this->id}", array($this, '_clear_aggregated_multidimensional_preview_applied_flag'), 9); |
|
205 | 205 | $this->is_multidimensional_aggregated = true; |
206 | 206 | } |
207 | 207 | } |
@@ -224,10 +224,10 @@ discard block |
||
224 | 224 | * @return bool If preview() has been called. |
225 | 225 | */ |
226 | 226 | public function is_current_blog_previewed() { |
227 | - if ( ! isset( $this->_previewed_blog_id ) ) { |
|
227 | + if ( ! isset($this->_previewed_blog_id)) { |
|
228 | 228 | return false; |
229 | 229 | } |
230 | - return ( get_current_blog_id() === $this->_previewed_blog_id ); |
|
230 | + return (get_current_blog_id() === $this->_previewed_blog_id); |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | /** |
@@ -253,18 +253,18 @@ discard block |
||
253 | 253 | * @return bool False when preview short-circuits due no change needing to be previewed. |
254 | 254 | */ |
255 | 255 | public function preview() { |
256 | - if ( ! isset( $this->_previewed_blog_id ) ) { |
|
256 | + if ( ! isset($this->_previewed_blog_id)) { |
|
257 | 257 | $this->_previewed_blog_id = get_current_blog_id(); |
258 | 258 | } |
259 | 259 | |
260 | 260 | // Prevent re-previewing an already-previewed setting. |
261 | - if ( $this->is_previewed ) { |
|
261 | + if ($this->is_previewed) { |
|
262 | 262 | return true; |
263 | 263 | } |
264 | 264 | |
265 | 265 | $id_base = $this->id_data['base']; |
266 | - $is_multidimensional = ! empty( $this->id_data['keys'] ); |
|
267 | - $multidimensional_filter = array( $this, '_multidimensional_preview_filter' ); |
|
266 | + $is_multidimensional = ! empty($this->id_data['keys']); |
|
267 | + $multidimensional_filter = array($this, '_multidimensional_preview_filter'); |
|
268 | 268 | |
269 | 269 | /* |
270 | 270 | * Check if the setting has a pre-existing value (an isset check), |
@@ -273,53 +273,53 @@ discard block |
||
273 | 273 | * to be previewed. |
274 | 274 | */ |
275 | 275 | $undefined = new stdClass(); |
276 | - $needs_preview = ( $undefined !== $this->post_value( $undefined ) ); |
|
276 | + $needs_preview = ($undefined !== $this->post_value($undefined)); |
|
277 | 277 | $value = null; |
278 | 278 | |
279 | 279 | // Since no post value was defined, check if we have an initial value set. |
280 | - if ( ! $needs_preview ) { |
|
281 | - if ( $this->is_multidimensional_aggregated ) { |
|
282 | - $root = self::$aggregated_multidimensionals[ $this->type ][ $id_base ]['root_value']; |
|
283 | - $value = $this->multidimensional_get( $root, $this->id_data['keys'], $undefined ); |
|
280 | + if ( ! $needs_preview) { |
|
281 | + if ($this->is_multidimensional_aggregated) { |
|
282 | + $root = self::$aggregated_multidimensionals[$this->type][$id_base]['root_value']; |
|
283 | + $value = $this->multidimensional_get($root, $this->id_data['keys'], $undefined); |
|
284 | 284 | } else { |
285 | 285 | $default = $this->default; |
286 | 286 | $this->default = $undefined; // Temporarily set default to undefined so we can detect if existing value is set. |
287 | 287 | $value = $this->value(); |
288 | 288 | $this->default = $default; |
289 | 289 | } |
290 | - $needs_preview = ( $undefined === $value ); // Because the default needs to be supplied. |
|
290 | + $needs_preview = ($undefined === $value); // Because the default needs to be supplied. |
|
291 | 291 | } |
292 | 292 | |
293 | 293 | // If the setting does not need previewing now, defer to when it has a value to preview. |
294 | - if ( ! $needs_preview ) { |
|
295 | - if ( ! has_action( "customize_post_value_set_{$this->id}", array( $this, 'preview' ) ) ) { |
|
296 | - add_action( "customize_post_value_set_{$this->id}", array( $this, 'preview' ) ); |
|
294 | + if ( ! $needs_preview) { |
|
295 | + if ( ! has_action("customize_post_value_set_{$this->id}", array($this, 'preview'))) { |
|
296 | + add_action("customize_post_value_set_{$this->id}", array($this, 'preview')); |
|
297 | 297 | } |
298 | 298 | return false; |
299 | 299 | } |
300 | 300 | |
301 | - switch ( $this->type ) { |
|
301 | + switch ($this->type) { |
|
302 | 302 | case 'theme_mod' : |
303 | - if ( ! $is_multidimensional ) { |
|
304 | - add_filter( "theme_mod_{$id_base}", array( $this, '_preview_filter' ) ); |
|
303 | + if ( ! $is_multidimensional) { |
|
304 | + add_filter("theme_mod_{$id_base}", array($this, '_preview_filter')); |
|
305 | 305 | } else { |
306 | - if ( empty( self::$aggregated_multidimensionals[ $this->type ][ $id_base ]['previewed_instances'] ) ) { |
|
306 | + if (empty(self::$aggregated_multidimensionals[$this->type][$id_base]['previewed_instances'])) { |
|
307 | 307 | // Only add this filter once for this ID base. |
308 | - add_filter( "theme_mod_{$id_base}", $multidimensional_filter ); |
|
308 | + add_filter("theme_mod_{$id_base}", $multidimensional_filter); |
|
309 | 309 | } |
310 | - self::$aggregated_multidimensionals[ $this->type ][ $id_base ]['previewed_instances'][ $this->id ] = $this; |
|
310 | + self::$aggregated_multidimensionals[$this->type][$id_base]['previewed_instances'][$this->id] = $this; |
|
311 | 311 | } |
312 | 312 | break; |
313 | 313 | case 'option' : |
314 | - if ( ! $is_multidimensional ) { |
|
315 | - add_filter( "pre_option_{$id_base}", array( $this, '_preview_filter' ) ); |
|
314 | + if ( ! $is_multidimensional) { |
|
315 | + add_filter("pre_option_{$id_base}", array($this, '_preview_filter')); |
|
316 | 316 | } else { |
317 | - if ( empty( self::$aggregated_multidimensionals[ $this->type ][ $id_base ]['previewed_instances'] ) ) { |
|
317 | + if (empty(self::$aggregated_multidimensionals[$this->type][$id_base]['previewed_instances'])) { |
|
318 | 318 | // Only add these filters once for this ID base. |
319 | - add_filter( "option_{$id_base}", $multidimensional_filter ); |
|
320 | - add_filter( "default_option_{$id_base}", $multidimensional_filter ); |
|
319 | + add_filter("option_{$id_base}", $multidimensional_filter); |
|
320 | + add_filter("default_option_{$id_base}", $multidimensional_filter); |
|
321 | 321 | } |
322 | - self::$aggregated_multidimensionals[ $this->type ][ $id_base ]['previewed_instances'][ $this->id ] = $this; |
|
322 | + self::$aggregated_multidimensionals[$this->type][$id_base]['previewed_instances'][$this->id] = $this; |
|
323 | 323 | } |
324 | 324 | break; |
325 | 325 | default : |
@@ -334,7 +334,7 @@ discard block |
||
334 | 334 | * |
335 | 335 | * @param WP_Customize_Setting $this {@see WP_Customize_Setting} instance. |
336 | 336 | */ |
337 | - do_action( "customize_preview_{$this->id}", $this ); |
|
337 | + do_action("customize_preview_{$this->id}", $this); |
|
338 | 338 | |
339 | 339 | /** |
340 | 340 | * Fires when the {@see WP_Customize_Setting::preview()} method is called for settings |
@@ -346,7 +346,7 @@ discard block |
||
346 | 346 | * |
347 | 347 | * @param WP_Customize_Setting $this {@see WP_Customize_Setting} instance. |
348 | 348 | */ |
349 | - do_action( "customize_preview_{$this->type}", $this ); |
|
349 | + do_action("customize_preview_{$this->type}", $this); |
|
350 | 350 | } |
351 | 351 | |
352 | 352 | $this->is_previewed = true; |
@@ -367,7 +367,7 @@ discard block |
||
367 | 367 | * @see WP_Customize_Setting::_multidimensional_preview_filter() |
368 | 368 | */ |
369 | 369 | final public function _clear_aggregated_multidimensional_preview_applied_flag() { |
370 | - unset( self::$aggregated_multidimensionals[ $this->type ][ $this->id_data['base'] ]['preview_applied_instances'][ $this->id ] ); |
|
370 | + unset(self::$aggregated_multidimensionals[$this->type][$this->id_data['base']]['preview_applied_instances'][$this->id]); |
|
371 | 371 | } |
372 | 372 | |
373 | 373 | /** |
@@ -382,14 +382,14 @@ discard block |
||
382 | 382 | * @param mixed $original Old value. |
383 | 383 | * @return mixed New or old value. |
384 | 384 | */ |
385 | - public function _preview_filter( $original ) { |
|
386 | - if ( ! $this->is_current_blog_previewed() ) { |
|
385 | + public function _preview_filter($original) { |
|
386 | + if ( ! $this->is_current_blog_previewed()) { |
|
387 | 387 | return $original; |
388 | 388 | } |
389 | 389 | |
390 | 390 | $undefined = new stdClass(); // Symbol hack. |
391 | - $post_value = $this->post_value( $undefined ); |
|
392 | - if ( $undefined !== $post_value ) { |
|
391 | + $post_value = $this->post_value($undefined); |
|
392 | + if ($undefined !== $post_value) { |
|
393 | 393 | $value = $post_value; |
394 | 394 | } else { |
395 | 395 | /* |
@@ -415,35 +415,35 @@ discard block |
||
415 | 415 | * @param mixed $original Original root value. |
416 | 416 | * @return mixed New or old value. |
417 | 417 | */ |
418 | - final public function _multidimensional_preview_filter( $original ) { |
|
419 | - if ( ! $this->is_current_blog_previewed() ) { |
|
418 | + final public function _multidimensional_preview_filter($original) { |
|
419 | + if ( ! $this->is_current_blog_previewed()) { |
|
420 | 420 | return $original; |
421 | 421 | } |
422 | 422 | |
423 | 423 | $id_base = $this->id_data['base']; |
424 | 424 | |
425 | 425 | // If no settings have been previewed yet (which should not be the case, since $this is), just pass through the original value. |
426 | - if ( empty( self::$aggregated_multidimensionals[ $this->type ][ $id_base ]['previewed_instances'] ) ) { |
|
426 | + if (empty(self::$aggregated_multidimensionals[$this->type][$id_base]['previewed_instances'])) { |
|
427 | 427 | return $original; |
428 | 428 | } |
429 | 429 | |
430 | - foreach ( self::$aggregated_multidimensionals[ $this->type ][ $id_base ]['previewed_instances'] as $previewed_setting ) { |
|
430 | + foreach (self::$aggregated_multidimensionals[$this->type][$id_base]['previewed_instances'] as $previewed_setting) { |
|
431 | 431 | // Skip applying previewed value for any settings that have already been applied. |
432 | - if ( ! empty( self::$aggregated_multidimensionals[ $this->type ][ $id_base ]['preview_applied_instances'][ $previewed_setting->id ] ) ) { |
|
432 | + if ( ! empty(self::$aggregated_multidimensionals[$this->type][$id_base]['preview_applied_instances'][$previewed_setting->id])) { |
|
433 | 433 | continue; |
434 | 434 | } |
435 | 435 | |
436 | 436 | // Do the replacements of the posted/default sub value into the root value. |
437 | - $value = $previewed_setting->post_value( $previewed_setting->default ); |
|
438 | - $root = self::$aggregated_multidimensionals[ $previewed_setting->type ][ $id_base ]['root_value']; |
|
439 | - $root = $previewed_setting->multidimensional_replace( $root, $previewed_setting->id_data['keys'], $value ); |
|
440 | - self::$aggregated_multidimensionals[ $previewed_setting->type ][ $id_base ]['root_value'] = $root; |
|
437 | + $value = $previewed_setting->post_value($previewed_setting->default); |
|
438 | + $root = self::$aggregated_multidimensionals[$previewed_setting->type][$id_base]['root_value']; |
|
439 | + $root = $previewed_setting->multidimensional_replace($root, $previewed_setting->id_data['keys'], $value); |
|
440 | + self::$aggregated_multidimensionals[$previewed_setting->type][$id_base]['root_value'] = $root; |
|
441 | 441 | |
442 | 442 | // Mark this setting having been applied so that it will be skipped when the filter is called again. |
443 | - self::$aggregated_multidimensionals[ $previewed_setting->type ][ $id_base ]['preview_applied_instances'][ $previewed_setting->id ] = true; |
|
443 | + self::$aggregated_multidimensionals[$previewed_setting->type][$id_base]['preview_applied_instances'][$previewed_setting->id] = true; |
|
444 | 444 | } |
445 | 445 | |
446 | - return self::$aggregated_multidimensionals[ $this->type ][ $id_base ]['root_value']; |
|
446 | + return self::$aggregated_multidimensionals[$this->type][$id_base]['root_value']; |
|
447 | 447 | } |
448 | 448 | |
449 | 449 | /** |
@@ -457,7 +457,7 @@ discard block |
||
457 | 457 | final public function save() { |
458 | 458 | $value = $this->post_value(); |
459 | 459 | |
460 | - if ( ! $this->check_capabilities() || ! isset( $value ) ) |
|
460 | + if ( ! $this->check_capabilities() || ! isset($value)) |
|
461 | 461 | return false; |
462 | 462 | |
463 | 463 | /** |
@@ -470,9 +470,9 @@ discard block |
||
470 | 470 | * |
471 | 471 | * @param WP_Customize_Setting $this {@see WP_Customize_Setting} instance. |
472 | 472 | */ |
473 | - do_action( 'customize_save_' . $this->id_data[ 'base' ], $this ); |
|
473 | + do_action('customize_save_'.$this->id_data['base'], $this); |
|
474 | 474 | |
475 | - $this->update( $value ); |
|
475 | + $this->update($value); |
|
476 | 476 | } |
477 | 477 | |
478 | 478 | /** |
@@ -483,8 +483,8 @@ discard block |
||
483 | 483 | * @param mixed $default A default value which is used as a fallback. Default is null. |
484 | 484 | * @return mixed The default value on failure, otherwise the sanitized value. |
485 | 485 | */ |
486 | - final public function post_value( $default = null ) { |
|
487 | - return $this->manager->post_value( $this, $default ); |
|
486 | + final public function post_value($default = null) { |
|
487 | + return $this->manager->post_value($this, $default); |
|
488 | 488 | } |
489 | 489 | |
490 | 490 | /** |
@@ -495,7 +495,7 @@ discard block |
||
495 | 495 | * @param string|array $value The value to sanitize. |
496 | 496 | * @return string|array|null Null if an input isn't valid, otherwise the sanitized value. |
497 | 497 | */ |
498 | - public function sanitize( $value ) { |
|
498 | + public function sanitize($value) { |
|
499 | 499 | |
500 | 500 | /** |
501 | 501 | * Filter a Customize setting value in un-slashed form. |
@@ -505,7 +505,7 @@ discard block |
||
505 | 505 | * @param mixed $value Value of the setting. |
506 | 506 | * @param WP_Customize_Setting $this WP_Customize_Setting instance. |
507 | 507 | */ |
508 | - return apply_filters( "customize_sanitize_{$this->id}", $value, $this ); |
|
508 | + return apply_filters("customize_sanitize_{$this->id}", $value, $this); |
|
509 | 509 | } |
510 | 510 | |
511 | 511 | /** |
@@ -517,12 +517,12 @@ discard block |
||
517 | 517 | * @param mixed $default Value to return if root does not exist. |
518 | 518 | * @return mixed |
519 | 519 | */ |
520 | - protected function get_root_value( $default = null ) { |
|
520 | + protected function get_root_value($default = null) { |
|
521 | 521 | $id_base = $this->id_data['base']; |
522 | - if ( 'option' === $this->type ) { |
|
523 | - return get_option( $id_base, $default ); |
|
524 | - } else if ( 'theme_mod' ) { |
|
525 | - return get_theme_mod( $id_base, $default ); |
|
522 | + if ('option' === $this->type) { |
|
523 | + return get_option($id_base, $default); |
|
524 | + } else if ('theme_mod') { |
|
525 | + return get_theme_mod($id_base, $default); |
|
526 | 526 | } else { |
527 | 527 | /* |
528 | 528 | * Any WP_Customize_Setting subclass implementing aggregate multidimensional |
@@ -542,16 +542,16 @@ discard block |
||
542 | 542 | * @param mixed $value Value to set as root of multidimensional setting. |
543 | 543 | * @return bool Whether the multidimensional root was updated successfully. |
544 | 544 | */ |
545 | - protected function set_root_value( $value ) { |
|
545 | + protected function set_root_value($value) { |
|
546 | 546 | $id_base = $this->id_data['base']; |
547 | - if ( 'option' === $this->type ) { |
|
547 | + if ('option' === $this->type) { |
|
548 | 548 | $autoload = true; |
549 | - if ( isset( self::$aggregated_multidimensionals[ $this->type ][ $this->id_data['base'] ]['autoload'] ) ) { |
|
550 | - $autoload = self::$aggregated_multidimensionals[ $this->type ][ $this->id_data['base'] ]['autoload']; |
|
549 | + if (isset(self::$aggregated_multidimensionals[$this->type][$this->id_data['base']]['autoload'])) { |
|
550 | + $autoload = self::$aggregated_multidimensionals[$this->type][$this->id_data['base']]['autoload']; |
|
551 | 551 | } |
552 | - return update_option( $id_base, $value, $autoload ); |
|
553 | - } else if ( 'theme_mod' ) { |
|
554 | - set_theme_mod( $id_base, $value ); |
|
552 | + return update_option($id_base, $value, $autoload); |
|
553 | + } else if ('theme_mod') { |
|
554 | + set_theme_mod($id_base, $value); |
|
555 | 555 | return true; |
556 | 556 | } else { |
557 | 557 | /* |
@@ -571,16 +571,16 @@ discard block |
||
571 | 571 | * @param mixed $value The value to update. |
572 | 572 | * @return bool The result of saving the value. |
573 | 573 | */ |
574 | - protected function update( $value ) { |
|
574 | + protected function update($value) { |
|
575 | 575 | $id_base = $this->id_data['base']; |
576 | - if ( 'option' === $this->type || 'theme_mod' === $this->type ) { |
|
577 | - if ( ! $this->is_multidimensional_aggregated ) { |
|
578 | - return $this->set_root_value( $value ); |
|
576 | + if ('option' === $this->type || 'theme_mod' === $this->type) { |
|
577 | + if ( ! $this->is_multidimensional_aggregated) { |
|
578 | + return $this->set_root_value($value); |
|
579 | 579 | } else { |
580 | - $root = self::$aggregated_multidimensionals[ $this->type ][ $id_base ]['root_value']; |
|
581 | - $root = $this->multidimensional_replace( $root, $this->id_data['keys'], $value ); |
|
582 | - self::$aggregated_multidimensionals[ $this->type ][ $id_base ]['root_value'] = $root; |
|
583 | - return $this->set_root_value( $root ); |
|
580 | + $root = self::$aggregated_multidimensionals[$this->type][$id_base]['root_value']; |
|
581 | + $root = $this->multidimensional_replace($root, $this->id_data['keys'], $value); |
|
582 | + self::$aggregated_multidimensionals[$this->type][$id_base]['root_value'] = $root; |
|
583 | + return $this->set_root_value($root); |
|
584 | 584 | } |
585 | 585 | } else { |
586 | 586 | /** |
@@ -594,9 +594,9 @@ discard block |
||
594 | 594 | * @param mixed $value Value of the setting. |
595 | 595 | * @param WP_Customize_Setting $this WP_Customize_Setting instance. |
596 | 596 | */ |
597 | - do_action( "customize_update_{$this->type}", $value, $this ); |
|
597 | + do_action("customize_update_{$this->type}", $value, $this); |
|
598 | 598 | |
599 | - return has_action( "customize_update_{$this->type}" ); |
|
599 | + return has_action("customize_update_{$this->type}"); |
|
600 | 600 | } |
601 | 601 | } |
602 | 602 | |
@@ -607,7 +607,7 @@ discard block |
||
607 | 607 | * @deprecated 4.4.0 Deprecated in favor of update() method. |
608 | 608 | */ |
609 | 609 | protected function _update_theme_mod() { |
610 | - _deprecated_function( __METHOD__, '4.4.0', __CLASS__ . '::update()' ); |
|
610 | + _deprecated_function(__METHOD__, '4.4.0', __CLASS__.'::update()'); |
|
611 | 611 | } |
612 | 612 | |
613 | 613 | /** |
@@ -617,7 +617,7 @@ discard block |
||
617 | 617 | * @deprecated 4.4.0 Deprecated in favor of update() method. |
618 | 618 | */ |
619 | 619 | protected function _update_option() { |
620 | - _deprecated_function( __METHOD__, '4.4.0', __CLASS__ . '::update()' ); |
|
620 | + _deprecated_function(__METHOD__, '4.4.0', __CLASS__.'::update()'); |
|
621 | 621 | } |
622 | 622 | |
623 | 623 | /** |
@@ -629,10 +629,10 @@ discard block |
||
629 | 629 | */ |
630 | 630 | public function value() { |
631 | 631 | $id_base = $this->id_data['base']; |
632 | - $is_core_type = ( 'option' === $this->type || 'theme_mod' === $this->type ); |
|
632 | + $is_core_type = ('option' === $this->type || 'theme_mod' === $this->type); |
|
633 | 633 | |
634 | - if ( ! $is_core_type && ! $this->is_multidimensional_aggregated ) { |
|
635 | - $value = $this->get_root_value( $this->default ); |
|
634 | + if ( ! $is_core_type && ! $this->is_multidimensional_aggregated) { |
|
635 | + $value = $this->get_root_value($this->default); |
|
636 | 636 | |
637 | 637 | /** |
638 | 638 | * Filter a Customize setting value not handled as a theme_mod or option. |
@@ -647,12 +647,12 @@ discard block |
||
647 | 647 | * |
648 | 648 | * @param mixed $default The setting default value. Default empty. |
649 | 649 | */ |
650 | - $value = apply_filters( "customize_value_{$id_base}", $value ); |
|
651 | - } else if ( $this->is_multidimensional_aggregated ) { |
|
652 | - $root_value = self::$aggregated_multidimensionals[ $this->type ][ $id_base ]['root_value']; |
|
653 | - $value = $this->multidimensional_get( $root_value, $this->id_data['keys'], $this->default ); |
|
650 | + $value = apply_filters("customize_value_{$id_base}", $value); |
|
651 | + } else if ($this->is_multidimensional_aggregated) { |
|
652 | + $root_value = self::$aggregated_multidimensionals[$this->type][$id_base]['root_value']; |
|
653 | + $value = $this->multidimensional_get($root_value, $this->id_data['keys'], $this->default); |
|
654 | 654 | } else { |
655 | - $value = $this->get_root_value( $this->default ); |
|
655 | + $value = $this->get_root_value($this->default); |
|
656 | 656 | } |
657 | 657 | return $value; |
658 | 658 | } |
@@ -676,10 +676,10 @@ discard block |
||
676 | 676 | * @param mixed $value The setting value. |
677 | 677 | * @param WP_Customize_Setting $this {@see WP_Customize_Setting} instance. |
678 | 678 | */ |
679 | - $value = apply_filters( "customize_sanitize_js_{$this->id}", $this->value(), $this ); |
|
679 | + $value = apply_filters("customize_sanitize_js_{$this->id}", $this->value(), $this); |
|
680 | 680 | |
681 | - if ( is_string( $value ) ) |
|
682 | - return html_entity_decode( $value, ENT_QUOTES, 'UTF-8'); |
|
681 | + if (is_string($value)) |
|
682 | + return html_entity_decode($value, ENT_QUOTES, 'UTF-8'); |
|
683 | 683 | |
684 | 684 | return $value; |
685 | 685 | } |
@@ -692,10 +692,10 @@ discard block |
||
692 | 692 | * @return bool False if theme doesn't support the setting or user can't change setting, otherwise true. |
693 | 693 | */ |
694 | 694 | final public function check_capabilities() { |
695 | - if ( $this->capability && ! call_user_func_array( 'current_user_can', (array) $this->capability ) ) |
|
695 | + if ($this->capability && ! call_user_func_array('current_user_can', (array) $this->capability)) |
|
696 | 696 | return false; |
697 | 697 | |
698 | - if ( $this->theme_supports && ! call_user_func_array( 'current_theme_supports', (array) $this->theme_supports ) ) |
|
698 | + if ($this->theme_supports && ! call_user_func_array('current_theme_supports', (array) $this->theme_supports)) |
|
699 | 699 | return false; |
700 | 700 | |
701 | 701 | return true; |
@@ -711,37 +711,37 @@ discard block |
||
711 | 711 | * @param bool $create Default is false. |
712 | 712 | * @return array|void Keys are 'root', 'node', and 'key'. |
713 | 713 | */ |
714 | - final protected function multidimensional( &$root, $keys, $create = false ) { |
|
715 | - if ( $create && empty( $root ) ) |
|
714 | + final protected function multidimensional(&$root, $keys, $create = false) { |
|
715 | + if ($create && empty($root)) |
|
716 | 716 | $root = array(); |
717 | 717 | |
718 | - if ( ! isset( $root ) || empty( $keys ) ) |
|
718 | + if ( ! isset($root) || empty($keys)) |
|
719 | 719 | return; |
720 | 720 | |
721 | - $last = array_pop( $keys ); |
|
721 | + $last = array_pop($keys); |
|
722 | 722 | $node = &$root; |
723 | 723 | |
724 | - foreach ( $keys as $key ) { |
|
725 | - if ( $create && ! isset( $node[ $key ] ) ) |
|
726 | - $node[ $key ] = array(); |
|
724 | + foreach ($keys as $key) { |
|
725 | + if ($create && ! isset($node[$key])) |
|
726 | + $node[$key] = array(); |
|
727 | 727 | |
728 | - if ( ! is_array( $node ) || ! isset( $node[ $key ] ) ) |
|
728 | + if ( ! is_array($node) || ! isset($node[$key])) |
|
729 | 729 | return; |
730 | 730 | |
731 | - $node = &$node[ $key ]; |
|
731 | + $node = &$node[$key]; |
|
732 | 732 | } |
733 | 733 | |
734 | - if ( $create ) { |
|
735 | - if ( ! is_array( $node ) ) { |
|
734 | + if ($create) { |
|
735 | + if ( ! is_array($node)) { |
|
736 | 736 | // account for an array overriding a string or object value |
737 | 737 | $node = array(); |
738 | 738 | } |
739 | - if ( ! isset( $node[ $last ] ) ) { |
|
740 | - $node[ $last ] = array(); |
|
739 | + if ( ! isset($node[$last])) { |
|
740 | + $node[$last] = array(); |
|
741 | 741 | } |
742 | 742 | } |
743 | 743 | |
744 | - if ( ! isset( $node[ $last ] ) ) |
|
744 | + if ( ! isset($node[$last])) |
|
745 | 745 | return; |
746 | 746 | |
747 | 747 | return array( |
@@ -761,16 +761,16 @@ discard block |
||
761 | 761 | * @param mixed $value The value to update. |
762 | 762 | * @return mixed |
763 | 763 | */ |
764 | - final protected function multidimensional_replace( $root, $keys, $value ) { |
|
765 | - if ( ! isset( $value ) ) |
|
764 | + final protected function multidimensional_replace($root, $keys, $value) { |
|
765 | + if ( ! isset($value)) |
|
766 | 766 | return $root; |
767 | - elseif ( empty( $keys ) ) // If there are no keys, we're replacing the root. |
|
767 | + elseif (empty($keys)) // If there are no keys, we're replacing the root. |
|
768 | 768 | return $value; |
769 | 769 | |
770 | - $result = $this->multidimensional( $root, $keys, true ); |
|
770 | + $result = $this->multidimensional($root, $keys, true); |
|
771 | 771 | |
772 | - if ( isset( $result ) ) |
|
773 | - $result['node'][ $result['key'] ] = $value; |
|
772 | + if (isset($result)) |
|
773 | + $result['node'][$result['key']] = $value; |
|
774 | 774 | |
775 | 775 | return $root; |
776 | 776 | } |
@@ -785,12 +785,12 @@ discard block |
||
785 | 785 | * @param mixed $default A default value which is used as a fallback. Default is null. |
786 | 786 | * @return mixed The requested value or the default value. |
787 | 787 | */ |
788 | - final protected function multidimensional_get( $root, $keys, $default = null ) { |
|
789 | - if ( empty( $keys ) ) // If there are no keys, test the root. |
|
790 | - return isset( $root ) ? $root : $default; |
|
788 | + final protected function multidimensional_get($root, $keys, $default = null) { |
|
789 | + if (empty($keys)) // If there are no keys, test the root. |
|
790 | + return isset($root) ? $root : $default; |
|
791 | 791 | |
792 | - $result = $this->multidimensional( $root, $keys ); |
|
793 | - return isset( $result ) ? $result['node'][ $result['key'] ] : $default; |
|
792 | + $result = $this->multidimensional($root, $keys); |
|
793 | + return isset($result) ? $result['node'][$result['key']] : $default; |
|
794 | 794 | } |
795 | 795 | |
796 | 796 | /** |
@@ -802,23 +802,23 @@ discard block |
||
802 | 802 | * @param $keys |
803 | 803 | * @return bool True if value is set, false if not. |
804 | 804 | */ |
805 | - final protected function multidimensional_isset( $root, $keys ) { |
|
806 | - $result = $this->multidimensional_get( $root, $keys ); |
|
807 | - return isset( $result ); |
|
805 | + final protected function multidimensional_isset($root, $keys) { |
|
806 | + $result = $this->multidimensional_get($root, $keys); |
|
807 | + return isset($result); |
|
808 | 808 | } |
809 | 809 | } |
810 | 810 | |
811 | 811 | /** WP_Customize_Filter_Setting class */ |
812 | -require_once( ABSPATH . WPINC . '/customize/class-wp-customize-filter-setting.php' ); |
|
812 | +require_once(ABSPATH.WPINC.'/customize/class-wp-customize-filter-setting.php'); |
|
813 | 813 | |
814 | 814 | /** WP_Customize_Header_Image_Setting class */ |
815 | -require_once( ABSPATH . WPINC . '/customize/class-wp-customize-header-image-setting.php' ); |
|
815 | +require_once(ABSPATH.WPINC.'/customize/class-wp-customize-header-image-setting.php'); |
|
816 | 816 | |
817 | 817 | /** WP_Customize_Background_Image_Setting class */ |
818 | -require_once( ABSPATH . WPINC . '/customize/class-wp-customize-background-image-setting.php' ); |
|
818 | +require_once(ABSPATH.WPINC.'/customize/class-wp-customize-background-image-setting.php'); |
|
819 | 819 | |
820 | 820 | /** WP_Customize_Nav_Menu_Item_Setting class */ |
821 | -require_once( ABSPATH . WPINC . '/customize/class-wp-customize-nav-menu-item-setting.php' ); |
|
821 | +require_once(ABSPATH.WPINC.'/customize/class-wp-customize-nav-menu-item-setting.php'); |
|
822 | 822 | |
823 | 823 | /** WP_Customize_Nav_Menu_Setting class */ |
824 | -require_once( ABSPATH . WPINC . '/customize/class-wp-customize-nav-menu-setting.php' ); |
|
824 | +require_once(ABSPATH.WPINC.'/customize/class-wp-customize-nav-menu-setting.php'); |
@@ -457,8 +457,9 @@ discard block |
||
457 | 457 | final public function save() { |
458 | 458 | $value = $this->post_value(); |
459 | 459 | |
460 | - if ( ! $this->check_capabilities() || ! isset( $value ) ) |
|
461 | - return false; |
|
460 | + if ( ! $this->check_capabilities() || ! isset( $value ) ) { |
|
461 | + return false; |
|
462 | + } |
|
462 | 463 | |
463 | 464 | /** |
464 | 465 | * Fires when the WP_Customize_Setting::save() method is called. |
@@ -678,8 +679,9 @@ discard block |
||
678 | 679 | */ |
679 | 680 | $value = apply_filters( "customize_sanitize_js_{$this->id}", $this->value(), $this ); |
680 | 681 | |
681 | - if ( is_string( $value ) ) |
|
682 | - return html_entity_decode( $value, ENT_QUOTES, 'UTF-8'); |
|
682 | + if ( is_string( $value ) ) { |
|
683 | + return html_entity_decode( $value, ENT_QUOTES, 'UTF-8'); |
|
684 | + } |
|
683 | 685 | |
684 | 686 | return $value; |
685 | 687 | } |
@@ -692,11 +694,13 @@ discard block |
||
692 | 694 | * @return bool False if theme doesn't support the setting or user can't change setting, otherwise true. |
693 | 695 | */ |
694 | 696 | final public function check_capabilities() { |
695 | - if ( $this->capability && ! call_user_func_array( 'current_user_can', (array) $this->capability ) ) |
|
696 | - return false; |
|
697 | + if ( $this->capability && ! call_user_func_array( 'current_user_can', (array) $this->capability ) ) { |
|
698 | + return false; |
|
699 | + } |
|
697 | 700 | |
698 | - if ( $this->theme_supports && ! call_user_func_array( 'current_theme_supports', (array) $this->theme_supports ) ) |
|
699 | - return false; |
|
701 | + if ( $this->theme_supports && ! call_user_func_array( 'current_theme_supports', (array) $this->theme_supports ) ) { |
|
702 | + return false; |
|
703 | + } |
|
700 | 704 | |
701 | 705 | return true; |
702 | 706 | } |
@@ -712,21 +716,25 @@ discard block |
||
712 | 716 | * @return array|void Keys are 'root', 'node', and 'key'. |
713 | 717 | */ |
714 | 718 | final protected function multidimensional( &$root, $keys, $create = false ) { |
715 | - if ( $create && empty( $root ) ) |
|
716 | - $root = array(); |
|
719 | + if ( $create && empty( $root ) ) { |
|
720 | + $root = array(); |
|
721 | + } |
|
717 | 722 | |
718 | - if ( ! isset( $root ) || empty( $keys ) ) |
|
719 | - return; |
|
723 | + if ( ! isset( $root ) || empty( $keys ) ) { |
|
724 | + return; |
|
725 | + } |
|
720 | 726 | |
721 | 727 | $last = array_pop( $keys ); |
722 | 728 | $node = &$root; |
723 | 729 | |
724 | 730 | foreach ( $keys as $key ) { |
725 | - if ( $create && ! isset( $node[ $key ] ) ) |
|
726 | - $node[ $key ] = array(); |
|
731 | + if ( $create && ! isset( $node[ $key ] ) ) { |
|
732 | + $node[ $key ] = array(); |
|
733 | + } |
|
727 | 734 | |
728 | - if ( ! is_array( $node ) || ! isset( $node[ $key ] ) ) |
|
729 | - return; |
|
735 | + if ( ! is_array( $node ) || ! isset( $node[ $key ] ) ) { |
|
736 | + return; |
|
737 | + } |
|
730 | 738 | |
731 | 739 | $node = &$node[ $key ]; |
732 | 740 | } |
@@ -741,8 +749,9 @@ discard block |
||
741 | 749 | } |
742 | 750 | } |
743 | 751 | |
744 | - if ( ! isset( $node[ $last ] ) ) |
|
745 | - return; |
|
752 | + if ( ! isset( $node[ $last ] ) ) { |
|
753 | + return; |
|
754 | + } |
|
746 | 755 | |
747 | 756 | return array( |
748 | 757 | 'root' => &$root, |
@@ -762,15 +771,18 @@ discard block |
||
762 | 771 | * @return mixed |
763 | 772 | */ |
764 | 773 | final protected function multidimensional_replace( $root, $keys, $value ) { |
765 | - if ( ! isset( $value ) ) |
|
766 | - return $root; |
|
767 | - elseif ( empty( $keys ) ) // If there are no keys, we're replacing the root. |
|
774 | + if ( ! isset( $value ) ) { |
|
775 | + return $root; |
|
776 | + } elseif ( empty( $keys ) ) { |
|
777 | + // If there are no keys, we're replacing the root. |
|
768 | 778 | return $value; |
779 | + } |
|
769 | 780 | |
770 | 781 | $result = $this->multidimensional( $root, $keys, true ); |
771 | 782 | |
772 | - if ( isset( $result ) ) |
|
773 | - $result['node'][ $result['key'] ] = $value; |
|
783 | + if ( isset( $result ) ) { |
|
784 | + $result['node'][ $result['key'] ] = $value; |
|
785 | + } |
|
774 | 786 | |
775 | 787 | return $root; |
776 | 788 | } |
@@ -786,8 +798,10 @@ discard block |
||
786 | 798 | * @return mixed The requested value or the default value. |
787 | 799 | */ |
788 | 800 | final protected function multidimensional_get( $root, $keys, $default = null ) { |
789 | - if ( empty( $keys ) ) // If there are no keys, test the root. |
|
801 | + if ( empty( $keys ) ) { |
|
802 | + // If there are no keys, test the root. |
|
790 | 803 | return isset( $root ) ? $root : $default; |
804 | + } |
|
791 | 805 | |
792 | 806 | $result = $this->multidimensional( $root, $keys ); |
793 | 807 | return isset( $result ) ? $result['node'][ $result['key'] ] : $default; |