@@ -63,7 +63,7 @@ |
||
63 | 63 | * @since 4.4.0 |
64 | 64 | * @access public |
65 | 65 | * |
66 | - * @return array Map of header name to header value. |
|
66 | + * @return integer Map of header name to header value. |
|
67 | 67 | */ |
68 | 68 | public function get_headers() { |
69 | 69 | return $this->headers; |
@@ -1,11 +1,11 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * HTTP API: WP_HTTP_Response class |
|
4 | - * |
|
5 | - * @package WordPress |
|
6 | - * @subpackage HTTP |
|
7 | - * @since 4.4.0 |
|
8 | - */ |
|
3 | + * HTTP API: WP_HTTP_Response class |
|
4 | + * |
|
5 | + * @package WordPress |
|
6 | + * @subpackage HTTP |
|
7 | + * @since 4.4.0 |
|
8 | + */ |
|
9 | 9 | |
10 | 10 | /** |
11 | 11 | * Core class used to prepare HTTP responses. |
@@ -51,10 +51,10 @@ discard block |
||
51 | 51 | * @param int $status Optional. HTTP status code. Default 200. |
52 | 52 | * @param array $headers Optional. HTTP header map. Default empty array. |
53 | 53 | */ |
54 | - public function __construct( $data = null, $status = 200, $headers = array() ) { |
|
54 | + public function __construct($data = null, $status = 200, $headers = array()) { |
|
55 | 55 | $this->data = $data; |
56 | - $this->set_status( $status ); |
|
57 | - $this->set_headers( $headers ); |
|
56 | + $this->set_status($status); |
|
57 | + $this->set_headers($headers); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | /** |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | * |
78 | 78 | * @param array $headers Map of header name to header value. |
79 | 79 | */ |
80 | - public function set_headers( $headers ) { |
|
80 | + public function set_headers($headers) { |
|
81 | 81 | $this->headers = $headers; |
82 | 82 | } |
83 | 83 | |
@@ -92,11 +92,11 @@ discard block |
||
92 | 92 | * @param bool $replace Optional. Whether to replace an existing header of the same name. |
93 | 93 | * Default true. |
94 | 94 | */ |
95 | - public function header( $key, $value, $replace = true ) { |
|
96 | - if ( $replace || ! isset( $this->headers[ $key ] ) ) { |
|
97 | - $this->headers[ $key ] = $value; |
|
95 | + public function header($key, $value, $replace = true) { |
|
96 | + if ($replace || ! isset($this->headers[$key])) { |
|
97 | + $this->headers[$key] = $value; |
|
98 | 98 | } else { |
99 | - $this->headers[ $key ] .= ', ' . $value; |
|
99 | + $this->headers[$key] .= ', '.$value; |
|
100 | 100 | } |
101 | 101 | } |
102 | 102 | |
@@ -120,8 +120,8 @@ discard block |
||
120 | 120 | * |
121 | 121 | * @param int $code HTTP status. |
122 | 122 | */ |
123 | - public function set_status( $code ) { |
|
124 | - $this->status = absint( $code ); |
|
123 | + public function set_status($code) { |
|
124 | + $this->status = absint($code); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | * |
145 | 145 | * @param mixed $data Response data. |
146 | 146 | */ |
147 | - public function set_data( $data ) { |
|
147 | + public function set_data($data) { |
|
148 | 148 | $this->data = $data; |
149 | 149 | } |
150 | 150 |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | * |
75 | 75 | * @param string $object_type Type of object whose meta is to be lazy-loaded. Accepts 'term' or 'comment'. |
76 | 76 | * @param array $object_ids Array of object IDs. |
77 | - * @return bool|WP_Error True on success, WP_Error on failure. |
|
77 | + * @return WP_Error|null True on success, WP_Error on failure. |
|
78 | 78 | */ |
79 | 79 | public function queue_objects( $object_type, $object_ids ) { |
80 | 80 | if ( ! isset( $this->settings[ $object_type ] ) ) { |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | * @access public |
116 | 116 | * |
117 | 117 | * @param string $object_type Object type. Accepts 'comment' or 'term'. |
118 | - * @return bool|WP_Error True on success, WP_Error on failure. |
|
118 | + * @return WP_Error|null True on success, WP_Error on failure. |
|
119 | 119 | */ |
120 | 120 | public function reset_queue( $object_type ) { |
121 | 121 | if ( ! isset( $this->settings[ $object_type ] ) ) { |
@@ -1,11 +1,11 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Meta API: WP_Metadata_Lazyloader class |
|
4 | - * |
|
5 | - * @package WordPress |
|
6 | - * @subpackage Meta |
|
7 | - * @since 4.5.0 |
|
8 | - */ |
|
3 | + * Meta API: WP_Metadata_Lazyloader class |
|
4 | + * |
|
5 | + * @package WordPress |
|
6 | + * @subpackage Meta |
|
7 | + * @since 4.5.0 |
|
8 | + */ |
|
9 | 9 | |
10 | 10 | /** |
11 | 11 | * Core class used for lazy-loading object metadata. |
@@ -57,11 +57,11 @@ discard block |
||
57 | 57 | $this->settings = array( |
58 | 58 | 'term' => array( |
59 | 59 | 'filter' => 'get_term_metadata', |
60 | - 'callback' => array( $this, 'lazyload_term_meta' ), |
|
60 | + 'callback' => array($this, 'lazyload_term_meta'), |
|
61 | 61 | ), |
62 | 62 | 'comment' => array( |
63 | 63 | 'filter' => 'get_comment_metadata', |
64 | - 'callback' => array( $this, 'lazyload_comment_meta' ), |
|
64 | + 'callback' => array($this, 'lazyload_comment_meta'), |
|
65 | 65 | ), |
66 | 66 | ); |
67 | 67 | } |
@@ -76,25 +76,25 @@ discard block |
||
76 | 76 | * @param array $object_ids Array of object IDs. |
77 | 77 | * @return bool|WP_Error True on success, WP_Error on failure. |
78 | 78 | */ |
79 | - public function queue_objects( $object_type, $object_ids ) { |
|
80 | - if ( ! isset( $this->settings[ $object_type ] ) ) { |
|
81 | - return new WP_Error( 'invalid_object_type', __( 'Invalid object type' ) ); |
|
79 | + public function queue_objects($object_type, $object_ids) { |
|
80 | + if ( ! isset($this->settings[$object_type])) { |
|
81 | + return new WP_Error('invalid_object_type', __('Invalid object type')); |
|
82 | 82 | } |
83 | 83 | |
84 | - $type_settings = $this->settings[ $object_type ]; |
|
84 | + $type_settings = $this->settings[$object_type]; |
|
85 | 85 | |
86 | - if ( ! isset( $this->pending_objects[ $object_type ] ) ) { |
|
87 | - $this->pending_objects[ $object_type ] = array(); |
|
86 | + if ( ! isset($this->pending_objects[$object_type])) { |
|
87 | + $this->pending_objects[$object_type] = array(); |
|
88 | 88 | } |
89 | 89 | |
90 | - foreach ( $object_ids as $object_id ) { |
|
90 | + foreach ($object_ids as $object_id) { |
|
91 | 91 | // Keyed by ID for faster lookup. |
92 | - if ( ! isset( $this->pending_objects[ $object_type ][ $object_id ] ) ) { |
|
93 | - $this->pending_objects[ $object_type ][ $object_id ] = 1; |
|
92 | + if ( ! isset($this->pending_objects[$object_type][$object_id])) { |
|
93 | + $this->pending_objects[$object_type][$object_id] = 1; |
|
94 | 94 | } |
95 | 95 | } |
96 | 96 | |
97 | - add_filter( $type_settings['filter'], $type_settings['callback'] ); |
|
97 | + add_filter($type_settings['filter'], $type_settings['callback']); |
|
98 | 98 | |
99 | 99 | /** |
100 | 100 | * Fires after objects are added to the metadata lazy-load queue. |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | * @param string $object_type Type of object being queued. |
106 | 106 | * @param WP_Metadata_Lazyloader $lazyloader The lazy-loader object. |
107 | 107 | */ |
108 | - do_action( 'metadata_lazyloader_queued_objects', $object_ids, $object_type, $this ); |
|
108 | + do_action('metadata_lazyloader_queued_objects', $object_ids, $object_type, $this); |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | /** |
@@ -117,15 +117,15 @@ discard block |
||
117 | 117 | * @param string $object_type Object type. Accepts 'comment' or 'term'. |
118 | 118 | * @return bool|WP_Error True on success, WP_Error on failure. |
119 | 119 | */ |
120 | - public function reset_queue( $object_type ) { |
|
121 | - if ( ! isset( $this->settings[ $object_type ] ) ) { |
|
122 | - return new WP_Error( 'invalid_object_type', __( 'Invalid object type' ) ); |
|
120 | + public function reset_queue($object_type) { |
|
121 | + if ( ! isset($this->settings[$object_type])) { |
|
122 | + return new WP_Error('invalid_object_type', __('Invalid object type')); |
|
123 | 123 | } |
124 | 124 | |
125 | - $type_settings = $this->settings[ $object_type ]; |
|
125 | + $type_settings = $this->settings[$object_type]; |
|
126 | 126 | |
127 | - $this->pending_objects[ $object_type ] = array(); |
|
128 | - remove_filter( $type_settings['filter'], $type_settings['callback'] ); |
|
127 | + $this->pending_objects[$object_type] = array(); |
|
128 | + remove_filter($type_settings['filter'], $type_settings['callback']); |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | /** |
@@ -141,12 +141,12 @@ discard block |
||
141 | 141 | * @return mixed In order not to short-circuit `get_metadata()`. Generally, this is `null`, but it could be |
142 | 142 | * another value if filtered by a plugin. |
143 | 143 | */ |
144 | - public function lazyload_term_meta( $check ) { |
|
145 | - if ( ! empty( $this->pending_objects['term'] ) ) { |
|
146 | - update_termmeta_cache( array_keys( $this->pending_objects['term'] ) ); |
|
144 | + public function lazyload_term_meta($check) { |
|
145 | + if ( ! empty($this->pending_objects['term'])) { |
|
146 | + update_termmeta_cache(array_keys($this->pending_objects['term'])); |
|
147 | 147 | |
148 | 148 | // No need to run again for this set of terms. |
149 | - $this->reset_queue( 'term' ); |
|
149 | + $this->reset_queue('term'); |
|
150 | 150 | } |
151 | 151 | |
152 | 152 | return $check; |
@@ -163,12 +163,12 @@ discard block |
||
163 | 163 | * @param mixed $check The `$check` param passed from the 'get_comment_metadata' hook. |
164 | 164 | * @return mixed The original value of `$check`, so as not to short-circuit `get_comment_metadata()`. |
165 | 165 | */ |
166 | - public function lazyload_comment_meta( $check ) { |
|
167 | - if ( ! empty( $this->pending_objects['comment'] ) ) { |
|
168 | - update_meta_cache( 'comment', array_keys( $this->pending_objects['comment'] ) ); |
|
166 | + public function lazyload_comment_meta($check) { |
|
167 | + if ( ! empty($this->pending_objects['comment'])) { |
|
168 | + update_meta_cache('comment', array_keys($this->pending_objects['comment'])); |
|
169 | 169 | |
170 | 170 | // No need to run again for this set of comments. |
171 | - $this->reset_queue( 'comment' ); |
|
171 | + $this->reset_queue('comment'); |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | return $check; |
@@ -205,7 +205,7 @@ |
||
205 | 205 | * @global wpdb $wpdb WordPress database abstraction object. |
206 | 206 | * |
207 | 207 | * @param int $post_id Post ID. |
208 | - * @return WP_Post|false Post object, false otherwise. |
|
208 | + * @return string Post object, false otherwise. |
|
209 | 209 | */ |
210 | 210 | public static function get_instance( $post_id ) { |
211 | 211 | global $wpdb; |
@@ -1,11 +1,11 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Post API: WP_Post class |
|
4 | - * |
|
5 | - * @package WordPress |
|
6 | - * @subpackage Post |
|
7 | - * @since 4.4.0 |
|
8 | - */ |
|
3 | + * Post API: WP_Post class |
|
4 | + * |
|
5 | + * @package WordPress |
|
6 | + * @subpackage Post |
|
7 | + * @since 4.4.0 |
|
8 | + */ |
|
9 | 9 | |
10 | 10 | /** |
11 | 11 | * Core class used to implement the WP_Post object. |
@@ -207,28 +207,28 @@ discard block |
||
207 | 207 | * @param int $post_id Post ID. |
208 | 208 | * @return WP_Post|false Post object, false otherwise. |
209 | 209 | */ |
210 | - public static function get_instance( $post_id ) { |
|
210 | + public static function get_instance($post_id) { |
|
211 | 211 | global $wpdb; |
212 | 212 | |
213 | 213 | $post_id = (int) $post_id; |
214 | - if ( ! $post_id ) |
|
214 | + if ( ! $post_id) |
|
215 | 215 | return false; |
216 | 216 | |
217 | - $_post = wp_cache_get( $post_id, 'posts' ); |
|
217 | + $_post = wp_cache_get($post_id, 'posts'); |
|
218 | 218 | |
219 | - if ( ! $_post ) { |
|
220 | - $_post = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE ID = %d LIMIT 1", $post_id ) ); |
|
219 | + if ( ! $_post) { |
|
220 | + $_post = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->posts WHERE ID = %d LIMIT 1", $post_id)); |
|
221 | 221 | |
222 | - if ( ! $_post ) |
|
222 | + if ( ! $_post) |
|
223 | 223 | return false; |
224 | 224 | |
225 | - $_post = sanitize_post( $_post, 'raw' ); |
|
226 | - wp_cache_add( $_post->ID, $_post, 'posts' ); |
|
227 | - } elseif ( empty( $_post->filter ) ) { |
|
228 | - $_post = sanitize_post( $_post, 'raw' ); |
|
225 | + $_post = sanitize_post($_post, 'raw'); |
|
226 | + wp_cache_add($_post->ID, $_post, 'posts'); |
|
227 | + } elseif (empty($_post->filter)) { |
|
228 | + $_post = sanitize_post($_post, 'raw'); |
|
229 | 229 | } |
230 | 230 | |
231 | - return new WP_Post( $_post ); |
|
231 | + return new WP_Post($_post); |
|
232 | 232 | } |
233 | 233 | |
234 | 234 | /** |
@@ -236,8 +236,8 @@ discard block |
||
236 | 236 | * |
237 | 237 | * @param WP_Post|object $post Post object. |
238 | 238 | */ |
239 | - public function __construct( $post ) { |
|
240 | - foreach ( get_object_vars( $post ) as $key => $value ) |
|
239 | + public function __construct($post) { |
|
240 | + foreach (get_object_vars($post) as $key => $value) |
|
241 | 241 | $this->$key = $value; |
242 | 242 | } |
243 | 243 | |
@@ -247,20 +247,20 @@ discard block |
||
247 | 247 | * @param string $key Property to check if set. |
248 | 248 | * @return bool |
249 | 249 | */ |
250 | - public function __isset( $key ) { |
|
251 | - if ( 'ancestors' == $key ) |
|
250 | + public function __isset($key) { |
|
251 | + if ('ancestors' == $key) |
|
252 | 252 | return true; |
253 | 253 | |
254 | - if ( 'page_template' == $key ) |
|
255 | - return ( 'page' == $this->post_type ); |
|
254 | + if ('page_template' == $key) |
|
255 | + return ('page' == $this->post_type); |
|
256 | 256 | |
257 | - if ( 'post_category' == $key ) |
|
257 | + if ('post_category' == $key) |
|
258 | 258 | return true; |
259 | 259 | |
260 | - if ( 'tags_input' == $key ) |
|
260 | + if ('tags_input' == $key) |
|
261 | 261 | return true; |
262 | 262 | |
263 | - return metadata_exists( 'post', $this->ID, $key ); |
|
263 | + return metadata_exists('post', $this->ID, $key); |
|
264 | 264 | } |
265 | 265 | |
266 | 266 | /** |
@@ -269,39 +269,39 @@ discard block |
||
269 | 269 | * @param string $key Key to get. |
270 | 270 | * @return mixed |
271 | 271 | */ |
272 | - public function __get( $key ) { |
|
273 | - if ( 'page_template' == $key && $this->__isset( $key ) ) { |
|
274 | - return get_post_meta( $this->ID, '_wp_page_template', true ); |
|
272 | + public function __get($key) { |
|
273 | + if ('page_template' == $key && $this->__isset($key)) { |
|
274 | + return get_post_meta($this->ID, '_wp_page_template', true); |
|
275 | 275 | } |
276 | 276 | |
277 | - if ( 'post_category' == $key ) { |
|
278 | - if ( is_object_in_taxonomy( $this->post_type, 'category' ) ) |
|
279 | - $terms = get_the_terms( $this, 'category' ); |
|
277 | + if ('post_category' == $key) { |
|
278 | + if (is_object_in_taxonomy($this->post_type, 'category')) |
|
279 | + $terms = get_the_terms($this, 'category'); |
|
280 | 280 | |
281 | - if ( empty( $terms ) ) |
|
281 | + if (empty($terms)) |
|
282 | 282 | return array(); |
283 | 283 | |
284 | - return wp_list_pluck( $terms, 'term_id' ); |
|
284 | + return wp_list_pluck($terms, 'term_id'); |
|
285 | 285 | } |
286 | 286 | |
287 | - if ( 'tags_input' == $key ) { |
|
288 | - if ( is_object_in_taxonomy( $this->post_type, 'post_tag' ) ) |
|
289 | - $terms = get_the_terms( $this, 'post_tag' ); |
|
287 | + if ('tags_input' == $key) { |
|
288 | + if (is_object_in_taxonomy($this->post_type, 'post_tag')) |
|
289 | + $terms = get_the_terms($this, 'post_tag'); |
|
290 | 290 | |
291 | - if ( empty( $terms ) ) |
|
291 | + if (empty($terms)) |
|
292 | 292 | return array(); |
293 | 293 | |
294 | - return wp_list_pluck( $terms, 'name' ); |
|
294 | + return wp_list_pluck($terms, 'name'); |
|
295 | 295 | } |
296 | 296 | |
297 | 297 | // Rest of the values need filtering. |
298 | - if ( 'ancestors' == $key ) |
|
299 | - $value = get_post_ancestors( $this ); |
|
298 | + if ('ancestors' == $key) |
|
299 | + $value = get_post_ancestors($this); |
|
300 | 300 | else |
301 | - $value = get_post_meta( $this->ID, $key, true ); |
|
301 | + $value = get_post_meta($this->ID, $key, true); |
|
302 | 302 | |
303 | - if ( $this->filter ) |
|
304 | - $value = sanitize_post_field( $key, $value, $this->ID, $this->filter ); |
|
303 | + if ($this->filter) |
|
304 | + $value = sanitize_post_field($key, $value, $this->ID, $this->filter); |
|
305 | 305 | |
306 | 306 | return $value; |
307 | 307 | } |
@@ -312,14 +312,14 @@ discard block |
||
312 | 312 | * @param string $filter Filter. |
313 | 313 | * @return self|array|bool|object|WP_Post |
314 | 314 | */ |
315 | - public function filter( $filter ) { |
|
316 | - if ( $this->filter == $filter ) |
|
315 | + public function filter($filter) { |
|
316 | + if ($this->filter == $filter) |
|
317 | 317 | return $this; |
318 | 318 | |
319 | - if ( $filter == 'raw' ) |
|
320 | - return self::get_instance( $this->ID ); |
|
319 | + if ($filter == 'raw') |
|
320 | + return self::get_instance($this->ID); |
|
321 | 321 | |
322 | - return sanitize_post( $this, $filter ); |
|
322 | + return sanitize_post($this, $filter); |
|
323 | 323 | } |
324 | 324 | |
325 | 325 | /** |
@@ -328,11 +328,11 @@ discard block |
||
328 | 328 | * @return array Object as array. |
329 | 329 | */ |
330 | 330 | public function to_array() { |
331 | - $post = get_object_vars( $this ); |
|
331 | + $post = get_object_vars($this); |
|
332 | 332 | |
333 | - foreach ( array( 'ancestors', 'page_template', 'post_category', 'tags_input' ) as $key ) { |
|
334 | - if ( $this->__isset( $key ) ) |
|
335 | - $post[ $key ] = $this->__get( $key ); |
|
333 | + foreach (array('ancestors', 'page_template', 'post_category', 'tags_input') as $key) { |
|
334 | + if ($this->__isset($key)) |
|
335 | + $post[$key] = $this->__get($key); |
|
336 | 336 | } |
337 | 337 | |
338 | 338 | return $post; |
@@ -211,16 +211,18 @@ discard block |
||
211 | 211 | global $wpdb; |
212 | 212 | |
213 | 213 | $post_id = (int) $post_id; |
214 | - if ( ! $post_id ) |
|
215 | - return false; |
|
214 | + if ( ! $post_id ) { |
|
215 | + return false; |
|
216 | + } |
|
216 | 217 | |
217 | 218 | $_post = wp_cache_get( $post_id, 'posts' ); |
218 | 219 | |
219 | 220 | if ( ! $_post ) { |
220 | 221 | $_post = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE ID = %d LIMIT 1", $post_id ) ); |
221 | 222 | |
222 | - if ( ! $_post ) |
|
223 | - return false; |
|
223 | + if ( ! $_post ) { |
|
224 | + return false; |
|
225 | + } |
|
224 | 226 | |
225 | 227 | $_post = sanitize_post( $_post, 'raw' ); |
226 | 228 | wp_cache_add( $_post->ID, $_post, 'posts' ); |
@@ -237,8 +239,9 @@ discard block |
||
237 | 239 | * @param WP_Post|object $post Post object. |
238 | 240 | */ |
239 | 241 | public function __construct( $post ) { |
240 | - foreach ( get_object_vars( $post ) as $key => $value ) |
|
241 | - $this->$key = $value; |
|
242 | + foreach ( get_object_vars( $post ) as $key => $value ) { |
|
243 | + $this->$key = $value; |
|
244 | + } |
|
242 | 245 | } |
243 | 246 | |
244 | 247 | /** |
@@ -248,17 +251,21 @@ discard block |
||
248 | 251 | * @return bool |
249 | 252 | */ |
250 | 253 | public function __isset( $key ) { |
251 | - if ( 'ancestors' == $key ) |
|
252 | - return true; |
|
254 | + if ( 'ancestors' == $key ) { |
|
255 | + return true; |
|
256 | + } |
|
253 | 257 | |
254 | - if ( 'page_template' == $key ) |
|
255 | - return ( 'page' == $this->post_type ); |
|
258 | + if ( 'page_template' == $key ) { |
|
259 | + return ( 'page' == $this->post_type ); |
|
260 | + } |
|
256 | 261 | |
257 | - if ( 'post_category' == $key ) |
|
258 | - return true; |
|
262 | + if ( 'post_category' == $key ) { |
|
263 | + return true; |
|
264 | + } |
|
259 | 265 | |
260 | - if ( 'tags_input' == $key ) |
|
261 | - return true; |
|
266 | + if ( 'tags_input' == $key ) { |
|
267 | + return true; |
|
268 | + } |
|
262 | 269 | |
263 | 270 | return metadata_exists( 'post', $this->ID, $key ); |
264 | 271 | } |
@@ -275,33 +282,39 @@ discard block |
||
275 | 282 | } |
276 | 283 | |
277 | 284 | if ( 'post_category' == $key ) { |
278 | - if ( is_object_in_taxonomy( $this->post_type, 'category' ) ) |
|
279 | - $terms = get_the_terms( $this, 'category' ); |
|
285 | + if ( is_object_in_taxonomy( $this->post_type, 'category' ) ) { |
|
286 | + $terms = get_the_terms( $this, 'category' ); |
|
287 | + } |
|
280 | 288 | |
281 | - if ( empty( $terms ) ) |
|
282 | - return array(); |
|
289 | + if ( empty( $terms ) ) { |
|
290 | + return array(); |
|
291 | + } |
|
283 | 292 | |
284 | 293 | return wp_list_pluck( $terms, 'term_id' ); |
285 | 294 | } |
286 | 295 | |
287 | 296 | if ( 'tags_input' == $key ) { |
288 | - if ( is_object_in_taxonomy( $this->post_type, 'post_tag' ) ) |
|
289 | - $terms = get_the_terms( $this, 'post_tag' ); |
|
297 | + if ( is_object_in_taxonomy( $this->post_type, 'post_tag' ) ) { |
|
298 | + $terms = get_the_terms( $this, 'post_tag' ); |
|
299 | + } |
|
290 | 300 | |
291 | - if ( empty( $terms ) ) |
|
292 | - return array(); |
|
301 | + if ( empty( $terms ) ) { |
|
302 | + return array(); |
|
303 | + } |
|
293 | 304 | |
294 | 305 | return wp_list_pluck( $terms, 'name' ); |
295 | 306 | } |
296 | 307 | |
297 | 308 | // Rest of the values need filtering. |
298 | - if ( 'ancestors' == $key ) |
|
299 | - $value = get_post_ancestors( $this ); |
|
300 | - else |
|
301 | - $value = get_post_meta( $this->ID, $key, true ); |
|
309 | + if ( 'ancestors' == $key ) { |
|
310 | + $value = get_post_ancestors( $this ); |
|
311 | + } else { |
|
312 | + $value = get_post_meta( $this->ID, $key, true ); |
|
313 | + } |
|
302 | 314 | |
303 | - if ( $this->filter ) |
|
304 | - $value = sanitize_post_field( $key, $value, $this->ID, $this->filter ); |
|
315 | + if ( $this->filter ) { |
|
316 | + $value = sanitize_post_field( $key, $value, $this->ID, $this->filter ); |
|
317 | + } |
|
305 | 318 | |
306 | 319 | return $value; |
307 | 320 | } |
@@ -313,11 +326,13 @@ discard block |
||
313 | 326 | * @return self|array|bool|object|WP_Post |
314 | 327 | */ |
315 | 328 | public function filter( $filter ) { |
316 | - if ( $this->filter == $filter ) |
|
317 | - return $this; |
|
329 | + if ( $this->filter == $filter ) { |
|
330 | + return $this; |
|
331 | + } |
|
318 | 332 | |
319 | - if ( $filter == 'raw' ) |
|
320 | - return self::get_instance( $this->ID ); |
|
333 | + if ( $filter == 'raw' ) { |
|
334 | + return self::get_instance( $this->ID ); |
|
335 | + } |
|
321 | 336 | |
322 | 337 | return sanitize_post( $this, $filter ); |
323 | 338 | } |
@@ -331,8 +346,9 @@ discard block |
||
331 | 346 | $post = get_object_vars( $this ); |
332 | 347 | |
333 | 348 | foreach ( array( 'ancestors', 'page_template', 'post_category', 'tags_input' ) as $key ) { |
334 | - if ( $this->__isset( $key ) ) |
|
335 | - $post[ $key ] = $this->__get( $key ); |
|
349 | + if ( $this->__isset( $key ) ) { |
|
350 | + $post[ $key ] = $this->__get( $key ); |
|
351 | + } |
|
336 | 352 | } |
337 | 353 | |
338 | 354 | return $post; |
@@ -440,7 +440,7 @@ discard block |
||
440 | 440 | * and care should be taken to use $theme->display('Name') to get a properly |
441 | 441 | * translated header. |
442 | 442 | * |
443 | - * @param mixed $offset |
|
443 | + * @param string $offset |
|
444 | 444 | * @return mixed |
445 | 445 | */ |
446 | 446 | public function offsetGet( $offset ) { |
@@ -974,7 +974,7 @@ discard block |
||
974 | 974 | * @since 3.4.0 |
975 | 975 | * @access public |
976 | 976 | * |
977 | - * @param mixed $type Optional. Array of extensions to return. Defaults to all files (null). |
|
977 | + * @param string $type Optional. Array of extensions to return. Defaults to all files (null). |
|
978 | 978 | * @param int $depth Optional. How deep to search for files. Defaults to a flat scan (0 depth). -1 depth is infinite. |
979 | 979 | * @param bool $search_parent Optional. Whether to return parent files. Defaults to false. |
980 | 980 | * @return array Array of files, keyed by the path to the file relative to the theme's directory, with the values |
@@ -1,11 +1,11 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * WP_Theme Class |
|
4 | - * |
|
5 | - * @package WordPress |
|
6 | - * @subpackage Theme |
|
7 | - * @since 3.4.0 |
|
8 | - */ |
|
3 | + * WP_Theme Class |
|
4 | + * |
|
5 | + * @package WordPress |
|
6 | + * @subpackage Theme |
|
7 | + * @since 3.4.0 |
|
8 | + */ |
|
9 | 9 | final class WP_Theme implements ArrayAccess { |
10 | 10 | |
11 | 11 | /** |
@@ -705,7 +705,7 @@ discard block |
||
705 | 705 | /** |
706 | 706 | * Mark up a theme header. |
707 | 707 | * |
708 | - * @since 3.4.0 |
|
708 | + * @since 3.4.0 |
|
709 | 709 | * @access private |
710 | 710 | * |
711 | 711 | * @staticvar string $comma |
@@ -198,19 +198,19 @@ discard block |
||
198 | 198 | * @param string $theme_root Theme root. |
199 | 199 | * @param WP_Error|void $_child If this theme is a parent theme, the child may be passed for validation purposes. |
200 | 200 | */ |
201 | - public function __construct( $theme_dir, $theme_root, $_child = null ) { |
|
201 | + public function __construct($theme_dir, $theme_root, $_child = null) { |
|
202 | 202 | global $wp_theme_directories; |
203 | 203 | |
204 | 204 | // Initialize caching on first run. |
205 | - if ( ! isset( self::$persistently_cache ) ) { |
|
205 | + if ( ! isset(self::$persistently_cache)) { |
|
206 | 206 | /** This action is documented in wp-includes/theme.php */ |
207 | - self::$persistently_cache = apply_filters( 'wp_cache_themes_persistently', false, 'WP_Theme' ); |
|
208 | - if ( self::$persistently_cache ) { |
|
209 | - wp_cache_add_global_groups( 'themes' ); |
|
210 | - if ( is_int( self::$persistently_cache ) ) |
|
207 | + self::$persistently_cache = apply_filters('wp_cache_themes_persistently', false, 'WP_Theme'); |
|
208 | + if (self::$persistently_cache) { |
|
209 | + wp_cache_add_global_groups('themes'); |
|
210 | + if (is_int(self::$persistently_cache)) |
|
211 | 211 | self::$cache_expiration = self::$persistently_cache; |
212 | 212 | } else { |
213 | - wp_cache_add_non_persistent_groups( 'themes' ); |
|
213 | + wp_cache_add_non_persistent_groups('themes'); |
|
214 | 214 | } |
215 | 215 | } |
216 | 216 | |
@@ -218,114 +218,114 @@ discard block |
||
218 | 218 | $this->stylesheet = $theme_dir; |
219 | 219 | |
220 | 220 | // Correct a situation where the theme is 'some-directory/some-theme' but 'some-directory' was passed in as part of the theme root instead. |
221 | - if ( ! in_array( $theme_root, (array) $wp_theme_directories ) && in_array( dirname( $theme_root ), (array) $wp_theme_directories ) ) { |
|
222 | - $this->stylesheet = basename( $this->theme_root ) . '/' . $this->stylesheet; |
|
223 | - $this->theme_root = dirname( $theme_root ); |
|
221 | + if ( ! in_array($theme_root, (array) $wp_theme_directories) && in_array(dirname($theme_root), (array) $wp_theme_directories)) { |
|
222 | + $this->stylesheet = basename($this->theme_root).'/'.$this->stylesheet; |
|
223 | + $this->theme_root = dirname($theme_root); |
|
224 | 224 | } |
225 | 225 | |
226 | - $this->cache_hash = md5( $this->theme_root . '/' . $this->stylesheet ); |
|
227 | - $theme_file = $this->stylesheet . '/style.css'; |
|
226 | + $this->cache_hash = md5($this->theme_root.'/'.$this->stylesheet); |
|
227 | + $theme_file = $this->stylesheet.'/style.css'; |
|
228 | 228 | |
229 | - $cache = $this->cache_get( 'theme' ); |
|
229 | + $cache = $this->cache_get('theme'); |
|
230 | 230 | |
231 | - if ( is_array( $cache ) ) { |
|
232 | - foreach ( array( 'errors', 'headers', 'template' ) as $key ) { |
|
233 | - if ( isset( $cache[ $key ] ) ) |
|
234 | - $this->$key = $cache[ $key ]; |
|
231 | + if (is_array($cache)) { |
|
232 | + foreach (array('errors', 'headers', 'template') as $key) { |
|
233 | + if (isset($cache[$key])) |
|
234 | + $this->$key = $cache[$key]; |
|
235 | 235 | } |
236 | - if ( $this->errors ) |
|
236 | + if ($this->errors) |
|
237 | 237 | return; |
238 | - if ( isset( $cache['theme_root_template'] ) ) |
|
238 | + if (isset($cache['theme_root_template'])) |
|
239 | 239 | $theme_root_template = $cache['theme_root_template']; |
240 | - } elseif ( ! file_exists( $this->theme_root . '/' . $theme_file ) ) { |
|
240 | + } elseif ( ! file_exists($this->theme_root.'/'.$theme_file)) { |
|
241 | 241 | $this->headers['Name'] = $this->stylesheet; |
242 | - if ( ! file_exists( $this->theme_root . '/' . $this->stylesheet ) ) |
|
243 | - $this->errors = new WP_Error( 'theme_not_found', sprintf( __( 'The theme directory "%s" does not exist.' ), esc_html( $this->stylesheet ) ) ); |
|
242 | + if ( ! file_exists($this->theme_root.'/'.$this->stylesheet)) |
|
243 | + $this->errors = new WP_Error('theme_not_found', sprintf(__('The theme directory "%s" does not exist.'), esc_html($this->stylesheet))); |
|
244 | 244 | else |
245 | - $this->errors = new WP_Error( 'theme_no_stylesheet', __( 'Stylesheet is missing.' ) ); |
|
245 | + $this->errors = new WP_Error('theme_no_stylesheet', __('Stylesheet is missing.')); |
|
246 | 246 | $this->template = $this->stylesheet; |
247 | - $this->cache_add( 'theme', array( 'headers' => $this->headers, 'errors' => $this->errors, 'stylesheet' => $this->stylesheet, 'template' => $this->template ) ); |
|
248 | - if ( ! file_exists( $this->theme_root ) ) // Don't cache this one. |
|
249 | - $this->errors->add( 'theme_root_missing', __( 'ERROR: The themes directory is either empty or doesn’t exist. Please check your installation.' ) ); |
|
247 | + $this->cache_add('theme', array('headers' => $this->headers, 'errors' => $this->errors, 'stylesheet' => $this->stylesheet, 'template' => $this->template)); |
|
248 | + if ( ! file_exists($this->theme_root)) // Don't cache this one. |
|
249 | + $this->errors->add('theme_root_missing', __('ERROR: The themes directory is either empty or doesn’t exist. Please check your installation.')); |
|
250 | 250 | return; |
251 | - } elseif ( ! is_readable( $this->theme_root . '/' . $theme_file ) ) { |
|
251 | + } elseif ( ! is_readable($this->theme_root.'/'.$theme_file)) { |
|
252 | 252 | $this->headers['Name'] = $this->stylesheet; |
253 | - $this->errors = new WP_Error( 'theme_stylesheet_not_readable', __( 'Stylesheet is not readable.' ) ); |
|
253 | + $this->errors = new WP_Error('theme_stylesheet_not_readable', __('Stylesheet is not readable.')); |
|
254 | 254 | $this->template = $this->stylesheet; |
255 | - $this->cache_add( 'theme', array( 'headers' => $this->headers, 'errors' => $this->errors, 'stylesheet' => $this->stylesheet, 'template' => $this->template ) ); |
|
255 | + $this->cache_add('theme', array('headers' => $this->headers, 'errors' => $this->errors, 'stylesheet' => $this->stylesheet, 'template' => $this->template)); |
|
256 | 256 | return; |
257 | 257 | } else { |
258 | - $this->headers = get_file_data( $this->theme_root . '/' . $theme_file, self::$file_headers, 'theme' ); |
|
258 | + $this->headers = get_file_data($this->theme_root.'/'.$theme_file, self::$file_headers, 'theme'); |
|
259 | 259 | // Default themes always trump their pretenders. |
260 | 260 | // Properly identify default themes that are inside a directory within wp-content/themes. |
261 | - if ( $default_theme_slug = array_search( $this->headers['Name'], self::$default_themes ) ) { |
|
262 | - if ( basename( $this->stylesheet ) != $default_theme_slug ) |
|
263 | - $this->headers['Name'] .= '/' . $this->stylesheet; |
|
261 | + if ($default_theme_slug = array_search($this->headers['Name'], self::$default_themes)) { |
|
262 | + if (basename($this->stylesheet) != $default_theme_slug) |
|
263 | + $this->headers['Name'] .= '/'.$this->stylesheet; |
|
264 | 264 | } |
265 | 265 | } |
266 | 266 | |
267 | 267 | // (If template is set from cache [and there are no errors], we know it's good.) |
268 | - if ( ! $this->template && ! ( $this->template = $this->headers['Template'] ) ) { |
|
268 | + if ( ! $this->template && ! ($this->template = $this->headers['Template'])) { |
|
269 | 269 | $this->template = $this->stylesheet; |
270 | - if ( ! file_exists( $this->theme_root . '/' . $this->stylesheet . '/index.php' ) ) { |
|
270 | + if ( ! file_exists($this->theme_root.'/'.$this->stylesheet.'/index.php')) { |
|
271 | 271 | $error_message = sprintf( |
272 | 272 | /* translators: 1: index.php, 2: Codex URL, 3: style.css */ |
273 | - __( 'Template is missing. Standalone themes need to have a %1$s template file. <a href="%2$s">Child themes</a> need to have a Template header in the %3$s stylesheet.' ), |
|
273 | + __('Template is missing. Standalone themes need to have a %1$s template file. <a href="%2$s">Child themes</a> need to have a Template header in the %3$s stylesheet.'), |
|
274 | 274 | '<code>index.php</code>', |
275 | - __( 'https://codex.wordpress.org/Child_Themes' ), |
|
275 | + __('https://codex.wordpress.org/Child_Themes'), |
|
276 | 276 | '<code>style.css</code>' |
277 | 277 | ); |
278 | - $this->errors = new WP_Error( 'theme_no_index', $error_message ); |
|
279 | - $this->cache_add( 'theme', array( 'headers' => $this->headers, 'errors' => $this->errors, 'stylesheet' => $this->stylesheet, 'template' => $this->template ) ); |
|
278 | + $this->errors = new WP_Error('theme_no_index', $error_message); |
|
279 | + $this->cache_add('theme', array('headers' => $this->headers, 'errors' => $this->errors, 'stylesheet' => $this->stylesheet, 'template' => $this->template)); |
|
280 | 280 | return; |
281 | 281 | } |
282 | 282 | } |
283 | 283 | |
284 | 284 | // If we got our data from cache, we can assume that 'template' is pointing to the right place. |
285 | - if ( ! is_array( $cache ) && $this->template != $this->stylesheet && ! file_exists( $this->theme_root . '/' . $this->template . '/index.php' ) ) { |
|
285 | + if ( ! is_array($cache) && $this->template != $this->stylesheet && ! file_exists($this->theme_root.'/'.$this->template.'/index.php')) { |
|
286 | 286 | // If we're in a directory of themes inside /themes, look for the parent nearby. |
287 | 287 | // wp-content/themes/directory-of-themes/* |
288 | - $parent_dir = dirname( $this->stylesheet ); |
|
289 | - if ( '.' != $parent_dir && file_exists( $this->theme_root . '/' . $parent_dir . '/' . $this->template . '/index.php' ) ) { |
|
290 | - $this->template = $parent_dir . '/' . $this->template; |
|
291 | - } elseif ( ( $directories = search_theme_directories() ) && isset( $directories[ $this->template ] ) ) { |
|
288 | + $parent_dir = dirname($this->stylesheet); |
|
289 | + if ('.' != $parent_dir && file_exists($this->theme_root.'/'.$parent_dir.'/'.$this->template.'/index.php')) { |
|
290 | + $this->template = $parent_dir.'/'.$this->template; |
|
291 | + } elseif (($directories = search_theme_directories()) && isset($directories[$this->template])) { |
|
292 | 292 | // Look for the template in the search_theme_directories() results, in case it is in another theme root. |
293 | 293 | // We don't look into directories of themes, just the theme root. |
294 | - $theme_root_template = $directories[ $this->template ]['theme_root']; |
|
294 | + $theme_root_template = $directories[$this->template]['theme_root']; |
|
295 | 295 | } else { |
296 | 296 | // Parent theme is missing. |
297 | - $this->errors = new WP_Error( 'theme_no_parent', sprintf( __( 'The parent theme is missing. Please install the "%s" parent theme.' ), esc_html( $this->template ) ) ); |
|
298 | - $this->cache_add( 'theme', array( 'headers' => $this->headers, 'errors' => $this->errors, 'stylesheet' => $this->stylesheet, 'template' => $this->template ) ); |
|
299 | - $this->parent = new WP_Theme( $this->template, $this->theme_root, $this ); |
|
297 | + $this->errors = new WP_Error('theme_no_parent', sprintf(__('The parent theme is missing. Please install the "%s" parent theme.'), esc_html($this->template))); |
|
298 | + $this->cache_add('theme', array('headers' => $this->headers, 'errors' => $this->errors, 'stylesheet' => $this->stylesheet, 'template' => $this->template)); |
|
299 | + $this->parent = new WP_Theme($this->template, $this->theme_root, $this); |
|
300 | 300 | return; |
301 | 301 | } |
302 | 302 | } |
303 | 303 | |
304 | 304 | // Set the parent, if we're a child theme. |
305 | - if ( $this->template != $this->stylesheet ) { |
|
305 | + if ($this->template != $this->stylesheet) { |
|
306 | 306 | // If we are a parent, then there is a problem. Only two generations allowed! Cancel things out. |
307 | - if ( $_child instanceof WP_Theme && $_child->template == $this->stylesheet ) { |
|
307 | + if ($_child instanceof WP_Theme && $_child->template == $this->stylesheet) { |
|
308 | 308 | $_child->parent = null; |
309 | - $_child->errors = new WP_Error( 'theme_parent_invalid', sprintf( __( 'The "%s" theme is not a valid parent theme.' ), esc_html( $_child->template ) ) ); |
|
310 | - $_child->cache_add( 'theme', array( 'headers' => $_child->headers, 'errors' => $_child->errors, 'stylesheet' => $_child->stylesheet, 'template' => $_child->template ) ); |
|
309 | + $_child->errors = new WP_Error('theme_parent_invalid', sprintf(__('The "%s" theme is not a valid parent theme.'), esc_html($_child->template))); |
|
310 | + $_child->cache_add('theme', array('headers' => $_child->headers, 'errors' => $_child->errors, 'stylesheet' => $_child->stylesheet, 'template' => $_child->template)); |
|
311 | 311 | // The two themes actually reference each other with the Template header. |
312 | - if ( $_child->stylesheet == $this->template ) { |
|
313 | - $this->errors = new WP_Error( 'theme_parent_invalid', sprintf( __( 'The "%s" theme is not a valid parent theme.' ), esc_html( $this->template ) ) ); |
|
314 | - $this->cache_add( 'theme', array( 'headers' => $this->headers, 'errors' => $this->errors, 'stylesheet' => $this->stylesheet, 'template' => $this->template ) ); |
|
312 | + if ($_child->stylesheet == $this->template) { |
|
313 | + $this->errors = new WP_Error('theme_parent_invalid', sprintf(__('The "%s" theme is not a valid parent theme.'), esc_html($this->template))); |
|
314 | + $this->cache_add('theme', array('headers' => $this->headers, 'errors' => $this->errors, 'stylesheet' => $this->stylesheet, 'template' => $this->template)); |
|
315 | 315 | } |
316 | 316 | return; |
317 | 317 | } |
318 | 318 | // Set the parent. Pass the current instance so we can do the crazy checks above and assess errors. |
319 | - $this->parent = new WP_Theme( $this->template, isset( $theme_root_template ) ? $theme_root_template : $this->theme_root, $this ); |
|
319 | + $this->parent = new WP_Theme($this->template, isset($theme_root_template) ? $theme_root_template : $this->theme_root, $this); |
|
320 | 320 | } |
321 | 321 | |
322 | 322 | // We're good. If we didn't retrieve from cache, set it. |
323 | - if ( ! is_array( $cache ) ) { |
|
324 | - $cache = array( 'headers' => $this->headers, 'errors' => $this->errors, 'stylesheet' => $this->stylesheet, 'template' => $this->template ); |
|
323 | + if ( ! is_array($cache)) { |
|
324 | + $cache = array('headers' => $this->headers, 'errors' => $this->errors, 'stylesheet' => $this->stylesheet, 'template' => $this->template); |
|
325 | 325 | // If the parent theme is in another root, we'll want to cache this. Avoids an entire branch of filesystem calls above. |
326 | - if ( isset( $theme_root_template ) ) |
|
326 | + if (isset($theme_root_template)) |
|
327 | 327 | $cache['theme_root_template'] = $theme_root_template; |
328 | - $this->cache_add( 'theme', $cache ); |
|
328 | + $this->cache_add('theme', $cache); |
|
329 | 329 | } |
330 | 330 | } |
331 | 331 | |
@@ -346,13 +346,13 @@ discard block |
||
346 | 346 | * @param string $offset Property to check if set. |
347 | 347 | * @return bool Whether the given property is set. |
348 | 348 | */ |
349 | - public function __isset( $offset ) { |
|
349 | + public function __isset($offset) { |
|
350 | 350 | static $properties = array( |
351 | 351 | 'name', 'title', 'version', 'parent_theme', 'template_dir', 'stylesheet_dir', 'template', 'stylesheet', |
352 | 352 | 'screenshot', 'description', 'author', 'tags', 'theme_root', 'theme_root_uri', |
353 | 353 | ); |
354 | 354 | |
355 | - return in_array( $offset, $properties ); |
|
355 | + return in_array($offset, $properties); |
|
356 | 356 | } |
357 | 357 | |
358 | 358 | /** |
@@ -361,8 +361,8 @@ discard block |
||
361 | 361 | * @param string $offset Property to get. |
362 | 362 | * @return mixed Property value. |
363 | 363 | */ |
364 | - public function __get( $offset ) { |
|
365 | - switch ( $offset ) { |
|
364 | + public function __get($offset) { |
|
365 | + switch ($offset) { |
|
366 | 366 | case 'name' : |
367 | 367 | case 'title' : |
368 | 368 | return $this->get('Name'); |
@@ -379,21 +379,21 @@ discard block |
||
379 | 379 | case 'stylesheet' : |
380 | 380 | return $this->get_stylesheet(); |
381 | 381 | case 'screenshot' : |
382 | - return $this->get_screenshot( 'relative' ); |
|
382 | + return $this->get_screenshot('relative'); |
|
383 | 383 | // 'author' and 'description' did not previously return translated data. |
384 | 384 | case 'description' : |
385 | 385 | return $this->display('Description'); |
386 | 386 | case 'author' : |
387 | 387 | return $this->display('Author'); |
388 | 388 | case 'tags' : |
389 | - return $this->get( 'Tags' ); |
|
389 | + return $this->get('Tags'); |
|
390 | 390 | case 'theme_root' : |
391 | 391 | return $this->get_theme_root(); |
392 | 392 | case 'theme_root_uri' : |
393 | 393 | return $this->get_theme_root_uri(); |
394 | 394 | // For cases where the array was converted to an object. |
395 | 395 | default : |
396 | - return $this->offsetGet( $offset ); |
|
396 | + return $this->offsetGet($offset); |
|
397 | 397 | } |
398 | 398 | } |
399 | 399 | |
@@ -403,14 +403,14 @@ discard block |
||
403 | 403 | * @param mixed $offset |
404 | 404 | * @param mixed $value |
405 | 405 | */ |
406 | - public function offsetSet( $offset, $value ) {} |
|
406 | + public function offsetSet($offset, $value) {} |
|
407 | 407 | |
408 | 408 | /** |
409 | 409 | * Method to implement ArrayAccess for keys formerly returned by get_themes() |
410 | 410 | * |
411 | 411 | * @param mixed $offset |
412 | 412 | */ |
413 | - public function offsetUnset( $offset ) {} |
|
413 | + public function offsetUnset($offset) {} |
|
414 | 414 | |
415 | 415 | /** |
416 | 416 | * Method to implement ArrayAccess for keys formerly returned by get_themes() |
@@ -420,14 +420,14 @@ discard block |
||
420 | 420 | * @param mixed $offset |
421 | 421 | * @return bool |
422 | 422 | */ |
423 | - public function offsetExists( $offset ) { |
|
423 | + public function offsetExists($offset) { |
|
424 | 424 | static $keys = array( |
425 | 425 | 'Name', 'Version', 'Status', 'Title', 'Author', 'Author Name', 'Author URI', 'Description', |
426 | 426 | 'Template', 'Stylesheet', 'Template Files', 'Stylesheet Files', 'Template Dir', 'Stylesheet Dir', |
427 | 427 | 'Screenshot', 'Tags', 'Theme Root', 'Theme Root URI', 'Parent Theme', |
428 | 428 | ); |
429 | 429 | |
430 | - return in_array( $offset, $keys ); |
|
430 | + return in_array($offset, $keys); |
|
431 | 431 | } |
432 | 432 | |
433 | 433 | /** |
@@ -443,38 +443,38 @@ discard block |
||
443 | 443 | * @param mixed $offset |
444 | 444 | * @return mixed |
445 | 445 | */ |
446 | - public function offsetGet( $offset ) { |
|
447 | - switch ( $offset ) { |
|
446 | + public function offsetGet($offset) { |
|
447 | + switch ($offset) { |
|
448 | 448 | case 'Name' : |
449 | 449 | case 'Title' : |
450 | 450 | // See note above about using translated data. get() is not ideal. |
451 | 451 | // It is only for backwards compatibility. Use display(). |
452 | 452 | return $this->get('Name'); |
453 | 453 | case 'Author' : |
454 | - return $this->display( 'Author'); |
|
454 | + return $this->display('Author'); |
|
455 | 455 | case 'Author Name' : |
456 | - return $this->display( 'Author', false); |
|
456 | + return $this->display('Author', false); |
|
457 | 457 | case 'Author URI' : |
458 | 458 | return $this->display('AuthorURI'); |
459 | 459 | case 'Description' : |
460 | - return $this->display( 'Description'); |
|
460 | + return $this->display('Description'); |
|
461 | 461 | case 'Version' : |
462 | 462 | case 'Status' : |
463 | - return $this->get( $offset ); |
|
463 | + return $this->get($offset); |
|
464 | 464 | case 'Template' : |
465 | 465 | return $this->get_template(); |
466 | 466 | case 'Stylesheet' : |
467 | 467 | return $this->get_stylesheet(); |
468 | 468 | case 'Template Files' : |
469 | - return $this->get_files( 'php', 1, true ); |
|
469 | + return $this->get_files('php', 1, true); |
|
470 | 470 | case 'Stylesheet Files' : |
471 | - return $this->get_files( 'css', 0, false ); |
|
471 | + return $this->get_files('css', 0, false); |
|
472 | 472 | case 'Template Dir' : |
473 | 473 | return $this->get_template_directory(); |
474 | 474 | case 'Stylesheet Dir' : |
475 | 475 | return $this->get_stylesheet_directory(); |
476 | 476 | case 'Screenshot' : |
477 | - return $this->get_screenshot( 'relative' ); |
|
477 | + return $this->get_screenshot('relative'); |
|
478 | 478 | case 'Tags' : |
479 | 479 | return $this->get('Tags'); |
480 | 480 | case 'Theme Root' : |
@@ -497,7 +497,7 @@ discard block |
||
497 | 497 | * @return WP_Error|false WP_Error if there are errors, or false. |
498 | 498 | */ |
499 | 499 | public function errors() { |
500 | - return is_wp_error( $this->errors ) ? $this->errors : false; |
|
500 | + return is_wp_error($this->errors) ? $this->errors : false; |
|
501 | 501 | } |
502 | 502 | |
503 | 503 | /** |
@@ -512,7 +512,7 @@ discard block |
||
512 | 512 | * @return bool Whether the theme exists. |
513 | 513 | */ |
514 | 514 | public function exists() { |
515 | - return ! ( $this->errors() && in_array( 'theme_not_found', $this->errors()->get_error_codes() ) ); |
|
515 | + return ! ($this->errors() && in_array('theme_not_found', $this->errors()->get_error_codes())); |
|
516 | 516 | } |
517 | 517 | |
518 | 518 | /** |
@@ -524,7 +524,7 @@ discard block |
||
524 | 524 | * @return WP_Theme|false Parent theme, or false if the current theme is not a child theme. |
525 | 525 | */ |
526 | 526 | public function parent() { |
527 | - return isset( $this->parent ) ? $this->parent : false; |
|
527 | + return isset($this->parent) ? $this->parent : false; |
|
528 | 528 | } |
529 | 529 | |
530 | 530 | /** |
@@ -539,8 +539,8 @@ discard block |
||
539 | 539 | * @param string $data Data to store |
540 | 540 | * @return bool Return value from wp_cache_add() |
541 | 541 | */ |
542 | - private function cache_add( $key, $data ) { |
|
543 | - return wp_cache_add( $key . '-' . $this->cache_hash, $data, 'themes', self::$cache_expiration ); |
|
542 | + private function cache_add($key, $data) { |
|
543 | + return wp_cache_add($key.'-'.$this->cache_hash, $data, 'themes', self::$cache_expiration); |
|
544 | 544 | } |
545 | 545 | |
546 | 546 | /** |
@@ -554,8 +554,8 @@ discard block |
||
554 | 554 | * @param string $key Type of data to retrieve (theme, screenshot, headers, page_templates) |
555 | 555 | * @return mixed Retrieved data |
556 | 556 | */ |
557 | - private function cache_get( $key ) { |
|
558 | - return wp_cache_get( $key . '-' . $this->cache_hash, 'themes' ); |
|
557 | + private function cache_get($key) { |
|
558 | + return wp_cache_get($key.'-'.$this->cache_hash, 'themes'); |
|
559 | 559 | } |
560 | 560 | |
561 | 561 | /** |
@@ -565,11 +565,11 @@ discard block |
||
565 | 565 | * @access public |
566 | 566 | */ |
567 | 567 | public function cache_delete() { |
568 | - foreach ( array( 'theme', 'screenshot', 'headers', 'page_templates' ) as $key ) |
|
569 | - wp_cache_delete( $key . '-' . $this->cache_hash, 'themes' ); |
|
568 | + foreach (array('theme', 'screenshot', 'headers', 'page_templates') as $key) |
|
569 | + wp_cache_delete($key.'-'.$this->cache_hash, 'themes'); |
|
570 | 570 | $this->template = $this->textdomain_loaded = $this->theme_root_uri = $this->parent = $this->errors = $this->headers_sanitized = $this->name_translated = null; |
571 | 571 | $this->headers = array(); |
572 | - $this->__construct( $this->stylesheet, $this->theme_root ); |
|
572 | + $this->__construct($this->stylesheet, $this->theme_root); |
|
573 | 573 | } |
574 | 574 | |
575 | 575 | /** |
@@ -589,29 +589,29 @@ discard block |
||
589 | 589 | * @param string $header Theme header. Name, Description, Author, Version, ThemeURI, AuthorURI, Status, Tags. |
590 | 590 | * @return string|false String on success, false on failure. |
591 | 591 | */ |
592 | - public function get( $header ) { |
|
593 | - if ( ! isset( $this->headers[ $header ] ) ) |
|
592 | + public function get($header) { |
|
593 | + if ( ! isset($this->headers[$header])) |
|
594 | 594 | return false; |
595 | 595 | |
596 | - if ( ! isset( $this->headers_sanitized ) ) { |
|
597 | - $this->headers_sanitized = $this->cache_get( 'headers' ); |
|
598 | - if ( ! is_array( $this->headers_sanitized ) ) |
|
596 | + if ( ! isset($this->headers_sanitized)) { |
|
597 | + $this->headers_sanitized = $this->cache_get('headers'); |
|
598 | + if ( ! is_array($this->headers_sanitized)) |
|
599 | 599 | $this->headers_sanitized = array(); |
600 | 600 | } |
601 | 601 | |
602 | - if ( isset( $this->headers_sanitized[ $header ] ) ) |
|
603 | - return $this->headers_sanitized[ $header ]; |
|
602 | + if (isset($this->headers_sanitized[$header])) |
|
603 | + return $this->headers_sanitized[$header]; |
|
604 | 604 | |
605 | 605 | // If themes are a persistent group, sanitize everything and cache it. One cache add is better than many cache sets. |
606 | - if ( self::$persistently_cache ) { |
|
607 | - foreach ( array_keys( $this->headers ) as $_header ) |
|
608 | - $this->headers_sanitized[ $_header ] = $this->sanitize_header( $_header, $this->headers[ $_header ] ); |
|
609 | - $this->cache_add( 'headers', $this->headers_sanitized ); |
|
606 | + if (self::$persistently_cache) { |
|
607 | + foreach (array_keys($this->headers) as $_header) |
|
608 | + $this->headers_sanitized[$_header] = $this->sanitize_header($_header, $this->headers[$_header]); |
|
609 | + $this->cache_add('headers', $this->headers_sanitized); |
|
610 | 610 | } else { |
611 | - $this->headers_sanitized[ $header ] = $this->sanitize_header( $header, $this->headers[ $header ] ); |
|
611 | + $this->headers_sanitized[$header] = $this->sanitize_header($header, $this->headers[$header]); |
|
612 | 612 | } |
613 | 613 | |
614 | - return $this->headers_sanitized[ $header ]; |
|
614 | + return $this->headers_sanitized[$header]; |
|
615 | 615 | } |
616 | 616 | |
617 | 617 | /** |
@@ -625,20 +625,20 @@ discard block |
||
625 | 625 | * @param bool $translate Optional. Whether to translate the header. Defaults to true. |
626 | 626 | * @return string|false Processed header, false on failure. |
627 | 627 | */ |
628 | - public function display( $header, $markup = true, $translate = true ) { |
|
629 | - $value = $this->get( $header ); |
|
630 | - if ( false === $value ) { |
|
628 | + public function display($header, $markup = true, $translate = true) { |
|
629 | + $value = $this->get($header); |
|
630 | + if (false === $value) { |
|
631 | 631 | return false; |
632 | 632 | } |
633 | 633 | |
634 | - if ( $translate && ( empty( $value ) || ! $this->load_textdomain() ) ) |
|
634 | + if ($translate && (empty($value) || ! $this->load_textdomain())) |
|
635 | 635 | $translate = false; |
636 | 636 | |
637 | - if ( $translate ) |
|
638 | - $value = $this->translate_header( $header, $value ); |
|
637 | + if ($translate) |
|
638 | + $value = $this->translate_header($header, $value); |
|
639 | 639 | |
640 | - if ( $markup ) |
|
641 | - $value = $this->markup_header( $header, $value, $translate ); |
|
640 | + if ($markup) |
|
641 | + $value = $this->markup_header($header, $value, $translate); |
|
642 | 642 | |
643 | 643 | return $value; |
644 | 644 | } |
@@ -656,46 +656,46 @@ discard block |
||
656 | 656 | * @param string $value Value to sanitize. |
657 | 657 | * @return mixed |
658 | 658 | */ |
659 | - private function sanitize_header( $header, $value ) { |
|
660 | - switch ( $header ) { |
|
659 | + private function sanitize_header($header, $value) { |
|
660 | + switch ($header) { |
|
661 | 661 | case 'Status' : |
662 | - if ( ! $value ) { |
|
662 | + if ( ! $value) { |
|
663 | 663 | $value = 'publish'; |
664 | 664 | break; |
665 | 665 | } |
666 | 666 | // Fall through otherwise. |
667 | 667 | case 'Name' : |
668 | 668 | static $header_tags = array( |
669 | - 'abbr' => array( 'title' => true ), |
|
670 | - 'acronym' => array( 'title' => true ), |
|
669 | + 'abbr' => array('title' => true), |
|
670 | + 'acronym' => array('title' => true), |
|
671 | 671 | 'code' => true, |
672 | 672 | 'em' => true, |
673 | 673 | 'strong' => true, |
674 | 674 | ); |
675 | - $value = wp_kses( $value, $header_tags ); |
|
675 | + $value = wp_kses($value, $header_tags); |
|
676 | 676 | break; |
677 | 677 | case 'Author' : |
678 | 678 | // There shouldn't be anchor tags in Author, but some themes like to be challenging. |
679 | 679 | case 'Description' : |
680 | 680 | static $header_tags_with_a = array( |
681 | - 'a' => array( 'href' => true, 'title' => true ), |
|
682 | - 'abbr' => array( 'title' => true ), |
|
683 | - 'acronym' => array( 'title' => true ), |
|
681 | + 'a' => array('href' => true, 'title' => true), |
|
682 | + 'abbr' => array('title' => true), |
|
683 | + 'acronym' => array('title' => true), |
|
684 | 684 | 'code' => true, |
685 | 685 | 'em' => true, |
686 | 686 | 'strong' => true, |
687 | 687 | ); |
688 | - $value = wp_kses( $value, $header_tags_with_a ); |
|
688 | + $value = wp_kses($value, $header_tags_with_a); |
|
689 | 689 | break; |
690 | 690 | case 'ThemeURI' : |
691 | 691 | case 'AuthorURI' : |
692 | - $value = esc_url_raw( $value ); |
|
692 | + $value = esc_url_raw($value); |
|
693 | 693 | break; |
694 | 694 | case 'Tags' : |
695 | - $value = array_filter( array_map( 'trim', explode( ',', strip_tags( $value ) ) ) ); |
|
695 | + $value = array_filter(array_map('trim', explode(',', strip_tags($value)))); |
|
696 | 696 | break; |
697 | 697 | case 'Version' : |
698 | - $value = strip_tags( $value ); |
|
698 | + $value = strip_tags($value); |
|
699 | 699 | break; |
700 | 700 | } |
701 | 701 | |
@@ -715,33 +715,33 @@ discard block |
||
715 | 715 | * @param string $translate Whether the header has been translated. |
716 | 716 | * @return string Value, marked up. |
717 | 717 | */ |
718 | - private function markup_header( $header, $value, $translate ) { |
|
719 | - switch ( $header ) { |
|
718 | + private function markup_header($header, $value, $translate) { |
|
719 | + switch ($header) { |
|
720 | 720 | case 'Name' : |
721 | - if ( empty( $value ) ) |
|
721 | + if (empty($value)) |
|
722 | 722 | $value = $this->get_stylesheet(); |
723 | 723 | break; |
724 | 724 | case 'Description' : |
725 | - $value = wptexturize( $value ); |
|
725 | + $value = wptexturize($value); |
|
726 | 726 | break; |
727 | 727 | case 'Author' : |
728 | - if ( $this->get('AuthorURI') ) { |
|
729 | - $value = sprintf( '<a href="%1$s">%2$s</a>', $this->display( 'AuthorURI', true, $translate ), $value ); |
|
730 | - } elseif ( ! $value ) { |
|
731 | - $value = __( 'Anonymous' ); |
|
728 | + if ($this->get('AuthorURI')) { |
|
729 | + $value = sprintf('<a href="%1$s">%2$s</a>', $this->display('AuthorURI', true, $translate), $value); |
|
730 | + } elseif ( ! $value) { |
|
731 | + $value = __('Anonymous'); |
|
732 | 732 | } |
733 | 733 | break; |
734 | 734 | case 'Tags' : |
735 | 735 | static $comma = null; |
736 | - if ( ! isset( $comma ) ) { |
|
736 | + if ( ! isset($comma)) { |
|
737 | 737 | /* translators: used between list items, there is a space after the comma */ |
738 | - $comma = __( ', ' ); |
|
738 | + $comma = __(', '); |
|
739 | 739 | } |
740 | - $value = implode( $comma, $value ); |
|
740 | + $value = implode($comma, $value); |
|
741 | 741 | break; |
742 | 742 | case 'ThemeURI' : |
743 | 743 | case 'AuthorURI' : |
744 | - $value = esc_url( $value ); |
|
744 | + $value = esc_url($value); |
|
745 | 745 | break; |
746 | 746 | } |
747 | 747 | |
@@ -760,38 +760,38 @@ discard block |
||
760 | 760 | * @param string $value Value to translate. |
761 | 761 | * @return string Translated value. |
762 | 762 | */ |
763 | - private function translate_header( $header, $value ) { |
|
764 | - switch ( $header ) { |
|
763 | + private function translate_header($header, $value) { |
|
764 | + switch ($header) { |
|
765 | 765 | case 'Name' : |
766 | 766 | // Cached for sorting reasons. |
767 | - if ( isset( $this->name_translated ) ) |
|
767 | + if (isset($this->name_translated)) |
|
768 | 768 | return $this->name_translated; |
769 | - $this->name_translated = translate( $value, $this->get('TextDomain' ) ); |
|
769 | + $this->name_translated = translate($value, $this->get('TextDomain')); |
|
770 | 770 | return $this->name_translated; |
771 | 771 | case 'Tags' : |
772 | - if ( empty( $value ) || ! function_exists( 'get_theme_feature_list' ) ) |
|
772 | + if (empty($value) || ! function_exists('get_theme_feature_list')) |
|
773 | 773 | return $value; |
774 | 774 | |
775 | 775 | static $tags_list; |
776 | - if ( ! isset( $tags_list ) ) { |
|
776 | + if ( ! isset($tags_list)) { |
|
777 | 777 | $tags_list = array(); |
778 | - $feature_list = get_theme_feature_list( false ); // No API |
|
779 | - foreach ( $feature_list as $tags ) |
|
778 | + $feature_list = get_theme_feature_list(false); // No API |
|
779 | + foreach ($feature_list as $tags) |
|
780 | 780 | $tags_list += $tags; |
781 | 781 | } |
782 | 782 | |
783 | - foreach ( $value as &$tag ) { |
|
784 | - if ( isset( $tags_list[ $tag ] ) ) { |
|
785 | - $tag = $tags_list[ $tag ]; |
|
786 | - } elseif ( isset( self::$tag_map[ $tag ] ) ) { |
|
787 | - $tag = $tags_list[ self::$tag_map[ $tag ] ]; |
|
783 | + foreach ($value as &$tag) { |
|
784 | + if (isset($tags_list[$tag])) { |
|
785 | + $tag = $tags_list[$tag]; |
|
786 | + } elseif (isset(self::$tag_map[$tag])) { |
|
787 | + $tag = $tags_list[self::$tag_map[$tag]]; |
|
788 | 788 | } |
789 | 789 | } |
790 | 790 | |
791 | 791 | return $value; |
792 | 792 | |
793 | 793 | default : |
794 | - $value = translate( $value, $this->get('TextDomain') ); |
|
794 | + $value = translate($value, $this->get('TextDomain')); |
|
795 | 795 | } |
796 | 796 | return $value; |
797 | 797 | } |
@@ -838,10 +838,10 @@ discard block |
||
838 | 838 | * @return string Absolute path of the stylesheet directory. |
839 | 839 | */ |
840 | 840 | public function get_stylesheet_directory() { |
841 | - if ( $this->errors() && in_array( 'theme_root_missing', $this->errors()->get_error_codes() ) ) |
|
841 | + if ($this->errors() && in_array('theme_root_missing', $this->errors()->get_error_codes())) |
|
842 | 842 | return ''; |
843 | 843 | |
844 | - return $this->theme_root . '/' . $this->stylesheet; |
|
844 | + return $this->theme_root.'/'.$this->stylesheet; |
|
845 | 845 | } |
846 | 846 | |
847 | 847 | /** |
@@ -856,12 +856,12 @@ discard block |
||
856 | 856 | * @return string Absolute path of the template directory. |
857 | 857 | */ |
858 | 858 | public function get_template_directory() { |
859 | - if ( $this->parent() ) |
|
859 | + if ($this->parent()) |
|
860 | 860 | $theme_root = $this->parent()->theme_root; |
861 | 861 | else |
862 | 862 | $theme_root = $this->theme_root; |
863 | 863 | |
864 | - return $theme_root . '/' . $this->template; |
|
864 | + return $theme_root.'/'.$this->template; |
|
865 | 865 | } |
866 | 866 | |
867 | 867 | /** |
@@ -876,7 +876,7 @@ discard block |
||
876 | 876 | * @return string URL to the stylesheet directory. |
877 | 877 | */ |
878 | 878 | public function get_stylesheet_directory_uri() { |
879 | - return $this->get_theme_root_uri() . '/' . str_replace( '%2F', '/', rawurlencode( $this->stylesheet ) ); |
|
879 | + return $this->get_theme_root_uri().'/'.str_replace('%2F', '/', rawurlencode($this->stylesheet)); |
|
880 | 880 | } |
881 | 881 | |
882 | 882 | /** |
@@ -891,12 +891,12 @@ discard block |
||
891 | 891 | * @return string URL to the template directory. |
892 | 892 | */ |
893 | 893 | public function get_template_directory_uri() { |
894 | - if ( $this->parent() ) |
|
894 | + if ($this->parent()) |
|
895 | 895 | $theme_root_uri = $this->parent()->get_theme_root_uri(); |
896 | 896 | else |
897 | 897 | $theme_root_uri = $this->get_theme_root_uri(); |
898 | 898 | |
899 | - return $theme_root_uri . '/' . str_replace( '%2F', '/', rawurlencode( $this->template ) ); |
|
899 | + return $theme_root_uri.'/'.str_replace('%2F', '/', rawurlencode($this->template)); |
|
900 | 900 | } |
901 | 901 | |
902 | 902 | /** |
@@ -926,8 +926,8 @@ discard block |
||
926 | 926 | * @return string Theme root URI. |
927 | 927 | */ |
928 | 928 | public function get_theme_root_uri() { |
929 | - if ( ! isset( $this->theme_root_uri ) ) |
|
930 | - $this->theme_root_uri = get_theme_root_uri( $this->stylesheet, $this->theme_root ); |
|
929 | + if ( ! isset($this->theme_root_uri)) |
|
930 | + $this->theme_root_uri = get_theme_root_uri($this->stylesheet, $this->theme_root); |
|
931 | 931 | return $this->theme_root_uri; |
932 | 932 | } |
933 | 933 | |
@@ -945,26 +945,26 @@ discard block |
||
945 | 945 | * @param string $uri Type of URL to return, either 'relative' or an absolute URI. Defaults to absolute URI. |
946 | 946 | * @return string|false Screenshot file. False if the theme does not have a screenshot. |
947 | 947 | */ |
948 | - public function get_screenshot( $uri = 'uri' ) { |
|
949 | - $screenshot = $this->cache_get( 'screenshot' ); |
|
950 | - if ( $screenshot ) { |
|
951 | - if ( 'relative' == $uri ) |
|
948 | + public function get_screenshot($uri = 'uri') { |
|
949 | + $screenshot = $this->cache_get('screenshot'); |
|
950 | + if ($screenshot) { |
|
951 | + if ('relative' == $uri) |
|
952 | 952 | return $screenshot; |
953 | - return $this->get_stylesheet_directory_uri() . '/' . $screenshot; |
|
954 | - } elseif ( 0 === $screenshot ) { |
|
953 | + return $this->get_stylesheet_directory_uri().'/'.$screenshot; |
|
954 | + } elseif (0 === $screenshot) { |
|
955 | 955 | return false; |
956 | 956 | } |
957 | 957 | |
958 | - foreach ( array( 'png', 'gif', 'jpg', 'jpeg' ) as $ext ) { |
|
959 | - if ( file_exists( $this->get_stylesheet_directory() . "/screenshot.$ext" ) ) { |
|
960 | - $this->cache_add( 'screenshot', 'screenshot.' . $ext ); |
|
961 | - if ( 'relative' == $uri ) |
|
962 | - return 'screenshot.' . $ext; |
|
963 | - return $this->get_stylesheet_directory_uri() . '/' . 'screenshot.' . $ext; |
|
958 | + foreach (array('png', 'gif', 'jpg', 'jpeg') as $ext) { |
|
959 | + if (file_exists($this->get_stylesheet_directory()."/screenshot.$ext")) { |
|
960 | + $this->cache_add('screenshot', 'screenshot.'.$ext); |
|
961 | + if ('relative' == $uri) |
|
962 | + return 'screenshot.'.$ext; |
|
963 | + return $this->get_stylesheet_directory_uri().'/'.'screenshot.'.$ext; |
|
964 | 964 | } |
965 | 965 | } |
966 | 966 | |
967 | - $this->cache_add( 'screenshot', 0 ); |
|
967 | + $this->cache_add('screenshot', 0); |
|
968 | 968 | return false; |
969 | 969 | } |
970 | 970 | |
@@ -980,11 +980,11 @@ discard block |
||
980 | 980 | * @return array Array of files, keyed by the path to the file relative to the theme's directory, with the values |
981 | 981 | * being absolute paths. |
982 | 982 | */ |
983 | - public function get_files( $type = null, $depth = 0, $search_parent = false ) { |
|
984 | - $files = (array) self::scandir( $this->get_stylesheet_directory(), $type, $depth ); |
|
983 | + public function get_files($type = null, $depth = 0, $search_parent = false) { |
|
984 | + $files = (array) self::scandir($this->get_stylesheet_directory(), $type, $depth); |
|
985 | 985 | |
986 | - if ( $search_parent && $this->parent() ) |
|
987 | - $files += (array) self::scandir( $this->get_template_directory(), $type, $depth ); |
|
986 | + if ($search_parent && $this->parent()) |
|
987 | + $files += (array) self::scandir($this->get_template_directory(), $type, $depth); |
|
988 | 988 | |
989 | 989 | return $files; |
990 | 990 | } |
@@ -998,35 +998,35 @@ discard block |
||
998 | 998 | * @param WP_Post|null $post Optional. The post being edited, provided for context. |
999 | 999 | * @return array Array of page templates, keyed by filename, with the value of the translated header name. |
1000 | 1000 | */ |
1001 | - public function get_page_templates( $post = null ) { |
|
1001 | + public function get_page_templates($post = null) { |
|
1002 | 1002 | // If you screw up your current theme and we invalidate your parent, most things still work. Let it slide. |
1003 | - if ( $this->errors() && $this->errors()->get_error_codes() !== array( 'theme_parent_invalid' ) ) |
|
1003 | + if ($this->errors() && $this->errors()->get_error_codes() !== array('theme_parent_invalid')) |
|
1004 | 1004 | return array(); |
1005 | 1005 | |
1006 | - $page_templates = $this->cache_get( 'page_templates' ); |
|
1006 | + $page_templates = $this->cache_get('page_templates'); |
|
1007 | 1007 | |
1008 | - if ( ! is_array( $page_templates ) ) { |
|
1008 | + if ( ! is_array($page_templates)) { |
|
1009 | 1009 | $page_templates = array(); |
1010 | 1010 | |
1011 | - $files = (array) $this->get_files( 'php', 1 ); |
|
1011 | + $files = (array) $this->get_files('php', 1); |
|
1012 | 1012 | |
1013 | - foreach ( $files as $file => $full_path ) { |
|
1014 | - if ( ! preg_match( '|Template Name:(.*)$|mi', file_get_contents( $full_path ), $header ) ) |
|
1013 | + foreach ($files as $file => $full_path) { |
|
1014 | + if ( ! preg_match('|Template Name:(.*)$|mi', file_get_contents($full_path), $header)) |
|
1015 | 1015 | continue; |
1016 | - $page_templates[ $file ] = _cleanup_header_comment( $header[1] ); |
|
1016 | + $page_templates[$file] = _cleanup_header_comment($header[1]); |
|
1017 | 1017 | } |
1018 | 1018 | |
1019 | - $this->cache_add( 'page_templates', $page_templates ); |
|
1019 | + $this->cache_add('page_templates', $page_templates); |
|
1020 | 1020 | } |
1021 | 1021 | |
1022 | - if ( $this->load_textdomain() ) { |
|
1023 | - foreach ( $page_templates as &$page_template ) { |
|
1024 | - $page_template = $this->translate_header( 'Template Name', $page_template ); |
|
1022 | + if ($this->load_textdomain()) { |
|
1023 | + foreach ($page_templates as &$page_template) { |
|
1024 | + $page_template = $this->translate_header('Template Name', $page_template); |
|
1025 | 1025 | } |
1026 | 1026 | } |
1027 | 1027 | |
1028 | - if ( $this->parent() ) |
|
1029 | - $page_templates += $this->parent()->get_page_templates( $post ); |
|
1028 | + if ($this->parent()) |
|
1029 | + $page_templates += $this->parent()->get_page_templates($post); |
|
1030 | 1030 | |
1031 | 1031 | /** |
1032 | 1032 | * Filter list of page templates for a theme. |
@@ -1039,7 +1039,7 @@ discard block |
||
1039 | 1039 | * @param WP_Theme $this The theme object. |
1040 | 1040 | * @param WP_Post|null $post The post being edited, provided for context, or null. |
1041 | 1041 | */ |
1042 | - return (array) apply_filters( 'theme_page_templates', $page_templates, $this, $post ); |
|
1042 | + return (array) apply_filters('theme_page_templates', $page_templates, $this, $post); |
|
1043 | 1043 | } |
1044 | 1044 | |
1045 | 1045 | /** |
@@ -1061,32 +1061,32 @@ discard block |
||
1061 | 1061 | * @return array|false Array of files, keyed by the path to the file relative to the `$path` directory prepended |
1062 | 1062 | * with `$relative_path`, with the values being absolute paths. False otherwise. |
1063 | 1063 | */ |
1064 | - private static function scandir( $path, $extensions = null, $depth = 0, $relative_path = '' ) { |
|
1065 | - if ( ! is_dir( $path ) ) |
|
1064 | + private static function scandir($path, $extensions = null, $depth = 0, $relative_path = '') { |
|
1065 | + if ( ! is_dir($path)) |
|
1066 | 1066 | return false; |
1067 | 1067 | |
1068 | - if ( $extensions ) { |
|
1068 | + if ($extensions) { |
|
1069 | 1069 | $extensions = (array) $extensions; |
1070 | - $_extensions = implode( '|', $extensions ); |
|
1070 | + $_extensions = implode('|', $extensions); |
|
1071 | 1071 | } |
1072 | 1072 | |
1073 | - $relative_path = trailingslashit( $relative_path ); |
|
1074 | - if ( '/' == $relative_path ) |
|
1073 | + $relative_path = trailingslashit($relative_path); |
|
1074 | + if ('/' == $relative_path) |
|
1075 | 1075 | $relative_path = ''; |
1076 | 1076 | |
1077 | - $results = scandir( $path ); |
|
1077 | + $results = scandir($path); |
|
1078 | 1078 | $files = array(); |
1079 | 1079 | |
1080 | - foreach ( $results as $result ) { |
|
1081 | - if ( '.' == $result[0] ) |
|
1080 | + foreach ($results as $result) { |
|
1081 | + if ('.' == $result[0]) |
|
1082 | 1082 | continue; |
1083 | - if ( is_dir( $path . '/' . $result ) ) { |
|
1084 | - if ( ! $depth || 'CVS' == $result ) |
|
1083 | + if (is_dir($path.'/'.$result)) { |
|
1084 | + if ( ! $depth || 'CVS' == $result) |
|
1085 | 1085 | continue; |
1086 | - $found = self::scandir( $path . '/' . $result, $extensions, $depth - 1 , $relative_path . $result ); |
|
1087 | - $files = array_merge_recursive( $files, $found ); |
|
1088 | - } elseif ( ! $extensions || preg_match( '~\.(' . $_extensions . ')$~', $result ) ) { |
|
1089 | - $files[ $relative_path . $result ] = $path . '/' . $result; |
|
1086 | + $found = self::scandir($path.'/'.$result, $extensions, $depth - 1, $relative_path.$result); |
|
1087 | + $files = array_merge_recursive($files, $found); |
|
1088 | + } elseif ( ! $extensions || preg_match('~\.('.$_extensions.')$~', $result)) { |
|
1089 | + $files[$relative_path.$result] = $path.'/'.$result; |
|
1090 | 1090 | } |
1091 | 1091 | } |
1092 | 1092 | |
@@ -1106,27 +1106,27 @@ discard block |
||
1106 | 1106 | * False if no textdomain was specified in the file headers, or if the domain could not be loaded. |
1107 | 1107 | */ |
1108 | 1108 | public function load_textdomain() { |
1109 | - if ( isset( $this->textdomain_loaded ) ) |
|
1109 | + if (isset($this->textdomain_loaded)) |
|
1110 | 1110 | return $this->textdomain_loaded; |
1111 | 1111 | |
1112 | 1112 | $textdomain = $this->get('TextDomain'); |
1113 | - if ( ! $textdomain ) { |
|
1113 | + if ( ! $textdomain) { |
|
1114 | 1114 | $this->textdomain_loaded = false; |
1115 | 1115 | return false; |
1116 | 1116 | } |
1117 | 1117 | |
1118 | - if ( is_textdomain_loaded( $textdomain ) ) { |
|
1118 | + if (is_textdomain_loaded($textdomain)) { |
|
1119 | 1119 | $this->textdomain_loaded = true; |
1120 | 1120 | return true; |
1121 | 1121 | } |
1122 | 1122 | |
1123 | 1123 | $path = $this->get_stylesheet_directory(); |
1124 | - if ( $domainpath = $this->get('DomainPath') ) |
|
1124 | + if ($domainpath = $this->get('DomainPath')) |
|
1125 | 1125 | $path .= $domainpath; |
1126 | 1126 | else |
1127 | 1127 | $path .= '/languages'; |
1128 | 1128 | |
1129 | - $this->textdomain_loaded = load_theme_textdomain( $textdomain, $path ); |
|
1129 | + $this->textdomain_loaded = load_theme_textdomain($textdomain, $path); |
|
1130 | 1130 | return $this->textdomain_loaded; |
1131 | 1131 | } |
1132 | 1132 | |
@@ -1141,19 +1141,19 @@ discard block |
||
1141 | 1141 | * @param int $blog_id Optional. Ignored if only network-wide settings are checked. Defaults to current site. |
1142 | 1142 | * @return bool Whether the theme is allowed for the network. Returns true in single-site. |
1143 | 1143 | */ |
1144 | - public function is_allowed( $check = 'both', $blog_id = null ) { |
|
1145 | - if ( ! is_multisite() ) |
|
1144 | + public function is_allowed($check = 'both', $blog_id = null) { |
|
1145 | + if ( ! is_multisite()) |
|
1146 | 1146 | return true; |
1147 | 1147 | |
1148 | - if ( 'both' == $check || 'network' == $check ) { |
|
1148 | + if ('both' == $check || 'network' == $check) { |
|
1149 | 1149 | $allowed = self::get_allowed_on_network(); |
1150 | - if ( ! empty( $allowed[ $this->get_stylesheet() ] ) ) |
|
1150 | + if ( ! empty($allowed[$this->get_stylesheet()])) |
|
1151 | 1151 | return true; |
1152 | 1152 | } |
1153 | 1153 | |
1154 | - if ( 'both' == $check || 'site' == $check ) { |
|
1155 | - $allowed = self::get_allowed_on_site( $blog_id ); |
|
1156 | - if ( ! empty( $allowed[ $this->get_stylesheet() ] ) ) |
|
1154 | + if ('both' == $check || 'site' == $check) { |
|
1155 | + $allowed = self::get_allowed_on_site($blog_id); |
|
1156 | + if ( ! empty($allowed[$this->get_stylesheet()])) |
|
1157 | 1157 | return true; |
1158 | 1158 | } |
1159 | 1159 | |
@@ -1168,9 +1168,9 @@ discard block |
||
1168 | 1168 | * @return WP_Theme|false Object, or false if no theme is installed, which would be bad. |
1169 | 1169 | */ |
1170 | 1170 | public static function get_core_default_theme() { |
1171 | - foreach ( array_reverse( self::$default_themes ) as $slug => $name ) { |
|
1172 | - $theme = wp_get_theme( $slug ); |
|
1173 | - if ( $theme->exists() ) { |
|
1171 | + foreach (array_reverse(self::$default_themes) as $slug => $name) { |
|
1172 | + $theme = wp_get_theme($slug); |
|
1173 | + if ($theme->exists()) { |
|
1174 | 1174 | return $theme; |
1175 | 1175 | } |
1176 | 1176 | } |
@@ -1188,7 +1188,7 @@ discard block |
||
1188 | 1188 | * @param int $blog_id Optional. ID of the site. Defaults to the current site. |
1189 | 1189 | * @return array Array of stylesheet names. |
1190 | 1190 | */ |
1191 | - public static function get_allowed( $blog_id = null ) { |
|
1191 | + public static function get_allowed($blog_id = null) { |
|
1192 | 1192 | /** |
1193 | 1193 | * Filter the array of themes allowed on the network. |
1194 | 1194 | * |
@@ -1200,8 +1200,8 @@ discard block |
||
1200 | 1200 | * @param array $allowed_themes An array of theme stylesheet names. |
1201 | 1201 | * @param int $blog_id ID of the site. |
1202 | 1202 | */ |
1203 | - $network = (array) apply_filters( 'network_allowed_themes', self::get_allowed_on_network(), $blog_id ); |
|
1204 | - return $network + self::get_allowed_on_site( $blog_id ); |
|
1203 | + $network = (array) apply_filters('network_allowed_themes', self::get_allowed_on_network(), $blog_id); |
|
1204 | + return $network + self::get_allowed_on_site($blog_id); |
|
1205 | 1205 | } |
1206 | 1206 | |
1207 | 1207 | /** |
@@ -1218,8 +1218,8 @@ discard block |
||
1218 | 1218 | */ |
1219 | 1219 | public static function get_allowed_on_network() { |
1220 | 1220 | static $allowed_themes; |
1221 | - if ( ! isset( $allowed_themes ) ) { |
|
1222 | - $allowed_themes = (array) get_site_option( 'allowedthemes' ); |
|
1221 | + if ( ! isset($allowed_themes)) { |
|
1222 | + $allowed_themes = (array) get_site_option('allowedthemes'); |
|
1223 | 1223 | } |
1224 | 1224 | |
1225 | 1225 | /** |
@@ -1229,7 +1229,7 @@ discard block |
||
1229 | 1229 | * |
1230 | 1230 | * @param array $allowed_themes An array of theme stylesheet names. |
1231 | 1231 | */ |
1232 | - $allowed_themes = apply_filters( 'allowed_themes', $allowed_themes ); |
|
1232 | + $allowed_themes = apply_filters('allowed_themes', $allowed_themes); |
|
1233 | 1233 | |
1234 | 1234 | return $allowed_themes; |
1235 | 1235 | } |
@@ -1247,13 +1247,13 @@ discard block |
||
1247 | 1247 | * @param int $blog_id Optional. ID of the site. Defaults to the current site. |
1248 | 1248 | * @return array Array of stylesheet names. |
1249 | 1249 | */ |
1250 | - public static function get_allowed_on_site( $blog_id = null ) { |
|
1250 | + public static function get_allowed_on_site($blog_id = null) { |
|
1251 | 1251 | static $allowed_themes = array(); |
1252 | 1252 | |
1253 | - if ( ! $blog_id || ! is_multisite() ) |
|
1253 | + if ( ! $blog_id || ! is_multisite()) |
|
1254 | 1254 | $blog_id = get_current_blog_id(); |
1255 | 1255 | |
1256 | - if ( isset( $allowed_themes[ $blog_id ] ) ) { |
|
1256 | + if (isset($allowed_themes[$blog_id])) { |
|
1257 | 1257 | /** |
1258 | 1258 | * Filter the array of themes allowed on the site. |
1259 | 1259 | * |
@@ -1262,57 +1262,57 @@ discard block |
||
1262 | 1262 | * @param array $allowed_themes An array of theme stylesheet names. |
1263 | 1263 | * @param int $blog_id ID of the site. Defaults to current site. |
1264 | 1264 | */ |
1265 | - return (array) apply_filters( 'site_allowed_themes', $allowed_themes[ $blog_id ], $blog_id ); |
|
1265 | + return (array) apply_filters('site_allowed_themes', $allowed_themes[$blog_id], $blog_id); |
|
1266 | 1266 | } |
1267 | 1267 | |
1268 | 1268 | $current = $blog_id == get_current_blog_id(); |
1269 | 1269 | |
1270 | - if ( $current ) { |
|
1271 | - $allowed_themes[ $blog_id ] = get_option( 'allowedthemes' ); |
|
1270 | + if ($current) { |
|
1271 | + $allowed_themes[$blog_id] = get_option('allowedthemes'); |
|
1272 | 1272 | } else { |
1273 | - switch_to_blog( $blog_id ); |
|
1274 | - $allowed_themes[ $blog_id ] = get_option( 'allowedthemes' ); |
|
1273 | + switch_to_blog($blog_id); |
|
1274 | + $allowed_themes[$blog_id] = get_option('allowedthemes'); |
|
1275 | 1275 | restore_current_blog(); |
1276 | 1276 | } |
1277 | 1277 | |
1278 | 1278 | // This is all super old MU back compat joy. |
1279 | 1279 | // 'allowedthemes' keys things by stylesheet. 'allowed_themes' keyed things by name. |
1280 | - if ( false === $allowed_themes[ $blog_id ] ) { |
|
1281 | - if ( $current ) { |
|
1282 | - $allowed_themes[ $blog_id ] = get_option( 'allowed_themes' ); |
|
1280 | + if (false === $allowed_themes[$blog_id]) { |
|
1281 | + if ($current) { |
|
1282 | + $allowed_themes[$blog_id] = get_option('allowed_themes'); |
|
1283 | 1283 | } else { |
1284 | - switch_to_blog( $blog_id ); |
|
1285 | - $allowed_themes[ $blog_id ] = get_option( 'allowed_themes' ); |
|
1284 | + switch_to_blog($blog_id); |
|
1285 | + $allowed_themes[$blog_id] = get_option('allowed_themes'); |
|
1286 | 1286 | restore_current_blog(); |
1287 | 1287 | } |
1288 | 1288 | |
1289 | - if ( ! is_array( $allowed_themes[ $blog_id ] ) || empty( $allowed_themes[ $blog_id ] ) ) { |
|
1290 | - $allowed_themes[ $blog_id ] = array(); |
|
1289 | + if ( ! is_array($allowed_themes[$blog_id]) || empty($allowed_themes[$blog_id])) { |
|
1290 | + $allowed_themes[$blog_id] = array(); |
|
1291 | 1291 | } else { |
1292 | 1292 | $converted = array(); |
1293 | 1293 | $themes = wp_get_themes(); |
1294 | - foreach ( $themes as $stylesheet => $theme_data ) { |
|
1295 | - if ( isset( $allowed_themes[ $blog_id ][ $theme_data->get('Name') ] ) ) |
|
1296 | - $converted[ $stylesheet ] = true; |
|
1294 | + foreach ($themes as $stylesheet => $theme_data) { |
|
1295 | + if (isset($allowed_themes[$blog_id][$theme_data->get('Name')])) |
|
1296 | + $converted[$stylesheet] = true; |
|
1297 | 1297 | } |
1298 | - $allowed_themes[ $blog_id ] = $converted; |
|
1298 | + $allowed_themes[$blog_id] = $converted; |
|
1299 | 1299 | } |
1300 | 1300 | // Set the option so we never have to go through this pain again. |
1301 | - if ( is_admin() && $allowed_themes[ $blog_id ] ) { |
|
1302 | - if ( $current ) { |
|
1303 | - update_option( 'allowedthemes', $allowed_themes[ $blog_id ] ); |
|
1304 | - delete_option( 'allowed_themes' ); |
|
1301 | + if (is_admin() && $allowed_themes[$blog_id]) { |
|
1302 | + if ($current) { |
|
1303 | + update_option('allowedthemes', $allowed_themes[$blog_id]); |
|
1304 | + delete_option('allowed_themes'); |
|
1305 | 1305 | } else { |
1306 | - switch_to_blog( $blog_id ); |
|
1307 | - update_option( 'allowedthemes', $allowed_themes[ $blog_id ] ); |
|
1308 | - delete_option( 'allowed_themes' ); |
|
1306 | + switch_to_blog($blog_id); |
|
1307 | + update_option('allowedthemes', $allowed_themes[$blog_id]); |
|
1308 | + delete_option('allowed_themes'); |
|
1309 | 1309 | restore_current_blog(); |
1310 | 1310 | } |
1311 | 1311 | } |
1312 | 1312 | } |
1313 | 1313 | |
1314 | 1314 | /** This filter is documented in wp-includes/class-wp-theme.php */ |
1315 | - return (array) apply_filters( 'site_allowed_themes', $allowed_themes[ $blog_id ], $blog_id ); |
|
1315 | + return (array) apply_filters('site_allowed_themes', $allowed_themes[$blog_id], $blog_id); |
|
1316 | 1316 | } |
1317 | 1317 | |
1318 | 1318 | /** |
@@ -1325,11 +1325,11 @@ discard block |
||
1325 | 1325 | * |
1326 | 1326 | * @param array $themes Array of themes to sort, passed by reference. |
1327 | 1327 | */ |
1328 | - public static function sort_by_name( &$themes ) { |
|
1329 | - if ( 0 === strpos( get_locale(), 'en_' ) ) { |
|
1330 | - uasort( $themes, array( 'WP_Theme', '_name_sort' ) ); |
|
1328 | + public static function sort_by_name(&$themes) { |
|
1329 | + if (0 === strpos(get_locale(), 'en_')) { |
|
1330 | + uasort($themes, array('WP_Theme', '_name_sort')); |
|
1331 | 1331 | } else { |
1332 | - uasort( $themes, array( 'WP_Theme', '_name_sort_i18n' ) ); |
|
1332 | + uasort($themes, array('WP_Theme', '_name_sort_i18n')); |
|
1333 | 1333 | } |
1334 | 1334 | } |
1335 | 1335 | |
@@ -1349,8 +1349,8 @@ discard block |
||
1349 | 1349 | * @return int Negative if `$a` falls lower in the natural order than `$b`. Zero if they fall equally. |
1350 | 1350 | * Greater than 0 if `$a` falls higher in the natural order than `$b`. Used with usort(). |
1351 | 1351 | */ |
1352 | - private static function _name_sort( $a, $b ) { |
|
1353 | - return strnatcasecmp( $a->headers['Name'], $b->headers['Name'] ); |
|
1352 | + private static function _name_sort($a, $b) { |
|
1353 | + return strnatcasecmp($a->headers['Name'], $b->headers['Name']); |
|
1354 | 1354 | } |
1355 | 1355 | |
1356 | 1356 | /** |
@@ -1366,8 +1366,8 @@ discard block |
||
1366 | 1366 | * @return int Negative if `$a` falls lower in the natural order than `$b`. Zero if they fall equally. |
1367 | 1367 | * Greater than 0 if `$a` falls higher in the natural order than `$b`. Used with usort(). |
1368 | 1368 | */ |
1369 | - private static function _name_sort_i18n( $a, $b ) { |
|
1369 | + private static function _name_sort_i18n($a, $b) { |
|
1370 | 1370 | // Don't mark up; Do translate. |
1371 | - return strnatcasecmp( $a->display( 'Name', false, true ), $b->display( 'Name', false, true ) ); |
|
1371 | + return strnatcasecmp($a->display('Name', false, true), $b->display('Name', false, true)); |
|
1372 | 1372 | } |
1373 | 1373 | } |
@@ -207,8 +207,9 @@ discard block |
||
207 | 207 | self::$persistently_cache = apply_filters( 'wp_cache_themes_persistently', false, 'WP_Theme' ); |
208 | 208 | if ( self::$persistently_cache ) { |
209 | 209 | wp_cache_add_global_groups( 'themes' ); |
210 | - if ( is_int( self::$persistently_cache ) ) |
|
211 | - self::$cache_expiration = self::$persistently_cache; |
|
210 | + if ( is_int( self::$persistently_cache ) ) { |
|
211 | + self::$cache_expiration = self::$persistently_cache; |
|
212 | + } |
|
212 | 213 | } else { |
213 | 214 | wp_cache_add_non_persistent_groups( 'themes' ); |
214 | 215 | } |
@@ -230,23 +231,29 @@ discard block |
||
230 | 231 | |
231 | 232 | if ( is_array( $cache ) ) { |
232 | 233 | foreach ( array( 'errors', 'headers', 'template' ) as $key ) { |
233 | - if ( isset( $cache[ $key ] ) ) |
|
234 | - $this->$key = $cache[ $key ]; |
|
234 | + if ( isset( $cache[ $key ] ) ) { |
|
235 | + $this->$key = $cache[ $key ]; |
|
236 | + } |
|
237 | + } |
|
238 | + if ( $this->errors ) { |
|
239 | + return; |
|
240 | + } |
|
241 | + if ( isset( $cache['theme_root_template'] ) ) { |
|
242 | + $theme_root_template = $cache['theme_root_template']; |
|
235 | 243 | } |
236 | - if ( $this->errors ) |
|
237 | - return; |
|
238 | - if ( isset( $cache['theme_root_template'] ) ) |
|
239 | - $theme_root_template = $cache['theme_root_template']; |
|
240 | 244 | } elseif ( ! file_exists( $this->theme_root . '/' . $theme_file ) ) { |
241 | 245 | $this->headers['Name'] = $this->stylesheet; |
242 | - if ( ! file_exists( $this->theme_root . '/' . $this->stylesheet ) ) |
|
243 | - $this->errors = new WP_Error( 'theme_not_found', sprintf( __( 'The theme directory "%s" does not exist.' ), esc_html( $this->stylesheet ) ) ); |
|
244 | - else |
|
245 | - $this->errors = new WP_Error( 'theme_no_stylesheet', __( 'Stylesheet is missing.' ) ); |
|
246 | + if ( ! file_exists( $this->theme_root . '/' . $this->stylesheet ) ) { |
|
247 | + $this->errors = new WP_Error( 'theme_not_found', sprintf( __( 'The theme directory "%s" does not exist.' ), esc_html( $this->stylesheet ) ) ); |
|
248 | + } else { |
|
249 | + $this->errors = new WP_Error( 'theme_no_stylesheet', __( 'Stylesheet is missing.' ) ); |
|
250 | + } |
|
246 | 251 | $this->template = $this->stylesheet; |
247 | 252 | $this->cache_add( 'theme', array( 'headers' => $this->headers, 'errors' => $this->errors, 'stylesheet' => $this->stylesheet, 'template' => $this->template ) ); |
248 | - if ( ! file_exists( $this->theme_root ) ) // Don't cache this one. |
|
253 | + if ( ! file_exists( $this->theme_root ) ) { |
|
254 | + // Don't cache this one. |
|
249 | 255 | $this->errors->add( 'theme_root_missing', __( 'ERROR: The themes directory is either empty or doesn’t exist. Please check your installation.' ) ); |
256 | + } |
|
250 | 257 | return; |
251 | 258 | } elseif ( ! is_readable( $this->theme_root . '/' . $theme_file ) ) { |
252 | 259 | $this->headers['Name'] = $this->stylesheet; |
@@ -259,8 +266,9 @@ discard block |
||
259 | 266 | // Default themes always trump their pretenders. |
260 | 267 | // Properly identify default themes that are inside a directory within wp-content/themes. |
261 | 268 | if ( $default_theme_slug = array_search( $this->headers['Name'], self::$default_themes ) ) { |
262 | - if ( basename( $this->stylesheet ) != $default_theme_slug ) |
|
263 | - $this->headers['Name'] .= '/' . $this->stylesheet; |
|
269 | + if ( basename( $this->stylesheet ) != $default_theme_slug ) { |
|
270 | + $this->headers['Name'] .= '/' . $this->stylesheet; |
|
271 | + } |
|
264 | 272 | } |
265 | 273 | } |
266 | 274 | |
@@ -323,8 +331,9 @@ discard block |
||
323 | 331 | if ( ! is_array( $cache ) ) { |
324 | 332 | $cache = array( 'headers' => $this->headers, 'errors' => $this->errors, 'stylesheet' => $this->stylesheet, 'template' => $this->template ); |
325 | 333 | // If the parent theme is in another root, we'll want to cache this. Avoids an entire branch of filesystem calls above. |
326 | - if ( isset( $theme_root_template ) ) |
|
327 | - $cache['theme_root_template'] = $theme_root_template; |
|
334 | + if ( isset( $theme_root_template ) ) { |
|
335 | + $cache['theme_root_template'] = $theme_root_template; |
|
336 | + } |
|
328 | 337 | $this->cache_add( 'theme', $cache ); |
329 | 338 | } |
330 | 339 | } |
@@ -565,8 +574,9 @@ discard block |
||
565 | 574 | * @access public |
566 | 575 | */ |
567 | 576 | public function cache_delete() { |
568 | - foreach ( array( 'theme', 'screenshot', 'headers', 'page_templates' ) as $key ) |
|
569 | - wp_cache_delete( $key . '-' . $this->cache_hash, 'themes' ); |
|
577 | + foreach ( array( 'theme', 'screenshot', 'headers', 'page_templates' ) as $key ) { |
|
578 | + wp_cache_delete( $key . '-' . $this->cache_hash, 'themes' ); |
|
579 | + } |
|
570 | 580 | $this->template = $this->textdomain_loaded = $this->theme_root_uri = $this->parent = $this->errors = $this->headers_sanitized = $this->name_translated = null; |
571 | 581 | $this->headers = array(); |
572 | 582 | $this->__construct( $this->stylesheet, $this->theme_root ); |
@@ -590,22 +600,26 @@ discard block |
||
590 | 600 | * @return string|false String on success, false on failure. |
591 | 601 | */ |
592 | 602 | public function get( $header ) { |
593 | - if ( ! isset( $this->headers[ $header ] ) ) |
|
594 | - return false; |
|
603 | + if ( ! isset( $this->headers[ $header ] ) ) { |
|
604 | + return false; |
|
605 | + } |
|
595 | 606 | |
596 | 607 | if ( ! isset( $this->headers_sanitized ) ) { |
597 | 608 | $this->headers_sanitized = $this->cache_get( 'headers' ); |
598 | - if ( ! is_array( $this->headers_sanitized ) ) |
|
599 | - $this->headers_sanitized = array(); |
|
609 | + if ( ! is_array( $this->headers_sanitized ) ) { |
|
610 | + $this->headers_sanitized = array(); |
|
611 | + } |
|
600 | 612 | } |
601 | 613 | |
602 | - if ( isset( $this->headers_sanitized[ $header ] ) ) |
|
603 | - return $this->headers_sanitized[ $header ]; |
|
614 | + if ( isset( $this->headers_sanitized[ $header ] ) ) { |
|
615 | + return $this->headers_sanitized[ $header ]; |
|
616 | + } |
|
604 | 617 | |
605 | 618 | // If themes are a persistent group, sanitize everything and cache it. One cache add is better than many cache sets. |
606 | 619 | if ( self::$persistently_cache ) { |
607 | - foreach ( array_keys( $this->headers ) as $_header ) |
|
608 | - $this->headers_sanitized[ $_header ] = $this->sanitize_header( $_header, $this->headers[ $_header ] ); |
|
620 | + foreach ( array_keys( $this->headers ) as $_header ) { |
|
621 | + $this->headers_sanitized[ $_header ] = $this->sanitize_header( $_header, $this->headers[ $_header ] ); |
|
622 | + } |
|
609 | 623 | $this->cache_add( 'headers', $this->headers_sanitized ); |
610 | 624 | } else { |
611 | 625 | $this->headers_sanitized[ $header ] = $this->sanitize_header( $header, $this->headers[ $header ] ); |
@@ -631,14 +645,17 @@ discard block |
||
631 | 645 | return false; |
632 | 646 | } |
633 | 647 | |
634 | - if ( $translate && ( empty( $value ) || ! $this->load_textdomain() ) ) |
|
635 | - $translate = false; |
|
648 | + if ( $translate && ( empty( $value ) || ! $this->load_textdomain() ) ) { |
|
649 | + $translate = false; |
|
650 | + } |
|
636 | 651 | |
637 | - if ( $translate ) |
|
638 | - $value = $this->translate_header( $header, $value ); |
|
652 | + if ( $translate ) { |
|
653 | + $value = $this->translate_header( $header, $value ); |
|
654 | + } |
|
639 | 655 | |
640 | - if ( $markup ) |
|
641 | - $value = $this->markup_header( $header, $value, $translate ); |
|
656 | + if ( $markup ) { |
|
657 | + $value = $this->markup_header( $header, $value, $translate ); |
|
658 | + } |
|
642 | 659 | |
643 | 660 | return $value; |
644 | 661 | } |
@@ -718,8 +735,9 @@ discard block |
||
718 | 735 | private function markup_header( $header, $value, $translate ) { |
719 | 736 | switch ( $header ) { |
720 | 737 | case 'Name' : |
721 | - if ( empty( $value ) ) |
|
722 | - $value = $this->get_stylesheet(); |
|
738 | + if ( empty( $value ) ) { |
|
739 | + $value = $this->get_stylesheet(); |
|
740 | + } |
|
723 | 741 | break; |
724 | 742 | case 'Description' : |
725 | 743 | $value = wptexturize( $value ); |
@@ -764,20 +782,23 @@ discard block |
||
764 | 782 | switch ( $header ) { |
765 | 783 | case 'Name' : |
766 | 784 | // Cached for sorting reasons. |
767 | - if ( isset( $this->name_translated ) ) |
|
768 | - return $this->name_translated; |
|
785 | + if ( isset( $this->name_translated ) ) { |
|
786 | + return $this->name_translated; |
|
787 | + } |
|
769 | 788 | $this->name_translated = translate( $value, $this->get('TextDomain' ) ); |
770 | 789 | return $this->name_translated; |
771 | 790 | case 'Tags' : |
772 | - if ( empty( $value ) || ! function_exists( 'get_theme_feature_list' ) ) |
|
773 | - return $value; |
|
791 | + if ( empty( $value ) || ! function_exists( 'get_theme_feature_list' ) ) { |
|
792 | + return $value; |
|
793 | + } |
|
774 | 794 | |
775 | 795 | static $tags_list; |
776 | 796 | if ( ! isset( $tags_list ) ) { |
777 | 797 | $tags_list = array(); |
778 | 798 | $feature_list = get_theme_feature_list( false ); // No API |
779 | - foreach ( $feature_list as $tags ) |
|
780 | - $tags_list += $tags; |
|
799 | + foreach ( $feature_list as $tags ) { |
|
800 | + $tags_list += $tags; |
|
801 | + } |
|
781 | 802 | } |
782 | 803 | |
783 | 804 | foreach ( $value as &$tag ) { |
@@ -838,8 +859,9 @@ discard block |
||
838 | 859 | * @return string Absolute path of the stylesheet directory. |
839 | 860 | */ |
840 | 861 | public function get_stylesheet_directory() { |
841 | - if ( $this->errors() && in_array( 'theme_root_missing', $this->errors()->get_error_codes() ) ) |
|
842 | - return ''; |
|
862 | + if ( $this->errors() && in_array( 'theme_root_missing', $this->errors()->get_error_codes() ) ) { |
|
863 | + return ''; |
|
864 | + } |
|
843 | 865 | |
844 | 866 | return $this->theme_root . '/' . $this->stylesheet; |
845 | 867 | } |
@@ -856,10 +878,11 @@ discard block |
||
856 | 878 | * @return string Absolute path of the template directory. |
857 | 879 | */ |
858 | 880 | public function get_template_directory() { |
859 | - if ( $this->parent() ) |
|
860 | - $theme_root = $this->parent()->theme_root; |
|
861 | - else |
|
862 | - $theme_root = $this->theme_root; |
|
881 | + if ( $this->parent() ) { |
|
882 | + $theme_root = $this->parent()->theme_root; |
|
883 | + } else { |
|
884 | + $theme_root = $this->theme_root; |
|
885 | + } |
|
863 | 886 | |
864 | 887 | return $theme_root . '/' . $this->template; |
865 | 888 | } |
@@ -891,10 +914,11 @@ discard block |
||
891 | 914 | * @return string URL to the template directory. |
892 | 915 | */ |
893 | 916 | public function get_template_directory_uri() { |
894 | - if ( $this->parent() ) |
|
895 | - $theme_root_uri = $this->parent()->get_theme_root_uri(); |
|
896 | - else |
|
897 | - $theme_root_uri = $this->get_theme_root_uri(); |
|
917 | + if ( $this->parent() ) { |
|
918 | + $theme_root_uri = $this->parent()->get_theme_root_uri(); |
|
919 | + } else { |
|
920 | + $theme_root_uri = $this->get_theme_root_uri(); |
|
921 | + } |
|
898 | 922 | |
899 | 923 | return $theme_root_uri . '/' . str_replace( '%2F', '/', rawurlencode( $this->template ) ); |
900 | 924 | } |
@@ -926,8 +950,9 @@ discard block |
||
926 | 950 | * @return string Theme root URI. |
927 | 951 | */ |
928 | 952 | public function get_theme_root_uri() { |
929 | - if ( ! isset( $this->theme_root_uri ) ) |
|
930 | - $this->theme_root_uri = get_theme_root_uri( $this->stylesheet, $this->theme_root ); |
|
953 | + if ( ! isset( $this->theme_root_uri ) ) { |
|
954 | + $this->theme_root_uri = get_theme_root_uri( $this->stylesheet, $this->theme_root ); |
|
955 | + } |
|
931 | 956 | return $this->theme_root_uri; |
932 | 957 | } |
933 | 958 | |
@@ -948,8 +973,9 @@ discard block |
||
948 | 973 | public function get_screenshot( $uri = 'uri' ) { |
949 | 974 | $screenshot = $this->cache_get( 'screenshot' ); |
950 | 975 | if ( $screenshot ) { |
951 | - if ( 'relative' == $uri ) |
|
952 | - return $screenshot; |
|
976 | + if ( 'relative' == $uri ) { |
|
977 | + return $screenshot; |
|
978 | + } |
|
953 | 979 | return $this->get_stylesheet_directory_uri() . '/' . $screenshot; |
954 | 980 | } elseif ( 0 === $screenshot ) { |
955 | 981 | return false; |
@@ -958,8 +984,9 @@ discard block |
||
958 | 984 | foreach ( array( 'png', 'gif', 'jpg', 'jpeg' ) as $ext ) { |
959 | 985 | if ( file_exists( $this->get_stylesheet_directory() . "/screenshot.$ext" ) ) { |
960 | 986 | $this->cache_add( 'screenshot', 'screenshot.' . $ext ); |
961 | - if ( 'relative' == $uri ) |
|
962 | - return 'screenshot.' . $ext; |
|
987 | + if ( 'relative' == $uri ) { |
|
988 | + return 'screenshot.' . $ext; |
|
989 | + } |
|
963 | 990 | return $this->get_stylesheet_directory_uri() . '/' . 'screenshot.' . $ext; |
964 | 991 | } |
965 | 992 | } |
@@ -983,8 +1010,9 @@ discard block |
||
983 | 1010 | public function get_files( $type = null, $depth = 0, $search_parent = false ) { |
984 | 1011 | $files = (array) self::scandir( $this->get_stylesheet_directory(), $type, $depth ); |
985 | 1012 | |
986 | - if ( $search_parent && $this->parent() ) |
|
987 | - $files += (array) self::scandir( $this->get_template_directory(), $type, $depth ); |
|
1013 | + if ( $search_parent && $this->parent() ) { |
|
1014 | + $files += (array) self::scandir( $this->get_template_directory(), $type, $depth ); |
|
1015 | + } |
|
988 | 1016 | |
989 | 1017 | return $files; |
990 | 1018 | } |
@@ -1000,8 +1028,9 @@ discard block |
||
1000 | 1028 | */ |
1001 | 1029 | public function get_page_templates( $post = null ) { |
1002 | 1030 | // If you screw up your current theme and we invalidate your parent, most things still work. Let it slide. |
1003 | - if ( $this->errors() && $this->errors()->get_error_codes() !== array( 'theme_parent_invalid' ) ) |
|
1004 | - return array(); |
|
1031 | + if ( $this->errors() && $this->errors()->get_error_codes() !== array( 'theme_parent_invalid' ) ) { |
|
1032 | + return array(); |
|
1033 | + } |
|
1005 | 1034 | |
1006 | 1035 | $page_templates = $this->cache_get( 'page_templates' ); |
1007 | 1036 | |
@@ -1011,8 +1040,9 @@ discard block |
||
1011 | 1040 | $files = (array) $this->get_files( 'php', 1 ); |
1012 | 1041 | |
1013 | 1042 | foreach ( $files as $file => $full_path ) { |
1014 | - if ( ! preg_match( '|Template Name:(.*)$|mi', file_get_contents( $full_path ), $header ) ) |
|
1015 | - continue; |
|
1043 | + if ( ! preg_match( '|Template Name:(.*)$|mi', file_get_contents( $full_path ), $header ) ) { |
|
1044 | + continue; |
|
1045 | + } |
|
1016 | 1046 | $page_templates[ $file ] = _cleanup_header_comment( $header[1] ); |
1017 | 1047 | } |
1018 | 1048 | |
@@ -1025,8 +1055,9 @@ discard block |
||
1025 | 1055 | } |
1026 | 1056 | } |
1027 | 1057 | |
1028 | - if ( $this->parent() ) |
|
1029 | - $page_templates += $this->parent()->get_page_templates( $post ); |
|
1058 | + if ( $this->parent() ) { |
|
1059 | + $page_templates += $this->parent()->get_page_templates( $post ); |
|
1060 | + } |
|
1030 | 1061 | |
1031 | 1062 | /** |
1032 | 1063 | * Filter list of page templates for a theme. |
@@ -1062,8 +1093,9 @@ discard block |
||
1062 | 1093 | * with `$relative_path`, with the values being absolute paths. False otherwise. |
1063 | 1094 | */ |
1064 | 1095 | private static function scandir( $path, $extensions = null, $depth = 0, $relative_path = '' ) { |
1065 | - if ( ! is_dir( $path ) ) |
|
1066 | - return false; |
|
1096 | + if ( ! is_dir( $path ) ) { |
|
1097 | + return false; |
|
1098 | + } |
|
1067 | 1099 | |
1068 | 1100 | if ( $extensions ) { |
1069 | 1101 | $extensions = (array) $extensions; |
@@ -1071,18 +1103,21 @@ discard block |
||
1071 | 1103 | } |
1072 | 1104 | |
1073 | 1105 | $relative_path = trailingslashit( $relative_path ); |
1074 | - if ( '/' == $relative_path ) |
|
1075 | - $relative_path = ''; |
|
1106 | + if ( '/' == $relative_path ) { |
|
1107 | + $relative_path = ''; |
|
1108 | + } |
|
1076 | 1109 | |
1077 | 1110 | $results = scandir( $path ); |
1078 | 1111 | $files = array(); |
1079 | 1112 | |
1080 | 1113 | foreach ( $results as $result ) { |
1081 | - if ( '.' == $result[0] ) |
|
1082 | - continue; |
|
1114 | + if ( '.' == $result[0] ) { |
|
1115 | + continue; |
|
1116 | + } |
|
1083 | 1117 | if ( is_dir( $path . '/' . $result ) ) { |
1084 | - if ( ! $depth || 'CVS' == $result ) |
|
1085 | - continue; |
|
1118 | + if ( ! $depth || 'CVS' == $result ) { |
|
1119 | + continue; |
|
1120 | + } |
|
1086 | 1121 | $found = self::scandir( $path . '/' . $result, $extensions, $depth - 1 , $relative_path . $result ); |
1087 | 1122 | $files = array_merge_recursive( $files, $found ); |
1088 | 1123 | } elseif ( ! $extensions || preg_match( '~\.(' . $_extensions . ')$~', $result ) ) { |
@@ -1106,8 +1141,9 @@ discard block |
||
1106 | 1141 | * False if no textdomain was specified in the file headers, or if the domain could not be loaded. |
1107 | 1142 | */ |
1108 | 1143 | public function load_textdomain() { |
1109 | - if ( isset( $this->textdomain_loaded ) ) |
|
1110 | - return $this->textdomain_loaded; |
|
1144 | + if ( isset( $this->textdomain_loaded ) ) { |
|
1145 | + return $this->textdomain_loaded; |
|
1146 | + } |
|
1111 | 1147 | |
1112 | 1148 | $textdomain = $this->get('TextDomain'); |
1113 | 1149 | if ( ! $textdomain ) { |
@@ -1121,10 +1157,11 @@ discard block |
||
1121 | 1157 | } |
1122 | 1158 | |
1123 | 1159 | $path = $this->get_stylesheet_directory(); |
1124 | - if ( $domainpath = $this->get('DomainPath') ) |
|
1125 | - $path .= $domainpath; |
|
1126 | - else |
|
1127 | - $path .= '/languages'; |
|
1160 | + if ( $domainpath = $this->get('DomainPath') ) { |
|
1161 | + $path .= $domainpath; |
|
1162 | + } else { |
|
1163 | + $path .= '/languages'; |
|
1164 | + } |
|
1128 | 1165 | |
1129 | 1166 | $this->textdomain_loaded = load_theme_textdomain( $textdomain, $path ); |
1130 | 1167 | return $this->textdomain_loaded; |
@@ -1142,19 +1179,22 @@ discard block |
||
1142 | 1179 | * @return bool Whether the theme is allowed for the network. Returns true in single-site. |
1143 | 1180 | */ |
1144 | 1181 | public function is_allowed( $check = 'both', $blog_id = null ) { |
1145 | - if ( ! is_multisite() ) |
|
1146 | - return true; |
|
1182 | + if ( ! is_multisite() ) { |
|
1183 | + return true; |
|
1184 | + } |
|
1147 | 1185 | |
1148 | 1186 | if ( 'both' == $check || 'network' == $check ) { |
1149 | 1187 | $allowed = self::get_allowed_on_network(); |
1150 | - if ( ! empty( $allowed[ $this->get_stylesheet() ] ) ) |
|
1151 | - return true; |
|
1188 | + if ( ! empty( $allowed[ $this->get_stylesheet() ] ) ) { |
|
1189 | + return true; |
|
1190 | + } |
|
1152 | 1191 | } |
1153 | 1192 | |
1154 | 1193 | if ( 'both' == $check || 'site' == $check ) { |
1155 | 1194 | $allowed = self::get_allowed_on_site( $blog_id ); |
1156 | - if ( ! empty( $allowed[ $this->get_stylesheet() ] ) ) |
|
1157 | - return true; |
|
1195 | + if ( ! empty( $allowed[ $this->get_stylesheet() ] ) ) { |
|
1196 | + return true; |
|
1197 | + } |
|
1158 | 1198 | } |
1159 | 1199 | |
1160 | 1200 | return false; |
@@ -1250,8 +1290,9 @@ discard block |
||
1250 | 1290 | public static function get_allowed_on_site( $blog_id = null ) { |
1251 | 1291 | static $allowed_themes = array(); |
1252 | 1292 | |
1253 | - if ( ! $blog_id || ! is_multisite() ) |
|
1254 | - $blog_id = get_current_blog_id(); |
|
1293 | + if ( ! $blog_id || ! is_multisite() ) { |
|
1294 | + $blog_id = get_current_blog_id(); |
|
1295 | + } |
|
1255 | 1296 | |
1256 | 1297 | if ( isset( $allowed_themes[ $blog_id ] ) ) { |
1257 | 1298 | /** |
@@ -1292,8 +1333,9 @@ discard block |
||
1292 | 1333 | $converted = array(); |
1293 | 1334 | $themes = wp_get_themes(); |
1294 | 1335 | foreach ( $themes as $stylesheet => $theme_data ) { |
1295 | - if ( isset( $allowed_themes[ $blog_id ][ $theme_data->get('Name') ] ) ) |
|
1296 | - $converted[ $stylesheet ] = true; |
|
1336 | + if ( isset( $allowed_themes[ $blog_id ][ $theme_data->get('Name') ] ) ) { |
|
1337 | + $converted[ $stylesheet ] = true; |
|
1338 | + } |
|
1297 | 1339 | } |
1298 | 1340 | $allowed_themes[ $blog_id ] = $converted; |
1299 | 1341 | } |
@@ -183,7 +183,7 @@ |
||
183 | 183 | * @access public |
184 | 184 | * |
185 | 185 | * @param string $name Property to check if set. |
186 | - * @return bool Whether the property is set. |
|
186 | + * @return boolean|null Whether the property is set. |
|
187 | 187 | */ |
188 | 188 | public function __isset( $name ) { |
189 | 189 | if ( in_array( $name, $this->compat_fields ) ) { |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | */ |
62 | 62 | public $request; |
63 | 63 | |
64 | - private $compat_fields = array( 'results', 'total_users' ); |
|
64 | + private $compat_fields = array('results', 'total_users'); |
|
65 | 65 | |
66 | 66 | // SQL clauses |
67 | 67 | public $query_fields; |
@@ -77,9 +77,9 @@ discard block |
||
77 | 77 | * |
78 | 78 | * @param null|string|array $query Optional. The query variables. |
79 | 79 | */ |
80 | - public function __construct( $query = null ) { |
|
81 | - if ( ! empty( $query ) ) { |
|
82 | - $this->prepare_query( $query ); |
|
80 | + public function __construct($query = null) { |
|
81 | + if ( ! empty($query)) { |
|
82 | + $this->prepare_query($query); |
|
83 | 83 | $this->query(); |
84 | 84 | } |
85 | 85 | } |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | * @param array $args Query vars, as passed to `WP_User_Query`. |
94 | 94 | * @return array Complete query variables with undefined ones filled in with defaults. |
95 | 95 | */ |
96 | - public static function fill_query_vars( $args ) { |
|
96 | + public static function fill_query_vars($args) { |
|
97 | 97 | $defaults = array( |
98 | 98 | 'blog_id' => $GLOBALS['blog_id'], |
99 | 99 | 'role' => '', |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | 'has_published_posts' => null, |
118 | 118 | ); |
119 | 119 | |
120 | - return wp_parse_args( $args, $defaults ); |
|
120 | + return wp_parse_args($args, $defaults); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
@@ -197,12 +197,12 @@ discard block |
||
197 | 197 | * public post types. |
198 | 198 | * } |
199 | 199 | */ |
200 | - public function prepare_query( $query = array() ) { |
|
200 | + public function prepare_query($query = array()) { |
|
201 | 201 | global $wpdb; |
202 | 202 | |
203 | - if ( empty( $this->query_vars ) || ! empty( $query ) ) { |
|
203 | + if (empty($this->query_vars) || ! empty($query)) { |
|
204 | 204 | $this->query_limit = null; |
205 | - $this->query_vars = $this->fill_query_vars( $query ); |
|
205 | + $this->query_vars = $this->fill_query_vars($query); |
|
206 | 206 | } |
207 | 207 | |
208 | 208 | /** |
@@ -216,99 +216,99 @@ discard block |
||
216 | 216 | * @param WP_User_Query $this The current WP_User_Query instance, |
217 | 217 | * passed by reference. |
218 | 218 | */ |
219 | - do_action( 'pre_get_users', $this ); |
|
219 | + do_action('pre_get_users', $this); |
|
220 | 220 | |
221 | 221 | // Ensure that query vars are filled after 'pre_get_users'. |
222 | - $qv =& $this->query_vars; |
|
223 | - $qv = $this->fill_query_vars( $qv ); |
|
222 | + $qv = & $this->query_vars; |
|
223 | + $qv = $this->fill_query_vars($qv); |
|
224 | 224 | |
225 | - if ( is_array( $qv['fields'] ) ) { |
|
226 | - $qv['fields'] = array_unique( $qv['fields'] ); |
|
225 | + if (is_array($qv['fields'])) { |
|
226 | + $qv['fields'] = array_unique($qv['fields']); |
|
227 | 227 | |
228 | 228 | $this->query_fields = array(); |
229 | - foreach ( $qv['fields'] as $field ) { |
|
230 | - $field = 'ID' === $field ? 'ID' : sanitize_key( $field ); |
|
229 | + foreach ($qv['fields'] as $field) { |
|
230 | + $field = 'ID' === $field ? 'ID' : sanitize_key($field); |
|
231 | 231 | $this->query_fields[] = "$wpdb->users.$field"; |
232 | 232 | } |
233 | - $this->query_fields = implode( ',', $this->query_fields ); |
|
234 | - } elseif ( 'all' == $qv['fields'] ) { |
|
233 | + $this->query_fields = implode(',', $this->query_fields); |
|
234 | + } elseif ('all' == $qv['fields']) { |
|
235 | 235 | $this->query_fields = "$wpdb->users.*"; |
236 | 236 | } else { |
237 | 237 | $this->query_fields = "$wpdb->users.ID"; |
238 | 238 | } |
239 | 239 | |
240 | - if ( isset( $qv['count_total'] ) && $qv['count_total'] ) |
|
241 | - $this->query_fields = 'SQL_CALC_FOUND_ROWS ' . $this->query_fields; |
|
240 | + if (isset($qv['count_total']) && $qv['count_total']) |
|
241 | + $this->query_fields = 'SQL_CALC_FOUND_ROWS '.$this->query_fields; |
|
242 | 242 | |
243 | 243 | $this->query_from = "FROM $wpdb->users"; |
244 | 244 | $this->query_where = "WHERE 1=1"; |
245 | 245 | |
246 | 246 | // Parse and sanitize 'include', for use by 'orderby' as well as 'include' below. |
247 | - if ( ! empty( $qv['include'] ) ) { |
|
248 | - $include = wp_parse_id_list( $qv['include'] ); |
|
247 | + if ( ! empty($qv['include'])) { |
|
248 | + $include = wp_parse_id_list($qv['include']); |
|
249 | 249 | } else { |
250 | 250 | $include = false; |
251 | 251 | } |
252 | 252 | |
253 | 253 | $blog_id = 0; |
254 | - if ( isset( $qv['blog_id'] ) ) { |
|
255 | - $blog_id = absint( $qv['blog_id'] ); |
|
254 | + if (isset($qv['blog_id'])) { |
|
255 | + $blog_id = absint($qv['blog_id']); |
|
256 | 256 | } |
257 | 257 | |
258 | - if ( isset( $qv['who'] ) && 'authors' == $qv['who'] && $blog_id ) { |
|
259 | - $qv['meta_key'] = $wpdb->get_blog_prefix( $blog_id ) . 'user_level'; |
|
258 | + if (isset($qv['who']) && 'authors' == $qv['who'] && $blog_id) { |
|
259 | + $qv['meta_key'] = $wpdb->get_blog_prefix($blog_id).'user_level'; |
|
260 | 260 | $qv['meta_value'] = 0; |
261 | 261 | $qv['meta_compare'] = '!='; |
262 | 262 | $qv['blog_id'] = $blog_id = 0; // Prevent extra meta query |
263 | 263 | } |
264 | 264 | |
265 | - if ( $qv['has_published_posts'] && $blog_id ) { |
|
266 | - if ( true === $qv['has_published_posts'] ) { |
|
267 | - $post_types = get_post_types( array( 'public' => true ) ); |
|
265 | + if ($qv['has_published_posts'] && $blog_id) { |
|
266 | + if (true === $qv['has_published_posts']) { |
|
267 | + $post_types = get_post_types(array('public' => true)); |
|
268 | 268 | } else { |
269 | 269 | $post_types = (array) $qv['has_published_posts']; |
270 | 270 | } |
271 | 271 | |
272 | - foreach ( $post_types as &$post_type ) { |
|
273 | - $post_type = $wpdb->prepare( '%s', $post_type ); |
|
272 | + foreach ($post_types as &$post_type) { |
|
273 | + $post_type = $wpdb->prepare('%s', $post_type); |
|
274 | 274 | } |
275 | 275 | |
276 | - $posts_table = $wpdb->get_blog_prefix( $blog_id ) . 'posts'; |
|
277 | - $this->query_where .= " AND $wpdb->users.ID IN ( SELECT DISTINCT $posts_table.post_author FROM $posts_table WHERE $posts_table.post_status = 'publish' AND $posts_table.post_type IN ( " . join( ", ", $post_types ) . " ) )"; |
|
276 | + $posts_table = $wpdb->get_blog_prefix($blog_id).'posts'; |
|
277 | + $this->query_where .= " AND $wpdb->users.ID IN ( SELECT DISTINCT $posts_table.post_author FROM $posts_table WHERE $posts_table.post_status = 'publish' AND $posts_table.post_type IN ( ".join(", ", $post_types)." ) )"; |
|
278 | 278 | } |
279 | 279 | |
280 | 280 | // Meta query. |
281 | 281 | $this->meta_query = new WP_Meta_Query(); |
282 | - $this->meta_query->parse_query_vars( $qv ); |
|
282 | + $this->meta_query->parse_query_vars($qv); |
|
283 | 283 | |
284 | 284 | $roles = array(); |
285 | - if ( isset( $qv['role'] ) ) { |
|
286 | - if ( is_array( $qv['role'] ) ) { |
|
285 | + if (isset($qv['role'])) { |
|
286 | + if (is_array($qv['role'])) { |
|
287 | 287 | $roles = $qv['role']; |
288 | - } elseif ( is_string( $qv['role'] ) && ! empty( $qv['role'] ) ) { |
|
289 | - $roles = array_map( 'trim', explode( ',', $qv['role'] ) ); |
|
288 | + } elseif (is_string($qv['role']) && ! empty($qv['role'])) { |
|
289 | + $roles = array_map('trim', explode(',', $qv['role'])); |
|
290 | 290 | } |
291 | 291 | } |
292 | 292 | |
293 | 293 | $role__in = array(); |
294 | - if ( isset( $qv['role__in'] ) ) { |
|
294 | + if (isset($qv['role__in'])) { |
|
295 | 295 | $role__in = (array) $qv['role__in']; |
296 | 296 | } |
297 | 297 | |
298 | 298 | $role__not_in = array(); |
299 | - if ( isset( $qv['role__not_in'] ) ) { |
|
299 | + if (isset($qv['role__not_in'])) { |
|
300 | 300 | $role__not_in = (array) $qv['role__not_in']; |
301 | 301 | } |
302 | 302 | |
303 | - if ( $blog_id && ( ! empty( $roles ) || ! empty( $role__in ) || ! empty( $role__not_in ) || is_multisite() ) ) { |
|
303 | + if ($blog_id && ( ! empty($roles) || ! empty($role__in) || ! empty($role__not_in) || is_multisite())) { |
|
304 | 304 | $role_queries = array(); |
305 | 305 | |
306 | - $roles_clauses = array( 'relation' => 'AND' ); |
|
307 | - if ( ! empty( $roles ) ) { |
|
308 | - foreach ( $roles as $role ) { |
|
306 | + $roles_clauses = array('relation' => 'AND'); |
|
307 | + if ( ! empty($roles)) { |
|
308 | + foreach ($roles as $role) { |
|
309 | 309 | $roles_clauses[] = array( |
310 | - 'key' => $wpdb->get_blog_prefix( $blog_id ) . 'capabilities', |
|
311 | - 'value' => '"' . $role . '"', |
|
310 | + 'key' => $wpdb->get_blog_prefix($blog_id).'capabilities', |
|
311 | + 'value' => '"'.$role.'"', |
|
312 | 312 | 'compare' => 'LIKE', |
313 | 313 | ); |
314 | 314 | } |
@@ -316,12 +316,12 @@ discard block |
||
316 | 316 | $role_queries[] = $roles_clauses; |
317 | 317 | } |
318 | 318 | |
319 | - $role__in_clauses = array( 'relation' => 'OR' ); |
|
320 | - if ( ! empty( $role__in ) ) { |
|
321 | - foreach ( $role__in as $role ) { |
|
319 | + $role__in_clauses = array('relation' => 'OR'); |
|
320 | + if ( ! empty($role__in)) { |
|
321 | + foreach ($role__in as $role) { |
|
322 | 322 | $role__in_clauses[] = array( |
323 | - 'key' => $wpdb->get_blog_prefix( $blog_id ) . 'capabilities', |
|
324 | - 'value' => '"' . $role . '"', |
|
323 | + 'key' => $wpdb->get_blog_prefix($blog_id).'capabilities', |
|
324 | + 'value' => '"'.$role.'"', |
|
325 | 325 | 'compare' => 'LIKE', |
326 | 326 | ); |
327 | 327 | } |
@@ -329,12 +329,12 @@ discard block |
||
329 | 329 | $role_queries[] = $role__in_clauses; |
330 | 330 | } |
331 | 331 | |
332 | - $role__not_in_clauses = array( 'relation' => 'AND' ); |
|
333 | - if ( ! empty( $role__not_in ) ) { |
|
334 | - foreach ( $role__not_in as $role ) { |
|
332 | + $role__not_in_clauses = array('relation' => 'AND'); |
|
333 | + if ( ! empty($role__not_in)) { |
|
334 | + foreach ($role__not_in as $role) { |
|
335 | 335 | $role__not_in_clauses[] = array( |
336 | - 'key' => $wpdb->get_blog_prefix( $blog_id ) . 'capabilities', |
|
337 | - 'value' => '"' . $role . '"', |
|
336 | + 'key' => $wpdb->get_blog_prefix($blog_id).'capabilities', |
|
337 | + 'value' => '"'.$role.'"', |
|
338 | 338 | 'compare' => 'NOT LIKE', |
339 | 339 | ); |
340 | 340 | } |
@@ -343,9 +343,9 @@ discard block |
||
343 | 343 | } |
344 | 344 | |
345 | 345 | // If there are no specific roles named, make sure the user is a member of the site. |
346 | - if ( empty( $role_queries ) ) { |
|
346 | + if (empty($role_queries)) { |
|
347 | 347 | $role_queries[] = array( |
348 | - 'key' => $wpdb->get_blog_prefix( $blog_id ) . 'capabilities', |
|
348 | + 'key' => $wpdb->get_blog_prefix($blog_id).'capabilities', |
|
349 | 349 | 'compare' => 'EXISTS', |
350 | 350 | ); |
351 | 351 | } |
@@ -353,50 +353,50 @@ discard block |
||
353 | 353 | // Specify that role queries should be joined with AND. |
354 | 354 | $role_queries['relation'] = 'AND'; |
355 | 355 | |
356 | - if ( empty( $this->meta_query->queries ) ) { |
|
356 | + if (empty($this->meta_query->queries)) { |
|
357 | 357 | $this->meta_query->queries = $role_queries; |
358 | 358 | } else { |
359 | 359 | // Append the cap query to the original queries and reparse the query. |
360 | 360 | $this->meta_query->queries = array( |
361 | 361 | 'relation' => 'AND', |
362 | - array( $this->meta_query->queries, $role_queries ), |
|
362 | + array($this->meta_query->queries, $role_queries), |
|
363 | 363 | ); |
364 | 364 | } |
365 | 365 | |
366 | - $this->meta_query->parse_query_vars( $this->meta_query->queries ); |
|
366 | + $this->meta_query->parse_query_vars($this->meta_query->queries); |
|
367 | 367 | } |
368 | 368 | |
369 | - if ( ! empty( $this->meta_query->queries ) ) { |
|
370 | - $clauses = $this->meta_query->get_sql( 'user', $wpdb->users, 'ID', $this ); |
|
369 | + if ( ! empty($this->meta_query->queries)) { |
|
370 | + $clauses = $this->meta_query->get_sql('user', $wpdb->users, 'ID', $this); |
|
371 | 371 | $this->query_from .= $clauses['join']; |
372 | 372 | $this->query_where .= $clauses['where']; |
373 | 373 | |
374 | - if ( $this->meta_query->has_or_relation() ) { |
|
375 | - $this->query_fields = 'DISTINCT ' . $this->query_fields; |
|
374 | + if ($this->meta_query->has_or_relation()) { |
|
375 | + $this->query_fields = 'DISTINCT '.$this->query_fields; |
|
376 | 376 | } |
377 | 377 | } |
378 | 378 | |
379 | 379 | // sorting |
380 | - $qv['order'] = isset( $qv['order'] ) ? strtoupper( $qv['order'] ) : ''; |
|
381 | - $order = $this->parse_order( $qv['order'] ); |
|
380 | + $qv['order'] = isset($qv['order']) ? strtoupper($qv['order']) : ''; |
|
381 | + $order = $this->parse_order($qv['order']); |
|
382 | 382 | |
383 | - if ( empty( $qv['orderby'] ) ) { |
|
383 | + if (empty($qv['orderby'])) { |
|
384 | 384 | // Default order is by 'user_login'. |
385 | - $ordersby = array( 'user_login' => $order ); |
|
386 | - } elseif ( is_array( $qv['orderby'] ) ) { |
|
385 | + $ordersby = array('user_login' => $order); |
|
386 | + } elseif (is_array($qv['orderby'])) { |
|
387 | 387 | $ordersby = $qv['orderby']; |
388 | 388 | } else { |
389 | 389 | // 'orderby' values may be a comma- or space-separated list. |
390 | - $ordersby = preg_split( '/[,\s]+/', $qv['orderby'] ); |
|
390 | + $ordersby = preg_split('/[,\s]+/', $qv['orderby']); |
|
391 | 391 | } |
392 | 392 | |
393 | 393 | $orderby_array = array(); |
394 | - foreach ( $ordersby as $_key => $_value ) { |
|
395 | - if ( ! $_value ) { |
|
394 | + foreach ($ordersby as $_key => $_value) { |
|
395 | + if ( ! $_value) { |
|
396 | 396 | continue; |
397 | 397 | } |
398 | 398 | |
399 | - if ( is_int( $_key ) ) { |
|
399 | + if (is_int($_key)) { |
|
400 | 400 | // Integer key means this is a flat array of 'orderby' fields. |
401 | 401 | $_orderby = $_value; |
402 | 402 | $_order = $order; |
@@ -406,58 +406,58 @@ discard block |
||
406 | 406 | $_order = $_value; |
407 | 407 | } |
408 | 408 | |
409 | - $parsed = $this->parse_orderby( $_orderby ); |
|
409 | + $parsed = $this->parse_orderby($_orderby); |
|
410 | 410 | |
411 | - if ( ! $parsed ) { |
|
411 | + if ( ! $parsed) { |
|
412 | 412 | continue; |
413 | 413 | } |
414 | 414 | |
415 | - $orderby_array[] = $parsed . ' ' . $this->parse_order( $_order ); |
|
415 | + $orderby_array[] = $parsed.' '.$this->parse_order($_order); |
|
416 | 416 | } |
417 | 417 | |
418 | 418 | // If no valid clauses were found, order by user_login. |
419 | - if ( empty( $orderby_array ) ) { |
|
419 | + if (empty($orderby_array)) { |
|
420 | 420 | $orderby_array[] = "user_login $order"; |
421 | 421 | } |
422 | 422 | |
423 | - $this->query_orderby = 'ORDER BY ' . implode( ', ', $orderby_array ); |
|
423 | + $this->query_orderby = 'ORDER BY '.implode(', ', $orderby_array); |
|
424 | 424 | |
425 | 425 | // limit |
426 | - if ( isset( $qv['number'] ) && $qv['number'] > 0 ) { |
|
427 | - if ( $qv['offset'] ) { |
|
426 | + if (isset($qv['number']) && $qv['number'] > 0) { |
|
427 | + if ($qv['offset']) { |
|
428 | 428 | $this->query_limit = $wpdb->prepare("LIMIT %d, %d", $qv['offset'], $qv['number']); |
429 | 429 | } else { |
430 | - $this->query_limit = $wpdb->prepare( "LIMIT %d, %d", $qv['number'] * ( $qv['paged'] - 1 ), $qv['number'] ); |
|
430 | + $this->query_limit = $wpdb->prepare("LIMIT %d, %d", $qv['number'] * ($qv['paged'] - 1), $qv['number']); |
|
431 | 431 | } |
432 | 432 | } |
433 | 433 | |
434 | 434 | $search = ''; |
435 | - if ( isset( $qv['search'] ) ) |
|
436 | - $search = trim( $qv['search'] ); |
|
435 | + if (isset($qv['search'])) |
|
436 | + $search = trim($qv['search']); |
|
437 | 437 | |
438 | - if ( $search ) { |
|
439 | - $leading_wild = ( ltrim($search, '*') != $search ); |
|
440 | - $trailing_wild = ( rtrim($search, '*') != $search ); |
|
441 | - if ( $leading_wild && $trailing_wild ) |
|
438 | + if ($search) { |
|
439 | + $leading_wild = (ltrim($search, '*') != $search); |
|
440 | + $trailing_wild = (rtrim($search, '*') != $search); |
|
441 | + if ($leading_wild && $trailing_wild) |
|
442 | 442 | $wild = 'both'; |
443 | - elseif ( $leading_wild ) |
|
443 | + elseif ($leading_wild) |
|
444 | 444 | $wild = 'leading'; |
445 | - elseif ( $trailing_wild ) |
|
445 | + elseif ($trailing_wild) |
|
446 | 446 | $wild = 'trailing'; |
447 | 447 | else |
448 | 448 | $wild = false; |
449 | - if ( $wild ) |
|
449 | + if ($wild) |
|
450 | 450 | $search = trim($search, '*'); |
451 | 451 | |
452 | 452 | $search_columns = array(); |
453 | - if ( $qv['search_columns'] ) |
|
454 | - $search_columns = array_intersect( $qv['search_columns'], array( 'ID', 'user_login', 'user_email', 'user_url', 'user_nicename' ) ); |
|
455 | - if ( ! $search_columns ) { |
|
456 | - if ( false !== strpos( $search, '@') ) |
|
453 | + if ($qv['search_columns']) |
|
454 | + $search_columns = array_intersect($qv['search_columns'], array('ID', 'user_login', 'user_email', 'user_url', 'user_nicename')); |
|
455 | + if ( ! $search_columns) { |
|
456 | + if (false !== strpos($search, '@')) |
|
457 | 457 | $search_columns = array('user_email'); |
458 | - elseif ( is_numeric($search) ) |
|
458 | + elseif (is_numeric($search)) |
|
459 | 459 | $search_columns = array('user_login', 'ID'); |
460 | - elseif ( preg_match('|^https?://|', $search) && ! ( is_multisite() && wp_is_large_network( 'users' ) ) ) |
|
460 | + elseif (preg_match('|^https?://|', $search) && ! (is_multisite() && wp_is_large_network('users'))) |
|
461 | 461 | $search_columns = array('user_url'); |
462 | 462 | else |
463 | 463 | $search_columns = array('user_login', 'user_url', 'user_email', 'user_nicename', 'display_name'); |
@@ -475,23 +475,23 @@ discard block |
||
475 | 475 | * @param string $search Text being searched. |
476 | 476 | * @param WP_User_Query $this The current WP_User_Query instance. |
477 | 477 | */ |
478 | - $search_columns = apply_filters( 'user_search_columns', $search_columns, $search, $this ); |
|
478 | + $search_columns = apply_filters('user_search_columns', $search_columns, $search, $this); |
|
479 | 479 | |
480 | - $this->query_where .= $this->get_search_sql( $search, $search_columns, $wild ); |
|
480 | + $this->query_where .= $this->get_search_sql($search, $search_columns, $wild); |
|
481 | 481 | } |
482 | 482 | |
483 | - if ( ! empty( $include ) ) { |
|
483 | + if ( ! empty($include)) { |
|
484 | 484 | // Sanitized earlier. |
485 | - $ids = implode( ',', $include ); |
|
485 | + $ids = implode(',', $include); |
|
486 | 486 | $this->query_where .= " AND $wpdb->users.ID IN ($ids)"; |
487 | - } elseif ( ! empty( $qv['exclude'] ) ) { |
|
488 | - $ids = implode( ',', wp_parse_id_list( $qv['exclude'] ) ); |
|
487 | + } elseif ( ! empty($qv['exclude'])) { |
|
488 | + $ids = implode(',', wp_parse_id_list($qv['exclude'])); |
|
489 | 489 | $this->query_where .= " AND $wpdb->users.ID NOT IN ($ids)"; |
490 | 490 | } |
491 | 491 | |
492 | 492 | // Date queries are allowed for the user_registered field. |
493 | - if ( ! empty( $qv['date_query'] ) && is_array( $qv['date_query'] ) ) { |
|
494 | - $date_query = new WP_Date_Query( $qv['date_query'], 'user_registered' ); |
|
493 | + if ( ! empty($qv['date_query']) && is_array($qv['date_query'])) { |
|
494 | + $date_query = new WP_Date_Query($qv['date_query'], 'user_registered'); |
|
495 | 495 | $this->query_where .= $date_query->get_sql(); |
496 | 496 | } |
497 | 497 | |
@@ -507,7 +507,7 @@ discard block |
||
507 | 507 | * @param WP_User_Query $this The current WP_User_Query instance, |
508 | 508 | * passed by reference. |
509 | 509 | */ |
510 | - do_action_ref_array( 'pre_user_query', array( &$this ) ); |
|
510 | + do_action_ref_array('pre_user_query', array(&$this)); |
|
511 | 511 | } |
512 | 512 | |
513 | 513 | /** |
@@ -520,14 +520,14 @@ discard block |
||
520 | 520 | public function query() { |
521 | 521 | global $wpdb; |
522 | 522 | |
523 | - $qv =& $this->query_vars; |
|
523 | + $qv = & $this->query_vars; |
|
524 | 524 | |
525 | 525 | $this->request = "SELECT $this->query_fields $this->query_from $this->query_where $this->query_orderby $this->query_limit"; |
526 | 526 | |
527 | - if ( is_array( $qv['fields'] ) || 'all' == $qv['fields'] ) { |
|
528 | - $this->results = $wpdb->get_results( $this->request ); |
|
527 | + if (is_array($qv['fields']) || 'all' == $qv['fields']) { |
|
528 | + $this->results = $wpdb->get_results($this->request); |
|
529 | 529 | } else { |
530 | - $this->results = $wpdb->get_col( $this->request ); |
|
530 | + $this->results = $wpdb->get_col($this->request); |
|
531 | 531 | } |
532 | 532 | |
533 | 533 | /** |
@@ -539,23 +539,23 @@ discard block |
||
539 | 539 | * |
540 | 540 | * @param string $sql The SELECT FOUND_ROWS() query for the current WP_User_Query. |
541 | 541 | */ |
542 | - if ( isset( $qv['count_total'] ) && $qv['count_total'] ) |
|
543 | - $this->total_users = $wpdb->get_var( apply_filters( 'found_users_query', 'SELECT FOUND_ROWS()' ) ); |
|
542 | + if (isset($qv['count_total']) && $qv['count_total']) |
|
543 | + $this->total_users = $wpdb->get_var(apply_filters('found_users_query', 'SELECT FOUND_ROWS()')); |
|
544 | 544 | |
545 | - if ( !$this->results ) |
|
545 | + if ( ! $this->results) |
|
546 | 546 | return; |
547 | 547 | |
548 | - if ( 'all_with_meta' == $qv['fields'] ) { |
|
549 | - cache_users( $this->results ); |
|
548 | + if ('all_with_meta' == $qv['fields']) { |
|
549 | + cache_users($this->results); |
|
550 | 550 | |
551 | 551 | $r = array(); |
552 | - foreach ( $this->results as $userid ) |
|
553 | - $r[ $userid ] = new WP_User( $userid, '', $qv['blog_id'] ); |
|
552 | + foreach ($this->results as $userid) |
|
553 | + $r[$userid] = new WP_User($userid, '', $qv['blog_id']); |
|
554 | 554 | |
555 | 555 | $this->results = $r; |
556 | - } elseif ( 'all' == $qv['fields'] ) { |
|
557 | - foreach ( $this->results as $key => $user ) { |
|
558 | - $this->results[ $key ] = new WP_User( $user, '', $qv['blog_id'] ); |
|
556 | + } elseif ('all' == $qv['fields']) { |
|
557 | + foreach ($this->results as $key => $user) { |
|
558 | + $this->results[$key] = new WP_User($user, '', $qv['blog_id']); |
|
559 | 559 | } |
560 | 560 | } |
561 | 561 | } |
@@ -569,8 +569,8 @@ discard block |
||
569 | 569 | * @param string $query_var Query variable key. |
570 | 570 | * @return mixed |
571 | 571 | */ |
572 | - public function get( $query_var ) { |
|
573 | - if ( isset( $this->query_vars[$query_var] ) ) |
|
572 | + public function get($query_var) { |
|
573 | + if (isset($this->query_vars[$query_var])) |
|
574 | 574 | return $this->query_vars[$query_var]; |
575 | 575 | |
576 | 576 | return null; |
@@ -585,7 +585,7 @@ discard block |
||
585 | 585 | * @param string $query_var Query variable key. |
586 | 586 | * @param mixed $value Query variable value. |
587 | 587 | */ |
588 | - public function set( $query_var, $value ) { |
|
588 | + public function set($query_var, $value) { |
|
589 | 589 | $this->query_vars[$query_var] = $value; |
590 | 590 | } |
591 | 591 | |
@@ -603,23 +603,23 @@ discard block |
||
603 | 603 | * Single site allows leading and trailing wildcards, Network Admin only trailing. |
604 | 604 | * @return string |
605 | 605 | */ |
606 | - protected function get_search_sql( $string, $cols, $wild = false ) { |
|
606 | + protected function get_search_sql($string, $cols, $wild = false) { |
|
607 | 607 | global $wpdb; |
608 | 608 | |
609 | 609 | $searches = array(); |
610 | - $leading_wild = ( 'leading' == $wild || 'both' == $wild ) ? '%' : ''; |
|
611 | - $trailing_wild = ( 'trailing' == $wild || 'both' == $wild ) ? '%' : ''; |
|
612 | - $like = $leading_wild . $wpdb->esc_like( $string ) . $trailing_wild; |
|
610 | + $leading_wild = ('leading' == $wild || 'both' == $wild) ? '%' : ''; |
|
611 | + $trailing_wild = ('trailing' == $wild || 'both' == $wild) ? '%' : ''; |
|
612 | + $like = $leading_wild.$wpdb->esc_like($string).$trailing_wild; |
|
613 | 613 | |
614 | - foreach ( $cols as $col ) { |
|
615 | - if ( 'ID' == $col ) { |
|
616 | - $searches[] = $wpdb->prepare( "$col = %s", $string ); |
|
614 | + foreach ($cols as $col) { |
|
615 | + if ('ID' == $col) { |
|
616 | + $searches[] = $wpdb->prepare("$col = %s", $string); |
|
617 | 617 | } else { |
618 | - $searches[] = $wpdb->prepare( "$col LIKE %s", $like ); |
|
618 | + $searches[] = $wpdb->prepare("$col LIKE %s", $like); |
|
619 | 619 | } |
620 | 620 | } |
621 | 621 | |
622 | - return ' AND (' . implode(' OR ', $searches) . ')'; |
|
622 | + return ' AND ('.implode(' OR ', $searches).')'; |
|
623 | 623 | } |
624 | 624 | |
625 | 625 | /** |
@@ -657,21 +657,21 @@ discard block |
||
657 | 657 | * @param string $orderby Alias for the field to order by. |
658 | 658 | * @return string Value to used in the ORDER clause, if `$orderby` is valid. |
659 | 659 | */ |
660 | - protected function parse_orderby( $orderby ) { |
|
660 | + protected function parse_orderby($orderby) { |
|
661 | 661 | global $wpdb; |
662 | 662 | |
663 | 663 | $meta_query_clauses = $this->meta_query->get_clauses(); |
664 | 664 | |
665 | 665 | $_orderby = ''; |
666 | - if ( in_array( $orderby, array( 'login', 'nicename', 'email', 'url', 'registered' ) ) ) { |
|
667 | - $_orderby = 'user_' . $orderby; |
|
668 | - } elseif ( in_array( $orderby, array( 'user_login', 'user_nicename', 'user_email', 'user_url', 'user_registered' ) ) ) { |
|
666 | + if (in_array($orderby, array('login', 'nicename', 'email', 'url', 'registered'))) { |
|
667 | + $_orderby = 'user_'.$orderby; |
|
668 | + } elseif (in_array($orderby, array('user_login', 'user_nicename', 'user_email', 'user_url', 'user_registered'))) { |
|
669 | 669 | $_orderby = $orderby; |
670 | - } elseif ( 'name' == $orderby || 'display_name' == $orderby ) { |
|
670 | + } elseif ('name' == $orderby || 'display_name' == $orderby) { |
|
671 | 671 | $_orderby = 'display_name'; |
672 | - } elseif ( 'post_count' == $orderby ) { |
|
672 | + } elseif ('post_count' == $orderby) { |
|
673 | 673 | // todo: avoid the JOIN |
674 | - $where = get_posts_by_author_sql( 'post' ); |
|
674 | + $where = get_posts_by_author_sql('post'); |
|
675 | 675 | $this->query_from .= " LEFT OUTER JOIN ( |
676 | 676 | SELECT post_author, COUNT(*) as post_count |
677 | 677 | FROM $wpdb->posts |
@@ -680,19 +680,19 @@ discard block |
||
680 | 680 | ) p ON ({$wpdb->users}.ID = p.post_author) |
681 | 681 | "; |
682 | 682 | $_orderby = 'post_count'; |
683 | - } elseif ( 'ID' == $orderby || 'id' == $orderby ) { |
|
683 | + } elseif ('ID' == $orderby || 'id' == $orderby) { |
|
684 | 684 | $_orderby = 'ID'; |
685 | - } elseif ( 'meta_value' == $orderby || $this->get( 'meta_key' ) == $orderby ) { |
|
685 | + } elseif ('meta_value' == $orderby || $this->get('meta_key') == $orderby) { |
|
686 | 686 | $_orderby = "$wpdb->usermeta.meta_value"; |
687 | - } elseif ( 'meta_value_num' == $orderby ) { |
|
687 | + } elseif ('meta_value_num' == $orderby) { |
|
688 | 688 | $_orderby = "$wpdb->usermeta.meta_value+0"; |
689 | - } elseif ( 'include' === $orderby && ! empty( $this->query_vars['include'] ) ) { |
|
690 | - $include = wp_parse_id_list( $this->query_vars['include'] ); |
|
691 | - $include_sql = implode( ',', $include ); |
|
689 | + } elseif ('include' === $orderby && ! empty($this->query_vars['include'])) { |
|
690 | + $include = wp_parse_id_list($this->query_vars['include']); |
|
691 | + $include_sql = implode(',', $include); |
|
692 | 692 | $_orderby = "FIELD( $wpdb->users.ID, $include_sql )"; |
693 | - } elseif ( isset( $meta_query_clauses[ $orderby ] ) ) { |
|
694 | - $meta_clause = $meta_query_clauses[ $orderby ]; |
|
695 | - $_orderby = sprintf( "CAST(%s.meta_value AS %s)", esc_sql( $meta_clause['alias'] ), esc_sql( $meta_clause['cast'] ) ); |
|
693 | + } elseif (isset($meta_query_clauses[$orderby])) { |
|
694 | + $meta_clause = $meta_query_clauses[$orderby]; |
|
695 | + $_orderby = sprintf("CAST(%s.meta_value AS %s)", esc_sql($meta_clause['alias']), esc_sql($meta_clause['cast'])); |
|
696 | 696 | } |
697 | 697 | |
698 | 698 | return $_orderby; |
@@ -707,12 +707,12 @@ discard block |
||
707 | 707 | * @param string $order The 'order' query variable. |
708 | 708 | * @return string The sanitized 'order' query variable. |
709 | 709 | */ |
710 | - protected function parse_order( $order ) { |
|
711 | - if ( ! is_string( $order ) || empty( $order ) ) { |
|
710 | + protected function parse_order($order) { |
|
711 | + if ( ! is_string($order) || empty($order)) { |
|
712 | 712 | return 'DESC'; |
713 | 713 | } |
714 | 714 | |
715 | - if ( 'ASC' === strtoupper( $order ) ) { |
|
715 | + if ('ASC' === strtoupper($order)) { |
|
716 | 716 | return 'ASC'; |
717 | 717 | } else { |
718 | 718 | return 'DESC'; |
@@ -728,8 +728,8 @@ discard block |
||
728 | 728 | * @param string $name Property to get. |
729 | 729 | * @return mixed Property. |
730 | 730 | */ |
731 | - public function __get( $name ) { |
|
732 | - if ( in_array( $name, $this->compat_fields ) ) { |
|
731 | + public function __get($name) { |
|
732 | + if (in_array($name, $this->compat_fields)) { |
|
733 | 733 | return $this->$name; |
734 | 734 | } |
735 | 735 | } |
@@ -744,8 +744,8 @@ discard block |
||
744 | 744 | * @param mixed $value Property value. |
745 | 745 | * @return mixed Newly-set property. |
746 | 746 | */ |
747 | - public function __set( $name, $value ) { |
|
748 | - if ( in_array( $name, $this->compat_fields ) ) { |
|
747 | + public function __set($name, $value) { |
|
748 | + if (in_array($name, $this->compat_fields)) { |
|
749 | 749 | return $this->$name = $value; |
750 | 750 | } |
751 | 751 | } |
@@ -759,9 +759,9 @@ discard block |
||
759 | 759 | * @param string $name Property to check if set. |
760 | 760 | * @return bool Whether the property is set. |
761 | 761 | */ |
762 | - public function __isset( $name ) { |
|
763 | - if ( in_array( $name, $this->compat_fields ) ) { |
|
764 | - return isset( $this->$name ); |
|
762 | + public function __isset($name) { |
|
763 | + if (in_array($name, $this->compat_fields)) { |
|
764 | + return isset($this->$name); |
|
765 | 765 | } |
766 | 766 | } |
767 | 767 | |
@@ -773,9 +773,9 @@ discard block |
||
773 | 773 | * |
774 | 774 | * @param string $name Property to unset. |
775 | 775 | */ |
776 | - public function __unset( $name ) { |
|
777 | - if ( in_array( $name, $this->compat_fields ) ) { |
|
778 | - unset( $this->$name ); |
|
776 | + public function __unset($name) { |
|
777 | + if (in_array($name, $this->compat_fields)) { |
|
778 | + unset($this->$name); |
|
779 | 779 | } |
780 | 780 | } |
781 | 781 | |
@@ -789,9 +789,9 @@ discard block |
||
789 | 789 | * @param array $arguments Arguments to pass when calling. |
790 | 790 | * @return mixed Return value of the callback, false otherwise. |
791 | 791 | */ |
792 | - public function __call( $name, $arguments ) { |
|
793 | - if ( 'get_search_sql' === $name ) { |
|
794 | - return call_user_func_array( array( $this, $name ), $arguments ); |
|
792 | + public function __call($name, $arguments) { |
|
793 | + if ('get_search_sql' === $name) { |
|
794 | + return call_user_func_array(array($this, $name), $arguments); |
|
795 | 795 | } |
796 | 796 | return false; |
797 | 797 | } |
@@ -237,8 +237,9 @@ discard block |
||
237 | 237 | $this->query_fields = "$wpdb->users.ID"; |
238 | 238 | } |
239 | 239 | |
240 | - if ( isset( $qv['count_total'] ) && $qv['count_total'] ) |
|
241 | - $this->query_fields = 'SQL_CALC_FOUND_ROWS ' . $this->query_fields; |
|
240 | + if ( isset( $qv['count_total'] ) && $qv['count_total'] ) { |
|
241 | + $this->query_fields = 'SQL_CALC_FOUND_ROWS ' . $this->query_fields; |
|
242 | + } |
|
242 | 243 | |
243 | 244 | $this->query_from = "FROM $wpdb->users"; |
244 | 245 | $this->query_where = "WHERE 1=1"; |
@@ -432,35 +433,40 @@ discard block |
||
432 | 433 | } |
433 | 434 | |
434 | 435 | $search = ''; |
435 | - if ( isset( $qv['search'] ) ) |
|
436 | - $search = trim( $qv['search'] ); |
|
436 | + if ( isset( $qv['search'] ) ) { |
|
437 | + $search = trim( $qv['search'] ); |
|
438 | + } |
|
437 | 439 | |
438 | 440 | if ( $search ) { |
439 | 441 | $leading_wild = ( ltrim($search, '*') != $search ); |
440 | 442 | $trailing_wild = ( rtrim($search, '*') != $search ); |
441 | - if ( $leading_wild && $trailing_wild ) |
|
442 | - $wild = 'both'; |
|
443 | - elseif ( $leading_wild ) |
|
444 | - $wild = 'leading'; |
|
445 | - elseif ( $trailing_wild ) |
|
446 | - $wild = 'trailing'; |
|
447 | - else |
|
448 | - $wild = false; |
|
449 | - if ( $wild ) |
|
450 | - $search = trim($search, '*'); |
|
443 | + if ( $leading_wild && $trailing_wild ) { |
|
444 | + $wild = 'both'; |
|
445 | + } elseif ( $leading_wild ) { |
|
446 | + $wild = 'leading'; |
|
447 | + } elseif ( $trailing_wild ) { |
|
448 | + $wild = 'trailing'; |
|
449 | + } else { |
|
450 | + $wild = false; |
|
451 | + } |
|
452 | + if ( $wild ) { |
|
453 | + $search = trim($search, '*'); |
|
454 | + } |
|
451 | 455 | |
452 | 456 | $search_columns = array(); |
453 | - if ( $qv['search_columns'] ) |
|
454 | - $search_columns = array_intersect( $qv['search_columns'], array( 'ID', 'user_login', 'user_email', 'user_url', 'user_nicename' ) ); |
|
457 | + if ( $qv['search_columns'] ) { |
|
458 | + $search_columns = array_intersect( $qv['search_columns'], array( 'ID', 'user_login', 'user_email', 'user_url', 'user_nicename' ) ); |
|
459 | + } |
|
455 | 460 | if ( ! $search_columns ) { |
456 | - if ( false !== strpos( $search, '@') ) |
|
457 | - $search_columns = array('user_email'); |
|
458 | - elseif ( is_numeric($search) ) |
|
459 | - $search_columns = array('user_login', 'ID'); |
|
460 | - elseif ( preg_match('|^https?://|', $search) && ! ( is_multisite() && wp_is_large_network( 'users' ) ) ) |
|
461 | - $search_columns = array('user_url'); |
|
462 | - else |
|
463 | - $search_columns = array('user_login', 'user_url', 'user_email', 'user_nicename', 'display_name'); |
|
461 | + if ( false !== strpos( $search, '@') ) { |
|
462 | + $search_columns = array('user_email'); |
|
463 | + } elseif ( is_numeric($search) ) { |
|
464 | + $search_columns = array('user_login', 'ID'); |
|
465 | + } elseif ( preg_match('|^https?://|', $search) && ! ( is_multisite() && wp_is_large_network( 'users' ) ) ) { |
|
466 | + $search_columns = array('user_url'); |
|
467 | + } else { |
|
468 | + $search_columns = array('user_login', 'user_url', 'user_email', 'user_nicename', 'display_name'); |
|
469 | + } |
|
464 | 470 | } |
465 | 471 | |
466 | 472 | /** |
@@ -539,18 +545,21 @@ discard block |
||
539 | 545 | * |
540 | 546 | * @param string $sql The SELECT FOUND_ROWS() query for the current WP_User_Query. |
541 | 547 | */ |
542 | - if ( isset( $qv['count_total'] ) && $qv['count_total'] ) |
|
543 | - $this->total_users = $wpdb->get_var( apply_filters( 'found_users_query', 'SELECT FOUND_ROWS()' ) ); |
|
548 | + if ( isset( $qv['count_total'] ) && $qv['count_total'] ) { |
|
549 | + $this->total_users = $wpdb->get_var( apply_filters( 'found_users_query', 'SELECT FOUND_ROWS()' ) ); |
|
550 | + } |
|
544 | 551 | |
545 | - if ( !$this->results ) |
|
546 | - return; |
|
552 | + if ( !$this->results ) { |
|
553 | + return; |
|
554 | + } |
|
547 | 555 | |
548 | 556 | if ( 'all_with_meta' == $qv['fields'] ) { |
549 | 557 | cache_users( $this->results ); |
550 | 558 | |
551 | 559 | $r = array(); |
552 | - foreach ( $this->results as $userid ) |
|
553 | - $r[ $userid ] = new WP_User( $userid, '', $qv['blog_id'] ); |
|
560 | + foreach ( $this->results as $userid ) { |
|
561 | + $r[ $userid ] = new WP_User( $userid, '', $qv['blog_id'] ); |
|
562 | + } |
|
554 | 563 | |
555 | 564 | $this->results = $r; |
556 | 565 | } elseif ( 'all' == $qv['fields'] ) { |
@@ -570,8 +579,9 @@ discard block |
||
570 | 579 | * @return mixed |
571 | 580 | */ |
572 | 581 | public function get( $query_var ) { |
573 | - if ( isset( $this->query_vars[$query_var] ) ) |
|
574 | - return $this->query_vars[$query_var]; |
|
582 | + if ( isset( $this->query_vars[$query_var] ) ) { |
|
583 | + return $this->query_vars[$query_var]; |
|
584 | + } |
|
575 | 585 | |
576 | 586 | return null; |
577 | 587 | } |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | * |
112 | 112 | * @global wpdb $wpdb WordPress database abstraction object. |
113 | 113 | * |
114 | - * @param int|string|stdClass|WP_User $id User's ID, a WP_User object, or a user object from the DB. |
|
114 | + * @param integer $id User's ID, a WP_User object, or a user object from the DB. |
|
115 | 115 | * @param string $name Optional. User's username |
116 | 116 | * @param int $blog_id Optional Site ID, defaults to current site. |
117 | 117 | */ |
@@ -702,11 +702,6 @@ discard block |
||
702 | 702 | * @see map_meta_cap() |
703 | 703 | * |
704 | 704 | * @param string $cap Capability name. |
705 | - * @param int $object_id,... Optional. ID of the specific object to check against if `$cap` is a "meta" cap. |
|
706 | - * "Meta" capabilities, e.g. 'edit_post', 'edit_user', etc., are capabilities used |
|
707 | - * by map_meta_cap() to map to other "primitive" capabilities, e.g. 'edit_posts', |
|
708 | - * 'edit_others_posts', etc. The parameter is accessed via func_get_args() and passed |
|
709 | - * to map_meta_cap(). |
|
710 | 705 | * @return bool Whether the current user has the given capability. If `$cap` is a meta cap and `$object_id` is |
711 | 706 | * passed, whether the current user has the given meta capability for the given object. |
712 | 707 | */ |
@@ -1,11 +1,11 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * User API: WP_User class |
|
4 | - * |
|
5 | - * @package WordPress |
|
6 | - * @subpackage Users |
|
7 | - * @since 4.4.0 |
|
8 | - */ |
|
3 | + * User API: WP_User class |
|
4 | + * |
|
5 | + * @package WordPress |
|
6 | + * @subpackage Users |
|
7 | + * @since 4.4.0 |
|
8 | + */ |
|
9 | 9 | |
10 | 10 | /** |
11 | 11 | * Core class used to implement the WP_User object. |
@@ -115,40 +115,40 @@ discard block |
||
115 | 115 | * @param string $name Optional. User's username |
116 | 116 | * @param int $blog_id Optional Site ID, defaults to current site. |
117 | 117 | */ |
118 | - public function __construct( $id = 0, $name = '', $blog_id = '' ) { |
|
119 | - if ( ! isset( self::$back_compat_keys ) ) { |
|
118 | + public function __construct($id = 0, $name = '', $blog_id = '') { |
|
119 | + if ( ! isset(self::$back_compat_keys)) { |
|
120 | 120 | $prefix = $GLOBALS['wpdb']->prefix; |
121 | 121 | self::$back_compat_keys = array( |
122 | 122 | 'user_firstname' => 'first_name', |
123 | 123 | 'user_lastname' => 'last_name', |
124 | 124 | 'user_description' => 'description', |
125 | - 'user_level' => $prefix . 'user_level', |
|
126 | - $prefix . 'usersettings' => $prefix . 'user-settings', |
|
127 | - $prefix . 'usersettingstime' => $prefix . 'user-settings-time', |
|
125 | + 'user_level' => $prefix.'user_level', |
|
126 | + $prefix.'usersettings' => $prefix.'user-settings', |
|
127 | + $prefix.'usersettingstime' => $prefix.'user-settings-time', |
|
128 | 128 | ); |
129 | 129 | } |
130 | 130 | |
131 | - if ( $id instanceof WP_User ) { |
|
132 | - $this->init( $id->data, $blog_id ); |
|
131 | + if ($id instanceof WP_User) { |
|
132 | + $this->init($id->data, $blog_id); |
|
133 | 133 | return; |
134 | - } elseif ( is_object( $id ) ) { |
|
135 | - $this->init( $id, $blog_id ); |
|
134 | + } elseif (is_object($id)) { |
|
135 | + $this->init($id, $blog_id); |
|
136 | 136 | return; |
137 | 137 | } |
138 | 138 | |
139 | - if ( ! empty( $id ) && ! is_numeric( $id ) ) { |
|
139 | + if ( ! empty($id) && ! is_numeric($id)) { |
|
140 | 140 | $name = $id; |
141 | 141 | $id = 0; |
142 | 142 | } |
143 | 143 | |
144 | - if ( $id ) { |
|
145 | - $data = self::get_data_by( 'id', $id ); |
|
144 | + if ($id) { |
|
145 | + $data = self::get_data_by('id', $id); |
|
146 | 146 | } else { |
147 | - $data = self::get_data_by( 'login', $name ); |
|
147 | + $data = self::get_data_by('login', $name); |
|
148 | 148 | } |
149 | 149 | |
150 | - if ( $data ) { |
|
151 | - $this->init( $data, $blog_id ); |
|
150 | + if ($data) { |
|
151 | + $this->init($data, $blog_id); |
|
152 | 152 | } else { |
153 | 153 | $this->data = new stdClass; |
154 | 154 | } |
@@ -160,11 +160,11 @@ discard block |
||
160 | 160 | * @param object $data User DB row object. |
161 | 161 | * @param int $blog_id Optional. The site ID to initialize for. |
162 | 162 | */ |
163 | - public function init( $data, $blog_id = '' ) { |
|
163 | + public function init($data, $blog_id = '') { |
|
164 | 164 | $this->data = $data; |
165 | 165 | $this->ID = (int) $data->ID; |
166 | 166 | |
167 | - $this->for_blog( $blog_id ); |
|
167 | + $this->for_blog($blog_id); |
|
168 | 168 | } |
169 | 169 | |
170 | 170 | /** |
@@ -181,30 +181,30 @@ discard block |
||
181 | 181 | * @param string|int $value The field value |
182 | 182 | * @return object|false Raw user object |
183 | 183 | */ |
184 | - public static function get_data_by( $field, $value ) { |
|
184 | + public static function get_data_by($field, $value) { |
|
185 | 185 | global $wpdb; |
186 | 186 | |
187 | 187 | // 'ID' is an alias of 'id'. |
188 | - if ( 'ID' === $field ) { |
|
188 | + if ('ID' === $field) { |
|
189 | 189 | $field = 'id'; |
190 | 190 | } |
191 | 191 | |
192 | - if ( 'id' == $field ) { |
|
192 | + if ('id' == $field) { |
|
193 | 193 | // Make sure the value is numeric to avoid casting objects, for example, |
194 | 194 | // to int 1. |
195 | - if ( ! is_numeric( $value ) ) |
|
195 | + if ( ! is_numeric($value)) |
|
196 | 196 | return false; |
197 | - $value = intval( $value ); |
|
198 | - if ( $value < 1 ) |
|
197 | + $value = intval($value); |
|
198 | + if ($value < 1) |
|
199 | 199 | return false; |
200 | 200 | } else { |
201 | - $value = trim( $value ); |
|
201 | + $value = trim($value); |
|
202 | 202 | } |
203 | 203 | |
204 | - if ( !$value ) |
|
204 | + if ( ! $value) |
|
205 | 205 | return false; |
206 | 206 | |
207 | - switch ( $field ) { |
|
207 | + switch ($field) { |
|
208 | 208 | case 'id': |
209 | 209 | $user_id = $value; |
210 | 210 | $db_field = 'ID'; |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | $db_field = 'user_email'; |
219 | 219 | break; |
220 | 220 | case 'login': |
221 | - $value = sanitize_user( $value ); |
|
221 | + $value = sanitize_user($value); |
|
222 | 222 | $user_id = wp_cache_get($value, 'userlogins'); |
223 | 223 | $db_field = 'user_login'; |
224 | 224 | break; |
@@ -226,17 +226,17 @@ discard block |
||
226 | 226 | return false; |
227 | 227 | } |
228 | 228 | |
229 | - if ( false !== $user_id ) { |
|
230 | - if ( $user = wp_cache_get( $user_id, 'users' ) ) |
|
229 | + if (false !== $user_id) { |
|
230 | + if ($user = wp_cache_get($user_id, 'users')) |
|
231 | 231 | return $user; |
232 | 232 | } |
233 | 233 | |
234 | - if ( !$user = $wpdb->get_row( $wpdb->prepare( |
|
234 | + if ( ! $user = $wpdb->get_row($wpdb->prepare( |
|
235 | 235 | "SELECT * FROM $wpdb->users WHERE $db_field = %s", $value |
236 | - ) ) ) |
|
236 | + ))) |
|
237 | 237 | return false; |
238 | 238 | |
239 | - update_user_caches( $user ); |
|
239 | + update_user_caches($user); |
|
240 | 240 | |
241 | 241 | return $user; |
242 | 242 | } |
@@ -251,9 +251,9 @@ discard block |
||
251 | 251 | * @param array $arguments Arguments to pass when calling. |
252 | 252 | * @return mixed|false Return value of the callback, false otherwise. |
253 | 253 | */ |
254 | - public function __call( $name, $arguments ) { |
|
255 | - if ( '_init_caps' === $name ) { |
|
256 | - return call_user_func_array( array( $this, $name ), $arguments ); |
|
254 | + public function __call($name, $arguments) { |
|
255 | + if ('_init_caps' === $name) { |
|
256 | + return call_user_func_array(array($this, $name), $arguments); |
|
257 | 257 | } |
258 | 258 | return false; |
259 | 259 | } |
@@ -267,25 +267,25 @@ discard block |
||
267 | 267 | * @param string $key User meta key to check if set. |
268 | 268 | * @return bool Whether the given user meta key is set. |
269 | 269 | */ |
270 | - public function __isset( $key ) { |
|
271 | - if ( 'id' == $key ) { |
|
272 | - _deprecated_argument( 'WP_User->id', '2.1', |
|
270 | + public function __isset($key) { |
|
271 | + if ('id' == $key) { |
|
272 | + _deprecated_argument('WP_User->id', '2.1', |
|
273 | 273 | sprintf( |
274 | 274 | /* translators: %s: WP_User->ID */ |
275 | - __( 'Use %s instead.' ), |
|
275 | + __('Use %s instead.'), |
|
276 | 276 | '<code>WP_User->ID</code>' |
277 | 277 | ) |
278 | 278 | ); |
279 | 279 | $key = 'ID'; |
280 | 280 | } |
281 | 281 | |
282 | - if ( isset( $this->data->$key ) ) |
|
282 | + if (isset($this->data->$key)) |
|
283 | 283 | return true; |
284 | 284 | |
285 | - if ( isset( self::$back_compat_keys[ $key ] ) ) |
|
286 | - $key = self::$back_compat_keys[ $key ]; |
|
285 | + if (isset(self::$back_compat_keys[$key])) |
|
286 | + $key = self::$back_compat_keys[$key]; |
|
287 | 287 | |
288 | - return metadata_exists( 'user', $this->ID, $key ); |
|
288 | + return metadata_exists('user', $this->ID, $key); |
|
289 | 289 | } |
290 | 290 | |
291 | 291 | /** |
@@ -297,28 +297,28 @@ discard block |
||
297 | 297 | * @param string $key User meta key to retrieve. |
298 | 298 | * @return mixed Value of the given user meta key (if set). If `$key` is 'id', the user ID. |
299 | 299 | */ |
300 | - public function __get( $key ) { |
|
301 | - if ( 'id' == $key ) { |
|
302 | - _deprecated_argument( 'WP_User->id', '2.1', |
|
300 | + public function __get($key) { |
|
301 | + if ('id' == $key) { |
|
302 | + _deprecated_argument('WP_User->id', '2.1', |
|
303 | 303 | sprintf( |
304 | 304 | /* translators: %s: WP_User->ID */ |
305 | - __( 'Use %s instead.' ), |
|
305 | + __('Use %s instead.'), |
|
306 | 306 | '<code>WP_User->ID</code>' |
307 | 307 | ) |
308 | 308 | ); |
309 | 309 | return $this->ID; |
310 | 310 | } |
311 | 311 | |
312 | - if ( isset( $this->data->$key ) ) { |
|
312 | + if (isset($this->data->$key)) { |
|
313 | 313 | $value = $this->data->$key; |
314 | 314 | } else { |
315 | - if ( isset( self::$back_compat_keys[ $key ] ) ) |
|
316 | - $key = self::$back_compat_keys[ $key ]; |
|
317 | - $value = get_user_meta( $this->ID, $key, true ); |
|
315 | + if (isset(self::$back_compat_keys[$key])) |
|
316 | + $key = self::$back_compat_keys[$key]; |
|
317 | + $value = get_user_meta($this->ID, $key, true); |
|
318 | 318 | } |
319 | 319 | |
320 | - if ( $this->filter ) { |
|
321 | - $value = sanitize_user_field( $key, $value, $this->ID, $this->filter ); |
|
320 | + if ($this->filter) { |
|
321 | + $value = sanitize_user_field($key, $value, $this->ID, $this->filter); |
|
322 | 322 | } |
323 | 323 | |
324 | 324 | return $value; |
@@ -336,12 +336,12 @@ discard block |
||
336 | 336 | * @param string $key User meta key. |
337 | 337 | * @param mixed $value User meta value. |
338 | 338 | */ |
339 | - public function __set( $key, $value ) { |
|
340 | - if ( 'id' == $key ) { |
|
341 | - _deprecated_argument( 'WP_User->id', '2.1', |
|
339 | + public function __set($key, $value) { |
|
340 | + if ('id' == $key) { |
|
341 | + _deprecated_argument('WP_User->id', '2.1', |
|
342 | 342 | sprintf( |
343 | 343 | /* translators: %s: WP_User->ID */ |
344 | - __( 'Use %s instead.' ), |
|
344 | + __('Use %s instead.'), |
|
345 | 345 | '<code>WP_User->ID</code>' |
346 | 346 | ) |
347 | 347 | ); |
@@ -360,23 +360,23 @@ discard block |
||
360 | 360 | * |
361 | 361 | * @param string $key User meta key to unset. |
362 | 362 | */ |
363 | - public function __unset( $key ) { |
|
364 | - if ( 'id' == $key ) { |
|
365 | - _deprecated_argument( 'WP_User->id', '2.1', |
|
363 | + public function __unset($key) { |
|
364 | + if ('id' == $key) { |
|
365 | + _deprecated_argument('WP_User->id', '2.1', |
|
366 | 366 | sprintf( |
367 | 367 | /* translators: %s: WP_User->ID */ |
368 | - __( 'Use %s instead.' ), |
|
368 | + __('Use %s instead.'), |
|
369 | 369 | '<code>WP_User->ID</code>' |
370 | 370 | ) |
371 | 371 | ); |
372 | 372 | } |
373 | 373 | |
374 | - if ( isset( $this->data->$key ) ) { |
|
375 | - unset( $this->data->$key ); |
|
374 | + if (isset($this->data->$key)) { |
|
375 | + unset($this->data->$key); |
|
376 | 376 | } |
377 | 377 | |
378 | - if ( isset( self::$back_compat_keys[ $key ] ) ) { |
|
379 | - unset( self::$back_compat_keys[ $key ] ); |
|
378 | + if (isset(self::$back_compat_keys[$key])) { |
|
379 | + unset(self::$back_compat_keys[$key]); |
|
380 | 380 | } |
381 | 381 | } |
382 | 382 | |
@@ -389,7 +389,7 @@ discard block |
||
389 | 389 | * @return bool True if user exists in the database, false if not. |
390 | 390 | */ |
391 | 391 | public function exists() { |
392 | - return ! empty( $this->ID ); |
|
392 | + return ! empty($this->ID); |
|
393 | 393 | } |
394 | 394 | |
395 | 395 | /** |
@@ -402,8 +402,8 @@ discard block |
||
402 | 402 | * @param string $key Property |
403 | 403 | * @return mixed |
404 | 404 | */ |
405 | - public function get( $key ) { |
|
406 | - return $this->__get( $key ); |
|
405 | + public function get($key) { |
|
406 | + return $this->__get($key); |
|
407 | 407 | } |
408 | 408 | |
409 | 409 | /** |
@@ -416,8 +416,8 @@ discard block |
||
416 | 416 | * @param string $key Property |
417 | 417 | * @return bool |
418 | 418 | */ |
419 | - public function has_prop( $key ) { |
|
420 | - return $this->__isset( $key ); |
|
419 | + public function has_prop($key) { |
|
420 | + return $this->__isset($key); |
|
421 | 421 | } |
422 | 422 | |
423 | 423 | /** |
@@ -428,7 +428,7 @@ discard block |
||
428 | 428 | * @return array Array representation. |
429 | 429 | */ |
430 | 430 | public function to_array() { |
431 | - return get_object_vars( $this->data ); |
|
431 | + return get_object_vars($this->data); |
|
432 | 432 | } |
433 | 433 | |
434 | 434 | /** |
@@ -446,17 +446,17 @@ discard block |
||
446 | 446 | * |
447 | 447 | * @param string $cap_key Optional capability key |
448 | 448 | */ |
449 | - protected function _init_caps( $cap_key = '' ) { |
|
449 | + protected function _init_caps($cap_key = '') { |
|
450 | 450 | global $wpdb; |
451 | 451 | |
452 | - if ( empty($cap_key) ) |
|
453 | - $this->cap_key = $wpdb->get_blog_prefix() . 'capabilities'; |
|
452 | + if (empty($cap_key)) |
|
453 | + $this->cap_key = $wpdb->get_blog_prefix().'capabilities'; |
|
454 | 454 | else |
455 | 455 | $this->cap_key = $cap_key; |
456 | 456 | |
457 | - $this->caps = get_user_meta( $this->ID, $this->cap_key, true ); |
|
457 | + $this->caps = get_user_meta($this->ID, $this->cap_key, true); |
|
458 | 458 | |
459 | - if ( ! is_array( $this->caps ) ) |
|
459 | + if ( ! is_array($this->caps)) |
|
460 | 460 | $this->caps = array(); |
461 | 461 | |
462 | 462 | $this->get_role_caps(); |
@@ -479,16 +479,16 @@ discard block |
||
479 | 479 | $wp_roles = wp_roles(); |
480 | 480 | |
481 | 481 | //Filter out caps that are not role names and assign to $this->roles |
482 | - if ( is_array( $this->caps ) ) |
|
483 | - $this->roles = array_filter( array_keys( $this->caps ), array( $wp_roles, 'is_role' ) ); |
|
482 | + if (is_array($this->caps)) |
|
483 | + $this->roles = array_filter(array_keys($this->caps), array($wp_roles, 'is_role')); |
|
484 | 484 | |
485 | 485 | //Build $allcaps from role caps, overlay user's $caps |
486 | 486 | $this->allcaps = array(); |
487 | - foreach ( (array) $this->roles as $role ) { |
|
488 | - $the_role = $wp_roles->get_role( $role ); |
|
489 | - $this->allcaps = array_merge( (array) $this->allcaps, (array) $the_role->capabilities ); |
|
487 | + foreach ((array) $this->roles as $role) { |
|
488 | + $the_role = $wp_roles->get_role($role); |
|
489 | + $this->allcaps = array_merge((array) $this->allcaps, (array) $the_role->capabilities); |
|
490 | 490 | } |
491 | - $this->allcaps = array_merge( (array) $this->allcaps, (array) $this->caps ); |
|
491 | + $this->allcaps = array_merge((array) $this->allcaps, (array) $this->caps); |
|
492 | 492 | |
493 | 493 | return $this->allcaps; |
494 | 494 | } |
@@ -503,13 +503,13 @@ discard block |
||
503 | 503 | * |
504 | 504 | * @param string $role Role name. |
505 | 505 | */ |
506 | - public function add_role( $role ) { |
|
507 | - if ( empty( $role ) ) { |
|
506 | + public function add_role($role) { |
|
507 | + if (empty($role)) { |
|
508 | 508 | return; |
509 | 509 | } |
510 | 510 | |
511 | 511 | $this->caps[$role] = true; |
512 | - update_user_meta( $this->ID, $this->cap_key, $this->caps ); |
|
512 | + update_user_meta($this->ID, $this->cap_key, $this->caps); |
|
513 | 513 | $this->get_role_caps(); |
514 | 514 | $this->update_user_level_from_caps(); |
515 | 515 | |
@@ -521,7 +521,7 @@ discard block |
||
521 | 521 | * @param int $user_id The user ID. |
522 | 522 | * @param string $role The new role. |
523 | 523 | */ |
524 | - do_action( 'add_user_role', $this->ID, $role ); |
|
524 | + do_action('add_user_role', $this->ID, $role); |
|
525 | 525 | } |
526 | 526 | |
527 | 527 | /** |
@@ -532,11 +532,11 @@ discard block |
||
532 | 532 | * |
533 | 533 | * @param string $role Role name. |
534 | 534 | */ |
535 | - public function remove_role( $role ) { |
|
536 | - if ( !in_array($role, $this->roles) ) |
|
535 | + public function remove_role($role) { |
|
536 | + if ( ! in_array($role, $this->roles)) |
|
537 | 537 | return; |
538 | - unset( $this->caps[$role] ); |
|
539 | - update_user_meta( $this->ID, $this->cap_key, $this->caps ); |
|
538 | + unset($this->caps[$role]); |
|
539 | + update_user_meta($this->ID, $this->cap_key, $this->caps); |
|
540 | 540 | $this->get_role_caps(); |
541 | 541 | $this->update_user_level_from_caps(); |
542 | 542 | |
@@ -548,7 +548,7 @@ discard block |
||
548 | 548 | * @param int $user_id The user ID. |
549 | 549 | * @param string $role The removed role. |
550 | 550 | */ |
551 | - do_action( 'remove_user_role', $this->ID, $role ); |
|
551 | + do_action('remove_user_role', $this->ID, $role); |
|
552 | 552 | } |
553 | 553 | |
554 | 554 | /** |
@@ -563,21 +563,21 @@ discard block |
||
563 | 563 | * |
564 | 564 | * @param string $role Role name. |
565 | 565 | */ |
566 | - public function set_role( $role ) { |
|
567 | - if ( 1 == count( $this->roles ) && $role == current( $this->roles ) ) |
|
566 | + public function set_role($role) { |
|
567 | + if (1 == count($this->roles) && $role == current($this->roles)) |
|
568 | 568 | return; |
569 | 569 | |
570 | - foreach ( (array) $this->roles as $oldrole ) |
|
571 | - unset( $this->caps[$oldrole] ); |
|
570 | + foreach ((array) $this->roles as $oldrole) |
|
571 | + unset($this->caps[$oldrole]); |
|
572 | 572 | |
573 | 573 | $old_roles = $this->roles; |
574 | - if ( !empty( $role ) ) { |
|
574 | + if ( ! empty($role)) { |
|
575 | 575 | $this->caps[$role] = true; |
576 | - $this->roles = array( $role => true ); |
|
576 | + $this->roles = array($role => true); |
|
577 | 577 | } else { |
578 | 578 | $this->roles = false; |
579 | 579 | } |
580 | - update_user_meta( $this->ID, $this->cap_key, $this->caps ); |
|
580 | + update_user_meta($this->ID, $this->cap_key, $this->caps); |
|
581 | 581 | $this->get_role_caps(); |
582 | 582 | $this->update_user_level_from_caps(); |
583 | 583 | |
@@ -591,7 +591,7 @@ discard block |
||
591 | 591 | * @param string $role The new role. |
592 | 592 | * @param array $old_roles An array of the user's previous roles. |
593 | 593 | */ |
594 | - do_action( 'set_user_role', $this->ID, $role, $old_roles ); |
|
594 | + do_action('set_user_role', $this->ID, $role, $old_roles); |
|
595 | 595 | } |
596 | 596 | |
597 | 597 | /** |
@@ -613,10 +613,10 @@ discard block |
||
613 | 613 | * @param string $item Level capability name. |
614 | 614 | * @return int Max Level. |
615 | 615 | */ |
616 | - public function level_reduction( $max, $item ) { |
|
617 | - if ( preg_match( '/^level_(10|[0-9])$/i', $item, $matches ) ) { |
|
618 | - $level = intval( $matches[1] ); |
|
619 | - return max( $max, $level ); |
|
616 | + public function level_reduction($max, $item) { |
|
617 | + if (preg_match('/^level_(10|[0-9])$/i', $item, $matches)) { |
|
618 | + $level = intval($matches[1]); |
|
619 | + return max($max, $level); |
|
620 | 620 | } else { |
621 | 621 | return $max; |
622 | 622 | } |
@@ -636,8 +636,8 @@ discard block |
||
636 | 636 | */ |
637 | 637 | public function update_user_level_from_caps() { |
638 | 638 | global $wpdb; |
639 | - $this->user_level = array_reduce( array_keys( $this->allcaps ), array( $this, 'level_reduction' ), 0 ); |
|
640 | - update_user_meta( $this->ID, $wpdb->get_blog_prefix() . 'user_level', $this->user_level ); |
|
639 | + $this->user_level = array_reduce(array_keys($this->allcaps), array($this, 'level_reduction'), 0); |
|
640 | + update_user_meta($this->ID, $wpdb->get_blog_prefix().'user_level', $this->user_level); |
|
641 | 641 | } |
642 | 642 | |
643 | 643 | /** |
@@ -649,9 +649,9 @@ discard block |
||
649 | 649 | * @param string $cap Capability name. |
650 | 650 | * @param bool $grant Whether to grant capability to user. |
651 | 651 | */ |
652 | - public function add_cap( $cap, $grant = true ) { |
|
652 | + public function add_cap($cap, $grant = true) { |
|
653 | 653 | $this->caps[$cap] = $grant; |
654 | - update_user_meta( $this->ID, $this->cap_key, $this->caps ); |
|
654 | + update_user_meta($this->ID, $this->cap_key, $this->caps); |
|
655 | 655 | $this->get_role_caps(); |
656 | 656 | $this->update_user_level_from_caps(); |
657 | 657 | } |
@@ -664,12 +664,12 @@ discard block |
||
664 | 664 | * |
665 | 665 | * @param string $cap Capability name. |
666 | 666 | */ |
667 | - public function remove_cap( $cap ) { |
|
668 | - if ( ! isset( $this->caps[ $cap ] ) ) { |
|
667 | + public function remove_cap($cap) { |
|
668 | + if ( ! isset($this->caps[$cap])) { |
|
669 | 669 | return; |
670 | 670 | } |
671 | - unset( $this->caps[ $cap ] ); |
|
672 | - update_user_meta( $this->ID, $this->cap_key, $this->caps ); |
|
671 | + unset($this->caps[$cap]); |
|
672 | + update_user_meta($this->ID, $this->cap_key, $this->caps); |
|
673 | 673 | $this->get_role_caps(); |
674 | 674 | $this->update_user_level_from_caps(); |
675 | 675 | } |
@@ -685,8 +685,8 @@ discard block |
||
685 | 685 | public function remove_all_caps() { |
686 | 686 | global $wpdb; |
687 | 687 | $this->caps = array(); |
688 | - delete_user_meta( $this->ID, $this->cap_key ); |
|
689 | - delete_user_meta( $this->ID, $wpdb->get_blog_prefix() . 'user_level' ); |
|
688 | + delete_user_meta($this->ID, $this->cap_key); |
|
689 | + delete_user_meta($this->ID, $wpdb->get_blog_prefix().'user_level'); |
|
690 | 690 | $this->get_role_caps(); |
691 | 691 | } |
692 | 692 | |
@@ -710,19 +710,19 @@ discard block |
||
710 | 710 | * @return bool Whether the current user has the given capability. If `$cap` is a meta cap and `$object_id` is |
711 | 711 | * passed, whether the current user has the given meta capability for the given object. |
712 | 712 | */ |
713 | - public function has_cap( $cap ) { |
|
714 | - if ( is_numeric( $cap ) ) { |
|
715 | - _deprecated_argument( __FUNCTION__, '2.0', __('Usage of user levels by plugins and themes is deprecated. Use roles and capabilities instead.') ); |
|
716 | - $cap = $this->translate_level_to_cap( $cap ); |
|
713 | + public function has_cap($cap) { |
|
714 | + if (is_numeric($cap)) { |
|
715 | + _deprecated_argument(__FUNCTION__, '2.0', __('Usage of user levels by plugins and themes is deprecated. Use roles and capabilities instead.')); |
|
716 | + $cap = $this->translate_level_to_cap($cap); |
|
717 | 717 | } |
718 | 718 | |
719 | - $args = array_slice( func_get_args(), 1 ); |
|
720 | - $args = array_merge( array( $cap, $this->ID ), $args ); |
|
721 | - $caps = call_user_func_array( 'map_meta_cap', $args ); |
|
719 | + $args = array_slice(func_get_args(), 1); |
|
720 | + $args = array_merge(array($cap, $this->ID), $args); |
|
721 | + $caps = call_user_func_array('map_meta_cap', $args); |
|
722 | 722 | |
723 | 723 | // Multisite super admin has all caps by definition, Unless specifically denied. |
724 | - if ( is_multisite() && is_super_admin( $this->ID ) ) { |
|
725 | - if ( in_array('do_not_allow', $caps) ) |
|
724 | + if (is_multisite() && is_super_admin($this->ID)) { |
|
725 | + if (in_array('do_not_allow', $caps)) |
|
726 | 726 | return false; |
727 | 727 | return true; |
728 | 728 | } |
@@ -738,14 +738,14 @@ discard block |
||
738 | 738 | * @param array $args Optional parameters passed to has_cap(), typically object ID. |
739 | 739 | * @param WP_User $user The user object. |
740 | 740 | */ |
741 | - $capabilities = apply_filters( 'user_has_cap', $this->allcaps, $caps, $args, $this ); |
|
741 | + $capabilities = apply_filters('user_has_cap', $this->allcaps, $caps, $args, $this); |
|
742 | 742 | |
743 | 743 | // Everyone is allowed to exist. |
744 | 744 | $capabilities['exist'] = true; |
745 | 745 | |
746 | 746 | // Must have ALL requested caps. |
747 | - foreach ( (array) $caps as $cap ) { |
|
748 | - if ( empty( $capabilities[ $cap ] ) ) |
|
747 | + foreach ((array) $caps as $cap) { |
|
748 | + if (empty($capabilities[$cap])) |
|
749 | 749 | return false; |
750 | 750 | } |
751 | 751 | |
@@ -763,8 +763,8 @@ discard block |
||
763 | 763 | * @param int $level Level number, 1 to 10. |
764 | 764 | * @return string |
765 | 765 | */ |
766 | - public function translate_level_to_cap( $level ) { |
|
767 | - return 'level_' . $level; |
|
766 | + public function translate_level_to_cap($level) { |
|
767 | + return 'level_'.$level; |
|
768 | 768 | } |
769 | 769 | |
770 | 770 | /** |
@@ -776,12 +776,12 @@ discard block |
||
776 | 776 | * |
777 | 777 | * @param int $blog_id Optional. Site ID, defaults to current site. |
778 | 778 | */ |
779 | - public function for_blog( $blog_id = '' ) { |
|
779 | + public function for_blog($blog_id = '') { |
|
780 | 780 | global $wpdb; |
781 | - if ( ! empty( $blog_id ) ) |
|
782 | - $cap_key = $wpdb->get_blog_prefix( $blog_id ) . 'capabilities'; |
|
781 | + if ( ! empty($blog_id)) |
|
782 | + $cap_key = $wpdb->get_blog_prefix($blog_id).'capabilities'; |
|
783 | 783 | else |
784 | 784 | $cap_key = ''; |
785 | - $this->_init_caps( $cap_key ); |
|
785 | + $this->_init_caps($cap_key); |
|
786 | 786 | } |
787 | 787 | } |
@@ -192,17 +192,20 @@ discard block |
||
192 | 192 | if ( 'id' == $field ) { |
193 | 193 | // Make sure the value is numeric to avoid casting objects, for example, |
194 | 194 | // to int 1. |
195 | - if ( ! is_numeric( $value ) ) |
|
196 | - return false; |
|
195 | + if ( ! is_numeric( $value ) ) { |
|
196 | + return false; |
|
197 | + } |
|
197 | 198 | $value = intval( $value ); |
198 | - if ( $value < 1 ) |
|
199 | - return false; |
|
199 | + if ( $value < 1 ) { |
|
200 | + return false; |
|
201 | + } |
|
200 | 202 | } else { |
201 | 203 | $value = trim( $value ); |
202 | 204 | } |
203 | 205 | |
204 | - if ( !$value ) |
|
205 | - return false; |
|
206 | + if ( !$value ) { |
|
207 | + return false; |
|
208 | + } |
|
206 | 209 | |
207 | 210 | switch ( $field ) { |
208 | 211 | case 'id': |
@@ -227,14 +230,16 @@ discard block |
||
227 | 230 | } |
228 | 231 | |
229 | 232 | if ( false !== $user_id ) { |
230 | - if ( $user = wp_cache_get( $user_id, 'users' ) ) |
|
231 | - return $user; |
|
233 | + if ( $user = wp_cache_get( $user_id, 'users' ) ) { |
|
234 | + return $user; |
|
235 | + } |
|
232 | 236 | } |
233 | 237 | |
234 | 238 | if ( !$user = $wpdb->get_row( $wpdb->prepare( |
235 | 239 | "SELECT * FROM $wpdb->users WHERE $db_field = %s", $value |
236 | - ) ) ) |
|
237 | - return false; |
|
240 | + ) ) ) { |
|
241 | + return false; |
|
242 | + } |
|
238 | 243 | |
239 | 244 | update_user_caches( $user ); |
240 | 245 | |
@@ -279,11 +284,13 @@ discard block |
||
279 | 284 | $key = 'ID'; |
280 | 285 | } |
281 | 286 | |
282 | - if ( isset( $this->data->$key ) ) |
|
283 | - return true; |
|
287 | + if ( isset( $this->data->$key ) ) { |
|
288 | + return true; |
|
289 | + } |
|
284 | 290 | |
285 | - if ( isset( self::$back_compat_keys[ $key ] ) ) |
|
286 | - $key = self::$back_compat_keys[ $key ]; |
|
291 | + if ( isset( self::$back_compat_keys[ $key ] ) ) { |
|
292 | + $key = self::$back_compat_keys[ $key ]; |
|
293 | + } |
|
287 | 294 | |
288 | 295 | return metadata_exists( 'user', $this->ID, $key ); |
289 | 296 | } |
@@ -312,8 +319,9 @@ discard block |
||
312 | 319 | if ( isset( $this->data->$key ) ) { |
313 | 320 | $value = $this->data->$key; |
314 | 321 | } else { |
315 | - if ( isset( self::$back_compat_keys[ $key ] ) ) |
|
316 | - $key = self::$back_compat_keys[ $key ]; |
|
322 | + if ( isset( self::$back_compat_keys[ $key ] ) ) { |
|
323 | + $key = self::$back_compat_keys[ $key ]; |
|
324 | + } |
|
317 | 325 | $value = get_user_meta( $this->ID, $key, true ); |
318 | 326 | } |
319 | 327 | |
@@ -449,15 +457,17 @@ discard block |
||
449 | 457 | protected function _init_caps( $cap_key = '' ) { |
450 | 458 | global $wpdb; |
451 | 459 | |
452 | - if ( empty($cap_key) ) |
|
453 | - $this->cap_key = $wpdb->get_blog_prefix() . 'capabilities'; |
|
454 | - else |
|
455 | - $this->cap_key = $cap_key; |
|
460 | + if ( empty($cap_key) ) { |
|
461 | + $this->cap_key = $wpdb->get_blog_prefix() . 'capabilities'; |
|
462 | + } else { |
|
463 | + $this->cap_key = $cap_key; |
|
464 | + } |
|
456 | 465 | |
457 | 466 | $this->caps = get_user_meta( $this->ID, $this->cap_key, true ); |
458 | 467 | |
459 | - if ( ! is_array( $this->caps ) ) |
|
460 | - $this->caps = array(); |
|
468 | + if ( ! is_array( $this->caps ) ) { |
|
469 | + $this->caps = array(); |
|
470 | + } |
|
461 | 471 | |
462 | 472 | $this->get_role_caps(); |
463 | 473 | } |
@@ -479,8 +489,9 @@ discard block |
||
479 | 489 | $wp_roles = wp_roles(); |
480 | 490 | |
481 | 491 | //Filter out caps that are not role names and assign to $this->roles |
482 | - if ( is_array( $this->caps ) ) |
|
483 | - $this->roles = array_filter( array_keys( $this->caps ), array( $wp_roles, 'is_role' ) ); |
|
492 | + if ( is_array( $this->caps ) ) { |
|
493 | + $this->roles = array_filter( array_keys( $this->caps ), array( $wp_roles, 'is_role' ) ); |
|
494 | + } |
|
484 | 495 | |
485 | 496 | //Build $allcaps from role caps, overlay user's $caps |
486 | 497 | $this->allcaps = array(); |
@@ -533,8 +544,9 @@ discard block |
||
533 | 544 | * @param string $role Role name. |
534 | 545 | */ |
535 | 546 | public function remove_role( $role ) { |
536 | - if ( !in_array($role, $this->roles) ) |
|
537 | - return; |
|
547 | + if ( !in_array($role, $this->roles) ) { |
|
548 | + return; |
|
549 | + } |
|
538 | 550 | unset( $this->caps[$role] ); |
539 | 551 | update_user_meta( $this->ID, $this->cap_key, $this->caps ); |
540 | 552 | $this->get_role_caps(); |
@@ -564,11 +576,13 @@ discard block |
||
564 | 576 | * @param string $role Role name. |
565 | 577 | */ |
566 | 578 | public function set_role( $role ) { |
567 | - if ( 1 == count( $this->roles ) && $role == current( $this->roles ) ) |
|
568 | - return; |
|
579 | + if ( 1 == count( $this->roles ) && $role == current( $this->roles ) ) { |
|
580 | + return; |
|
581 | + } |
|
569 | 582 | |
570 | - foreach ( (array) $this->roles as $oldrole ) |
|
571 | - unset( $this->caps[$oldrole] ); |
|
583 | + foreach ( (array) $this->roles as $oldrole ) { |
|
584 | + unset( $this->caps[$oldrole] ); |
|
585 | + } |
|
572 | 586 | |
573 | 587 | $old_roles = $this->roles; |
574 | 588 | if ( !empty( $role ) ) { |
@@ -722,8 +736,9 @@ discard block |
||
722 | 736 | |
723 | 737 | // Multisite super admin has all caps by definition, Unless specifically denied. |
724 | 738 | if ( is_multisite() && is_super_admin( $this->ID ) ) { |
725 | - if ( in_array('do_not_allow', $caps) ) |
|
726 | - return false; |
|
739 | + if ( in_array('do_not_allow', $caps) ) { |
|
740 | + return false; |
|
741 | + } |
|
727 | 742 | return true; |
728 | 743 | } |
729 | 744 | |
@@ -745,8 +760,9 @@ discard block |
||
745 | 760 | |
746 | 761 | // Must have ALL requested caps. |
747 | 762 | foreach ( (array) $caps as $cap ) { |
748 | - if ( empty( $capabilities[ $cap ] ) ) |
|
749 | - return false; |
|
763 | + if ( empty( $capabilities[ $cap ] ) ) { |
|
764 | + return false; |
|
765 | + } |
|
750 | 766 | } |
751 | 767 | |
752 | 768 | return true; |
@@ -778,10 +794,11 @@ discard block |
||
778 | 794 | */ |
779 | 795 | public function for_blog( $blog_id = '' ) { |
780 | 796 | global $wpdb; |
781 | - if ( ! empty( $blog_id ) ) |
|
782 | - $cap_key = $wpdb->get_blog_prefix( $blog_id ) . 'capabilities'; |
|
783 | - else |
|
784 | - $cap_key = ''; |
|
797 | + if ( ! empty( $blog_id ) ) { |
|
798 | + $cap_key = $wpdb->get_blog_prefix( $blog_id ) . 'capabilities'; |
|
799 | + } else { |
|
800 | + $cap_key = ''; |
|
801 | + } |
|
785 | 802 | $this->_init_caps( $cap_key ); |
786 | 803 | } |
787 | 804 | } |
@@ -317,7 +317,7 @@ discard block |
||
317 | 317 | * |
318 | 318 | * @param array $args Display arguments. See {@see WP_Widget::widget()} for information |
319 | 319 | * on accepted arguments. |
320 | - * @param int|array $widget_args { |
|
320 | + * @param integer $widget_args { |
|
321 | 321 | * Optional. Internal order number of the widget instance, or array of multi-widget arguments. |
322 | 322 | * Default 1. |
323 | 323 | * |
@@ -457,7 +457,7 @@ discard block |
||
457 | 457 | * @since 2.8.0 |
458 | 458 | * @access public |
459 | 459 | * |
460 | - * @param int|array $widget_args Widget instance number or array of widget arguments. |
|
460 | + * @param integer $widget_args Widget instance number or array of widget arguments. |
|
461 | 461 | * @return string|null |
462 | 462 | */ |
463 | 463 | public function form_callback( $widget_args = 1 ) { |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | * 'before_widget', and 'after_widget'. |
99 | 99 | * @param array $instance The settings for the particular instance of the widget. |
100 | 100 | */ |
101 | - public function widget( $args, $instance ) { |
|
101 | + public function widget($args, $instance) { |
|
102 | 102 | die('function WP_Widget::widget() must be over-ridden in a sub-class.'); |
103 | 103 | } |
104 | 104 | |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | * @param array $old_instance Old settings for this instance. |
118 | 118 | * @return array Settings to save or bool false to cancel saving. |
119 | 119 | */ |
120 | - public function update( $new_instance, $old_instance ) { |
|
120 | + public function update($new_instance, $old_instance) { |
|
121 | 121 | return $new_instance; |
122 | 122 | } |
123 | 123 | |
@@ -130,8 +130,8 @@ discard block |
||
130 | 130 | * @param array $instance Current settings. |
131 | 131 | * @return string Default return is 'noform'. |
132 | 132 | */ |
133 | - public function form( $instance ) { |
|
134 | - echo '<p class="no-options-widget">' . __('There are no options for this widget.') . '</p>'; |
|
133 | + public function form($instance) { |
|
134 | + echo '<p class="no-options-widget">'.__('There are no options for this widget.').'</p>'; |
|
135 | 135 | return 'noform'; |
136 | 136 | } |
137 | 137 | |
@@ -151,12 +151,12 @@ discard block |
||
151 | 151 | * @param array $control_options Optional. Widget control options. See wp_register_widget_control() for |
152 | 152 | * information on accepted arguments. Default empty array. |
153 | 153 | */ |
154 | - public function __construct( $id_base, $name, $widget_options = array(), $control_options = array() ) { |
|
155 | - $this->id_base = empty($id_base) ? preg_replace( '/(wp_)?widget_/', '', strtolower(get_class($this)) ) : strtolower($id_base); |
|
154 | + public function __construct($id_base, $name, $widget_options = array(), $control_options = array()) { |
|
155 | + $this->id_base = empty($id_base) ? preg_replace('/(wp_)?widget_/', '', strtolower(get_class($this))) : strtolower($id_base); |
|
156 | 156 | $this->name = $name; |
157 | - $this->option_name = 'widget_' . $this->id_base; |
|
158 | - $this->widget_options = wp_parse_args( $widget_options, array('classname' => $this->option_name) ); |
|
159 | - $this->control_options = wp_parse_args( $control_options, array('id_base' => $this->id_base) ); |
|
157 | + $this->option_name = 'widget_'.$this->id_base; |
|
158 | + $this->widget_options = wp_parse_args($widget_options, array('classname' => $this->option_name)); |
|
159 | + $this->control_options = wp_parse_args($control_options, array('id_base' => $this->id_base)); |
|
160 | 160 | } |
161 | 161 | |
162 | 162 | /** |
@@ -167,9 +167,9 @@ discard block |
||
167 | 167 | * @param array $widget_options |
168 | 168 | * @param array $control_options |
169 | 169 | */ |
170 | - public function WP_Widget( $id_base, $name, $widget_options = array(), $control_options = array() ) { |
|
171 | - _deprecated_constructor( 'WP_Widget', '4.3.0', get_class( $this ) ); |
|
172 | - WP_Widget::__construct( $id_base, $name, $widget_options, $control_options ); |
|
170 | + public function WP_Widget($id_base, $name, $widget_options = array(), $control_options = array()) { |
|
171 | + _deprecated_constructor('WP_Widget', '4.3.0', get_class($this)); |
|
172 | + WP_Widget::__construct($id_base, $name, $widget_options, $control_options); |
|
173 | 173 | } |
174 | 174 | |
175 | 175 | /** |
@@ -184,10 +184,10 @@ discard block |
||
184 | 184 | * @return string Name attribute for $field_name |
185 | 185 | */ |
186 | 186 | public function get_field_name($field_name) { |
187 | - if ( false === $pos = strpos( $field_name, '[' ) ) { |
|
188 | - return 'widget-' . $this->id_base . '[' . $this->number . '][' . $field_name . ']'; |
|
187 | + if (false === $pos = strpos($field_name, '[')) { |
|
188 | + return 'widget-'.$this->id_base.'['.$this->number.']['.$field_name.']'; |
|
189 | 189 | } else { |
190 | - return 'widget-' . $this->id_base . '[' . $this->number . '][' . substr_replace( $field_name, '][', $pos, strlen( '[' ) ); |
|
190 | + return 'widget-'.$this->id_base.'['.$this->number.']['.substr_replace($field_name, '][', $pos, strlen('[')); |
|
191 | 191 | } |
192 | 192 | } |
193 | 193 | |
@@ -204,8 +204,8 @@ discard block |
||
204 | 204 | * @param string $field_name Field name. |
205 | 205 | * @return string ID attribute for `$field_name`. |
206 | 206 | */ |
207 | - public function get_field_id( $field_name ) { |
|
208 | - return 'widget-' . $this->id_base . '-' . $this->number . '-' . trim( str_replace( array( '[]', '[', ']' ), array( '', '-', '' ), $field_name ), '-' ); |
|
207 | + public function get_field_id($field_name) { |
|
208 | + return 'widget-'.$this->id_base.'-'.$this->number.'-'.trim(str_replace(array('[]', '[', ']'), array('', '-', ''), $field_name), '-'); |
|
209 | 209 | } |
210 | 210 | |
211 | 211 | /** |
@@ -219,23 +219,23 @@ discard block |
||
219 | 219 | $empty = true; |
220 | 220 | |
221 | 221 | // When $settings is an array-like object, get an intrinsic array for use with array_keys(). |
222 | - if ( $settings instanceof ArrayObject || $settings instanceof ArrayIterator ) { |
|
222 | + if ($settings instanceof ArrayObject || $settings instanceof ArrayIterator) { |
|
223 | 223 | $settings = $settings->getArrayCopy(); |
224 | 224 | } |
225 | 225 | |
226 | - if ( is_array( $settings ) ) { |
|
227 | - foreach ( array_keys( $settings ) as $number ) { |
|
228 | - if ( is_numeric( $number ) ) { |
|
229 | - $this->_set( $number ); |
|
230 | - $this->_register_one( $number ); |
|
226 | + if (is_array($settings)) { |
|
227 | + foreach (array_keys($settings) as $number) { |
|
228 | + if (is_numeric($number)) { |
|
229 | + $this->_set($number); |
|
230 | + $this->_register_one($number); |
|
231 | 231 | $empty = false; |
232 | 232 | } |
233 | 233 | } |
234 | 234 | } |
235 | 235 | |
236 | - if ( $empty ) { |
|
236 | + if ($empty) { |
|
237 | 237 | // If there are none, we register the widget's existence with a generic template. |
238 | - $this->_set( 1 ); |
|
238 | + $this->_set(1); |
|
239 | 239 | $this->_register_one(); |
240 | 240 | } |
241 | 241 | } |
@@ -251,7 +251,7 @@ discard block |
||
251 | 251 | */ |
252 | 252 | public function _set($number) { |
253 | 253 | $this->number = $number; |
254 | - $this->id = $this->id_base . '-' . $number; |
|
254 | + $this->id = $this->id_base.'-'.$number; |
|
255 | 255 | } |
256 | 256 | |
257 | 257 | /** |
@@ -304,7 +304,7 @@ discard block |
||
304 | 304 | */ |
305 | 305 | public function is_preview() { |
306 | 306 | global $wp_customize; |
307 | - return ( isset( $wp_customize ) && $wp_customize->is_preview() ) ; |
|
307 | + return (isset($wp_customize) && $wp_customize->is_preview()); |
|
308 | 308 | } |
309 | 309 | |
310 | 310 | /** |
@@ -324,17 +324,17 @@ discard block |
||
324 | 324 | * @type int $number Number increment used for multiples of the same widget. |
325 | 325 | * } |
326 | 326 | */ |
327 | - public function display_callback( $args, $widget_args = 1 ) { |
|
328 | - if ( is_numeric( $widget_args ) ) { |
|
329 | - $widget_args = array( 'number' => $widget_args ); |
|
327 | + public function display_callback($args, $widget_args = 1) { |
|
328 | + if (is_numeric($widget_args)) { |
|
329 | + $widget_args = array('number' => $widget_args); |
|
330 | 330 | } |
331 | 331 | |
332 | - $widget_args = wp_parse_args( $widget_args, array( 'number' => -1 ) ); |
|
333 | - $this->_set( $widget_args['number'] ); |
|
332 | + $widget_args = wp_parse_args($widget_args, array('number' => -1)); |
|
333 | + $this->_set($widget_args['number']); |
|
334 | 334 | $instances = $this->get_settings(); |
335 | 335 | |
336 | - if ( array_key_exists( $this->number, $instances ) ) { |
|
337 | - $instance = $instances[ $this->number ]; |
|
336 | + if (array_key_exists($this->number, $instances)) { |
|
337 | + $instance = $instances[$this->number]; |
|
338 | 338 | |
339 | 339 | /** |
340 | 340 | * Filter the settings for a particular widget instance. |
@@ -347,21 +347,21 @@ discard block |
||
347 | 347 | * @param WP_Widget $this The current widget instance. |
348 | 348 | * @param array $args An array of default widget arguments. |
349 | 349 | */ |
350 | - $instance = apply_filters( 'widget_display_callback', $instance, $this, $args ); |
|
350 | + $instance = apply_filters('widget_display_callback', $instance, $this, $args); |
|
351 | 351 | |
352 | - if ( false === $instance ) { |
|
352 | + if (false === $instance) { |
|
353 | 353 | return; |
354 | 354 | } |
355 | 355 | |
356 | 356 | $was_cache_addition_suspended = wp_suspend_cache_addition(); |
357 | - if ( $this->is_preview() && ! $was_cache_addition_suspended ) { |
|
358 | - wp_suspend_cache_addition( true ); |
|
357 | + if ($this->is_preview() && ! $was_cache_addition_suspended) { |
|
358 | + wp_suspend_cache_addition(true); |
|
359 | 359 | } |
360 | 360 | |
361 | - $this->widget( $args, $instance ); |
|
361 | + $this->widget($args, $instance); |
|
362 | 362 | |
363 | - if ( $this->is_preview() ) { |
|
364 | - wp_suspend_cache_addition( $was_cache_addition_suspended ); |
|
363 | + if ($this->is_preview()) { |
|
364 | + wp_suspend_cache_addition($was_cache_addition_suspended); |
|
365 | 365 | } |
366 | 366 | } |
367 | 367 | } |
@@ -376,53 +376,53 @@ discard block |
||
376 | 376 | * |
377 | 377 | * @param int $deprecated Not used. |
378 | 378 | */ |
379 | - public function update_callback( $deprecated = 1 ) { |
|
379 | + public function update_callback($deprecated = 1) { |
|
380 | 380 | global $wp_registered_widgets; |
381 | 381 | |
382 | 382 | $all_instances = $this->get_settings(); |
383 | 383 | |
384 | 384 | // We need to update the data |
385 | - if ( $this->updated ) |
|
385 | + if ($this->updated) |
|
386 | 386 | return; |
387 | 387 | |
388 | - if ( isset($_POST['delete_widget']) && $_POST['delete_widget'] ) { |
|
388 | + if (isset($_POST['delete_widget']) && $_POST['delete_widget']) { |
|
389 | 389 | // Delete the settings for this instance of the widget |
390 | - if ( isset($_POST['the-widget-id']) ) |
|
390 | + if (isset($_POST['the-widget-id'])) |
|
391 | 391 | $del_id = $_POST['the-widget-id']; |
392 | 392 | else |
393 | 393 | return; |
394 | 394 | |
395 | - if ( isset($wp_registered_widgets[$del_id]['params'][0]['number']) ) { |
|
395 | + if (isset($wp_registered_widgets[$del_id]['params'][0]['number'])) { |
|
396 | 396 | $number = $wp_registered_widgets[$del_id]['params'][0]['number']; |
397 | 397 | |
398 | - if ( $this->id_base . '-' . $number == $del_id ) |
|
398 | + if ($this->id_base.'-'.$number == $del_id) |
|
399 | 399 | unset($all_instances[$number]); |
400 | 400 | } |
401 | 401 | } else { |
402 | - if ( isset($_POST['widget-' . $this->id_base]) && is_array($_POST['widget-' . $this->id_base]) ) { |
|
403 | - $settings = $_POST['widget-' . $this->id_base]; |
|
404 | - } elseif ( isset($_POST['id_base']) && $_POST['id_base'] == $this->id_base ) { |
|
402 | + if (isset($_POST['widget-'.$this->id_base]) && is_array($_POST['widget-'.$this->id_base])) { |
|
403 | + $settings = $_POST['widget-'.$this->id_base]; |
|
404 | + } elseif (isset($_POST['id_base']) && $_POST['id_base'] == $this->id_base) { |
|
405 | 405 | $num = $_POST['multi_number'] ? (int) $_POST['multi_number'] : (int) $_POST['widget_number']; |
406 | - $settings = array( $num => array() ); |
|
406 | + $settings = array($num => array()); |
|
407 | 407 | } else { |
408 | 408 | return; |
409 | 409 | } |
410 | 410 | |
411 | - foreach ( $settings as $number => $new_instance ) { |
|
411 | + foreach ($settings as $number => $new_instance) { |
|
412 | 412 | $new_instance = stripslashes_deep($new_instance); |
413 | 413 | $this->_set($number); |
414 | 414 | |
415 | 415 | $old_instance = isset($all_instances[$number]) ? $all_instances[$number] : array(); |
416 | 416 | |
417 | 417 | $was_cache_addition_suspended = wp_suspend_cache_addition(); |
418 | - if ( $this->is_preview() && ! $was_cache_addition_suspended ) { |
|
419 | - wp_suspend_cache_addition( true ); |
|
418 | + if ($this->is_preview() && ! $was_cache_addition_suspended) { |
|
419 | + wp_suspend_cache_addition(true); |
|
420 | 420 | } |
421 | 421 | |
422 | - $instance = $this->update( $new_instance, $old_instance ); |
|
422 | + $instance = $this->update($new_instance, $old_instance); |
|
423 | 423 | |
424 | - if ( $this->is_preview() ) { |
|
425 | - wp_suspend_cache_addition( $was_cache_addition_suspended ); |
|
424 | + if ($this->is_preview()) { |
|
425 | + wp_suspend_cache_addition($was_cache_addition_suspended); |
|
426 | 426 | } |
427 | 427 | |
428 | 428 | /** |
@@ -438,8 +438,8 @@ discard block |
||
438 | 438 | * @param array $old_instance Array of old widget settings. |
439 | 439 | * @param WP_Widget $this The current widget instance. |
440 | 440 | */ |
441 | - $instance = apply_filters( 'widget_update_callback', $instance, $new_instance, $old_instance, $this ); |
|
442 | - if ( false !== $instance ) { |
|
441 | + $instance = apply_filters('widget_update_callback', $instance, $new_instance, $old_instance, $this); |
|
442 | + if (false !== $instance) { |
|
443 | 443 | $all_instances[$number] = $instance; |
444 | 444 | } |
445 | 445 | |
@@ -460,11 +460,11 @@ discard block |
||
460 | 460 | * @param int|array $widget_args Widget instance number or array of widget arguments. |
461 | 461 | * @return string|null |
462 | 462 | */ |
463 | - public function form_callback( $widget_args = 1 ) { |
|
464 | - if ( is_numeric($widget_args) ) |
|
465 | - $widget_args = array( 'number' => $widget_args ); |
|
463 | + public function form_callback($widget_args = 1) { |
|
464 | + if (is_numeric($widget_args)) |
|
465 | + $widget_args = array('number' => $widget_args); |
|
466 | 466 | |
467 | - $widget_args = wp_parse_args( $widget_args, array( 'number' => -1 ) ); |
|
467 | + $widget_args = wp_parse_args($widget_args, array('number' => -1)); |
|
468 | 468 | $all_instances = $this->get_settings(); |
469 | 469 | |
470 | 470 | if ( -1 == $widget_args['number'] ) { |
@@ -473,7 +473,7 @@ discard block |
||
473 | 473 | $instance = array(); |
474 | 474 | } else { |
475 | 475 | $this->_set($widget_args['number']); |
476 | - $instance = $all_instances[ $widget_args['number'] ]; |
|
476 | + $instance = $all_instances[$widget_args['number']]; |
|
477 | 477 | } |
478 | 478 | |
479 | 479 | /** |
@@ -486,10 +486,10 @@ discard block |
||
486 | 486 | * @param array $instance The current widget instance's settings. |
487 | 487 | * @param WP_Widget $this The current widget instance. |
488 | 488 | */ |
489 | - $instance = apply_filters( 'widget_form_callback', $instance, $this ); |
|
489 | + $instance = apply_filters('widget_form_callback', $instance, $this); |
|
490 | 490 | |
491 | 491 | $return = null; |
492 | - if ( false !== $instance ) { |
|
492 | + if (false !== $instance) { |
|
493 | 493 | $return = $this->form($instance); |
494 | 494 | |
495 | 495 | /** |
@@ -508,7 +508,7 @@ discard block |
||
508 | 508 | * @param null $return Return null if new fields are added. |
509 | 509 | * @param array $instance An array of the widget's settings. |
510 | 510 | */ |
511 | - do_action_ref_array( 'in_widget_form', array( &$this, &$return, $instance ) ); |
|
511 | + do_action_ref_array('in_widget_form', array(&$this, &$return, $instance)); |
|
512 | 512 | } |
513 | 513 | return $return; |
514 | 514 | } |
@@ -522,10 +522,10 @@ discard block |
||
522 | 522 | * @param integer $number Optional. The unique order number of this widget instance |
523 | 523 | * compared to other instances of the same class. Default -1. |
524 | 524 | */ |
525 | - public function _register_one( $number = -1 ) { |
|
526 | - wp_register_sidebar_widget( $this->id, $this->name, $this->_get_display_callback(), $this->widget_options, array( 'number' => $number ) ); |
|
527 | - _register_widget_update_callback( $this->id_base, $this->_get_update_callback(), $this->control_options, array( 'number' => -1 ) ); |
|
528 | - _register_widget_form_callback( $this->id, $this->name, $this->_get_form_callback(), $this->control_options, array( 'number' => $number ) ); |
|
525 | + public function _register_one($number = -1) { |
|
526 | + wp_register_sidebar_widget($this->id, $this->name, $this->_get_display_callback(), $this->widget_options, array('number' => $number)); |
|
527 | + _register_widget_update_callback($this->id_base, $this->_get_update_callback(), $this->control_options, array('number' => -1)); |
|
528 | + _register_widget_form_callback($this->id, $this->name, $this->_get_form_callback(), $this->control_options, array('number' => $number)); |
|
529 | 529 | } |
530 | 530 | |
531 | 531 | /** |
@@ -536,9 +536,9 @@ discard block |
||
536 | 536 | * |
537 | 537 | * @param array $settings Multi-dimensional array of widget instance settings. |
538 | 538 | */ |
539 | - public function save_settings( $settings ) { |
|
539 | + public function save_settings($settings) { |
|
540 | 540 | $settings['_multiwidget'] = 1; |
541 | - update_option( $this->option_name, $settings ); |
|
541 | + update_option($this->option_name, $settings); |
|
542 | 542 | } |
543 | 543 | |
544 | 544 | /** |
@@ -551,27 +551,27 @@ discard block |
||
551 | 551 | */ |
552 | 552 | public function get_settings() { |
553 | 553 | |
554 | - $settings = get_option( $this->option_name ); |
|
554 | + $settings = get_option($this->option_name); |
|
555 | 555 | |
556 | - if ( false === $settings ) { |
|
557 | - if ( isset( $this->alt_option_name ) ) { |
|
558 | - $settings = get_option( $this->alt_option_name ); |
|
556 | + if (false === $settings) { |
|
557 | + if (isset($this->alt_option_name)) { |
|
558 | + $settings = get_option($this->alt_option_name); |
|
559 | 559 | } else { |
560 | 560 | // Save an option so it can be autoloaded next time. |
561 | - $this->save_settings( array() ); |
|
561 | + $this->save_settings(array()); |
|
562 | 562 | } |
563 | 563 | } |
564 | 564 | |
565 | - if ( ! is_array( $settings ) && ! ( $settings instanceof ArrayObject || $settings instanceof ArrayIterator ) ) { |
|
565 | + if ( ! is_array($settings) && ! ($settings instanceof ArrayObject || $settings instanceof ArrayIterator)) { |
|
566 | 566 | $settings = array(); |
567 | 567 | } |
568 | 568 | |
569 | - if ( ! empty( $settings ) && ! isset( $settings['_multiwidget'] ) ) { |
|
569 | + if ( ! empty($settings) && ! isset($settings['_multiwidget'])) { |
|
570 | 570 | // Old format, convert if single widget. |
571 | - $settings = wp_convert_widget_settings( $this->id_base, $this->option_name, $settings ); |
|
571 | + $settings = wp_convert_widget_settings($this->id_base, $this->option_name, $settings); |
|
572 | 572 | } |
573 | 573 | |
574 | - unset( $settings['_multiwidget'], $settings['__i__'] ); |
|
574 | + unset($settings['_multiwidget'], $settings['__i__']); |
|
575 | 575 | return $settings; |
576 | 576 | } |
577 | 577 | } |
@@ -382,21 +382,24 @@ discard block |
||
382 | 382 | $all_instances = $this->get_settings(); |
383 | 383 | |
384 | 384 | // We need to update the data |
385 | - if ( $this->updated ) |
|
386 | - return; |
|
385 | + if ( $this->updated ) { |
|
386 | + return; |
|
387 | + } |
|
387 | 388 | |
388 | 389 | if ( isset($_POST['delete_widget']) && $_POST['delete_widget'] ) { |
389 | 390 | // Delete the settings for this instance of the widget |
390 | - if ( isset($_POST['the-widget-id']) ) |
|
391 | - $del_id = $_POST['the-widget-id']; |
|
392 | - else |
|
393 | - return; |
|
391 | + if ( isset($_POST['the-widget-id']) ) { |
|
392 | + $del_id = $_POST['the-widget-id']; |
|
393 | + } else { |
|
394 | + return; |
|
395 | + } |
|
394 | 396 | |
395 | 397 | if ( isset($wp_registered_widgets[$del_id]['params'][0]['number']) ) { |
396 | 398 | $number = $wp_registered_widgets[$del_id]['params'][0]['number']; |
397 | 399 | |
398 | - if ( $this->id_base . '-' . $number == $del_id ) |
|
399 | - unset($all_instances[$number]); |
|
400 | + if ( $this->id_base . '-' . $number == $del_id ) { |
|
401 | + unset($all_instances[$number]); |
|
402 | + } |
|
400 | 403 | } |
401 | 404 | } else { |
402 | 405 | if ( isset($_POST['widget-' . $this->id_base]) && is_array($_POST['widget-' . $this->id_base]) ) { |
@@ -461,8 +464,9 @@ discard block |
||
461 | 464 | * @return string|null |
462 | 465 | */ |
463 | 466 | public function form_callback( $widget_args = 1 ) { |
464 | - if ( is_numeric($widget_args) ) |
|
465 | - $widget_args = array( 'number' => $widget_args ); |
|
467 | + if ( is_numeric($widget_args) ) { |
|
468 | + $widget_args = array( 'number' => $widget_args ); |
|
469 | + } |
|
466 | 470 | |
467 | 471 | $widget_args = wp_parse_args( $widget_args, array( 'number' => -1 ) ); |
468 | 472 | $all_instances = $this->get_settings(); |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | * @since 1.5.0 |
18 | 18 | * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object. |
19 | 19 | * |
20 | - * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to retrieve the author. |
|
20 | + * @param integer $comment_ID Optional. WP_Comment or the ID of the comment for which to retrieve the author. |
|
21 | 21 | * Default current comment. |
22 | 22 | * @return string The comment author |
23 | 23 | */ |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | * @since 0.71 |
53 | 53 | * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object. |
54 | 54 | * |
55 | - * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to print the author. |
|
55 | + * @param integer $comment_ID Optional. WP_Comment or the ID of the comment for which to print the author. |
|
56 | 56 | * Default current comment. |
57 | 57 | */ |
58 | 58 | function comment_author( $comment_ID = 0 ) { |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | * @since 1.5.0 |
78 | 78 | * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object. |
79 | 79 | * |
80 | - * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to get the author's email. |
|
80 | + * @param integer $comment_ID Optional. WP_Comment or the ID of the comment for which to get the author's email. |
|
81 | 81 | * Default current comment. |
82 | 82 | * @return string The current comment author's email |
83 | 83 | */ |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | * @since 0.71 |
110 | 110 | * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object. |
111 | 111 | * |
112 | - * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to print the author's email. |
|
112 | + * @param integer $comment_ID Optional. WP_Comment or the ID of the comment for which to print the author's email. |
|
113 | 113 | * Default current comment. |
114 | 114 | */ |
115 | 115 | function comment_author_email( $comment_ID = 0 ) { |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | * @since 1.5.0 |
202 | 202 | * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object. |
203 | 203 | * |
204 | - * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to get the author's link. |
|
204 | + * @param integer $comment_ID Optional. WP_Comment or the ID of the comment for which to get the author's link. |
|
205 | 205 | * Default current comment. |
206 | 206 | * @return string The comment author name or HTML link for author's URL. |
207 | 207 | */ |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | * @since 0.71 |
236 | 236 | * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object. |
237 | 237 | * |
238 | - * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to print the author's link. |
|
238 | + * @param integer $comment_ID Optional. WP_Comment or the ID of the comment for which to print the author's link. |
|
239 | 239 | * Default current comment. |
240 | 240 | */ |
241 | 241 | function comment_author_link( $comment_ID = 0 ) { |
@@ -248,7 +248,7 @@ discard block |
||
248 | 248 | * @since 1.5.0 |
249 | 249 | * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object. |
250 | 250 | * |
251 | - * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to get the author's IP address. |
|
251 | + * @param integer $comment_ID Optional. WP_Comment or the ID of the comment for which to get the author's IP address. |
|
252 | 252 | * Default current comment. |
253 | 253 | * @return string Comment author's IP address. |
254 | 254 | */ |
@@ -274,7 +274,7 @@ discard block |
||
274 | 274 | * @since 0.71 |
275 | 275 | * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object. |
276 | 276 | * |
277 | - * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to print the author's IP address. |
|
277 | + * @param integer $comment_ID Optional. WP_Comment or the ID of the comment for which to print the author's IP address. |
|
278 | 278 | * Default current comment. |
279 | 279 | */ |
280 | 280 | function comment_author_IP( $comment_ID = 0 ) { |
@@ -287,7 +287,7 @@ discard block |
||
287 | 287 | * @since 1.5.0 |
288 | 288 | * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object. |
289 | 289 | * |
290 | - * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to get the author's URL. |
|
290 | + * @param integer $comment_ID Optional. WP_Comment or the ID of the comment for which to get the author's URL. |
|
291 | 291 | * Default current comment. |
292 | 292 | * @return string Comment author URL. |
293 | 293 | */ |
@@ -315,7 +315,7 @@ discard block |
||
315 | 315 | * @since 0.71 |
316 | 316 | * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object. |
317 | 317 | * |
318 | - * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to print the author's URL. |
|
318 | + * @param integer $comment_ID Optional. WP_Comment or the ID of the comment for which to print the author's URL. |
|
319 | 319 | * Default current comment. |
320 | 320 | */ |
321 | 321 | function comment_author_url( $comment_ID = 0 ) { |
@@ -513,7 +513,7 @@ discard block |
||
513 | 513 | * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object. |
514 | 514 | * |
515 | 515 | * @param string $d Optional. The format of the date. Default user's setting. |
516 | - * @param int|WP_Comment $comment_ID WP_Comment or ID of the comment for which to get the date. |
|
516 | + * @param integer $comment_ID WP_Comment or ID of the comment for which to get the date. |
|
517 | 517 | * Default current comment. |
518 | 518 | * @return string The comment's date. |
519 | 519 | */ |
@@ -542,7 +542,7 @@ discard block |
||
542 | 542 | * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object. |
543 | 543 | * |
544 | 544 | * @param string $d Optional. The format of the date. Default user's settings. |
545 | - * @param int|WP_Comment $comment_ID WP_Comment or ID of the comment for which to print the date. |
|
545 | + * @param integer $comment_ID WP_Comment or ID of the comment for which to print the date. |
|
546 | 546 | * Default current comment. |
547 | 547 | */ |
548 | 548 | function comment_date( $d = '', $comment_ID = 0 ) { |
@@ -559,7 +559,7 @@ discard block |
||
559 | 559 | * @since 1.5.0 |
560 | 560 | * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object. |
561 | 561 | * |
562 | - * @param int|WP_Comment $comment_ID WP_Comment or ID of the comment for which to get the excerpt. |
|
562 | + * @param integer $comment_ID WP_Comment or ID of the comment for which to get the excerpt. |
|
563 | 563 | * Default current comment. |
564 | 564 | * @return string The maybe truncated comment with 20 words or less. |
565 | 565 | */ |
@@ -605,7 +605,7 @@ discard block |
||
605 | 605 | * @since 1.2.0 |
606 | 606 | * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object. |
607 | 607 | * |
608 | - * @param int|WP_Comment $comment_ID WP_Comment or ID of the comment for which to print the excerpt. |
|
608 | + * @param integer $comment_ID WP_Comment or ID of the comment for which to print the excerpt. |
|
609 | 609 | * Default current comment. |
610 | 610 | */ |
611 | 611 | function comment_excerpt( $comment_ID = 0 ) { |
@@ -775,7 +775,7 @@ discard block |
||
775 | 775 | * |
776 | 776 | * @since 1.5.0 |
777 | 777 | * |
778 | - * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global $post. |
|
778 | + * @param integer $post_id Optional. Post ID or WP_Post object. Default is global $post. |
|
779 | 779 | * @return string The link to the comments. |
780 | 780 | */ |
781 | 781 | function get_comments_link( $post_id = 0 ) { |
@@ -814,7 +814,7 @@ discard block |
||
814 | 814 | * |
815 | 815 | * @since 1.5.0 |
816 | 816 | * |
817 | - * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global $post. |
|
817 | + * @param integer $post_id Optional. Post ID or WP_Post object. Default is global $post. |
|
818 | 818 | * @return int The number of comments a post has. |
819 | 819 | */ |
820 | 820 | function get_comments_number( $post_id = 0 ) { |
@@ -902,7 +902,7 @@ discard block |
||
902 | 902 | * |
903 | 903 | * @see Walker_Comment::comment() |
904 | 904 | * |
905 | - * @param int|WP_Comment $comment_ID WP_Comment or ID of the comment for which to get the text. |
|
905 | + * @param integer $comment_ID WP_Comment or ID of the comment for which to get the text. |
|
906 | 906 | * Default current comment. |
907 | 907 | * @param array $args Optional. An array of arguments. Default empty. |
908 | 908 | * @return string The comment content. |
@@ -932,7 +932,7 @@ discard block |
||
932 | 932 | * |
933 | 933 | * @see Walker_Comment::comment() |
934 | 934 | * |
935 | - * @param int|WP_Comment $comment_ID WP_Comment or ID of the comment for which to print the text. |
|
935 | + * @param integer $comment_ID WP_Comment or ID of the comment for which to print the text. |
|
936 | 936 | * Default current comment. |
937 | 937 | * @param array $args Optional. An array of arguments. Default empty array. Default empty. |
938 | 938 | */ |
@@ -1005,7 +1005,7 @@ discard block |
||
1005 | 1005 | * @since 1.5.0 |
1006 | 1006 | * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object. |
1007 | 1007 | * |
1008 | - * @param int|WP_Comment $comment_ID Optional. WP_Comment or ID of the comment for which to get the type. |
|
1008 | + * @param integer $comment_ID Optional. WP_Comment or ID of the comment for which to get the type. |
|
1009 | 1009 | * Default current comment. |
1010 | 1010 | * @return string The comment type. |
1011 | 1011 | */ |
@@ -2126,11 +2126,11 @@ discard block |
||
2126 | 2126 | $html5 = 'html5' === $args['format']; |
2127 | 2127 | $fields = array( |
2128 | 2128 | 'author' => '<p class="comment-form-author">' . '<label for="author">' . __( 'Name' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' . |
2129 | - '<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30" maxlength="245"' . $aria_req . $html_req . ' /></p>', |
|
2129 | + '<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30" maxlength="245"' . $aria_req . $html_req . ' /></p>', |
|
2130 | 2130 | 'email' => '<p class="comment-form-email"><label for="email">' . __( 'Email' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' . |
2131 | - '<input id="email" name="email" ' . ( $html5 ? 'type="email"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30" maxlength="100" aria-describedby="email-notes"' . $aria_req . $html_req . ' /></p>', |
|
2131 | + '<input id="email" name="email" ' . ( $html5 ? 'type="email"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30" maxlength="100" aria-describedby="email-notes"' . $aria_req . $html_req . ' /></p>', |
|
2132 | 2132 | 'url' => '<p class="comment-form-url"><label for="url">' . __( 'Website' ) . '</label> ' . |
2133 | - '<input id="url" name="url" ' . ( $html5 ? 'type="url"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" maxlength="200" /></p>', |
|
2133 | + '<input id="url" name="url" ' . ( $html5 ? 'type="url"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" maxlength="200" /></p>', |
|
2134 | 2134 | ); |
2135 | 2135 | |
2136 | 2136 | $required_text = sprintf( ' ' . __('Required fields are marked %s'), '<span class="required">*</span>' ); |
@@ -2148,20 +2148,20 @@ discard block |
||
2148 | 2148 | 'comment_field' => '<p class="comment-form-comment"><label for="comment">' . _x( 'Comment', 'noun' ) . '</label> <textarea id="comment" name="comment" cols="45" rows="8" maxlength="65525" aria-required="true" required="required"></textarea></p>', |
2149 | 2149 | /** This filter is documented in wp-includes/link-template.php */ |
2150 | 2150 | 'must_log_in' => '<p class="must-log-in">' . sprintf( |
2151 | - /* translators: %s: login URL */ |
|
2152 | - __( 'You must be <a href="%s">logged in</a> to post a comment.' ), |
|
2153 | - wp_login_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) |
|
2154 | - ) . '</p>', |
|
2151 | + /* translators: %s: login URL */ |
|
2152 | + __( 'You must be <a href="%s">logged in</a> to post a comment.' ), |
|
2153 | + wp_login_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) |
|
2154 | + ) . '</p>', |
|
2155 | 2155 | /** This filter is documented in wp-includes/link-template.php */ |
2156 | 2156 | 'logged_in_as' => '<p class="logged-in-as">' . sprintf( |
2157 | - /* translators: 1: edit user link, 2: accessibility text, 3: user name, 4: logout URL */ |
|
2158 | - __( '<a href="%1$s" aria-label="%2$s">Logged in as %3$s</a>. <a href="%4$s">Log out?</a>' ), |
|
2159 | - get_edit_user_link(), |
|
2160 | - /* translators: %s: user name */ |
|
2161 | - esc_attr( sprintf( __( 'Logged in as %s. Edit your profile.' ), $user_identity ) ), |
|
2162 | - $user_identity, |
|
2163 | - wp_logout_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) |
|
2164 | - ) . '</p>', |
|
2157 | + /* translators: 1: edit user link, 2: accessibility text, 3: user name, 4: logout URL */ |
|
2158 | + __( '<a href="%1$s" aria-label="%2$s">Logged in as %3$s</a>. <a href="%4$s">Log out?</a>' ), |
|
2159 | + get_edit_user_link(), |
|
2160 | + /* translators: %s: user name */ |
|
2161 | + esc_attr( sprintf( __( 'Logged in as %s. Edit your profile.' ), $user_identity ) ), |
|
2162 | + $user_identity, |
|
2163 | + wp_logout_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) |
|
2164 | + ) . '</p>', |
|
2165 | 2165 | 'comment_notes_before' => '<p class="comment-notes"><span id="email-notes">' . __( 'Your email address will not be published.' ) . '</span>'. ( $req ? $required_text : '' ) . '</p>', |
2166 | 2166 | 'comment_notes_after' => '', |
2167 | 2167 | 'id_form' => 'commentform', |
@@ -21,11 +21,11 @@ discard block |
||
21 | 21 | * Default current comment. |
22 | 22 | * @return string The comment author |
23 | 23 | */ |
24 | -function get_comment_author( $comment_ID = 0 ) { |
|
25 | - $comment = get_comment( $comment_ID ); |
|
24 | +function get_comment_author($comment_ID = 0) { |
|
25 | + $comment = get_comment($comment_ID); |
|
26 | 26 | |
27 | - if ( empty( $comment->comment_author ) ) { |
|
28 | - if ( $comment->user_id && $user = get_userdata( $comment->user_id ) ) |
|
27 | + if (empty($comment->comment_author)) { |
|
28 | + if ($comment->user_id && $user = get_userdata($comment->user_id)) |
|
29 | 29 | $author = $user->display_name; |
30 | 30 | else |
31 | 31 | $author = __('Anonymous'); |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | * @param int $comment_ID The comment ID. |
44 | 44 | * @param WP_Comment $comment The comment object. |
45 | 45 | */ |
46 | - return apply_filters( 'get_comment_author', $author, $comment->comment_ID, $comment ); |
|
46 | + return apply_filters('get_comment_author', $author, $comment->comment_ID, $comment); |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
@@ -55,9 +55,9 @@ discard block |
||
55 | 55 | * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to print the author. |
56 | 56 | * Default current comment. |
57 | 57 | */ |
58 | -function comment_author( $comment_ID = 0 ) { |
|
59 | - $comment = get_comment( $comment_ID ); |
|
60 | - $author = get_comment_author( $comment ); |
|
58 | +function comment_author($comment_ID = 0) { |
|
59 | + $comment = get_comment($comment_ID); |
|
60 | + $author = get_comment_author($comment); |
|
61 | 61 | |
62 | 62 | /** |
63 | 63 | * Filter the comment author's name for display. |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | * @param string $author The comment author's username. |
69 | 69 | * @param int $comment_ID The comment ID. |
70 | 70 | */ |
71 | - echo apply_filters( 'comment_author', $author, $comment->comment_ID ); |
|
71 | + echo apply_filters('comment_author', $author, $comment->comment_ID); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | /** |
@@ -81,8 +81,8 @@ discard block |
||
81 | 81 | * Default current comment. |
82 | 82 | * @return string The current comment author's email |
83 | 83 | */ |
84 | -function get_comment_author_email( $comment_ID = 0 ) { |
|
85 | - $comment = get_comment( $comment_ID ); |
|
84 | +function get_comment_author_email($comment_ID = 0) { |
|
85 | + $comment = get_comment($comment_ID); |
|
86 | 86 | |
87 | 87 | /** |
88 | 88 | * Filter the comment author's returned email address. |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | * @param int $comment_ID The comment ID. |
95 | 95 | * @param WP_Comment $comment The comment object. |
96 | 96 | */ |
97 | - return apply_filters( 'get_comment_author_email', $comment->comment_author_email, $comment->comment_ID, $comment ); |
|
97 | + return apply_filters('get_comment_author_email', $comment->comment_author_email, $comment->comment_ID, $comment); |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | /** |
@@ -112,9 +112,9 @@ discard block |
||
112 | 112 | * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to print the author's email. |
113 | 113 | * Default current comment. |
114 | 114 | */ |
115 | -function comment_author_email( $comment_ID = 0 ) { |
|
116 | - $comment = get_comment( $comment_ID ); |
|
117 | - $author_email = get_comment_author_email( $comment ); |
|
115 | +function comment_author_email($comment_ID = 0) { |
|
116 | + $comment = get_comment($comment_ID); |
|
117 | + $author_email = get_comment_author_email($comment); |
|
118 | 118 | |
119 | 119 | /** |
120 | 120 | * Filter the comment author's email for display. |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | * @param string $author_email The comment author's email address. |
126 | 126 | * @param int $comment_ID The comment ID. |
127 | 127 | */ |
128 | - echo apply_filters( 'author_email', $author_email, $comment->comment_ID ); |
|
128 | + echo apply_filters('author_email', $author_email, $comment->comment_ID); |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | /** |
@@ -144,8 +144,8 @@ discard block |
||
144 | 144 | * @param string $before Optional. Text or HTML to display before the email link. Default empty. |
145 | 145 | * @param string $after Optional. Text or HTML to display after the email link. Default empty. |
146 | 146 | */ |
147 | -function comment_author_email_link( $linktext = '', $before = '', $after = '' ) { |
|
148 | - if ( $link = get_comment_author_email_link( $linktext, $before, $after ) ) |
|
147 | +function comment_author_email_link($linktext = '', $before = '', $after = '') { |
|
148 | + if ($link = get_comment_author_email_link($linktext, $before, $after)) |
|
149 | 149 | echo $link; |
150 | 150 | } |
151 | 151 | |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | * @param string $after Optional. Text or HTML to display after the email link. Default empty. |
167 | 167 | * @return string |
168 | 168 | */ |
169 | -function get_comment_author_email_link( $linktext = '', $before = '', $after = '' ) { |
|
169 | +function get_comment_author_email_link($linktext = '', $before = '', $after = '') { |
|
170 | 170 | $comment = get_comment(); |
171 | 171 | /** |
172 | 172 | * Filter the comment author's email for display. |
@@ -180,11 +180,11 @@ discard block |
||
180 | 180 | * @param string $comment_author_email The comment author's email address. |
181 | 181 | * @param WP_Comment $comment The comment object. |
182 | 182 | */ |
183 | - $email = apply_filters( 'comment_email', $comment->comment_author_email, $comment ); |
|
184 | - if ((!empty($email)) && ($email != '@')) { |
|
183 | + $email = apply_filters('comment_email', $comment->comment_author_email, $comment); |
|
184 | + if (( ! empty($email)) && ($email != '@')) { |
|
185 | 185 | $display = ($linktext != '') ? $linktext : $email; |
186 | 186 | $return = $before; |
187 | - $return .= sprintf( '<a href="%1$s">%2$s</a>', esc_url( 'mailto:' . $email ), esc_html( $display ) ); |
|
187 | + $return .= sprintf('<a href="%1$s">%2$s</a>', esc_url('mailto:'.$email), esc_html($display)); |
|
188 | 188 | $return .= $after; |
189 | 189 | return $return; |
190 | 190 | } else { |
@@ -205,12 +205,12 @@ discard block |
||
205 | 205 | * Default current comment. |
206 | 206 | * @return string The comment author name or HTML link for author's URL. |
207 | 207 | */ |
208 | -function get_comment_author_link( $comment_ID = 0 ) { |
|
209 | - $comment = get_comment( $comment_ID ); |
|
210 | - $url = get_comment_author_url( $comment ); |
|
211 | - $author = get_comment_author( $comment ); |
|
208 | +function get_comment_author_link($comment_ID = 0) { |
|
209 | + $comment = get_comment($comment_ID); |
|
210 | + $url = get_comment_author_url($comment); |
|
211 | + $author = get_comment_author($comment); |
|
212 | 212 | |
213 | - if ( empty( $url ) || 'http://' == $url ) |
|
213 | + if (empty($url) || 'http://' == $url) |
|
214 | 214 | $return = $author; |
215 | 215 | else |
216 | 216 | $return = "<a href='$url' rel='external nofollow' class='url'>$author</a>"; |
@@ -226,7 +226,7 @@ discard block |
||
226 | 226 | * @param string $author The comment author's username. |
227 | 227 | * @param int $comment_ID The comment ID. |
228 | 228 | */ |
229 | - return apply_filters( 'get_comment_author_link', $return, $author, $comment->comment_ID ); |
|
229 | + return apply_filters('get_comment_author_link', $return, $author, $comment->comment_ID); |
|
230 | 230 | } |
231 | 231 | |
232 | 232 | /** |
@@ -238,8 +238,8 @@ discard block |
||
238 | 238 | * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to print the author's link. |
239 | 239 | * Default current comment. |
240 | 240 | */ |
241 | -function comment_author_link( $comment_ID = 0 ) { |
|
242 | - echo get_comment_author_link( $comment_ID ); |
|
241 | +function comment_author_link($comment_ID = 0) { |
|
242 | + echo get_comment_author_link($comment_ID); |
|
243 | 243 | } |
244 | 244 | |
245 | 245 | /** |
@@ -252,8 +252,8 @@ discard block |
||
252 | 252 | * Default current comment. |
253 | 253 | * @return string Comment author's IP address. |
254 | 254 | */ |
255 | -function get_comment_author_IP( $comment_ID = 0 ) { |
|
256 | - $comment = get_comment( $comment_ID ); |
|
255 | +function get_comment_author_IP($comment_ID = 0) { |
|
256 | + $comment = get_comment($comment_ID); |
|
257 | 257 | |
258 | 258 | /** |
259 | 259 | * Filter the comment author's returned IP address. |
@@ -265,7 +265,7 @@ discard block |
||
265 | 265 | * @param int $comment_ID The comment ID. |
266 | 266 | * @param WP_Comment $comment The comment object. |
267 | 267 | */ |
268 | - return apply_filters( 'get_comment_author_IP', $comment->comment_author_IP, $comment->comment_ID, $comment ); |
|
268 | + return apply_filters('get_comment_author_IP', $comment->comment_author_IP, $comment->comment_ID, $comment); |
|
269 | 269 | } |
270 | 270 | |
271 | 271 | /** |
@@ -277,8 +277,8 @@ discard block |
||
277 | 277 | * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to print the author's IP address. |
278 | 278 | * Default current comment. |
279 | 279 | */ |
280 | -function comment_author_IP( $comment_ID = 0 ) { |
|
281 | - echo esc_html( get_comment_author_IP( $comment_ID ) ); |
|
280 | +function comment_author_IP($comment_ID = 0) { |
|
281 | + echo esc_html(get_comment_author_IP($comment_ID)); |
|
282 | 282 | } |
283 | 283 | |
284 | 284 | /** |
@@ -291,10 +291,10 @@ discard block |
||
291 | 291 | * Default current comment. |
292 | 292 | * @return string Comment author URL. |
293 | 293 | */ |
294 | -function get_comment_author_url( $comment_ID = 0 ) { |
|
295 | - $comment = get_comment( $comment_ID ); |
|
294 | +function get_comment_author_url($comment_ID = 0) { |
|
295 | + $comment = get_comment($comment_ID); |
|
296 | 296 | $url = ('http://' == $comment->comment_author_url) ? '' : $comment->comment_author_url; |
297 | - $url = esc_url( $url, array('http', 'https') ); |
|
297 | + $url = esc_url($url, array('http', 'https')); |
|
298 | 298 | |
299 | 299 | /** |
300 | 300 | * Filter the comment author's URL. |
@@ -306,7 +306,7 @@ discard block |
||
306 | 306 | * @param int $comment_ID The comment ID. |
307 | 307 | * @param WP_Comment $comment The comment object. |
308 | 308 | */ |
309 | - return apply_filters( 'get_comment_author_url', $url, $comment->comment_ID, $comment ); |
|
309 | + return apply_filters('get_comment_author_url', $url, $comment->comment_ID, $comment); |
|
310 | 310 | } |
311 | 311 | |
312 | 312 | /** |
@@ -318,9 +318,9 @@ discard block |
||
318 | 318 | * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to print the author's URL. |
319 | 319 | * Default current comment. |
320 | 320 | */ |
321 | -function comment_author_url( $comment_ID = 0 ) { |
|
322 | - $comment = get_comment( $comment_ID ); |
|
323 | - $author_url = get_comment_author_url( $comment ); |
|
321 | +function comment_author_url($comment_ID = 0) { |
|
322 | + $comment = get_comment($comment_ID); |
|
323 | + $author_url = get_comment_author_url($comment); |
|
324 | 324 | |
325 | 325 | /** |
326 | 326 | * Filter the comment author's URL for display. |
@@ -331,7 +331,7 @@ discard block |
||
331 | 331 | * @param string $author_url The comment author's URL. |
332 | 332 | * @param int $comment_ID The comment ID. |
333 | 333 | */ |
334 | - echo apply_filters( 'comment_url', $author_url, $comment->comment_ID ); |
|
334 | + echo apply_filters('comment_url', $author_url, $comment->comment_ID); |
|
335 | 335 | } |
336 | 336 | |
337 | 337 | /** |
@@ -354,13 +354,13 @@ discard block |
||
354 | 354 | * Default empty. |
355 | 355 | * @return string The HTML link between the $before and $after parameters. |
356 | 356 | */ |
357 | -function get_comment_author_url_link( $linktext = '', $before = '', $after = '' ) { |
|
357 | +function get_comment_author_url_link($linktext = '', $before = '', $after = '') { |
|
358 | 358 | $url = get_comment_author_url(); |
359 | 359 | $display = ($linktext != '') ? $linktext : $url; |
360 | - $display = str_replace( 'http://www.', '', $display ); |
|
361 | - $display = str_replace( 'http://', '', $display ); |
|
360 | + $display = str_replace('http://www.', '', $display); |
|
361 | + $display = str_replace('http://', '', $display); |
|
362 | 362 | |
363 | - if ( '/' == substr($display, -1) ) { |
|
363 | + if ('/' == substr($display, -1)) { |
|
364 | 364 | $display = substr($display, 0, -1); |
365 | 365 | } |
366 | 366 | |
@@ -373,7 +373,7 @@ discard block |
||
373 | 373 | * |
374 | 374 | * @param string $return The HTML-formatted comment author URL link. |
375 | 375 | */ |
376 | - return apply_filters( 'get_comment_author_url_link', $return ); |
|
376 | + return apply_filters('get_comment_author_url_link', $return); |
|
377 | 377 | } |
378 | 378 | |
379 | 379 | /** |
@@ -388,8 +388,8 @@ discard block |
||
388 | 388 | * @param string $after Optional. Text or HTML to display after the email link. |
389 | 389 | * Default empty. |
390 | 390 | */ |
391 | -function comment_author_url_link( $linktext = '', $before = '', $after = '' ) { |
|
392 | - echo get_comment_author_url_link( $linktext, $before, $after ); |
|
391 | +function comment_author_url_link($linktext = '', $before = '', $after = '') { |
|
392 | + echo get_comment_author_url_link($linktext, $before, $after); |
|
393 | 393 | } |
394 | 394 | |
395 | 395 | /** |
@@ -406,10 +406,10 @@ discard block |
||
406 | 406 | * Default true. |
407 | 407 | * @return string If `$echo` is false, the class will be returned. Void otherwise. |
408 | 408 | */ |
409 | -function comment_class( $class = '', $comment = null, $post_id = null, $echo = true ) { |
|
409 | +function comment_class($class = '', $comment = null, $post_id = null, $echo = true) { |
|
410 | 410 | // Separates classes with a single space, collates classes for comment DIV |
411 | - $class = 'class="' . join( ' ', get_comment_class( $class, $comment, $post_id ) ) . '"'; |
|
412 | - if ( $echo) |
|
411 | + $class = 'class="'.join(' ', get_comment_class($class, $comment, $post_id)).'"'; |
|
412 | + if ($echo) |
|
413 | 413 | echo $class; |
414 | 414 | else |
415 | 415 | return $class; |
@@ -430,39 +430,39 @@ discard block |
||
430 | 430 | * @param int|WP_Post $post_id Post ID or WP_Post object. Default current post. |
431 | 431 | * @return array An array of classes. |
432 | 432 | */ |
433 | -function get_comment_class( $class = '', $comment_id = null, $post_id = null ) { |
|
433 | +function get_comment_class($class = '', $comment_id = null, $post_id = null) { |
|
434 | 434 | global $comment_alt, $comment_depth, $comment_thread_alt; |
435 | 435 | |
436 | 436 | $classes = array(); |
437 | 437 | |
438 | - $comment = get_comment( $comment_id ); |
|
439 | - if ( ! $comment ) { |
|
438 | + $comment = get_comment($comment_id); |
|
439 | + if ( ! $comment) { |
|
440 | 440 | return $classes; |
441 | 441 | } |
442 | 442 | |
443 | 443 | // Get the comment type (comment, trackback), |
444 | - $classes[] = ( empty( $comment->comment_type ) ) ? 'comment' : $comment->comment_type; |
|
444 | + $classes[] = (empty($comment->comment_type)) ? 'comment' : $comment->comment_type; |
|
445 | 445 | |
446 | 446 | // Add classes for comment authors that are registered users. |
447 | - if ( $comment->user_id > 0 && $user = get_userdata( $comment->user_id ) ) { |
|
447 | + if ($comment->user_id > 0 && $user = get_userdata($comment->user_id)) { |
|
448 | 448 | $classes[] = 'byuser'; |
449 | - $classes[] = 'comment-author-' . sanitize_html_class( $user->user_nicename, $comment->user_id ); |
|
449 | + $classes[] = 'comment-author-'.sanitize_html_class($user->user_nicename, $comment->user_id); |
|
450 | 450 | // For comment authors who are the author of the post |
451 | - if ( $post = get_post($post_id) ) { |
|
452 | - if ( $comment->user_id === $post->post_author ) { |
|
451 | + if ($post = get_post($post_id)) { |
|
452 | + if ($comment->user_id === $post->post_author) { |
|
453 | 453 | $classes[] = 'bypostauthor'; |
454 | 454 | } |
455 | 455 | } |
456 | 456 | } |
457 | 457 | |
458 | - if ( empty($comment_alt) ) |
|
458 | + if (empty($comment_alt)) |
|
459 | 459 | $comment_alt = 0; |
460 | - if ( empty($comment_depth) ) |
|
460 | + if (empty($comment_depth)) |
|
461 | 461 | $comment_depth = 1; |
462 | - if ( empty($comment_thread_alt) ) |
|
462 | + if (empty($comment_thread_alt)) |
|
463 | 463 | $comment_thread_alt = 0; |
464 | 464 | |
465 | - if ( $comment_alt % 2 ) { |
|
465 | + if ($comment_alt % 2) { |
|
466 | 466 | $classes[] = 'odd'; |
467 | 467 | $classes[] = 'alt'; |
468 | 468 | } else { |
@@ -472,8 +472,8 @@ discard block |
||
472 | 472 | $comment_alt++; |
473 | 473 | |
474 | 474 | // Alt for top-level comments |
475 | - if ( 1 == $comment_depth ) { |
|
476 | - if ( $comment_thread_alt % 2 ) { |
|
475 | + if (1 == $comment_depth) { |
|
476 | + if ($comment_thread_alt % 2) { |
|
477 | 477 | $classes[] = 'thread-odd'; |
478 | 478 | $classes[] = 'thread-alt'; |
479 | 479 | } else { |
@@ -484,8 +484,8 @@ discard block |
||
484 | 484 | |
485 | 485 | $classes[] = "depth-$comment_depth"; |
486 | 486 | |
487 | - if ( !empty($class) ) { |
|
488 | - if ( !is_array( $class ) ) |
|
487 | + if ( ! empty($class)) { |
|
488 | + if ( ! is_array($class)) |
|
489 | 489 | $class = preg_split('#\s+#', $class); |
490 | 490 | $classes = array_merge($classes, $class); |
491 | 491 | } |
@@ -503,7 +503,7 @@ discard block |
||
503 | 503 | * @param WP_Comment $comment The comment object. |
504 | 504 | * @param int|WP_Post $post_id The post ID or WP_Post object. |
505 | 505 | */ |
506 | - return apply_filters( 'comment_class', $classes, $class, $comment->comment_ID, $comment, $post_id ); |
|
506 | + return apply_filters('comment_class', $classes, $class, $comment->comment_ID, $comment, $post_id); |
|
507 | 507 | } |
508 | 508 | |
509 | 509 | /** |
@@ -517,9 +517,9 @@ discard block |
||
517 | 517 | * Default current comment. |
518 | 518 | * @return string The comment's date. |
519 | 519 | */ |
520 | -function get_comment_date( $d = '', $comment_ID = 0 ) { |
|
521 | - $comment = get_comment( $comment_ID ); |
|
522 | - if ( '' == $d ) |
|
520 | +function get_comment_date($d = '', $comment_ID = 0) { |
|
521 | + $comment = get_comment($comment_ID); |
|
522 | + if ('' == $d) |
|
523 | 523 | $date = mysql2date(get_option('date_format'), $comment->comment_date); |
524 | 524 | else |
525 | 525 | $date = mysql2date($d, $comment->comment_date); |
@@ -532,7 +532,7 @@ discard block |
||
532 | 532 | * @param string $d The format of the date. |
533 | 533 | * @param WP_Comment $comment The comment object. |
534 | 534 | */ |
535 | - return apply_filters( 'get_comment_date', $date, $d, $comment ); |
|
535 | + return apply_filters('get_comment_date', $date, $d, $comment); |
|
536 | 536 | } |
537 | 537 | |
538 | 538 | /** |
@@ -545,8 +545,8 @@ discard block |
||
545 | 545 | * @param int|WP_Comment $comment_ID WP_Comment or ID of the comment for which to print the date. |
546 | 546 | * Default current comment. |
547 | 547 | */ |
548 | -function comment_date( $d = '', $comment_ID = 0 ) { |
|
549 | - echo get_comment_date( $d, $comment_ID ); |
|
548 | +function comment_date($d = '', $comment_ID = 0) { |
|
549 | + echo get_comment_date($d, $comment_ID); |
|
550 | 550 | } |
551 | 551 | |
552 | 552 | /** |
@@ -563,10 +563,10 @@ discard block |
||
563 | 563 | * Default current comment. |
564 | 564 | * @return string The maybe truncated comment with 20 words or less. |
565 | 565 | */ |
566 | -function get_comment_excerpt( $comment_ID = 0 ) { |
|
567 | - $comment = get_comment( $comment_ID ); |
|
568 | - $comment_text = strip_tags( str_replace( array( "\n", "\r" ), ' ', $comment->comment_content ) ); |
|
569 | - $words = explode( ' ', $comment_text ); |
|
566 | +function get_comment_excerpt($comment_ID = 0) { |
|
567 | + $comment = get_comment($comment_ID); |
|
568 | + $comment_text = strip_tags(str_replace(array("\n", "\r"), ' ', $comment->comment_content)); |
|
569 | + $words = explode(' ', $comment_text); |
|
570 | 570 | |
571 | 571 | /** |
572 | 572 | * Filter the amount of words used in the comment excerpt. |
@@ -575,15 +575,15 @@ discard block |
||
575 | 575 | * |
576 | 576 | * @param int $comment_excerpt_length The amount of words you want to display in the comment excerpt. |
577 | 577 | */ |
578 | - $comment_excerpt_length = apply_filters( 'comment_excerpt_length', 20 ); |
|
578 | + $comment_excerpt_length = apply_filters('comment_excerpt_length', 20); |
|
579 | 579 | |
580 | - $use_ellipsis = count( $words ) > $comment_excerpt_length; |
|
581 | - if ( $use_ellipsis ) { |
|
582 | - $words = array_slice( $words, 0, $comment_excerpt_length ); |
|
580 | + $use_ellipsis = count($words) > $comment_excerpt_length; |
|
581 | + if ($use_ellipsis) { |
|
582 | + $words = array_slice($words, 0, $comment_excerpt_length); |
|
583 | 583 | } |
584 | 584 | |
585 | - $excerpt = trim( join( ' ', $words ) ); |
|
586 | - if ( $use_ellipsis ) { |
|
585 | + $excerpt = trim(join(' ', $words)); |
|
586 | + if ($use_ellipsis) { |
|
587 | 587 | $excerpt .= '…'; |
588 | 588 | } |
589 | 589 | /** |
@@ -596,7 +596,7 @@ discard block |
||
596 | 596 | * @param int $comment_ID The comment ID. |
597 | 597 | * @param WP_Comment $comment The comment object. |
598 | 598 | */ |
599 | - return apply_filters( 'get_comment_excerpt', $excerpt, $comment->comment_ID, $comment ); |
|
599 | + return apply_filters('get_comment_excerpt', $excerpt, $comment->comment_ID, $comment); |
|
600 | 600 | } |
601 | 601 | |
602 | 602 | /** |
@@ -608,9 +608,9 @@ discard block |
||
608 | 608 | * @param int|WP_Comment $comment_ID WP_Comment or ID of the comment for which to print the excerpt. |
609 | 609 | * Default current comment. |
610 | 610 | */ |
611 | -function comment_excerpt( $comment_ID = 0 ) { |
|
612 | - $comment = get_comment( $comment_ID ); |
|
613 | - $comment_excerpt = get_comment_excerpt( $comment ); |
|
611 | +function comment_excerpt($comment_ID = 0) { |
|
612 | + $comment = get_comment($comment_ID); |
|
613 | + $comment_excerpt = get_comment_excerpt($comment); |
|
614 | 614 | |
615 | 615 | /** |
616 | 616 | * Filter the comment excerpt for display. |
@@ -621,7 +621,7 @@ discard block |
||
621 | 621 | * @param string $comment_excerpt The comment excerpt text. |
622 | 622 | * @param int $comment_ID The comment ID. |
623 | 623 | */ |
624 | - echo apply_filters( 'comment_excerpt', $comment_excerpt, $comment->comment_ID ); |
|
624 | + echo apply_filters('comment_excerpt', $comment_excerpt, $comment->comment_ID); |
|
625 | 625 | } |
626 | 626 | |
627 | 627 | /** |
@@ -643,7 +643,7 @@ discard block |
||
643 | 643 | * @param int $comment_ID The current comment ID. |
644 | 644 | * @param WP_Comment $comment The comment object. |
645 | 645 | */ |
646 | - return apply_filters( 'get_comment_ID', $comment->comment_ID, $comment ); |
|
646 | + return apply_filters('get_comment_ID', $comment->comment_ID, $comment); |
|
647 | 647 | } |
648 | 648 | |
649 | 649 | /** |
@@ -679,14 +679,14 @@ discard block |
||
679 | 679 | * } |
680 | 680 | * @return string The permalink to the given comment. |
681 | 681 | */ |
682 | -function get_comment_link( $comment = null, $args = array() ) { |
|
682 | +function get_comment_link($comment = null, $args = array()) { |
|
683 | 683 | global $wp_rewrite, $in_comment_loop; |
684 | 684 | |
685 | 685 | $comment = get_comment($comment); |
686 | 686 | |
687 | 687 | // Backwards compat |
688 | - if ( ! is_array( $args ) ) { |
|
689 | - $args = array( 'page' => $args ); |
|
688 | + if ( ! is_array($args)) { |
|
689 | + $args = array('page' => $args); |
|
690 | 690 | } |
691 | 691 | |
692 | 692 | $defaults = array( |
@@ -696,33 +696,33 @@ discard block |
||
696 | 696 | 'max_depth' => '', |
697 | 697 | 'cpage' => null, |
698 | 698 | ); |
699 | - $args = wp_parse_args( $args, $defaults ); |
|
699 | + $args = wp_parse_args($args, $defaults); |
|
700 | 700 | |
701 | - $link = get_permalink( $comment->comment_post_ID ); |
|
701 | + $link = get_permalink($comment->comment_post_ID); |
|
702 | 702 | |
703 | 703 | // The 'cpage' param takes precedence. |
704 | - if ( ! is_null( $args['cpage'] ) ) { |
|
704 | + if ( ! is_null($args['cpage'])) { |
|
705 | 705 | $cpage = $args['cpage']; |
706 | 706 | |
707 | 707 | // No 'cpage' is provided, so we calculate one. |
708 | 708 | } else { |
709 | - if ( '' === $args['per_page'] && get_option( 'page_comments' ) ) { |
|
709 | + if ('' === $args['per_page'] && get_option('page_comments')) { |
|
710 | 710 | $args['per_page'] = get_option('comments_per_page'); |
711 | 711 | } |
712 | 712 | |
713 | - if ( empty( $args['per_page'] ) ) { |
|
713 | + if (empty($args['per_page'])) { |
|
714 | 714 | $args['per_page'] = 0; |
715 | 715 | $args['page'] = 0; |
716 | 716 | } |
717 | 717 | |
718 | 718 | $cpage = $args['page']; |
719 | 719 | |
720 | - if ( '' == $cpage ) { |
|
721 | - if ( ! empty( $in_comment_loop ) ) { |
|
722 | - $cpage = get_query_var( 'cpage' ); |
|
720 | + if ('' == $cpage) { |
|
721 | + if ( ! empty($in_comment_loop)) { |
|
722 | + $cpage = get_query_var('cpage'); |
|
723 | 723 | } else { |
724 | 724 | // Requires a database hit, so we only do it when we can't figure out from context. |
725 | - $cpage = get_page_of_comment( $comment->comment_ID, $args ); |
|
725 | + $cpage = get_page_of_comment($comment->comment_ID, $args); |
|
726 | 726 | } |
727 | 727 | } |
728 | 728 | |
@@ -730,29 +730,29 @@ discard block |
||
730 | 730 | * If the default page displays the oldest comments, the permalinks for comments on the default page |
731 | 731 | * do not need a 'cpage' query var. |
732 | 732 | */ |
733 | - if ( 'oldest' === get_option( 'default_comments_page' ) && 1 === $cpage ) { |
|
733 | + if ('oldest' === get_option('default_comments_page') && 1 === $cpage) { |
|
734 | 734 | $cpage = ''; |
735 | 735 | } |
736 | 736 | } |
737 | 737 | |
738 | - if ( $cpage && get_option( 'page_comments' ) ) { |
|
739 | - if ( $wp_rewrite->using_permalinks() ) { |
|
740 | - if ( $cpage ) { |
|
741 | - $link = trailingslashit( $link ) . $wp_rewrite->comments_pagination_base . '-' . $cpage; |
|
738 | + if ($cpage && get_option('page_comments')) { |
|
739 | + if ($wp_rewrite->using_permalinks()) { |
|
740 | + if ($cpage) { |
|
741 | + $link = trailingslashit($link).$wp_rewrite->comments_pagination_base.'-'.$cpage; |
|
742 | 742 | } |
743 | 743 | |
744 | - $link = user_trailingslashit( $link, 'comment' ); |
|
745 | - } elseif ( $cpage ) { |
|
746 | - $link = add_query_arg( 'cpage', $cpage, $link ); |
|
744 | + $link = user_trailingslashit($link, 'comment'); |
|
745 | + } elseif ($cpage) { |
|
746 | + $link = add_query_arg('cpage', $cpage, $link); |
|
747 | 747 | } |
748 | 748 | |
749 | 749 | } |
750 | 750 | |
751 | - if ( $wp_rewrite->using_permalinks() ) { |
|
752 | - $link = user_trailingslashit( $link, 'comment' ); |
|
751 | + if ($wp_rewrite->using_permalinks()) { |
|
752 | + $link = user_trailingslashit($link, 'comment'); |
|
753 | 753 | } |
754 | 754 | |
755 | - $link = $link . '#comment-' . $comment->comment_ID; |
|
755 | + $link = $link.'#comment-'.$comment->comment_ID; |
|
756 | 756 | |
757 | 757 | /** |
758 | 758 | * Filter the returned single comment permalink. |
@@ -767,7 +767,7 @@ discard block |
||
767 | 767 | * @param array $args An array of arguments to override the defaults. |
768 | 768 | * @param int $cpage The calculated 'cpage' value. |
769 | 769 | */ |
770 | - return apply_filters( 'get_comment_link', $link, $comment, $args, $cpage ); |
|
770 | + return apply_filters('get_comment_link', $link, $comment, $args, $cpage); |
|
771 | 771 | } |
772 | 772 | |
773 | 773 | /** |
@@ -778,9 +778,9 @@ discard block |
||
778 | 778 | * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global $post. |
779 | 779 | * @return string The link to the comments. |
780 | 780 | */ |
781 | -function get_comments_link( $post_id = 0 ) { |
|
782 | - $hash = get_comments_number( $post_id ) ? '#comments' : '#respond'; |
|
783 | - $comments_link = get_permalink( $post_id ) . $hash; |
|
781 | +function get_comments_link($post_id = 0) { |
|
782 | + $hash = get_comments_number($post_id) ? '#comments' : '#respond'; |
|
783 | + $comments_link = get_permalink($post_id).$hash; |
|
784 | 784 | |
785 | 785 | /** |
786 | 786 | * Filter the returned post comments permalink. |
@@ -790,7 +790,7 @@ discard block |
||
790 | 790 | * @param string $comments_link Post comments permalink with '#comments' appended. |
791 | 791 | * @param int|WP_Post $post_id Post ID or WP_Post object. |
792 | 792 | */ |
793 | - return apply_filters( 'get_comments_link', $comments_link, $post_id ); |
|
793 | + return apply_filters('get_comments_link', $comments_link, $post_id); |
|
794 | 794 | } |
795 | 795 | |
796 | 796 | /** |
@@ -801,12 +801,12 @@ discard block |
||
801 | 801 | * @param string $deprecated Not Used. |
802 | 802 | * @param string $deprecated_2 Not Used. |
803 | 803 | */ |
804 | -function comments_link( $deprecated = '', $deprecated_2 = '' ) { |
|
805 | - if ( !empty( $deprecated ) ) |
|
806 | - _deprecated_argument( __FUNCTION__, '0.72' ); |
|
807 | - if ( !empty( $deprecated_2 ) ) |
|
808 | - _deprecated_argument( __FUNCTION__, '1.3' ); |
|
809 | - echo esc_url( get_comments_link() ); |
|
804 | +function comments_link($deprecated = '', $deprecated_2 = '') { |
|
805 | + if ( ! empty($deprecated)) |
|
806 | + _deprecated_argument(__FUNCTION__, '0.72'); |
|
807 | + if ( ! empty($deprecated_2)) |
|
808 | + _deprecated_argument(__FUNCTION__, '1.3'); |
|
809 | + echo esc_url(get_comments_link()); |
|
810 | 810 | } |
811 | 811 | |
812 | 812 | /** |
@@ -817,10 +817,10 @@ discard block |
||
817 | 817 | * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global $post. |
818 | 818 | * @return int The number of comments a post has. |
819 | 819 | */ |
820 | -function get_comments_number( $post_id = 0 ) { |
|
821 | - $post = get_post( $post_id ); |
|
820 | +function get_comments_number($post_id = 0) { |
|
821 | + $post = get_post($post_id); |
|
822 | 822 | |
823 | - if ( ! $post ) { |
|
823 | + if ( ! $post) { |
|
824 | 824 | $count = 0; |
825 | 825 | } else { |
826 | 826 | $count = $post->comment_count; |
@@ -835,7 +835,7 @@ discard block |
||
835 | 835 | * @param int $count Number of comments a post has. |
836 | 836 | * @param int $post_id Post ID. |
837 | 837 | */ |
838 | - return apply_filters( 'get_comments_number', $count, $post_id ); |
|
838 | + return apply_filters('get_comments_number', $count, $post_id); |
|
839 | 839 | } |
840 | 840 | |
841 | 841 | /** |
@@ -848,11 +848,11 @@ discard block |
||
848 | 848 | * @param string $more Optional. Text for more than one comment. Default false. |
849 | 849 | * @param string $deprecated Not used. |
850 | 850 | */ |
851 | -function comments_number( $zero = false, $one = false, $more = false, $deprecated = '' ) { |
|
852 | - if ( ! empty( $deprecated ) ) { |
|
853 | - _deprecated_argument( __FUNCTION__, '1.3' ); |
|
851 | +function comments_number($zero = false, $one = false, $more = false, $deprecated = '') { |
|
852 | + if ( ! empty($deprecated)) { |
|
853 | + _deprecated_argument(__FUNCTION__, '1.3'); |
|
854 | 854 | } |
855 | - echo get_comments_number_text( $zero, $one, $more ); |
|
855 | + echo get_comments_number_text($zero, $one, $more); |
|
856 | 856 | } |
857 | 857 | |
858 | 858 | /** |
@@ -864,21 +864,21 @@ discard block |
||
864 | 864 | * @param string $one Optional. Text for one comment. Default false. |
865 | 865 | * @param string $more Optional. Text for more than one comment. Default false. |
866 | 866 | */ |
867 | -function get_comments_number_text( $zero = false, $one = false, $more = false ) { |
|
867 | +function get_comments_number_text($zero = false, $one = false, $more = false) { |
|
868 | 868 | $number = get_comments_number(); |
869 | 869 | |
870 | - if ( $number > 1 ) { |
|
871 | - if ( false === $more ) { |
|
870 | + if ($number > 1) { |
|
871 | + if (false === $more) { |
|
872 | 872 | /* translators: %s: number of comments */ |
873 | - $output = sprintf( _n( '%s Comment', '%s Comments', $number ), number_format_i18n( $number ) ); |
|
873 | + $output = sprintf(_n('%s Comment', '%s Comments', $number), number_format_i18n($number)); |
|
874 | 874 | } else { |
875 | 875 | // % Comments |
876 | - $output = str_replace( '%', number_format_i18n( $number ), $more ); |
|
876 | + $output = str_replace('%', number_format_i18n($number), $more); |
|
877 | 877 | } |
878 | - } elseif ( $number == 0 ) { |
|
879 | - $output = ( false === $zero ) ? __( 'No Comments' ) : $zero; |
|
878 | + } elseif ($number == 0) { |
|
879 | + $output = (false === $zero) ? __('No Comments') : $zero; |
|
880 | 880 | } else { // must be one |
881 | - $output = ( false === $one ) ? __( '1 Comment' ) : $one; |
|
881 | + $output = (false === $one) ? __('1 Comment') : $one; |
|
882 | 882 | } |
883 | 883 | /** |
884 | 884 | * Filter the comments count for display. |
@@ -891,7 +891,7 @@ discard block |
||
891 | 891 | * is equal to 0, 1, or 1+. |
892 | 892 | * @param int $number The number of post comments. |
893 | 893 | */ |
894 | - return apply_filters( 'comments_number', $output, $number ); |
|
894 | + return apply_filters('comments_number', $output, $number); |
|
895 | 895 | } |
896 | 896 | |
897 | 897 | /** |
@@ -907,8 +907,8 @@ discard block |
||
907 | 907 | * @param array $args Optional. An array of arguments. Default empty. |
908 | 908 | * @return string The comment content. |
909 | 909 | */ |
910 | -function get_comment_text( $comment_ID = 0, $args = array() ) { |
|
911 | - $comment = get_comment( $comment_ID ); |
|
910 | +function get_comment_text($comment_ID = 0, $args = array()) { |
|
911 | + $comment = get_comment($comment_ID); |
|
912 | 912 | |
913 | 913 | /** |
914 | 914 | * Filter the text of a comment. |
@@ -921,7 +921,7 @@ discard block |
||
921 | 921 | * @param WP_Comment $comment The comment object. |
922 | 922 | * @param array $args An array of arguments. |
923 | 923 | */ |
924 | - return apply_filters( 'get_comment_text', $comment->comment_content, $comment, $args ); |
|
924 | + return apply_filters('get_comment_text', $comment->comment_content, $comment, $args); |
|
925 | 925 | } |
926 | 926 | |
927 | 927 | /** |
@@ -936,10 +936,10 @@ discard block |
||
936 | 936 | * Default current comment. |
937 | 937 | * @param array $args Optional. An array of arguments. Default empty array. Default empty. |
938 | 938 | */ |
939 | -function comment_text( $comment_ID = 0, $args = array() ) { |
|
940 | - $comment = get_comment( $comment_ID ); |
|
939 | +function comment_text($comment_ID = 0, $args = array()) { |
|
940 | + $comment = get_comment($comment_ID); |
|
941 | 941 | |
942 | - $comment_text = get_comment_text( $comment, $args ); |
|
942 | + $comment_text = get_comment_text($comment, $args); |
|
943 | 943 | /** |
944 | 944 | * Filter the text of a comment to be displayed. |
945 | 945 | * |
@@ -951,7 +951,7 @@ discard block |
||
951 | 951 | * @param WP_Comment $comment The comment object. |
952 | 952 | * @param array $args An array of arguments. |
953 | 953 | */ |
954 | - echo apply_filters( 'comment_text', $comment_text, $comment, $args ); |
|
954 | + echo apply_filters('comment_text', $comment_text, $comment, $args); |
|
955 | 955 | } |
956 | 956 | |
957 | 957 | /** |
@@ -965,11 +965,11 @@ discard block |
||
965 | 965 | * Default true. |
966 | 966 | * @return string The formatted time. |
967 | 967 | */ |
968 | -function get_comment_time( $d = '', $gmt = false, $translate = true ) { |
|
968 | +function get_comment_time($d = '', $gmt = false, $translate = true) { |
|
969 | 969 | $comment = get_comment(); |
970 | 970 | |
971 | 971 | $comment_date = $gmt ? $comment->comment_date_gmt : $comment->comment_date; |
972 | - if ( '' == $d ) |
|
972 | + if ('' == $d) |
|
973 | 973 | $date = mysql2date(get_option('time_format'), $comment_date, $translate); |
974 | 974 | else |
975 | 975 | $date = mysql2date($d, $comment_date, $translate); |
@@ -985,7 +985,7 @@ discard block |
||
985 | 985 | * @param bool $translate Whether the time is translated. |
986 | 986 | * @param WP_Comment $comment The comment object. |
987 | 987 | */ |
988 | - return apply_filters( 'get_comment_time', $date, $d, $gmt, $translate, $comment ); |
|
988 | + return apply_filters('get_comment_time', $date, $d, $gmt, $translate, $comment); |
|
989 | 989 | } |
990 | 990 | |
991 | 991 | /** |
@@ -995,7 +995,7 @@ discard block |
||
995 | 995 | * |
996 | 996 | * @param string $d Optional. The format of the time. Default user's settings. |
997 | 997 | */ |
998 | -function comment_time( $d = '' ) { |
|
998 | +function comment_time($d = '') { |
|
999 | 999 | echo get_comment_time($d); |
1000 | 1000 | } |
1001 | 1001 | |
@@ -1009,9 +1009,9 @@ discard block |
||
1009 | 1009 | * Default current comment. |
1010 | 1010 | * @return string The comment type. |
1011 | 1011 | */ |
1012 | -function get_comment_type( $comment_ID = 0 ) { |
|
1013 | - $comment = get_comment( $comment_ID ); |
|
1014 | - if ( '' == $comment->comment_type ) |
|
1012 | +function get_comment_type($comment_ID = 0) { |
|
1013 | + $comment = get_comment($comment_ID); |
|
1014 | + if ('' == $comment->comment_type) |
|
1015 | 1015 | $comment->comment_type = 'comment'; |
1016 | 1016 | |
1017 | 1017 | /** |
@@ -1024,7 +1024,7 @@ discard block |
||
1024 | 1024 | * @param int $comment_ID The comment ID. |
1025 | 1025 | * @param WP_Comment $comment The comment object. |
1026 | 1026 | */ |
1027 | - return apply_filters( 'get_comment_type', $comment->comment_type, $comment->comment_ID, $comment ); |
|
1027 | + return apply_filters('get_comment_type', $comment->comment_type, $comment->comment_ID, $comment); |
|
1028 | 1028 | } |
1029 | 1029 | |
1030 | 1030 | /** |
@@ -1036,12 +1036,12 @@ discard block |
||
1036 | 1036 | * @param string $trackbacktxt Optional. String to display for trackback type. Default false. |
1037 | 1037 | * @param string $pingbacktxt Optional. String to display for pingback type. Default false. |
1038 | 1038 | */ |
1039 | -function comment_type( $commenttxt = false, $trackbacktxt = false, $pingbacktxt = false ) { |
|
1040 | - if ( false === $commenttxt ) $commenttxt = _x( 'Comment', 'noun' ); |
|
1041 | - if ( false === $trackbacktxt ) $trackbacktxt = __( 'Trackback' ); |
|
1042 | - if ( false === $pingbacktxt ) $pingbacktxt = __( 'Pingback' ); |
|
1039 | +function comment_type($commenttxt = false, $trackbacktxt = false, $pingbacktxt = false) { |
|
1040 | + if (false === $commenttxt) $commenttxt = _x('Comment', 'noun'); |
|
1041 | + if (false === $trackbacktxt) $trackbacktxt = __('Trackback'); |
|
1042 | + if (false === $pingbacktxt) $pingbacktxt = __('Pingback'); |
|
1043 | 1043 | $type = get_comment_type(); |
1044 | - switch( $type ) { |
|
1044 | + switch ($type) { |
|
1045 | 1045 | case 'trackback' : |
1046 | 1046 | echo $trackbacktxt; |
1047 | 1047 | break; |
@@ -1065,10 +1065,10 @@ discard block |
||
1065 | 1065 | * @return string The trackback URL after being filtered. |
1066 | 1066 | */ |
1067 | 1067 | function get_trackback_url() { |
1068 | - if ( '' != get_option('permalink_structure') ) |
|
1069 | - $tb_url = trailingslashit(get_permalink()) . user_trailingslashit('trackback', 'single_trackback'); |
|
1068 | + if ('' != get_option('permalink_structure')) |
|
1069 | + $tb_url = trailingslashit(get_permalink()).user_trailingslashit('trackback', 'single_trackback'); |
|
1070 | 1070 | else |
1071 | - $tb_url = get_option('siteurl') . '/wp-trackback.php?p=' . get_the_ID(); |
|
1071 | + $tb_url = get_option('siteurl').'/wp-trackback.php?p='.get_the_ID(); |
|
1072 | 1072 | |
1073 | 1073 | /** |
1074 | 1074 | * Filter the returned trackback URL. |
@@ -1077,7 +1077,7 @@ discard block |
||
1077 | 1077 | * |
1078 | 1078 | * @param string $tb_url The trackback URL. |
1079 | 1079 | */ |
1080 | - return apply_filters( 'trackback_url', $tb_url ); |
|
1080 | + return apply_filters('trackback_url', $tb_url); |
|
1081 | 1081 | } |
1082 | 1082 | |
1083 | 1083 | /** |
@@ -1089,17 +1089,17 @@ discard block |
||
1089 | 1089 | * @return void|string Should only be used to echo the trackback URL, use get_trackback_url() |
1090 | 1090 | * for the result instead. |
1091 | 1091 | */ |
1092 | -function trackback_url( $deprecated_echo = true ) { |
|
1093 | - if ( true !== $deprecated_echo ) { |
|
1094 | - _deprecated_argument( __FUNCTION__, '2.5', |
|
1092 | +function trackback_url($deprecated_echo = true) { |
|
1093 | + if (true !== $deprecated_echo) { |
|
1094 | + _deprecated_argument(__FUNCTION__, '2.5', |
|
1095 | 1095 | /* translators: %s: get_trackback_url() */ |
1096 | - sprintf( __( 'Use %s instead if you do not want the value echoed.' ), |
|
1096 | + sprintf(__('Use %s instead if you do not want the value echoed.'), |
|
1097 | 1097 | '<code>get_trackback_url()</code>' |
1098 | 1098 | ) |
1099 | 1099 | ); |
1100 | 1100 | } |
1101 | 1101 | |
1102 | - if ( $deprecated_echo ) { |
|
1102 | + if ($deprecated_echo) { |
|
1103 | 1103 | echo get_trackback_url(); |
1104 | 1104 | } else { |
1105 | 1105 | return get_trackback_url(); |
@@ -1115,12 +1115,12 @@ discard block |
||
1115 | 1115 | * |
1116 | 1116 | * @param int $deprecated Not used (Was $timezone = 0). |
1117 | 1117 | */ |
1118 | -function trackback_rdf( $deprecated = '' ) { |
|
1119 | - if ( ! empty( $deprecated ) ) { |
|
1120 | - _deprecated_argument( __FUNCTION__, '2.5' ); |
|
1118 | +function trackback_rdf($deprecated = '') { |
|
1119 | + if ( ! empty($deprecated)) { |
|
1120 | + _deprecated_argument(__FUNCTION__, '2.5'); |
|
1121 | 1121 | } |
1122 | 1122 | |
1123 | - if ( isset( $_SERVER['HTTP_USER_AGENT'] ) && false !== stripos( $_SERVER['HTTP_USER_AGENT'], 'W3C_Validator' ) ) { |
|
1123 | + if (isset($_SERVER['HTTP_USER_AGENT']) && false !== stripos($_SERVER['HTTP_USER_AGENT'], 'W3C_Validator')) { |
|
1124 | 1124 | return; |
1125 | 1125 | } |
1126 | 1126 | |
@@ -1146,11 +1146,11 @@ discard block |
||
1146 | 1146 | * @param int|WP_Post $post_id Post ID or WP_Post object. Default current post. |
1147 | 1147 | * @return bool True if the comments are open. |
1148 | 1148 | */ |
1149 | -function comments_open( $post_id = null ) { |
|
1149 | +function comments_open($post_id = null) { |
|
1150 | 1150 | |
1151 | 1151 | $_post = get_post($post_id); |
1152 | 1152 | |
1153 | - $open = ( 'open' == $_post->comment_status ); |
|
1153 | + $open = ('open' == $_post->comment_status); |
|
1154 | 1154 | |
1155 | 1155 | /** |
1156 | 1156 | * Filter whether the current post is open for comments. |
@@ -1160,7 +1160,7 @@ discard block |
||
1160 | 1160 | * @param bool $open Whether the current post is open for comments. |
1161 | 1161 | * @param int|WP_Post $post_id The post ID or WP_Post object. |
1162 | 1162 | */ |
1163 | - return apply_filters( 'comments_open', $open, $post_id ); |
|
1163 | + return apply_filters('comments_open', $open, $post_id); |
|
1164 | 1164 | } |
1165 | 1165 | |
1166 | 1166 | /** |
@@ -1171,11 +1171,11 @@ discard block |
||
1171 | 1171 | * @param int|WP_Post $post_id Post ID or WP_Post object. Default current post. |
1172 | 1172 | * @return bool True if pings are accepted |
1173 | 1173 | */ |
1174 | -function pings_open( $post_id = null ) { |
|
1174 | +function pings_open($post_id = null) { |
|
1175 | 1175 | |
1176 | 1176 | $_post = get_post($post_id); |
1177 | 1177 | |
1178 | - $open = ( 'open' == $_post->ping_status ); |
|
1178 | + $open = ('open' == $_post->ping_status); |
|
1179 | 1179 | |
1180 | 1180 | /** |
1181 | 1181 | * Filter whether the current post is open for pings. |
@@ -1185,7 +1185,7 @@ discard block |
||
1185 | 1185 | * @param bool $open Whether the current post is open for pings. |
1186 | 1186 | * @param int|WP_Post $post_id The post ID or WP_Post object. |
1187 | 1187 | */ |
1188 | - return apply_filters( 'pings_open', $open, $post_id ); |
|
1188 | + return apply_filters('pings_open', $open, $post_id); |
|
1189 | 1189 | } |
1190 | 1190 | |
1191 | 1191 | /** |
@@ -1206,8 +1206,8 @@ discard block |
||
1206 | 1206 | $post = get_post(); |
1207 | 1207 | $post_id = $post ? $post->ID : 0; |
1208 | 1208 | |
1209 | - if ( current_user_can( 'unfiltered_html' ) ) { |
|
1210 | - wp_nonce_field( 'unfiltered-html-comment_' . $post_id, '_wp_unfiltered_html_comment_disabled', false ); |
|
1209 | + if (current_user_can('unfiltered_html')) { |
|
1210 | + wp_nonce_field('unfiltered-html-comment_'.$post_id, '_wp_unfiltered_html_comment_disabled', false); |
|
1211 | 1211 | echo "<script>(function(){if(window===window.parent){document.getElementById('_wp_unfiltered_html_comment_disabled').name='_wp_unfiltered_html_comment';}})();</script>\n"; |
1212 | 1212 | } |
1213 | 1213 | } |
@@ -1247,13 +1247,13 @@ discard block |
||
1247 | 1247 | * @param bool $separate_comments Optional. Whether to separate the comments by comment type. |
1248 | 1248 | * Default false. |
1249 | 1249 | */ |
1250 | -function comments_template( $file = '/comments.php', $separate_comments = false ) { |
|
1250 | +function comments_template($file = '/comments.php', $separate_comments = false) { |
|
1251 | 1251 | global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_ID, $user_identity, $overridden_cpage; |
1252 | 1252 | |
1253 | - if ( !(is_single() || is_page() || $withcomments) || empty($post) ) |
|
1253 | + if ( ! (is_single() || is_page() || $withcomments) || empty($post)) |
|
1254 | 1254 | return; |
1255 | 1255 | |
1256 | - if ( empty($file) ) |
|
1256 | + if (empty($file)) |
|
1257 | 1257 | $file = '/comments.php'; |
1258 | 1258 | |
1259 | 1259 | $req = get_option('require_name_email'); |
@@ -1289,31 +1289,31 @@ discard block |
||
1289 | 1289 | 'update_comment_meta_cache' => false, // We lazy-load comment meta for performance. |
1290 | 1290 | ); |
1291 | 1291 | |
1292 | - if ( get_option('thread_comments') ) { |
|
1292 | + if (get_option('thread_comments')) { |
|
1293 | 1293 | $comment_args['hierarchical'] = 'threaded'; |
1294 | 1294 | } else { |
1295 | 1295 | $comment_args['hierarchical'] = false; |
1296 | 1296 | } |
1297 | 1297 | |
1298 | - if ( $user_ID ) { |
|
1299 | - $comment_args['include_unapproved'] = array( $user_ID ); |
|
1300 | - } elseif ( ! empty( $comment_author_email ) ) { |
|
1301 | - $comment_args['include_unapproved'] = array( $comment_author_email ); |
|
1298 | + if ($user_ID) { |
|
1299 | + $comment_args['include_unapproved'] = array($user_ID); |
|
1300 | + } elseif ( ! empty($comment_author_email)) { |
|
1301 | + $comment_args['include_unapproved'] = array($comment_author_email); |
|
1302 | 1302 | } |
1303 | 1303 | |
1304 | 1304 | $per_page = 0; |
1305 | - if ( get_option( 'page_comments' ) ) { |
|
1306 | - $per_page = (int) get_query_var( 'comments_per_page' ); |
|
1307 | - if ( 0 === $per_page ) { |
|
1308 | - $per_page = (int) get_option( 'comments_per_page' ); |
|
1305 | + if (get_option('page_comments')) { |
|
1306 | + $per_page = (int) get_query_var('comments_per_page'); |
|
1307 | + if (0 === $per_page) { |
|
1308 | + $per_page = (int) get_option('comments_per_page'); |
|
1309 | 1309 | } |
1310 | 1310 | |
1311 | 1311 | $comment_args['number'] = $per_page; |
1312 | - $page = (int) get_query_var( 'cpage' ); |
|
1312 | + $page = (int) get_query_var('cpage'); |
|
1313 | 1313 | |
1314 | - if ( $page ) { |
|
1315 | - $comment_args['offset'] = ( $page - 1 ) * $per_page; |
|
1316 | - } elseif ( 'oldest' === get_option( 'default_comments_page' ) ) { |
|
1314 | + if ($page) { |
|
1315 | + $comment_args['offset'] = ($page - 1) * $per_page; |
|
1316 | + } elseif ('oldest' === get_option('default_comments_page')) { |
|
1317 | 1317 | $comment_args['offset'] = 0; |
1318 | 1318 | } else { |
1319 | 1319 | // If fetching the first page of 'newest', we need a top-level comment count. |
@@ -1325,17 +1325,17 @@ discard block |
||
1325 | 1325 | 'status' => 'approve', |
1326 | 1326 | ); |
1327 | 1327 | |
1328 | - if ( $comment_args['hierarchical'] ) { |
|
1328 | + if ($comment_args['hierarchical']) { |
|
1329 | 1329 | $top_level_args['parent'] = 0; |
1330 | 1330 | } |
1331 | 1331 | |
1332 | - if ( isset( $comment_args['include_unapproved'] ) ) { |
|
1332 | + if (isset($comment_args['include_unapproved'])) { |
|
1333 | 1333 | $top_level_args['include_unapproved'] = $comment_args['include_unapproved']; |
1334 | 1334 | } |
1335 | 1335 | |
1336 | - $top_level_count = $top_level_query->query( $top_level_args ); |
|
1336 | + $top_level_count = $top_level_query->query($top_level_args); |
|
1337 | 1337 | |
1338 | - $comment_args['offset'] = ( ceil( $top_level_count / $per_page ) - 1 ) * $per_page; |
|
1338 | + $comment_args['offset'] = (ceil($top_level_count / $per_page) - 1) * $per_page; |
|
1339 | 1339 | } |
1340 | 1340 | } |
1341 | 1341 | |
@@ -1362,22 +1362,22 @@ discard block |
||
1362 | 1362 | * @type int $number Number of comments to fetch. |
1363 | 1363 | * } |
1364 | 1364 | */ |
1365 | - $comment_args = apply_filters( 'comments_template_query_args', $comment_args ); |
|
1366 | - $comment_query = new WP_Comment_Query( $comment_args ); |
|
1365 | + $comment_args = apply_filters('comments_template_query_args', $comment_args); |
|
1366 | + $comment_query = new WP_Comment_Query($comment_args); |
|
1367 | 1367 | $_comments = $comment_query->comments; |
1368 | 1368 | |
1369 | 1369 | // Trees must be flattened before they're passed to the walker. |
1370 | - if ( $comment_args['hierarchical'] ) { |
|
1370 | + if ($comment_args['hierarchical']) { |
|
1371 | 1371 | $comments_flat = array(); |
1372 | - foreach ( $_comments as $_comment ) { |
|
1372 | + foreach ($_comments as $_comment) { |
|
1373 | 1373 | $comments_flat[] = $_comment; |
1374 | - $comment_children = $_comment->get_children( array( |
|
1374 | + $comment_children = $_comment->get_children(array( |
|
1375 | 1375 | 'format' => 'flat', |
1376 | 1376 | 'status' => $comment_args['status'], |
1377 | 1377 | 'orderby' => $comment_args['orderby'] |
1378 | - ) ); |
|
1378 | + )); |
|
1379 | 1379 | |
1380 | - foreach ( $comment_children as $comment_child ) { |
|
1380 | + foreach ($comment_children as $comment_child) { |
|
1381 | 1381 | $comments_flat[] = $comment_child; |
1382 | 1382 | } |
1383 | 1383 | } |
@@ -1393,13 +1393,13 @@ discard block |
||
1393 | 1393 | * @param array $comments Array of comments supplied to the comments template. |
1394 | 1394 | * @param int $post_ID Post ID. |
1395 | 1395 | */ |
1396 | - $wp_query->comments = apply_filters( 'comments_array', $comments_flat, $post->ID ); |
|
1396 | + $wp_query->comments = apply_filters('comments_array', $comments_flat, $post->ID); |
|
1397 | 1397 | |
1398 | 1398 | $comments = &$wp_query->comments; |
1399 | 1399 | $wp_query->comment_count = count($wp_query->comments); |
1400 | 1400 | $wp_query->max_num_comment_pages = $comment_query->max_num_pages; |
1401 | 1401 | |
1402 | - if ( $separate_comments ) { |
|
1402 | + if ($separate_comments) { |
|
1403 | 1403 | $wp_query->comments_by_type = separate_comments($comments); |
1404 | 1404 | $comments_by_type = &$wp_query->comments_by_type; |
1405 | 1405 | } else { |
@@ -1407,15 +1407,15 @@ discard block |
||
1407 | 1407 | } |
1408 | 1408 | |
1409 | 1409 | $overridden_cpage = false; |
1410 | - if ( '' == get_query_var( 'cpage' ) && $wp_query->max_num_comment_pages > 1 ) { |
|
1411 | - set_query_var( 'cpage', 'newest' == get_option('default_comments_page') ? get_comment_pages_count() : 1 ); |
|
1410 | + if ('' == get_query_var('cpage') && $wp_query->max_num_comment_pages > 1) { |
|
1411 | + set_query_var('cpage', 'newest' == get_option('default_comments_page') ? get_comment_pages_count() : 1); |
|
1412 | 1412 | $overridden_cpage = true; |
1413 | 1413 | } |
1414 | 1414 | |
1415 | - if ( !defined('COMMENTS_TEMPLATE') ) |
|
1415 | + if ( ! defined('COMMENTS_TEMPLATE')) |
|
1416 | 1416 | define('COMMENTS_TEMPLATE', true); |
1417 | 1417 | |
1418 | - $theme_template = STYLESHEETPATH . $file; |
|
1418 | + $theme_template = STYLESHEETPATH.$file; |
|
1419 | 1419 | /** |
1420 | 1420 | * Filter the path to the theme template file used for the comments template. |
1421 | 1421 | * |
@@ -1423,13 +1423,13 @@ discard block |
||
1423 | 1423 | * |
1424 | 1424 | * @param string $theme_template The path to the theme template file. |
1425 | 1425 | */ |
1426 | - $include = apply_filters( 'comments_template', $theme_template ); |
|
1427 | - if ( file_exists( $include ) ) |
|
1428 | - require( $include ); |
|
1429 | - elseif ( file_exists( TEMPLATEPATH . $file ) ) |
|
1430 | - require( TEMPLATEPATH . $file ); |
|
1426 | + $include = apply_filters('comments_template', $theme_template); |
|
1427 | + if (file_exists($include)) |
|
1428 | + require($include); |
|
1429 | + elseif (file_exists(TEMPLATEPATH.$file)) |
|
1430 | + require(TEMPLATEPATH.$file); |
|
1431 | 1431 | else // Backward compat code will be removed in a future release |
1432 | - require( ABSPATH . WPINC . '/theme-compat/comments.php'); |
|
1432 | + require(ABSPATH.WPINC.'/theme-compat/comments.php'); |
|
1433 | 1433 | } |
1434 | 1434 | |
1435 | 1435 | /** |
@@ -1446,45 +1446,45 @@ discard block |
||
1446 | 1446 | * @param string $none Optional. String to display when comments have been turned off. |
1447 | 1447 | * Default false. |
1448 | 1448 | */ |
1449 | -function comments_popup_link( $zero = false, $one = false, $more = false, $css_class = '', $none = false ) { |
|
1449 | +function comments_popup_link($zero = false, $one = false, $more = false, $css_class = '', $none = false) { |
|
1450 | 1450 | $id = get_the_ID(); |
1451 | 1451 | $title = get_the_title(); |
1452 | - $number = get_comments_number( $id ); |
|
1452 | + $number = get_comments_number($id); |
|
1453 | 1453 | |
1454 | - if ( false === $zero ) { |
|
1454 | + if (false === $zero) { |
|
1455 | 1455 | /* translators: %s: post title */ |
1456 | - $zero = sprintf( __( 'No Comments<span class="screen-reader-text"> on %s</span>' ), $title ); |
|
1456 | + $zero = sprintf(__('No Comments<span class="screen-reader-text"> on %s</span>'), $title); |
|
1457 | 1457 | } |
1458 | 1458 | |
1459 | - if ( false === $one ) { |
|
1459 | + if (false === $one) { |
|
1460 | 1460 | /* translators: %s: post title */ |
1461 | - $one = sprintf( __( '1 Comment<span class="screen-reader-text"> on %s</span>' ), $title ); |
|
1461 | + $one = sprintf(__('1 Comment<span class="screen-reader-text"> on %s</span>'), $title); |
|
1462 | 1462 | } |
1463 | 1463 | |
1464 | - if ( false === $more ) { |
|
1464 | + if (false === $more) { |
|
1465 | 1465 | /* translators: 1: Number of comments 2: post title */ |
1466 | - $more = _n( '%1$s Comment<span class="screen-reader-text"> on %2$s</span>', '%1$s Comments<span class="screen-reader-text"> on %2$s</span>', $number ); |
|
1467 | - $more = sprintf( $more, number_format_i18n( $number ), $title ); |
|
1466 | + $more = _n('%1$s Comment<span class="screen-reader-text"> on %2$s</span>', '%1$s Comments<span class="screen-reader-text"> on %2$s</span>', $number); |
|
1467 | + $more = sprintf($more, number_format_i18n($number), $title); |
|
1468 | 1468 | } |
1469 | 1469 | |
1470 | - if ( false === $none ) { |
|
1470 | + if (false === $none) { |
|
1471 | 1471 | /* translators: %s: post title */ |
1472 | - $none = sprintf( __( 'Comments Off<span class="screen-reader-text"> on %s</span>' ), $title ); |
|
1472 | + $none = sprintf(__('Comments Off<span class="screen-reader-text"> on %s</span>'), $title); |
|
1473 | 1473 | } |
1474 | 1474 | |
1475 | - if ( 0 == $number && !comments_open() && !pings_open() ) { |
|
1476 | - echo '<span' . ((!empty($css_class)) ? ' class="' . esc_attr( $css_class ) . '"' : '') . '>' . $none . '</span>'; |
|
1475 | + if (0 == $number && ! comments_open() && ! pings_open()) { |
|
1476 | + echo '<span'.(( ! empty($css_class)) ? ' class="'.esc_attr($css_class).'"' : '').'>'.$none.'</span>'; |
|
1477 | 1477 | return; |
1478 | 1478 | } |
1479 | 1479 | |
1480 | - if ( post_password_required() ) { |
|
1481 | - _e( 'Enter your password to view comments.' ); |
|
1480 | + if (post_password_required()) { |
|
1481 | + _e('Enter your password to view comments.'); |
|
1482 | 1482 | return; |
1483 | 1483 | } |
1484 | 1484 | |
1485 | 1485 | echo '<a href="'; |
1486 | - if ( 0 == $number ) { |
|
1487 | - $respond_link = get_permalink() . '#respond'; |
|
1486 | + if (0 == $number) { |
|
1487 | + $respond_link = get_permalink().'#respond'; |
|
1488 | 1488 | /** |
1489 | 1489 | * Filter the respond link when a post has no comments. |
1490 | 1490 | * |
@@ -1493,13 +1493,13 @@ discard block |
||
1493 | 1493 | * @param string $respond_link The default response link. |
1494 | 1494 | * @param integer $id The post ID. |
1495 | 1495 | */ |
1496 | - echo apply_filters( 'respond_link', $respond_link, $id ); |
|
1496 | + echo apply_filters('respond_link', $respond_link, $id); |
|
1497 | 1497 | } else { |
1498 | 1498 | comments_link(); |
1499 | 1499 | } |
1500 | 1500 | echo '"'; |
1501 | 1501 | |
1502 | - if ( !empty( $css_class ) ) { |
|
1502 | + if ( ! empty($css_class)) { |
|
1503 | 1503 | echo ' class="'.$css_class.'" '; |
1504 | 1504 | } |
1505 | 1505 | |
@@ -1511,10 +1511,10 @@ discard block |
||
1511 | 1511 | * |
1512 | 1512 | * @param string $attributes The comments link attributes. Default empty. |
1513 | 1513 | */ |
1514 | - echo apply_filters( 'comments_popup_link_attributes', $attributes ); |
|
1514 | + echo apply_filters('comments_popup_link_attributes', $attributes); |
|
1515 | 1515 | |
1516 | 1516 | echo '>'; |
1517 | - comments_number( $zero, $one, $more ); |
|
1517 | + comments_number($zero, $one, $more); |
|
1518 | 1518 | echo '</a>'; |
1519 | 1519 | } |
1520 | 1520 | |
@@ -1545,33 +1545,33 @@ discard block |
||
1545 | 1545 | * Default current post. |
1546 | 1546 | * @return void|false|string Link to show comment form, if successful. False, if comments are closed. |
1547 | 1547 | */ |
1548 | -function get_comment_reply_link( $args = array(), $comment = null, $post = null ) { |
|
1548 | +function get_comment_reply_link($args = array(), $comment = null, $post = null) { |
|
1549 | 1549 | $defaults = array( |
1550 | 1550 | 'add_below' => 'comment', |
1551 | 1551 | 'respond_id' => 'respond', |
1552 | - 'reply_text' => __( 'Reply' ), |
|
1553 | - 'reply_to_text' => __( 'Reply to %s' ), |
|
1554 | - 'login_text' => __( 'Log in to Reply' ), |
|
1552 | + 'reply_text' => __('Reply'), |
|
1553 | + 'reply_to_text' => __('Reply to %s'), |
|
1554 | + 'login_text' => __('Log in to Reply'), |
|
1555 | 1555 | 'depth' => 0, |
1556 | 1556 | 'before' => '', |
1557 | 1557 | 'after' => '' |
1558 | 1558 | ); |
1559 | 1559 | |
1560 | - $args = wp_parse_args( $args, $defaults ); |
|
1560 | + $args = wp_parse_args($args, $defaults); |
|
1561 | 1561 | |
1562 | - if ( 0 == $args['depth'] || $args['max_depth'] <= $args['depth'] ) { |
|
1562 | + if (0 == $args['depth'] || $args['max_depth'] <= $args['depth']) { |
|
1563 | 1563 | return; |
1564 | 1564 | } |
1565 | 1565 | |
1566 | - $comment = get_comment( $comment ); |
|
1566 | + $comment = get_comment($comment); |
|
1567 | 1567 | |
1568 | - if ( empty( $post ) ) { |
|
1568 | + if (empty($post)) { |
|
1569 | 1569 | $post = $comment->comment_post_ID; |
1570 | 1570 | } |
1571 | 1571 | |
1572 | - $post = get_post( $post ); |
|
1572 | + $post = get_post($post); |
|
1573 | 1573 | |
1574 | - if ( ! comments_open( $post->ID ) ) { |
|
1574 | + if ( ! comments_open($post->ID)) { |
|
1575 | 1575 | return false; |
1576 | 1576 | } |
1577 | 1577 | |
@@ -1585,22 +1585,22 @@ discard block |
||
1585 | 1585 | * @param WP_Comment $comment The object of the comment being replied to. |
1586 | 1586 | * @param WP_Post $post The WP_Post object. |
1587 | 1587 | */ |
1588 | - $args = apply_filters( 'comment_reply_link_args', $args, $comment, $post ); |
|
1588 | + $args = apply_filters('comment_reply_link_args', $args, $comment, $post); |
|
1589 | 1589 | |
1590 | - if ( get_option( 'comment_registration' ) && ! is_user_logged_in() ) { |
|
1591 | - $link = sprintf( '<a rel="nofollow" class="comment-reply-login" href="%s">%s</a>', |
|
1592 | - esc_url( wp_login_url( get_permalink() ) ), |
|
1590 | + if (get_option('comment_registration') && ! is_user_logged_in()) { |
|
1591 | + $link = sprintf('<a rel="nofollow" class="comment-reply-login" href="%s">%s</a>', |
|
1592 | + esc_url(wp_login_url(get_permalink())), |
|
1593 | 1593 | $args['login_text'] |
1594 | 1594 | ); |
1595 | 1595 | } else { |
1596 | - $onclick = sprintf( 'return addComment.moveForm( "%1$s-%2$s", "%2$s", "%3$s", "%4$s" )', |
|
1596 | + $onclick = sprintf('return addComment.moveForm( "%1$s-%2$s", "%2$s", "%3$s", "%4$s" )', |
|
1597 | 1597 | $args['add_below'], $comment->comment_ID, $args['respond_id'], $post->ID |
1598 | 1598 | ); |
1599 | 1599 | |
1600 | - $link = sprintf( "<a rel='nofollow' class='comment-reply-link' href='%s' onclick='%s' aria-label='%s'>%s</a>", |
|
1601 | - esc_url( add_query_arg( 'replytocom', $comment->comment_ID, get_permalink( $post->ID ) ) ) . "#" . $args['respond_id'], |
|
1600 | + $link = sprintf("<a rel='nofollow' class='comment-reply-link' href='%s' onclick='%s' aria-label='%s'>%s</a>", |
|
1601 | + esc_url(add_query_arg('replytocom', $comment->comment_ID, get_permalink($post->ID)))."#".$args['respond_id'], |
|
1602 | 1602 | $onclick, |
1603 | - esc_attr( sprintf( $args['reply_to_text'], $comment->comment_author ) ), |
|
1603 | + esc_attr(sprintf($args['reply_to_text'], $comment->comment_author)), |
|
1604 | 1604 | $args['reply_text'] |
1605 | 1605 | ); |
1606 | 1606 | } |
@@ -1615,7 +1615,7 @@ discard block |
||
1615 | 1615 | * @param object $comment The object of the comment being replied. |
1616 | 1616 | * @param WP_Post $post The WP_Post object. |
1617 | 1617 | */ |
1618 | - return apply_filters( 'comment_reply_link', $args['before'] . $link . $args['after'], $args, $comment, $post ); |
|
1618 | + return apply_filters('comment_reply_link', $args['before'].$link.$args['after'], $args, $comment, $post); |
|
1619 | 1619 | } |
1620 | 1620 | |
1621 | 1621 | /** |
@@ -1672,27 +1672,27 @@ discard block |
||
1672 | 1672 | |
1673 | 1673 | $post = get_post($post); |
1674 | 1674 | |
1675 | - if ( ! comments_open( $post->ID ) ) { |
|
1675 | + if ( ! comments_open($post->ID)) { |
|
1676 | 1676 | return false; |
1677 | 1677 | } |
1678 | 1678 | |
1679 | - if ( get_option('comment_registration') && ! is_user_logged_in() ) { |
|
1680 | - $link = sprintf( '<a rel="nofollow" class="comment-reply-login" href="%s">%s</a>', |
|
1681 | - wp_login_url( get_permalink() ), |
|
1679 | + if (get_option('comment_registration') && ! is_user_logged_in()) { |
|
1680 | + $link = sprintf('<a rel="nofollow" class="comment-reply-login" href="%s">%s</a>', |
|
1681 | + wp_login_url(get_permalink()), |
|
1682 | 1682 | $args['login_text'] |
1683 | 1683 | ); |
1684 | 1684 | } else { |
1685 | - $onclick = sprintf( 'return addComment.moveForm( "%1$s-%2$s", "0", "%3$s", "%2$s" )', |
|
1685 | + $onclick = sprintf('return addComment.moveForm( "%1$s-%2$s", "0", "%3$s", "%2$s" )', |
|
1686 | 1686 | $args['add_below'], $post->ID, $args['respond_id'] |
1687 | 1687 | ); |
1688 | 1688 | |
1689 | - $link = sprintf( "<a rel='nofollow' class='comment-reply-link' href='%s' onclick='%s'>%s</a>", |
|
1690 | - get_permalink( $post->ID ) . '#' . $args['respond_id'], |
|
1689 | + $link = sprintf("<a rel='nofollow' class='comment-reply-link' href='%s' onclick='%s'>%s</a>", |
|
1690 | + get_permalink($post->ID).'#'.$args['respond_id'], |
|
1691 | 1691 | $onclick, |
1692 | 1692 | $args['reply_text'] |
1693 | 1693 | ); |
1694 | 1694 | } |
1695 | - $formatted_link = $args['before'] . $link . $args['after']; |
|
1695 | + $formatted_link = $args['before'].$link.$args['after']; |
|
1696 | 1696 | |
1697 | 1697 | /** |
1698 | 1698 | * Filter the formatted post comments link HTML. |
@@ -1702,7 +1702,7 @@ discard block |
||
1702 | 1702 | * @param string $formatted The HTML-formatted post comments link. |
1703 | 1703 | * @param int|WP_Post $post The post ID or WP_Post object. |
1704 | 1704 | */ |
1705 | - return apply_filters( 'post_comments_link', $formatted_link, $post ); |
|
1705 | + return apply_filters('post_comments_link', $formatted_link, $post); |
|
1706 | 1706 | } |
1707 | 1707 | |
1708 | 1708 | /** |
@@ -1729,14 +1729,14 @@ discard block |
||
1729 | 1729 | * @param string $text Optional. Text to display for cancel reply link. Default empty. |
1730 | 1730 | * @return string |
1731 | 1731 | */ |
1732 | -function get_cancel_comment_reply_link( $text = '' ) { |
|
1733 | - if ( empty($text) ) |
|
1732 | +function get_cancel_comment_reply_link($text = '') { |
|
1733 | + if (empty($text)) |
|
1734 | 1734 | $text = __('Click here to cancel reply.'); |
1735 | 1735 | |
1736 | 1736 | $style = isset($_GET['replytocom']) ? '' : ' style="display:none;"'; |
1737 | - $link = esc_html( remove_query_arg('replytocom') ) . '#respond'; |
|
1737 | + $link = esc_html(remove_query_arg('replytocom')).'#respond'; |
|
1738 | 1738 | |
1739 | - $formatted_link = '<a rel="nofollow" id="cancel-comment-reply-link" href="' . $link . '"' . $style . '>' . $text . '</a>'; |
|
1739 | + $formatted_link = '<a rel="nofollow" id="cancel-comment-reply-link" href="'.$link.'"'.$style.'>'.$text.'</a>'; |
|
1740 | 1740 | |
1741 | 1741 | /** |
1742 | 1742 | * Filter the cancel comment reply link HTML. |
@@ -1747,7 +1747,7 @@ discard block |
||
1747 | 1747 | * @param string $link Cancel comment reply link URL. |
1748 | 1748 | * @param string $text Cancel comment reply link text. |
1749 | 1749 | */ |
1750 | - return apply_filters( 'cancel_comment_reply_link', $formatted_link, $link, $text ); |
|
1750 | + return apply_filters('cancel_comment_reply_link', $formatted_link, $link, $text); |
|
1751 | 1751 | } |
1752 | 1752 | |
1753 | 1753 | /** |
@@ -1757,7 +1757,7 @@ discard block |
||
1757 | 1757 | * |
1758 | 1758 | * @param string $text Optional. Text to display for cancel reply link. Default empty. |
1759 | 1759 | */ |
1760 | -function cancel_comment_reply_link( $text = '' ) { |
|
1760 | +function cancel_comment_reply_link($text = '') { |
|
1761 | 1761 | echo get_cancel_comment_reply_link($text); |
1762 | 1762 | } |
1763 | 1763 | |
@@ -1769,8 +1769,8 @@ discard block |
||
1769 | 1769 | * @param int $id Optional. Post ID. Default current post ID. |
1770 | 1770 | * @return string Hidden input HTML for replying to comments |
1771 | 1771 | */ |
1772 | -function get_comment_id_fields( $id = 0 ) { |
|
1773 | - if ( empty( $id ) ) |
|
1772 | +function get_comment_id_fields($id = 0) { |
|
1773 | + if (empty($id)) |
|
1774 | 1774 | $id = get_the_ID(); |
1775 | 1775 | |
1776 | 1776 | $replytoid = isset($_GET['replytocom']) ? (int) $_GET['replytocom'] : 0; |
@@ -1786,7 +1786,7 @@ discard block |
||
1786 | 1786 | * @param int $id The post ID. |
1787 | 1787 | * @param int $replytoid The id of the comment being replied to. |
1788 | 1788 | */ |
1789 | - return apply_filters( 'comment_id_fields', $result, $id, $replytoid ); |
|
1789 | + return apply_filters('comment_id_fields', $result, $id, $replytoid); |
|
1790 | 1790 | } |
1791 | 1791 | |
1792 | 1792 | /** |
@@ -1796,8 +1796,8 @@ discard block |
||
1796 | 1796 | * |
1797 | 1797 | * @param int $id Optional. Post ID. Default current post ID. |
1798 | 1798 | */ |
1799 | -function comment_id_fields( $id = 0 ) { |
|
1800 | - echo get_comment_id_fields( $id ); |
|
1799 | +function comment_id_fields($id = 0) { |
|
1800 | + echo get_comment_id_fields($id); |
|
1801 | 1801 | } |
1802 | 1802 | |
1803 | 1803 | /** |
@@ -1820,21 +1820,21 @@ discard block |
||
1820 | 1820 | * @param string $linktoparent Optional. Boolean to control making the author's name a link |
1821 | 1821 | * to their comment. Default true. |
1822 | 1822 | */ |
1823 | -function comment_form_title( $noreplytext = false, $replytext = false, $linktoparent = true ) { |
|
1823 | +function comment_form_title($noreplytext = false, $replytext = false, $linktoparent = true) { |
|
1824 | 1824 | global $comment; |
1825 | 1825 | |
1826 | - if ( false === $noreplytext ) $noreplytext = __( 'Leave a Reply' ); |
|
1827 | - if ( false === $replytext ) $replytext = __( 'Leave a Reply to %s' ); |
|
1826 | + if (false === $noreplytext) $noreplytext = __('Leave a Reply'); |
|
1827 | + if (false === $replytext) $replytext = __('Leave a Reply to %s'); |
|
1828 | 1828 | |
1829 | 1829 | $replytoid = isset($_GET['replytocom']) ? (int) $_GET['replytocom'] : 0; |
1830 | 1830 | |
1831 | - if ( 0 == $replytoid ) |
|
1831 | + if (0 == $replytoid) |
|
1832 | 1832 | echo $noreplytext; |
1833 | 1833 | else { |
1834 | 1834 | // Sets the global so that template tags can be used in the comment form. |
1835 | 1835 | $comment = get_comment($replytoid); |
1836 | - $author = ( $linktoparent ) ? '<a href="#comment-' . get_comment_ID() . '">' . get_comment_author( $comment ) . '</a>' : get_comment_author( $comment ); |
|
1837 | - printf( $replytext, $author ); |
|
1836 | + $author = ($linktoparent) ? '<a href="#comment-'.get_comment_ID().'">'.get_comment_author($comment).'</a>' : get_comment_author($comment); |
|
1837 | + printf($replytext, $author); |
|
1838 | 1838 | } |
1839 | 1839 | } |
1840 | 1840 | |
@@ -1876,7 +1876,7 @@ discard block |
||
1876 | 1876 | * } |
1877 | 1877 | * @param array $comments Optional. Array of WP_Comment objects. |
1878 | 1878 | */ |
1879 | -function wp_list_comments( $args = array(), $comments = null ) { |
|
1879 | +function wp_list_comments($args = array(), $comments = null) { |
|
1880 | 1880 | global $wp_query, $comment_alt, $comment_depth, $comment_thread_alt, $overridden_cpage, $in_comment_loop; |
1881 | 1881 | |
1882 | 1882 | $in_comment_loop = true; |
@@ -1896,12 +1896,12 @@ discard block |
||
1896 | 1896 | 'avatar_size' => 32, |
1897 | 1897 | 'reverse_top_level' => null, |
1898 | 1898 | 'reverse_children' => '', |
1899 | - 'format' => current_theme_supports( 'html5', 'comment-list' ) ? 'html5' : 'xhtml', |
|
1899 | + 'format' => current_theme_supports('html5', 'comment-list') ? 'html5' : 'xhtml', |
|
1900 | 1900 | 'short_ping' => false, |
1901 | 1901 | 'echo' => true, |
1902 | 1902 | ); |
1903 | 1903 | |
1904 | - $r = wp_parse_args( $args, $defaults ); |
|
1904 | + $r = wp_parse_args($args, $defaults); |
|
1905 | 1905 | |
1906 | 1906 | /** |
1907 | 1907 | * Filter the arguments used in retrieving the comment list. |
@@ -1912,16 +1912,16 @@ discard block |
||
1912 | 1912 | * |
1913 | 1913 | * @param array $r An array of arguments for displaying comments. |
1914 | 1914 | */ |
1915 | - $r = apply_filters( 'wp_list_comments_args', $r ); |
|
1915 | + $r = apply_filters('wp_list_comments_args', $r); |
|
1916 | 1916 | |
1917 | 1917 | // Figure out what comments we'll be looping through ($_comments) |
1918 | - if ( null !== $comments ) { |
|
1918 | + if (null !== $comments) { |
|
1919 | 1919 | $comments = (array) $comments; |
1920 | - if ( empty($comments) ) |
|
1920 | + if (empty($comments)) |
|
1921 | 1921 | return; |
1922 | - if ( 'all' != $r['type'] ) { |
|
1922 | + if ('all' != $r['type']) { |
|
1923 | 1923 | $comments_by_type = separate_comments($comments); |
1924 | - if ( empty($comments_by_type[$r['type']]) ) |
|
1924 | + if (empty($comments_by_type[$r['type']])) |
|
1925 | 1925 | return; |
1926 | 1926 | $_comments = $comments_by_type[$r['type']]; |
1927 | 1927 | } else { |
@@ -1932,29 +1932,29 @@ discard block |
||
1932 | 1932 | * If 'page' or 'per_page' has been passed, and does not match what's in $wp_query, |
1933 | 1933 | * perform a separate comment query and allow Walker_Comment to paginate. |
1934 | 1934 | */ |
1935 | - if ( $r['page'] || $r['per_page'] ) { |
|
1936 | - $current_cpage = get_query_var( 'cpage' ); |
|
1937 | - if ( ! $current_cpage ) { |
|
1938 | - $current_cpage = 'newest' === get_option( 'default_comments_page' ) ? 1 : $wp_query->max_num_comment_pages; |
|
1935 | + if ($r['page'] || $r['per_page']) { |
|
1936 | + $current_cpage = get_query_var('cpage'); |
|
1937 | + if ( ! $current_cpage) { |
|
1938 | + $current_cpage = 'newest' === get_option('default_comments_page') ? 1 : $wp_query->max_num_comment_pages; |
|
1939 | 1939 | } |
1940 | 1940 | |
1941 | - $current_per_page = get_query_var( 'comments_per_page' ); |
|
1942 | - if ( $r['page'] != $current_cpage || $r['per_page'] != $current_per_page ) { |
|
1941 | + $current_per_page = get_query_var('comments_per_page'); |
|
1942 | + if ($r['page'] != $current_cpage || $r['per_page'] != $current_per_page) { |
|
1943 | 1943 | |
1944 | - $comments = get_comments( array( |
|
1944 | + $comments = get_comments(array( |
|
1945 | 1945 | 'post_id' => get_the_ID(), |
1946 | 1946 | 'orderby' => 'comment_date_gmt', |
1947 | 1947 | 'order' => 'ASC', |
1948 | 1948 | 'status' => 'all', |
1949 | - ) ); |
|
1949 | + )); |
|
1950 | 1950 | |
1951 | - if ( 'all' != $r['type'] ) { |
|
1952 | - $comments_by_type = separate_comments( $comments ); |
|
1953 | - if ( empty( $comments_by_type[ $r['type'] ] ) ) { |
|
1951 | + if ('all' != $r['type']) { |
|
1952 | + $comments_by_type = separate_comments($comments); |
|
1953 | + if (empty($comments_by_type[$r['type']])) { |
|
1954 | 1954 | return; |
1955 | 1955 | } |
1956 | 1956 | |
1957 | - $_comments = $comments_by_type[ $r['type'] ]; |
|
1957 | + $_comments = $comments_by_type[$r['type']]; |
|
1958 | 1958 | } else { |
1959 | 1959 | $_comments = $comments; |
1960 | 1960 | } |
@@ -1962,29 +1962,29 @@ discard block |
||
1962 | 1962 | |
1963 | 1963 | // Otherwise, fall back on the comments from `$wp_query->comments`. |
1964 | 1964 | } else { |
1965 | - if ( empty($wp_query->comments) ) |
|
1965 | + if (empty($wp_query->comments)) |
|
1966 | 1966 | return; |
1967 | - if ( 'all' != $r['type'] ) { |
|
1968 | - if ( empty($wp_query->comments_by_type) ) |
|
1967 | + if ('all' != $r['type']) { |
|
1968 | + if (empty($wp_query->comments_by_type)) |
|
1969 | 1969 | $wp_query->comments_by_type = separate_comments($wp_query->comments); |
1970 | - if ( empty($wp_query->comments_by_type[$r['type']]) ) |
|
1970 | + if (empty($wp_query->comments_by_type[$r['type']])) |
|
1971 | 1971 | return; |
1972 | 1972 | $_comments = $wp_query->comments_by_type[$r['type']]; |
1973 | 1973 | } else { |
1974 | 1974 | $_comments = $wp_query->comments; |
1975 | 1975 | } |
1976 | 1976 | |
1977 | - if ( $wp_query->max_num_comment_pages ) { |
|
1978 | - $default_comments_page = get_option( 'default_comments_page' ); |
|
1979 | - $cpage = get_query_var( 'cpage' ); |
|
1980 | - if ( 'newest' === $default_comments_page ) { |
|
1977 | + if ($wp_query->max_num_comment_pages) { |
|
1978 | + $default_comments_page = get_option('default_comments_page'); |
|
1979 | + $cpage = get_query_var('cpage'); |
|
1980 | + if ('newest' === $default_comments_page) { |
|
1981 | 1981 | $r['cpage'] = $cpage; |
1982 | 1982 | |
1983 | 1983 | /* |
1984 | 1984 | * When first page shows oldest comments, post permalink is the same as |
1985 | 1985 | * the comment permalink. |
1986 | 1986 | */ |
1987 | - } elseif ( $cpage == 1 ) { |
|
1987 | + } elseif ($cpage == 1) { |
|
1988 | 1988 | $r['cpage'] = ''; |
1989 | 1989 | } else { |
1990 | 1990 | $r['cpage'] = $cpage; |
@@ -1996,52 +1996,52 @@ discard block |
||
1996 | 1996 | } |
1997 | 1997 | } |
1998 | 1998 | |
1999 | - if ( '' === $r['per_page'] && get_option( 'page_comments' ) ) { |
|
1999 | + if ('' === $r['per_page'] && get_option('page_comments')) { |
|
2000 | 2000 | $r['per_page'] = get_query_var('comments_per_page'); |
2001 | 2001 | } |
2002 | 2002 | |
2003 | - if ( empty($r['per_page']) ) { |
|
2003 | + if (empty($r['per_page'])) { |
|
2004 | 2004 | $r['per_page'] = 0; |
2005 | 2005 | $r['page'] = 0; |
2006 | 2006 | } |
2007 | 2007 | |
2008 | - if ( '' === $r['max_depth'] ) { |
|
2009 | - if ( get_option('thread_comments') ) |
|
2008 | + if ('' === $r['max_depth']) { |
|
2009 | + if (get_option('thread_comments')) |
|
2010 | 2010 | $r['max_depth'] = get_option('thread_comments_depth'); |
2011 | 2011 | else |
2012 | 2012 | $r['max_depth'] = -1; |
2013 | 2013 | } |
2014 | 2014 | |
2015 | - if ( '' === $r['page'] ) { |
|
2016 | - if ( empty($overridden_cpage) ) { |
|
2015 | + if ('' === $r['page']) { |
|
2016 | + if (empty($overridden_cpage)) { |
|
2017 | 2017 | $r['page'] = get_query_var('cpage'); |
2018 | 2018 | } else { |
2019 | 2019 | $threaded = ( -1 != $r['max_depth'] ); |
2020 | - $r['page'] = ( 'newest' == get_option('default_comments_page') ) ? get_comment_pages_count($_comments, $r['per_page'], $threaded) : 1; |
|
2021 | - set_query_var( 'cpage', $r['page'] ); |
|
2020 | + $r['page'] = ('newest' == get_option('default_comments_page')) ? get_comment_pages_count($_comments, $r['per_page'], $threaded) : 1; |
|
2021 | + set_query_var('cpage', $r['page']); |
|
2022 | 2022 | } |
2023 | 2023 | } |
2024 | 2024 | // Validation check |
2025 | 2025 | $r['page'] = intval($r['page']); |
2026 | - if ( 0 == $r['page'] && 0 != $r['per_page'] ) |
|
2026 | + if (0 == $r['page'] && 0 != $r['per_page']) |
|
2027 | 2027 | $r['page'] = 1; |
2028 | 2028 | |
2029 | - if ( null === $r['reverse_top_level'] ) |
|
2030 | - $r['reverse_top_level'] = ( 'desc' == get_option('comment_order') ); |
|
2029 | + if (null === $r['reverse_top_level']) |
|
2030 | + $r['reverse_top_level'] = ('desc' == get_option('comment_order')); |
|
2031 | 2031 | |
2032 | - wp_queue_comments_for_comment_meta_lazyload( $_comments ); |
|
2032 | + wp_queue_comments_for_comment_meta_lazyload($_comments); |
|
2033 | 2033 | |
2034 | - if ( empty( $r['walker'] ) ) { |
|
2034 | + if (empty($r['walker'])) { |
|
2035 | 2035 | $walker = new Walker_Comment; |
2036 | 2036 | } else { |
2037 | 2037 | $walker = $r['walker']; |
2038 | 2038 | } |
2039 | 2039 | |
2040 | - $output = $walker->paged_walk( $_comments, $r['max_depth'], $r['page'], $r['per_page'], $r ); |
|
2040 | + $output = $walker->paged_walk($_comments, $r['max_depth'], $r['page'], $r['per_page'], $r); |
|
2041 | 2041 | |
2042 | 2042 | $in_comment_loop = false; |
2043 | 2043 | |
2044 | - if ( $r['echo'] ) { |
|
2044 | + if ($r['echo']) { |
|
2045 | 2045 | echo $output; |
2046 | 2046 | } else { |
2047 | 2047 | return $output; |
@@ -2108,32 +2108,32 @@ discard block |
||
2108 | 2108 | * } |
2109 | 2109 | * @param int|WP_Post $post_id Post ID or WP_Post object to generate the form for. Default current post. |
2110 | 2110 | */ |
2111 | -function comment_form( $args = array(), $post_id = null ) { |
|
2112 | - if ( null === $post_id ) |
|
2111 | +function comment_form($args = array(), $post_id = null) { |
|
2112 | + if (null === $post_id) |
|
2113 | 2113 | $post_id = get_the_ID(); |
2114 | 2114 | |
2115 | 2115 | $commenter = wp_get_current_commenter(); |
2116 | 2116 | $user = wp_get_current_user(); |
2117 | 2117 | $user_identity = $user->exists() ? $user->display_name : ''; |
2118 | 2118 | |
2119 | - $args = wp_parse_args( $args ); |
|
2120 | - if ( ! isset( $args['format'] ) ) |
|
2121 | - $args['format'] = current_theme_supports( 'html5', 'comment-form' ) ? 'html5' : 'xhtml'; |
|
2119 | + $args = wp_parse_args($args); |
|
2120 | + if ( ! isset($args['format'])) |
|
2121 | + $args['format'] = current_theme_supports('html5', 'comment-form') ? 'html5' : 'xhtml'; |
|
2122 | 2122 | |
2123 | - $req = get_option( 'require_name_email' ); |
|
2124 | - $aria_req = ( $req ? " aria-required='true'" : '' ); |
|
2125 | - $html_req = ( $req ? " required='required'" : '' ); |
|
2123 | + $req = get_option('require_name_email'); |
|
2124 | + $aria_req = ($req ? " aria-required='true'" : ''); |
|
2125 | + $html_req = ($req ? " required='required'" : ''); |
|
2126 | 2126 | $html5 = 'html5' === $args['format']; |
2127 | - $fields = array( |
|
2128 | - 'author' => '<p class="comment-form-author">' . '<label for="author">' . __( 'Name' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' . |
|
2129 | - '<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30" maxlength="245"' . $aria_req . $html_req . ' /></p>', |
|
2130 | - 'email' => '<p class="comment-form-email"><label for="email">' . __( 'Email' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' . |
|
2131 | - '<input id="email" name="email" ' . ( $html5 ? 'type="email"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30" maxlength="100" aria-describedby="email-notes"' . $aria_req . $html_req . ' /></p>', |
|
2132 | - 'url' => '<p class="comment-form-url"><label for="url">' . __( 'Website' ) . '</label> ' . |
|
2133 | - '<input id="url" name="url" ' . ( $html5 ? 'type="url"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" maxlength="200" /></p>', |
|
2127 | + $fields = array( |
|
2128 | + 'author' => '<p class="comment-form-author">'.'<label for="author">'.__('Name').($req ? ' <span class="required">*</span>' : '').'</label> '. |
|
2129 | + '<input id="author" name="author" type="text" value="'.esc_attr($commenter['comment_author']).'" size="30" maxlength="245"'.$aria_req.$html_req.' /></p>', |
|
2130 | + 'email' => '<p class="comment-form-email"><label for="email">'.__('Email').($req ? ' <span class="required">*</span>' : '').'</label> '. |
|
2131 | + '<input id="email" name="email" '.($html5 ? 'type="email"' : 'type="text"').' value="'.esc_attr($commenter['comment_author_email']).'" size="30" maxlength="100" aria-describedby="email-notes"'.$aria_req.$html_req.' /></p>', |
|
2132 | + 'url' => '<p class="comment-form-url"><label for="url">'.__('Website').'</label> '. |
|
2133 | + '<input id="url" name="url" '.($html5 ? 'type="url"' : 'type="text"').' value="'.esc_attr($commenter['comment_author_url']).'" size="30" maxlength="200" /></p>', |
|
2134 | 2134 | ); |
2135 | 2135 | |
2136 | - $required_text = sprintf( ' ' . __('Required fields are marked %s'), '<span class="required">*</span>' ); |
|
2136 | + $required_text = sprintf(' '.__('Required fields are marked %s'), '<span class="required">*</span>'); |
|
2137 | 2137 | |
2138 | 2138 | /** |
2139 | 2139 | * Filter the default comment form fields. |
@@ -2142,41 +2142,41 @@ discard block |
||
2142 | 2142 | * |
2143 | 2143 | * @param array $fields The default comment fields. |
2144 | 2144 | */ |
2145 | - $fields = apply_filters( 'comment_form_default_fields', $fields ); |
|
2145 | + $fields = apply_filters('comment_form_default_fields', $fields); |
|
2146 | 2146 | $defaults = array( |
2147 | 2147 | 'fields' => $fields, |
2148 | - 'comment_field' => '<p class="comment-form-comment"><label for="comment">' . _x( 'Comment', 'noun' ) . '</label> <textarea id="comment" name="comment" cols="45" rows="8" maxlength="65525" aria-required="true" required="required"></textarea></p>', |
|
2148 | + 'comment_field' => '<p class="comment-form-comment"><label for="comment">'._x('Comment', 'noun').'</label> <textarea id="comment" name="comment" cols="45" rows="8" maxlength="65525" aria-required="true" required="required"></textarea></p>', |
|
2149 | 2149 | /** This filter is documented in wp-includes/link-template.php */ |
2150 | - 'must_log_in' => '<p class="must-log-in">' . sprintf( |
|
2150 | + 'must_log_in' => '<p class="must-log-in">'.sprintf( |
|
2151 | 2151 | /* translators: %s: login URL */ |
2152 | - __( 'You must be <a href="%s">logged in</a> to post a comment.' ), |
|
2153 | - wp_login_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) |
|
2154 | - ) . '</p>', |
|
2152 | + __('You must be <a href="%s">logged in</a> to post a comment.'), |
|
2153 | + wp_login_url(apply_filters('the_permalink', get_permalink($post_id))) |
|
2154 | + ).'</p>', |
|
2155 | 2155 | /** This filter is documented in wp-includes/link-template.php */ |
2156 | - 'logged_in_as' => '<p class="logged-in-as">' . sprintf( |
|
2156 | + 'logged_in_as' => '<p class="logged-in-as">'.sprintf( |
|
2157 | 2157 | /* translators: 1: edit user link, 2: accessibility text, 3: user name, 4: logout URL */ |
2158 | - __( '<a href="%1$s" aria-label="%2$s">Logged in as %3$s</a>. <a href="%4$s">Log out?</a>' ), |
|
2158 | + __('<a href="%1$s" aria-label="%2$s">Logged in as %3$s</a>. <a href="%4$s">Log out?</a>'), |
|
2159 | 2159 | get_edit_user_link(), |
2160 | 2160 | /* translators: %s: user name */ |
2161 | - esc_attr( sprintf( __( 'Logged in as %s. Edit your profile.' ), $user_identity ) ), |
|
2161 | + esc_attr(sprintf(__('Logged in as %s. Edit your profile.'), $user_identity)), |
|
2162 | 2162 | $user_identity, |
2163 | - wp_logout_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) |
|
2164 | - ) . '</p>', |
|
2165 | - 'comment_notes_before' => '<p class="comment-notes"><span id="email-notes">' . __( 'Your email address will not be published.' ) . '</span>'. ( $req ? $required_text : '' ) . '</p>', |
|
2163 | + wp_logout_url(apply_filters('the_permalink', get_permalink($post_id))) |
|
2164 | + ).'</p>', |
|
2165 | + 'comment_notes_before' => '<p class="comment-notes"><span id="email-notes">'.__('Your email address will not be published.').'</span>'.($req ? $required_text : '').'</p>', |
|
2166 | 2166 | 'comment_notes_after' => '', |
2167 | 2167 | 'id_form' => 'commentform', |
2168 | 2168 | 'id_submit' => 'submit', |
2169 | 2169 | 'class_form' => 'comment-form', |
2170 | 2170 | 'class_submit' => 'submit', |
2171 | 2171 | 'name_submit' => 'submit', |
2172 | - 'title_reply' => __( 'Leave a Reply' ), |
|
2173 | - 'title_reply_to' => __( 'Leave a Reply to %s' ), |
|
2172 | + 'title_reply' => __('Leave a Reply'), |
|
2173 | + 'title_reply_to' => __('Leave a Reply to %s'), |
|
2174 | 2174 | 'title_reply_before' => '<h3 id="reply-title" class="comment-reply-title">', |
2175 | 2175 | 'title_reply_after' => '</h3>', |
2176 | 2176 | 'cancel_reply_before' => ' <small>', |
2177 | 2177 | 'cancel_reply_after' => '</small>', |
2178 | - 'cancel_reply_link' => __( 'Cancel reply' ), |
|
2179 | - 'label_submit' => __( 'Post Comment' ), |
|
2178 | + 'cancel_reply_link' => __('Cancel reply'), |
|
2179 | + 'label_submit' => __('Post Comment'), |
|
2180 | 2180 | 'submit_button' => '<input name="%1$s" type="submit" id="%2$s" class="%3$s" value="%4$s" />', |
2181 | 2181 | 'submit_field' => '<p class="form-submit">%1$s %2$s</p>', |
2182 | 2182 | 'format' => 'xhtml', |
@@ -2191,53 +2191,53 @@ discard block |
||
2191 | 2191 | * |
2192 | 2192 | * @param array $defaults The default comment form arguments. |
2193 | 2193 | */ |
2194 | - $args = wp_parse_args( $args, apply_filters( 'comment_form_defaults', $defaults ) ); |
|
2194 | + $args = wp_parse_args($args, apply_filters('comment_form_defaults', $defaults)); |
|
2195 | 2195 | |
2196 | 2196 | // Ensure that the filtered args contain all required default values. |
2197 | - $args = array_merge( $defaults, $args ); |
|
2197 | + $args = array_merge($defaults, $args); |
|
2198 | 2198 | |
2199 | - if ( comments_open( $post_id ) ) : ?> |
|
2199 | + if (comments_open($post_id)) : ?> |
|
2200 | 2200 | <?php |
2201 | 2201 | /** |
2202 | 2202 | * Fires before the comment form. |
2203 | 2203 | * |
2204 | 2204 | * @since 3.0.0 |
2205 | 2205 | */ |
2206 | - do_action( 'comment_form_before' ); |
|
2206 | + do_action('comment_form_before'); |
|
2207 | 2207 | ?> |
2208 | 2208 | <div id="respond" class="comment-respond"> |
2209 | 2209 | <?php |
2210 | 2210 | echo $args['title_reply_before']; |
2211 | 2211 | |
2212 | - comment_form_title( $args['title_reply'], $args['title_reply_to'] ); |
|
2212 | + comment_form_title($args['title_reply'], $args['title_reply_to']); |
|
2213 | 2213 | |
2214 | 2214 | echo $args['cancel_reply_before']; |
2215 | 2215 | |
2216 | - cancel_comment_reply_link( $args['cancel_reply_link'] ); |
|
2216 | + cancel_comment_reply_link($args['cancel_reply_link']); |
|
2217 | 2217 | |
2218 | 2218 | echo $args['cancel_reply_after']; |
2219 | 2219 | |
2220 | 2220 | echo $args['title_reply_after']; |
2221 | 2221 | |
2222 | - if ( get_option( 'comment_registration' ) && !is_user_logged_in() ) : |
|
2222 | + if (get_option('comment_registration') && ! is_user_logged_in()) : |
|
2223 | 2223 | echo $args['must_log_in']; |
2224 | 2224 | /** |
2225 | 2225 | * Fires after the HTML-formatted 'must log in after' message in the comment form. |
2226 | 2226 | * |
2227 | 2227 | * @since 3.0.0 |
2228 | 2228 | */ |
2229 | - do_action( 'comment_form_must_log_in_after' ); |
|
2229 | + do_action('comment_form_must_log_in_after'); |
|
2230 | 2230 | else : ?> |
2231 | - <form action="<?php echo site_url( '/wp-comments-post.php' ); ?>" method="post" id="<?php echo esc_attr( $args['id_form'] ); ?>" class="<?php echo esc_attr( $args['class_form'] ); ?>"<?php echo $html5 ? ' novalidate' : ''; ?>> |
|
2231 | + <form action="<?php echo site_url('/wp-comments-post.php'); ?>" method="post" id="<?php echo esc_attr($args['id_form']); ?>" class="<?php echo esc_attr($args['class_form']); ?>"<?php echo $html5 ? ' novalidate' : ''; ?>> |
|
2232 | 2232 | <?php |
2233 | 2233 | /** |
2234 | 2234 | * Fires at the top of the comment form, inside the form tag. |
2235 | 2235 | * |
2236 | 2236 | * @since 3.0.0 |
2237 | 2237 | */ |
2238 | - do_action( 'comment_form_top' ); |
|
2238 | + do_action('comment_form_top'); |
|
2239 | 2239 | |
2240 | - if ( is_user_logged_in() ) : |
|
2240 | + if (is_user_logged_in()) : |
|
2241 | 2241 | /** |
2242 | 2242 | * Filter the 'logged in' message for the comment form for display. |
2243 | 2243 | * |
@@ -2249,7 +2249,7 @@ discard block |
||
2249 | 2249 | * @param string $user_identity If the commenter is a registered user, |
2250 | 2250 | * the display name, blank otherwise. |
2251 | 2251 | */ |
2252 | - echo apply_filters( 'comment_form_logged_in', $args['logged_in_as'], $commenter, $user_identity ); |
|
2252 | + echo apply_filters('comment_form_logged_in', $args['logged_in_as'], $commenter, $user_identity); |
|
2253 | 2253 | |
2254 | 2254 | /** |
2255 | 2255 | * Fires after the is_user_logged_in() check in the comment form. |
@@ -2261,7 +2261,7 @@ discard block |
||
2261 | 2261 | * @param string $user_identity If the commenter is a registered user, |
2262 | 2262 | * the display name, blank otherwise. |
2263 | 2263 | */ |
2264 | - do_action( 'comment_form_logged_in_after', $commenter, $user_identity ); |
|
2264 | + do_action('comment_form_logged_in_after', $commenter, $user_identity); |
|
2265 | 2265 | |
2266 | 2266 | else : |
2267 | 2267 | |
@@ -2270,7 +2270,7 @@ discard block |
||
2270 | 2270 | endif; |
2271 | 2271 | |
2272 | 2272 | // Prepare an array of all fields, including the textarea |
2273 | - $comment_fields = array( 'comment' => $args['comment_field'] ) + (array) $args['fields']; |
|
2273 | + $comment_fields = array('comment' => $args['comment_field']) + (array) $args['fields']; |
|
2274 | 2274 | |
2275 | 2275 | /** |
2276 | 2276 | * Filter the comment form fields, including the textarea. |
@@ -2279,18 +2279,18 @@ discard block |
||
2279 | 2279 | * |
2280 | 2280 | * @param array $comment_fields The comment fields. |
2281 | 2281 | */ |
2282 | - $comment_fields = apply_filters( 'comment_form_fields', $comment_fields ); |
|
2282 | + $comment_fields = apply_filters('comment_form_fields', $comment_fields); |
|
2283 | 2283 | |
2284 | 2284 | // Get an array of field names, excluding the textarea |
2285 | - $comment_field_keys = array_diff( array_keys( $comment_fields ), array( 'comment' ) ); |
|
2285 | + $comment_field_keys = array_diff(array_keys($comment_fields), array('comment')); |
|
2286 | 2286 | |
2287 | 2287 | // Get the first and the last field name, excluding the textarea |
2288 | - $first_field = reset( $comment_field_keys ); |
|
2289 | - $last_field = end( $comment_field_keys ); |
|
2288 | + $first_field = reset($comment_field_keys); |
|
2289 | + $last_field = end($comment_field_keys); |
|
2290 | 2290 | |
2291 | - foreach ( $comment_fields as $name => $field ) { |
|
2291 | + foreach ($comment_fields as $name => $field) { |
|
2292 | 2292 | |
2293 | - if ( 'comment' === $name ) { |
|
2293 | + if ('comment' === $name) { |
|
2294 | 2294 | |
2295 | 2295 | /** |
2296 | 2296 | * Filter the content of the comment textarea field for display. |
@@ -2299,19 +2299,19 @@ discard block |
||
2299 | 2299 | * |
2300 | 2300 | * @param string $args_comment_field The content of the comment textarea field. |
2301 | 2301 | */ |
2302 | - echo apply_filters( 'comment_form_field_comment', $field ); |
|
2302 | + echo apply_filters('comment_form_field_comment', $field); |
|
2303 | 2303 | |
2304 | 2304 | echo $args['comment_notes_after']; |
2305 | 2305 | |
2306 | - } elseif ( ! is_user_logged_in() ) { |
|
2306 | + } elseif ( ! is_user_logged_in()) { |
|
2307 | 2307 | |
2308 | - if ( $first_field === $name ) { |
|
2308 | + if ($first_field === $name) { |
|
2309 | 2309 | /** |
2310 | 2310 | * Fires before the comment fields in the comment form, excluding the textarea. |
2311 | 2311 | * |
2312 | 2312 | * @since 3.0.0 |
2313 | 2313 | */ |
2314 | - do_action( 'comment_form_before_fields' ); |
|
2314 | + do_action('comment_form_before_fields'); |
|
2315 | 2315 | } |
2316 | 2316 | |
2317 | 2317 | /** |
@@ -2324,25 +2324,25 @@ discard block |
||
2324 | 2324 | * |
2325 | 2325 | * @param string $field The HTML-formatted output of the comment form field. |
2326 | 2326 | */ |
2327 | - echo apply_filters( "comment_form_field_{$name}", $field ) . "\n"; |
|
2327 | + echo apply_filters("comment_form_field_{$name}", $field)."\n"; |
|
2328 | 2328 | |
2329 | - if ( $last_field === $name ) { |
|
2329 | + if ($last_field === $name) { |
|
2330 | 2330 | /** |
2331 | 2331 | * Fires after the comment fields in the comment form, excluding the textarea. |
2332 | 2332 | * |
2333 | 2333 | * @since 3.0.0 |
2334 | 2334 | */ |
2335 | - do_action( 'comment_form_after_fields' ); |
|
2335 | + do_action('comment_form_after_fields'); |
|
2336 | 2336 | } |
2337 | 2337 | } |
2338 | 2338 | } |
2339 | 2339 | |
2340 | 2340 | $submit_button = sprintf( |
2341 | 2341 | $args['submit_button'], |
2342 | - esc_attr( $args['name_submit'] ), |
|
2343 | - esc_attr( $args['id_submit'] ), |
|
2344 | - esc_attr( $args['class_submit'] ), |
|
2345 | - esc_attr( $args['label_submit'] ) |
|
2342 | + esc_attr($args['name_submit']), |
|
2343 | + esc_attr($args['id_submit']), |
|
2344 | + esc_attr($args['class_submit']), |
|
2345 | + esc_attr($args['label_submit']) |
|
2346 | 2346 | ); |
2347 | 2347 | |
2348 | 2348 | /** |
@@ -2353,12 +2353,12 @@ discard block |
||
2353 | 2353 | * @param string $submit_button HTML markup for the submit button. |
2354 | 2354 | * @param array $args Arguments passed to `comment_form()`. |
2355 | 2355 | */ |
2356 | - $submit_button = apply_filters( 'comment_form_submit_button', $submit_button, $args ); |
|
2356 | + $submit_button = apply_filters('comment_form_submit_button', $submit_button, $args); |
|
2357 | 2357 | |
2358 | 2358 | $submit_field = sprintf( |
2359 | 2359 | $args['submit_field'], |
2360 | 2360 | $submit_button, |
2361 | - get_comment_id_fields( $post_id ) |
|
2361 | + get_comment_id_fields($post_id) |
|
2362 | 2362 | ); |
2363 | 2363 | |
2364 | 2364 | /** |
@@ -2372,7 +2372,7 @@ discard block |
||
2372 | 2372 | * @param string $submit_field HTML markup for the submit field. |
2373 | 2373 | * @param array $args Arguments passed to comment_form(). |
2374 | 2374 | */ |
2375 | - echo apply_filters( 'comment_form_submit_field', $submit_field, $args ); |
|
2375 | + echo apply_filters('comment_form_submit_field', $submit_field, $args); |
|
2376 | 2376 | |
2377 | 2377 | /** |
2378 | 2378 | * Fires at the bottom of the comment form, inside the closing </form> tag. |
@@ -2381,7 +2381,7 @@ discard block |
||
2381 | 2381 | * |
2382 | 2382 | * @param int $post_id The post ID. |
2383 | 2383 | */ |
2384 | - do_action( 'comment_form', $post_id ); |
|
2384 | + do_action('comment_form', $post_id); |
|
2385 | 2385 | ?> |
2386 | 2386 | </form> |
2387 | 2387 | <?php endif; ?> |
@@ -2392,13 +2392,13 @@ discard block |
||
2392 | 2392 | * |
2393 | 2393 | * @since 3.0.0 |
2394 | 2394 | */ |
2395 | - do_action( 'comment_form_after' ); |
|
2395 | + do_action('comment_form_after'); |
|
2396 | 2396 | else : |
2397 | 2397 | /** |
2398 | 2398 | * Fires after the comment form if comments are closed. |
2399 | 2399 | * |
2400 | 2400 | * @since 3.0.0 |
2401 | 2401 | */ |
2402 | - do_action( 'comment_form_comments_closed' ); |
|
2402 | + do_action('comment_form_comments_closed'); |
|
2403 | 2403 | endif; |
2404 | 2404 | } |
@@ -25,10 +25,11 @@ discard block |
||
25 | 25 | $comment = get_comment( $comment_ID ); |
26 | 26 | |
27 | 27 | if ( empty( $comment->comment_author ) ) { |
28 | - if ( $comment->user_id && $user = get_userdata( $comment->user_id ) ) |
|
29 | - $author = $user->display_name; |
|
30 | - else |
|
31 | - $author = __('Anonymous'); |
|
28 | + if ( $comment->user_id && $user = get_userdata( $comment->user_id ) ) { |
|
29 | + $author = $user->display_name; |
|
30 | + } else { |
|
31 | + $author = __('Anonymous'); |
|
32 | + } |
|
32 | 33 | } else { |
33 | 34 | $author = $comment->comment_author; |
34 | 35 | } |
@@ -145,9 +146,10 @@ discard block |
||
145 | 146 | * @param string $after Optional. Text or HTML to display after the email link. Default empty. |
146 | 147 | */ |
147 | 148 | function comment_author_email_link( $linktext = '', $before = '', $after = '' ) { |
148 | - if ( $link = get_comment_author_email_link( $linktext, $before, $after ) ) |
|
149 | - echo $link; |
|
150 | -} |
|
149 | + if ( $link = get_comment_author_email_link( $linktext, $before, $after ) ) { |
|
150 | + echo $link; |
|
151 | + } |
|
152 | + } |
|
151 | 153 | |
152 | 154 | /** |
153 | 155 | * Return the html email link to the author of the current comment. |
@@ -210,10 +212,11 @@ discard block |
||
210 | 212 | $url = get_comment_author_url( $comment ); |
211 | 213 | $author = get_comment_author( $comment ); |
212 | 214 | |
213 | - if ( empty( $url ) || 'http://' == $url ) |
|
214 | - $return = $author; |
|
215 | - else |
|
216 | - $return = "<a href='$url' rel='external nofollow' class='url'>$author</a>"; |
|
215 | + if ( empty( $url ) || 'http://' == $url ) { |
|
216 | + $return = $author; |
|
217 | + } else { |
|
218 | + $return = "<a href='$url' rel='external nofollow' class='url'>$author</a>"; |
|
219 | + } |
|
217 | 220 | |
218 | 221 | /** |
219 | 222 | * Filter the comment author's link for display. |
@@ -409,11 +412,12 @@ discard block |
||
409 | 412 | function comment_class( $class = '', $comment = null, $post_id = null, $echo = true ) { |
410 | 413 | // Separates classes with a single space, collates classes for comment DIV |
411 | 414 | $class = 'class="' . join( ' ', get_comment_class( $class, $comment, $post_id ) ) . '"'; |
412 | - if ( $echo) |
|
413 | - echo $class; |
|
414 | - else |
|
415 | - return $class; |
|
416 | -} |
|
415 | + if ( $echo) { |
|
416 | + echo $class; |
|
417 | + } else { |
|
418 | + return $class; |
|
419 | + } |
|
420 | + } |
|
417 | 421 | |
418 | 422 | /** |
419 | 423 | * Returns the classes for the comment div as an array. |
@@ -455,12 +459,15 @@ discard block |
||
455 | 459 | } |
456 | 460 | } |
457 | 461 | |
458 | - if ( empty($comment_alt) ) |
|
459 | - $comment_alt = 0; |
|
460 | - if ( empty($comment_depth) ) |
|
461 | - $comment_depth = 1; |
|
462 | - if ( empty($comment_thread_alt) ) |
|
463 | - $comment_thread_alt = 0; |
|
462 | + if ( empty($comment_alt) ) { |
|
463 | + $comment_alt = 0; |
|
464 | + } |
|
465 | + if ( empty($comment_depth) ) { |
|
466 | + $comment_depth = 1; |
|
467 | + } |
|
468 | + if ( empty($comment_thread_alt) ) { |
|
469 | + $comment_thread_alt = 0; |
|
470 | + } |
|
464 | 471 | |
465 | 472 | if ( $comment_alt % 2 ) { |
466 | 473 | $classes[] = 'odd'; |
@@ -485,8 +492,9 @@ discard block |
||
485 | 492 | $classes[] = "depth-$comment_depth"; |
486 | 493 | |
487 | 494 | if ( !empty($class) ) { |
488 | - if ( !is_array( $class ) ) |
|
489 | - $class = preg_split('#\s+#', $class); |
|
495 | + if ( !is_array( $class ) ) { |
|
496 | + $class = preg_split('#\s+#', $class); |
|
497 | + } |
|
490 | 498 | $classes = array_merge($classes, $class); |
491 | 499 | } |
492 | 500 | |
@@ -519,10 +527,11 @@ discard block |
||
519 | 527 | */ |
520 | 528 | function get_comment_date( $d = '', $comment_ID = 0 ) { |
521 | 529 | $comment = get_comment( $comment_ID ); |
522 | - if ( '' == $d ) |
|
523 | - $date = mysql2date(get_option('date_format'), $comment->comment_date); |
|
524 | - else |
|
525 | - $date = mysql2date($d, $comment->comment_date); |
|
530 | + if ( '' == $d ) { |
|
531 | + $date = mysql2date(get_option('date_format'), $comment->comment_date); |
|
532 | + } else { |
|
533 | + $date = mysql2date($d, $comment->comment_date); |
|
534 | + } |
|
526 | 535 | /** |
527 | 536 | * Filter the returned comment date. |
528 | 537 | * |
@@ -802,10 +811,12 @@ discard block |
||
802 | 811 | * @param string $deprecated_2 Not Used. |
803 | 812 | */ |
804 | 813 | function comments_link( $deprecated = '', $deprecated_2 = '' ) { |
805 | - if ( !empty( $deprecated ) ) |
|
806 | - _deprecated_argument( __FUNCTION__, '0.72' ); |
|
807 | - if ( !empty( $deprecated_2 ) ) |
|
808 | - _deprecated_argument( __FUNCTION__, '1.3' ); |
|
814 | + if ( !empty( $deprecated ) ) { |
|
815 | + _deprecated_argument( __FUNCTION__, '0.72' ); |
|
816 | + } |
|
817 | + if ( !empty( $deprecated_2 ) ) { |
|
818 | + _deprecated_argument( __FUNCTION__, '1.3' ); |
|
819 | + } |
|
809 | 820 | echo esc_url( get_comments_link() ); |
810 | 821 | } |
811 | 822 | |
@@ -969,10 +980,11 @@ discard block |
||
969 | 980 | $comment = get_comment(); |
970 | 981 | |
971 | 982 | $comment_date = $gmt ? $comment->comment_date_gmt : $comment->comment_date; |
972 | - if ( '' == $d ) |
|
973 | - $date = mysql2date(get_option('time_format'), $comment_date, $translate); |
|
974 | - else |
|
975 | - $date = mysql2date($d, $comment_date, $translate); |
|
983 | + if ( '' == $d ) { |
|
984 | + $date = mysql2date(get_option('time_format'), $comment_date, $translate); |
|
985 | + } else { |
|
986 | + $date = mysql2date($d, $comment_date, $translate); |
|
987 | + } |
|
976 | 988 | |
977 | 989 | /** |
978 | 990 | * Filter the returned comment time. |
@@ -1011,8 +1023,9 @@ discard block |
||
1011 | 1023 | */ |
1012 | 1024 | function get_comment_type( $comment_ID = 0 ) { |
1013 | 1025 | $comment = get_comment( $comment_ID ); |
1014 | - if ( '' == $comment->comment_type ) |
|
1015 | - $comment->comment_type = 'comment'; |
|
1026 | + if ( '' == $comment->comment_type ) { |
|
1027 | + $comment->comment_type = 'comment'; |
|
1028 | + } |
|
1016 | 1029 | |
1017 | 1030 | /** |
1018 | 1031 | * Filter the returned comment type. |
@@ -1037,9 +1050,15 @@ discard block |
||
1037 | 1050 | * @param string $pingbacktxt Optional. String to display for pingback type. Default false. |
1038 | 1051 | */ |
1039 | 1052 | function comment_type( $commenttxt = false, $trackbacktxt = false, $pingbacktxt = false ) { |
1040 | - if ( false === $commenttxt ) $commenttxt = _x( 'Comment', 'noun' ); |
|
1041 | - if ( false === $trackbacktxt ) $trackbacktxt = __( 'Trackback' ); |
|
1042 | - if ( false === $pingbacktxt ) $pingbacktxt = __( 'Pingback' ); |
|
1053 | + if ( false === $commenttxt ) { |
|
1054 | + $commenttxt = _x( 'Comment', 'noun' ); |
|
1055 | + } |
|
1056 | + if ( false === $trackbacktxt ) { |
|
1057 | + $trackbacktxt = __( 'Trackback' ); |
|
1058 | + } |
|
1059 | + if ( false === $pingbacktxt ) { |
|
1060 | + $pingbacktxt = __( 'Pingback' ); |
|
1061 | + } |
|
1043 | 1062 | $type = get_comment_type(); |
1044 | 1063 | switch( $type ) { |
1045 | 1064 | case 'trackback' : |
@@ -1065,10 +1084,11 @@ discard block |
||
1065 | 1084 | * @return string The trackback URL after being filtered. |
1066 | 1085 | */ |
1067 | 1086 | function get_trackback_url() { |
1068 | - if ( '' != get_option('permalink_structure') ) |
|
1069 | - $tb_url = trailingslashit(get_permalink()) . user_trailingslashit('trackback', 'single_trackback'); |
|
1070 | - else |
|
1071 | - $tb_url = get_option('siteurl') . '/wp-trackback.php?p=' . get_the_ID(); |
|
1087 | + if ( '' != get_option('permalink_structure') ) { |
|
1088 | + $tb_url = trailingslashit(get_permalink()) . user_trailingslashit('trackback', 'single_trackback'); |
|
1089 | + } else { |
|
1090 | + $tb_url = get_option('siteurl') . '/wp-trackback.php?p=' . get_the_ID(); |
|
1091 | + } |
|
1072 | 1092 | |
1073 | 1093 | /** |
1074 | 1094 | * Filter the returned trackback URL. |
@@ -1250,11 +1270,13 @@ discard block |
||
1250 | 1270 | function comments_template( $file = '/comments.php', $separate_comments = false ) { |
1251 | 1271 | global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_ID, $user_identity, $overridden_cpage; |
1252 | 1272 | |
1253 | - if ( !(is_single() || is_page() || $withcomments) || empty($post) ) |
|
1254 | - return; |
|
1273 | + if ( !(is_single() || is_page() || $withcomments) || empty($post) ) { |
|
1274 | + return; |
|
1275 | + } |
|
1255 | 1276 | |
1256 | - if ( empty($file) ) |
|
1257 | - $file = '/comments.php'; |
|
1277 | + if ( empty($file) ) { |
|
1278 | + $file = '/comments.php'; |
|
1279 | + } |
|
1258 | 1280 | |
1259 | 1281 | $req = get_option('require_name_email'); |
1260 | 1282 | |
@@ -1412,8 +1434,9 @@ discard block |
||
1412 | 1434 | $overridden_cpage = true; |
1413 | 1435 | } |
1414 | 1436 | |
1415 | - if ( !defined('COMMENTS_TEMPLATE') ) |
|
1416 | - define('COMMENTS_TEMPLATE', true); |
|
1437 | + if ( !defined('COMMENTS_TEMPLATE') ) { |
|
1438 | + define('COMMENTS_TEMPLATE', true); |
|
1439 | + } |
|
1417 | 1440 | |
1418 | 1441 | $theme_template = STYLESHEETPATH . $file; |
1419 | 1442 | /** |
@@ -1424,13 +1447,15 @@ discard block |
||
1424 | 1447 | * @param string $theme_template The path to the theme template file. |
1425 | 1448 | */ |
1426 | 1449 | $include = apply_filters( 'comments_template', $theme_template ); |
1427 | - if ( file_exists( $include ) ) |
|
1428 | - require( $include ); |
|
1429 | - elseif ( file_exists( TEMPLATEPATH . $file ) ) |
|
1430 | - require( TEMPLATEPATH . $file ); |
|
1431 | - else // Backward compat code will be removed in a future release |
|
1450 | + if ( file_exists( $include ) ) { |
|
1451 | + require( $include ); |
|
1452 | + } elseif ( file_exists( TEMPLATEPATH . $file ) ) { |
|
1453 | + require( TEMPLATEPATH . $file ); |
|
1454 | + } else { |
|
1455 | + // Backward compat code will be removed in a future release |
|
1432 | 1456 | require( ABSPATH . WPINC . '/theme-compat/comments.php'); |
1433 | -} |
|
1457 | + } |
|
1458 | + } |
|
1434 | 1459 | |
1435 | 1460 | /** |
1436 | 1461 | * Displays the link to the comments for the current post ID. |
@@ -1730,8 +1755,9 @@ discard block |
||
1730 | 1755 | * @return string |
1731 | 1756 | */ |
1732 | 1757 | function get_cancel_comment_reply_link( $text = '' ) { |
1733 | - if ( empty($text) ) |
|
1734 | - $text = __('Click here to cancel reply.'); |
|
1758 | + if ( empty($text) ) { |
|
1759 | + $text = __('Click here to cancel reply.'); |
|
1760 | + } |
|
1735 | 1761 | |
1736 | 1762 | $style = isset($_GET['replytocom']) ? '' : ' style="display:none;"'; |
1737 | 1763 | $link = esc_html( remove_query_arg('replytocom') ) . '#respond'; |
@@ -1770,8 +1796,9 @@ discard block |
||
1770 | 1796 | * @return string Hidden input HTML for replying to comments |
1771 | 1797 | */ |
1772 | 1798 | function get_comment_id_fields( $id = 0 ) { |
1773 | - if ( empty( $id ) ) |
|
1774 | - $id = get_the_ID(); |
|
1799 | + if ( empty( $id ) ) { |
|
1800 | + $id = get_the_ID(); |
|
1801 | + } |
|
1775 | 1802 | |
1776 | 1803 | $replytoid = isset($_GET['replytocom']) ? (int) $_GET['replytocom'] : 0; |
1777 | 1804 | $result = "<input type='hidden' name='comment_post_ID' value='$id' id='comment_post_ID' />\n"; |
@@ -1823,14 +1850,18 @@ discard block |
||
1823 | 1850 | function comment_form_title( $noreplytext = false, $replytext = false, $linktoparent = true ) { |
1824 | 1851 | global $comment; |
1825 | 1852 | |
1826 | - if ( false === $noreplytext ) $noreplytext = __( 'Leave a Reply' ); |
|
1827 | - if ( false === $replytext ) $replytext = __( 'Leave a Reply to %s' ); |
|
1853 | + if ( false === $noreplytext ) { |
|
1854 | + $noreplytext = __( 'Leave a Reply' ); |
|
1855 | + } |
|
1856 | + if ( false === $replytext ) { |
|
1857 | + $replytext = __( 'Leave a Reply to %s' ); |
|
1858 | + } |
|
1828 | 1859 | |
1829 | 1860 | $replytoid = isset($_GET['replytocom']) ? (int) $_GET['replytocom'] : 0; |
1830 | 1861 | |
1831 | - if ( 0 == $replytoid ) |
|
1832 | - echo $noreplytext; |
|
1833 | - else { |
|
1862 | + if ( 0 == $replytoid ) { |
|
1863 | + echo $noreplytext; |
|
1864 | + } else { |
|
1834 | 1865 | // Sets the global so that template tags can be used in the comment form. |
1835 | 1866 | $comment = get_comment($replytoid); |
1836 | 1867 | $author = ( $linktoparent ) ? '<a href="#comment-' . get_comment_ID() . '">' . get_comment_author( $comment ) . '</a>' : get_comment_author( $comment ); |
@@ -1917,12 +1948,14 @@ discard block |
||
1917 | 1948 | // Figure out what comments we'll be looping through ($_comments) |
1918 | 1949 | if ( null !== $comments ) { |
1919 | 1950 | $comments = (array) $comments; |
1920 | - if ( empty($comments) ) |
|
1921 | - return; |
|
1951 | + if ( empty($comments) ) { |
|
1952 | + return; |
|
1953 | + } |
|
1922 | 1954 | if ( 'all' != $r['type'] ) { |
1923 | 1955 | $comments_by_type = separate_comments($comments); |
1924 | - if ( empty($comments_by_type[$r['type']]) ) |
|
1925 | - return; |
|
1956 | + if ( empty($comments_by_type[$r['type']]) ) { |
|
1957 | + return; |
|
1958 | + } |
|
1926 | 1959 | $_comments = $comments_by_type[$r['type']]; |
1927 | 1960 | } else { |
1928 | 1961 | $_comments = $comments; |
@@ -1962,13 +1995,16 @@ discard block |
||
1962 | 1995 | |
1963 | 1996 | // Otherwise, fall back on the comments from `$wp_query->comments`. |
1964 | 1997 | } else { |
1965 | - if ( empty($wp_query->comments) ) |
|
1966 | - return; |
|
1998 | + if ( empty($wp_query->comments) ) { |
|
1999 | + return; |
|
2000 | + } |
|
1967 | 2001 | if ( 'all' != $r['type'] ) { |
1968 | - if ( empty($wp_query->comments_by_type) ) |
|
1969 | - $wp_query->comments_by_type = separate_comments($wp_query->comments); |
|
1970 | - if ( empty($wp_query->comments_by_type[$r['type']]) ) |
|
1971 | - return; |
|
2002 | + if ( empty($wp_query->comments_by_type) ) { |
|
2003 | + $wp_query->comments_by_type = separate_comments($wp_query->comments); |
|
2004 | + } |
|
2005 | + if ( empty($wp_query->comments_by_type[$r['type']]) ) { |
|
2006 | + return; |
|
2007 | + } |
|
1972 | 2008 | $_comments = $wp_query->comments_by_type[$r['type']]; |
1973 | 2009 | } else { |
1974 | 2010 | $_comments = $wp_query->comments; |
@@ -2006,10 +2042,11 @@ discard block |
||
2006 | 2042 | } |
2007 | 2043 | |
2008 | 2044 | if ( '' === $r['max_depth'] ) { |
2009 | - if ( get_option('thread_comments') ) |
|
2010 | - $r['max_depth'] = get_option('thread_comments_depth'); |
|
2011 | - else |
|
2012 | - $r['max_depth'] = -1; |
|
2045 | + if ( get_option('thread_comments') ) { |
|
2046 | + $r['max_depth'] = get_option('thread_comments_depth'); |
|
2047 | + } else { |
|
2048 | + $r['max_depth'] = -1; |
|
2049 | + } |
|
2013 | 2050 | } |
2014 | 2051 | |
2015 | 2052 | if ( '' === $r['page'] ) { |
@@ -2023,11 +2060,13 @@ discard block |
||
2023 | 2060 | } |
2024 | 2061 | // Validation check |
2025 | 2062 | $r['page'] = intval($r['page']); |
2026 | - if ( 0 == $r['page'] && 0 != $r['per_page'] ) |
|
2027 | - $r['page'] = 1; |
|
2063 | + if ( 0 == $r['page'] && 0 != $r['per_page'] ) { |
|
2064 | + $r['page'] = 1; |
|
2065 | + } |
|
2028 | 2066 | |
2029 | - if ( null === $r['reverse_top_level'] ) |
|
2030 | - $r['reverse_top_level'] = ( 'desc' == get_option('comment_order') ); |
|
2067 | + if ( null === $r['reverse_top_level'] ) { |
|
2068 | + $r['reverse_top_level'] = ( 'desc' == get_option('comment_order') ); |
|
2069 | + } |
|
2031 | 2070 | |
2032 | 2071 | wp_queue_comments_for_comment_meta_lazyload( $_comments ); |
2033 | 2072 | |
@@ -2109,16 +2148,18 @@ discard block |
||
2109 | 2148 | * @param int|WP_Post $post_id Post ID or WP_Post object to generate the form for. Default current post. |
2110 | 2149 | */ |
2111 | 2150 | function comment_form( $args = array(), $post_id = null ) { |
2112 | - if ( null === $post_id ) |
|
2113 | - $post_id = get_the_ID(); |
|
2151 | + if ( null === $post_id ) { |
|
2152 | + $post_id = get_the_ID(); |
|
2153 | + } |
|
2114 | 2154 | |
2115 | 2155 | $commenter = wp_get_current_commenter(); |
2116 | 2156 | $user = wp_get_current_user(); |
2117 | 2157 | $user_identity = $user->exists() ? $user->display_name : ''; |
2118 | 2158 | |
2119 | 2159 | $args = wp_parse_args( $args ); |
2120 | - if ( ! isset( $args['format'] ) ) |
|
2121 | - $args['format'] = current_theme_supports( 'html5', 'comment-form' ) ? 'html5' : 'xhtml'; |
|
2160 | + if ( ! isset( $args['format'] ) ) { |
|
2161 | + $args['format'] = current_theme_supports( 'html5', 'comment-form' ) ? 'html5' : 'xhtml'; |
|
2162 | + } |
|
2122 | 2163 | |
2123 | 2164 | $req = get_option( 'require_name_email' ); |
2124 | 2165 | $aria_req = ( $req ? " aria-required='true'" : '' ); |
@@ -2227,8 +2268,11 @@ discard block |
||
2227 | 2268 | * @since 3.0.0 |
2228 | 2269 | */ |
2229 | 2270 | do_action( 'comment_form_must_log_in_after' ); |
2230 | - else : ?> |
|
2231 | - <form action="<?php echo site_url( '/wp-comments-post.php' ); ?>" method="post" id="<?php echo esc_attr( $args['id_form'] ); ?>" class="<?php echo esc_attr( $args['class_form'] ); ?>"<?php echo $html5 ? ' novalidate' : ''; ?>> |
|
2271 | + else { |
|
2272 | + : ?> |
|
2273 | + <form action="<?php echo site_url( '/wp-comments-post.php' ); |
|
2274 | + } |
|
2275 | + ?>" method="post" id="<?php echo esc_attr( $args['id_form'] ); ?>" class="<?php echo esc_attr( $args['class_form'] ); ?>"<?php echo $html5 ? ' novalidate' : ''; ?>> |
|
2232 | 2276 | <?php |
2233 | 2277 | /** |
2234 | 2278 | * Fires at the top of the comment form, inside the form tag. |
@@ -2263,9 +2307,11 @@ discard block |
||
2263 | 2307 | */ |
2264 | 2308 | do_action( 'comment_form_logged_in_after', $commenter, $user_identity ); |
2265 | 2309 | |
2266 | - else : |
|
2310 | + else { |
|
2311 | + : |
|
2267 | 2312 | |
2268 | 2313 | echo $args['comment_notes_before']; |
2314 | + } |
|
2269 | 2315 | |
2270 | 2316 | endif; |
2271 | 2317 | |
@@ -2393,12 +2439,14 @@ discard block |
||
2393 | 2439 | * @since 3.0.0 |
2394 | 2440 | */ |
2395 | 2441 | do_action( 'comment_form_after' ); |
2396 | - else : |
|
2442 | + else { |
|
2443 | + : |
|
2397 | 2444 | /** |
2398 | 2445 | * Fires after the comment form if comments are closed. |
2399 | 2446 | * |
2400 | 2447 | * @since 3.0.0 |
2401 | 2448 | */ |
2402 | 2449 | do_action( 'comment_form_comments_closed' ); |
2450 | + } |
|
2403 | 2451 | endif; |
2404 | 2452 | } |
@@ -978,7 +978,7 @@ discard block |
||
978 | 978 | * |
979 | 979 | * @global wpdb $wpdb WordPress database abstraction object. |
980 | 980 | * |
981 | - * @return array Maximum character length for the comment form fields. |
|
981 | + * @return string Maximum character length for the comment form fields. |
|
982 | 982 | */ |
983 | 983 | function wp_get_comment_fields_max_lengths() { |
984 | 984 | global $wpdb; |
@@ -1492,7 +1492,7 @@ discard block |
||
1492 | 1492 | * |
1493 | 1493 | * @since 2.0.4 |
1494 | 1494 | * |
1495 | - * @return array Comment author, email, url respectively. |
|
1495 | + * @return string Comment author, email, url respectively. |
|
1496 | 1496 | */ |
1497 | 1497 | function wp_get_current_commenter() { |
1498 | 1498 | // Cookies should already be sanitized. |
@@ -1558,7 +1558,7 @@ discard block |
||
1558 | 1558 | * new comment. |
1559 | 1559 | * @type int $user_id ID of the user who submitted the comment. Default 0. |
1560 | 1560 | * } |
1561 | - * @return int|false The new comment's ID on success, false on failure. |
|
1561 | + * @return string The new comment's ID on success, false on failure. |
|
1562 | 1562 | */ |
1563 | 1563 | function wp_insert_comment( $commentdata ) { |
1564 | 1564 | global $wpdb; |
@@ -2644,7 +2644,7 @@ discard block |
||
2644 | 2644 | * |
2645 | 2645 | * @param WP_Post $posts Post data object. |
2646 | 2646 | * @param WP_Query $query Query object. |
2647 | - * @return array |
|
2647 | + * @return WP_Post |
|
2648 | 2648 | */ |
2649 | 2649 | function _close_comments_for_old_posts( $posts, $query ) { |
2650 | 2650 | if ( empty( $posts ) || ! $query->is_singular() || ! get_option( 'close_comments_for_old_posts' ) ) |
@@ -1,10 +1,10 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Core Comment API |
|
4 | - * |
|
5 | - * @package WordPress |
|
6 | - * @subpackage Comment |
|
7 | - */ |
|
3 | + * Core Comment API |
|
4 | + * |
|
5 | + * @package WordPress |
|
6 | + * @subpackage Comment |
|
7 | + */ |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Check whether a comment passes internal checks to be allowed to add. |
@@ -40,15 +40,15 @@ discard block |
||
40 | 40 | global $wpdb; |
41 | 41 | |
42 | 42 | // If manual moderation is enabled, skip all checks and return false. |
43 | - if ( 1 == get_option('comment_moderation') ) |
|
43 | + if (1 == get_option('comment_moderation')) |
|
44 | 44 | return false; |
45 | 45 | |
46 | 46 | /** This filter is documented in wp-includes/comment-template.php */ |
47 | - $comment = apply_filters( 'comment_text', $comment ); |
|
47 | + $comment = apply_filters('comment_text', $comment); |
|
48 | 48 | |
49 | 49 | // Check for the number of external links if a max allowed number is set. |
50 | - if ( $max_links = get_option( 'comment_max_links' ) ) { |
|
51 | - $num_links = preg_match_all( '/<a [^>]*href/i', $comment, $out ); |
|
50 | + if ($max_links = get_option('comment_max_links')) { |
|
51 | + $num_links = preg_match_all('/<a [^>]*href/i', $comment, $out); |
|
52 | 52 | |
53 | 53 | /** |
54 | 54 | * Filter the maximum number of links allowed in a comment. |
@@ -58,27 +58,27 @@ discard block |
||
58 | 58 | * @param int $num_links The number of links allowed. |
59 | 59 | * @param string $url Comment author's URL. Included in allowed links total. |
60 | 60 | */ |
61 | - $num_links = apply_filters( 'comment_max_links_url', $num_links, $url ); |
|
61 | + $num_links = apply_filters('comment_max_links_url', $num_links, $url); |
|
62 | 62 | |
63 | 63 | /* |
64 | 64 | * If the number of links in the comment exceeds the allowed amount, |
65 | 65 | * fail the check by returning false. |
66 | 66 | */ |
67 | - if ( $num_links >= $max_links ) |
|
67 | + if ($num_links >= $max_links) |
|
68 | 68 | return false; |
69 | 69 | } |
70 | 70 | |
71 | 71 | $mod_keys = trim(get_option('moderation_keys')); |
72 | 72 | |
73 | 73 | // If moderation 'keys' (keywords) are set, process them. |
74 | - if ( !empty($mod_keys) ) { |
|
75 | - $words = explode("\n", $mod_keys ); |
|
74 | + if ( ! empty($mod_keys)) { |
|
75 | + $words = explode("\n", $mod_keys); |
|
76 | 76 | |
77 | - foreach ( (array) $words as $word) { |
|
77 | + foreach ((array) $words as $word) { |
|
78 | 78 | $word = trim($word); |
79 | 79 | |
80 | 80 | // Skip empty lines. |
81 | - if ( empty($word) ) |
|
81 | + if (empty($word)) |
|
82 | 82 | continue; |
83 | 83 | |
84 | 84 | /* |
@@ -92,12 +92,12 @@ discard block |
||
92 | 92 | * fail the check for the given field by returning false. |
93 | 93 | */ |
94 | 94 | $pattern = "#$word#i"; |
95 | - if ( preg_match($pattern, $author) ) return false; |
|
96 | - if ( preg_match($pattern, $email) ) return false; |
|
97 | - if ( preg_match($pattern, $url) ) return false; |
|
98 | - if ( preg_match($pattern, $comment) ) return false; |
|
99 | - if ( preg_match($pattern, $user_ip) ) return false; |
|
100 | - if ( preg_match($pattern, $user_agent) ) return false; |
|
95 | + if (preg_match($pattern, $author)) return false; |
|
96 | + if (preg_match($pattern, $email)) return false; |
|
97 | + if (preg_match($pattern, $url)) return false; |
|
98 | + if (preg_match($pattern, $comment)) return false; |
|
99 | + if (preg_match($pattern, $user_ip)) return false; |
|
100 | + if (preg_match($pattern, $user_agent)) return false; |
|
101 | 101 | } |
102 | 102 | } |
103 | 103 | |
@@ -108,12 +108,12 @@ discard block |
||
108 | 108 | * as well as whether there are any moderation keywords (if set) present in the author |
109 | 109 | * email address. If both checks pass, return true. Otherwise, return false. |
110 | 110 | */ |
111 | - if ( 1 == get_option('comment_whitelist')) { |
|
112 | - if ( 'trackback' != $comment_type && 'pingback' != $comment_type && $author != '' && $email != '' ) { |
|
111 | + if (1 == get_option('comment_whitelist')) { |
|
112 | + if ('trackback' != $comment_type && 'pingback' != $comment_type && $author != '' && $email != '') { |
|
113 | 113 | // expected_slashed ($author, $email) |
114 | 114 | $ok_to_comment = $wpdb->get_var("SELECT comment_approved FROM $wpdb->comments WHERE comment_author = '$author' AND comment_author_email = '$email' and comment_approved = '1' LIMIT 1"); |
115 | - if ( ( 1 == $ok_to_comment ) && |
|
116 | - ( empty($mod_keys) || false === strpos( $email, $mod_keys) ) ) |
|
115 | + if ((1 == $ok_to_comment) && |
|
116 | + (empty($mod_keys) || false === strpos($email, $mod_keys))) |
|
117 | 117 | return true; |
118 | 118 | else |
119 | 119 | return false; |
@@ -136,8 +136,8 @@ discard block |
||
136 | 136 | * @return int|array $comments The approved comments, or number of comments if `$count` |
137 | 137 | * argument is true. |
138 | 138 | */ |
139 | -function get_approved_comments( $post_id, $args = array() ) { |
|
140 | - if ( ! $post_id ) { |
|
139 | +function get_approved_comments($post_id, $args = array()) { |
|
140 | + if ( ! $post_id) { |
|
141 | 141 | return array(); |
142 | 142 | } |
143 | 143 | |
@@ -146,10 +146,10 @@ discard block |
||
146 | 146 | 'post_id' => $post_id, |
147 | 147 | 'order' => 'ASC', |
148 | 148 | ); |
149 | - $r = wp_parse_args( $args, $defaults ); |
|
149 | + $r = wp_parse_args($args, $defaults); |
|
150 | 150 | |
151 | 151 | $query = new WP_Comment_Query; |
152 | - return $query->query( $r ); |
|
152 | + return $query->query($r); |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | /** |
@@ -167,20 +167,20 @@ discard block |
||
167 | 167 | * @param string $output Optional. OBJECT or ARRAY_A or ARRAY_N constants. |
168 | 168 | * @return WP_Comment|array|null Depends on $output value. |
169 | 169 | */ |
170 | -function get_comment( &$comment = null, $output = OBJECT ) { |
|
171 | - if ( empty( $comment ) && isset( $GLOBALS['comment'] ) ) { |
|
170 | +function get_comment(&$comment = null, $output = OBJECT) { |
|
171 | + if (empty($comment) && isset($GLOBALS['comment'])) { |
|
172 | 172 | $comment = $GLOBALS['comment']; |
173 | 173 | } |
174 | 174 | |
175 | - if ( $comment instanceof WP_Comment ) { |
|
175 | + if ($comment instanceof WP_Comment) { |
|
176 | 176 | $_comment = $comment; |
177 | - } elseif ( is_object( $comment ) ) { |
|
178 | - $_comment = new WP_Comment( $comment ); |
|
177 | + } elseif (is_object($comment)) { |
|
178 | + $_comment = new WP_Comment($comment); |
|
179 | 179 | } else { |
180 | - $_comment = WP_Comment::get_instance( $comment ); |
|
180 | + $_comment = WP_Comment::get_instance($comment); |
|
181 | 181 | } |
182 | 182 | |
183 | - if ( ! $_comment ) { |
|
183 | + if ( ! $_comment) { |
|
184 | 184 | return null; |
185 | 185 | } |
186 | 186 | |
@@ -191,14 +191,14 @@ discard block |
||
191 | 191 | * |
192 | 192 | * @param mixed $_comment Comment data. |
193 | 193 | */ |
194 | - $_comment = apply_filters( 'get_comment', $_comment ); |
|
194 | + $_comment = apply_filters('get_comment', $_comment); |
|
195 | 195 | |
196 | - if ( $output == OBJECT ) { |
|
196 | + if ($output == OBJECT) { |
|
197 | 197 | return $_comment; |
198 | - } elseif ( $output == ARRAY_A ) { |
|
198 | + } elseif ($output == ARRAY_A) { |
|
199 | 199 | return $_comment->to_array(); |
200 | - } elseif ( $output == ARRAY_N ) { |
|
201 | - return array_values( $_comment->to_array() ); |
|
200 | + } elseif ($output == ARRAY_N) { |
|
201 | + return array_values($_comment->to_array()); |
|
202 | 202 | } |
203 | 203 | return $_comment; |
204 | 204 | } |
@@ -214,9 +214,9 @@ discard block |
||
214 | 214 | * for information on accepted arguments. Default empty. |
215 | 215 | * @return int|array List of comments or number of found comments if `$count` argument is true. |
216 | 216 | */ |
217 | -function get_comments( $args = '' ) { |
|
217 | +function get_comments($args = '') { |
|
218 | 218 | $query = new WP_Comment_Query; |
219 | - return $query->query( $args ); |
|
219 | + return $query->query($args); |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | /** |
@@ -231,10 +231,10 @@ discard block |
||
231 | 231 | */ |
232 | 232 | function get_comment_statuses() { |
233 | 233 | $status = array( |
234 | - 'hold' => __( 'Unapproved' ), |
|
235 | - 'approve' => _x( 'Approved', 'comment status' ), |
|
236 | - 'spam' => _x( 'Spam', 'comment status' ), |
|
237 | - 'trash' => _x( 'Trash', 'comment status' ), |
|
234 | + 'hold' => __('Unapproved'), |
|
235 | + 'approve' => _x('Approved', 'comment status'), |
|
236 | + 'spam' => _x('Spam', 'comment status'), |
|
237 | + 'trash' => _x('Trash', 'comment status'), |
|
238 | 238 | ); |
239 | 239 | |
240 | 240 | return $status; |
@@ -249,8 +249,8 @@ discard block |
||
249 | 249 | * @param string $comment_type Optional. Comment type. Default 'comment'. |
250 | 250 | * @return string Expected return value is 'open' or 'closed'. |
251 | 251 | */ |
252 | -function get_default_comment_status( $post_type = 'post', $comment_type = 'comment' ) { |
|
253 | - switch ( $comment_type ) { |
|
252 | +function get_default_comment_status($post_type = 'post', $comment_type = 'comment') { |
|
253 | + switch ($comment_type) { |
|
254 | 254 | case 'pingback' : |
255 | 255 | case 'trackback' : |
256 | 256 | $supports = 'trackbacks'; |
@@ -262,10 +262,10 @@ discard block |
||
262 | 262 | } |
263 | 263 | |
264 | 264 | // Set the status. |
265 | - if ( 'page' === $post_type ) { |
|
265 | + if ('page' === $post_type) { |
|
266 | 266 | $status = 'closed'; |
267 | - } elseif ( post_type_supports( $post_type, $supports ) ) { |
|
268 | - $status = get_option( "default_{$option}_status" ); |
|
267 | + } elseif (post_type_supports($post_type, $supports)) { |
|
268 | + $status = get_option("default_{$option}_status"); |
|
269 | 269 | } else { |
270 | 270 | $status = 'closed'; |
271 | 271 | } |
@@ -280,7 +280,7 @@ discard block |
||
280 | 280 | * @param string $post_type Post type. Default is `post`. |
281 | 281 | * @param string $comment_type Type of comment. Default is `comment`. |
282 | 282 | */ |
283 | - return apply_filters( 'get_default_comment_status' , $status, $post_type, $comment_type ); |
|
283 | + return apply_filters('get_default_comment_status', $status, $post_type, $comment_type); |
|
284 | 284 | } |
285 | 285 | |
286 | 286 | /** |
@@ -299,12 +299,12 @@ discard block |
||
299 | 299 | global $wpdb; |
300 | 300 | static $cache_lastcommentmodified = array(); |
301 | 301 | |
302 | - if ( isset($cache_lastcommentmodified[$timezone]) ) |
|
302 | + if (isset($cache_lastcommentmodified[$timezone])) |
|
303 | 303 | return $cache_lastcommentmodified[$timezone]; |
304 | 304 | |
305 | 305 | $add_seconds_server = date('Z'); |
306 | 306 | |
307 | - switch ( strtolower($timezone)) { |
|
307 | + switch (strtolower($timezone)) { |
|
308 | 308 | case 'gmt': |
309 | 309 | $lastcommentmodified = $wpdb->get_var("SELECT comment_date_gmt FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 1"); |
310 | 310 | break; |
@@ -335,13 +335,13 @@ discard block |
||
335 | 335 | * @param int $post_id Optional. Comment amount in post if > 0, else total comments blog wide. |
336 | 336 | * @return array The amount of spam, approved, awaiting moderation, and total comments. |
337 | 337 | */ |
338 | -function get_comment_count( $post_id = 0 ) { |
|
338 | +function get_comment_count($post_id = 0) { |
|
339 | 339 | global $wpdb; |
340 | 340 | |
341 | 341 | $post_id = (int) $post_id; |
342 | 342 | |
343 | 343 | $where = ''; |
344 | - if ( $post_id > 0 ) { |
|
344 | + if ($post_id > 0) { |
|
345 | 345 | $where = $wpdb->prepare("WHERE comment_post_ID = %d", $post_id); |
346 | 346 | } |
347 | 347 | |
@@ -362,8 +362,8 @@ discard block |
||
362 | 362 | 'all' => 0, |
363 | 363 | ); |
364 | 364 | |
365 | - foreach ( $totals as $row ) { |
|
366 | - switch ( $row['comment_approved'] ) { |
|
365 | + foreach ($totals as $row) { |
|
366 | + switch ($row['comment_approved']) { |
|
367 | 367 | case 'trash': |
368 | 368 | $comment_count['trash'] = $row['total']; |
369 | 369 | break; |
@@ -475,20 +475,20 @@ discard block |
||
475 | 475 | * |
476 | 476 | * @param array $comments Array of comment objects. |
477 | 477 | */ |
478 | -function wp_queue_comments_for_comment_meta_lazyload( $comments ) { |
|
478 | +function wp_queue_comments_for_comment_meta_lazyload($comments) { |
|
479 | 479 | // Don't use `wp_list_pluck()` to avoid by-reference manipulation. |
480 | 480 | $comment_ids = array(); |
481 | - if ( is_array( $comments ) ) { |
|
482 | - foreach ( $comments as $comment ) { |
|
483 | - if ( $comment instanceof WP_Comment ) { |
|
481 | + if (is_array($comments)) { |
|
482 | + foreach ($comments as $comment) { |
|
483 | + if ($comment instanceof WP_Comment) { |
|
484 | 484 | $comment_ids[] = $comment->comment_ID; |
485 | 485 | } |
486 | 486 | } |
487 | 487 | } |
488 | 488 | |
489 | - if ( $comment_ids ) { |
|
489 | + if ($comment_ids) { |
|
490 | 490 | $lazyloader = wp_metadata_lazyloader(); |
491 | - $lazyloader->queue_objects( 'comment', $comment_ids ); |
|
491 | + $lazyloader->queue_objects('comment', $comment_ids); |
|
492 | 492 | } |
493 | 493 | } |
494 | 494 | |
@@ -502,7 +502,7 @@ discard block |
||
502 | 502 | * @since 3.4.0 |
503 | 503 | */ |
504 | 504 | function wp_set_comment_cookies($comment, $user) { |
505 | - if ( $user->exists() ) |
|
505 | + if ($user->exists()) |
|
506 | 506 | return; |
507 | 507 | |
508 | 508 | /** |
@@ -512,11 +512,11 @@ discard block |
||
512 | 512 | * |
513 | 513 | * @param int $seconds Comment cookie lifetime. Default 30000000. |
514 | 514 | */ |
515 | - $comment_cookie_lifetime = apply_filters( 'comment_cookie_lifetime', 30000000 ); |
|
516 | - $secure = ( 'https' === parse_url( home_url(), PHP_URL_SCHEME ) ); |
|
517 | - setcookie( 'comment_author_' . COOKIEHASH, $comment->comment_author, time() + $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN, $secure ); |
|
518 | - setcookie( 'comment_author_email_' . COOKIEHASH, $comment->comment_author_email, time() + $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN, $secure ); |
|
519 | - setcookie( 'comment_author_url_' . COOKIEHASH, esc_url($comment->comment_author_url), time() + $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN, $secure ); |
|
515 | + $comment_cookie_lifetime = apply_filters('comment_cookie_lifetime', 30000000); |
|
516 | + $secure = ('https' === parse_url(home_url(), PHP_URL_SCHEME)); |
|
517 | + setcookie('comment_author_'.COOKIEHASH, $comment->comment_author, time() + $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN, $secure); |
|
518 | + setcookie('comment_author_email_'.COOKIEHASH, $comment->comment_author_email, time() + $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN, $secure); |
|
519 | + setcookie('comment_author_url_'.COOKIEHASH, esc_url($comment->comment_author_url), time() + $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN, $secure); |
|
520 | 520 | } |
521 | 521 | |
522 | 522 | /** |
@@ -528,7 +528,7 @@ discard block |
||
528 | 528 | * @since 2.0.4 |
529 | 529 | */ |
530 | 530 | function sanitize_comment_cookies() { |
531 | - if ( isset( $_COOKIE['comment_author_' . COOKIEHASH] ) ) { |
|
531 | + if (isset($_COOKIE['comment_author_'.COOKIEHASH])) { |
|
532 | 532 | /** |
533 | 533 | * Filter the comment author's name cookie before it is set. |
534 | 534 | * |
@@ -539,13 +539,13 @@ discard block |
||
539 | 539 | * |
540 | 540 | * @param string $author_cookie The comment author name cookie. |
541 | 541 | */ |
542 | - $comment_author = apply_filters( 'pre_comment_author_name', $_COOKIE['comment_author_' . COOKIEHASH] ); |
|
542 | + $comment_author = apply_filters('pre_comment_author_name', $_COOKIE['comment_author_'.COOKIEHASH]); |
|
543 | 543 | $comment_author = wp_unslash($comment_author); |
544 | 544 | $comment_author = esc_attr($comment_author); |
545 | - $_COOKIE['comment_author_' . COOKIEHASH] = $comment_author; |
|
545 | + $_COOKIE['comment_author_'.COOKIEHASH] = $comment_author; |
|
546 | 546 | } |
547 | 547 | |
548 | - if ( isset( $_COOKIE['comment_author_email_' . COOKIEHASH] ) ) { |
|
548 | + if (isset($_COOKIE['comment_author_email_'.COOKIEHASH])) { |
|
549 | 549 | /** |
550 | 550 | * Filter the comment author's email cookie before it is set. |
551 | 551 | * |
@@ -556,13 +556,13 @@ discard block |
||
556 | 556 | * |
557 | 557 | * @param string $author_email_cookie The comment author email cookie. |
558 | 558 | */ |
559 | - $comment_author_email = apply_filters( 'pre_comment_author_email', $_COOKIE['comment_author_email_' . COOKIEHASH] ); |
|
559 | + $comment_author_email = apply_filters('pre_comment_author_email', $_COOKIE['comment_author_email_'.COOKIEHASH]); |
|
560 | 560 | $comment_author_email = wp_unslash($comment_author_email); |
561 | 561 | $comment_author_email = esc_attr($comment_author_email); |
562 | 562 | $_COOKIE['comment_author_email_'.COOKIEHASH] = $comment_author_email; |
563 | 563 | } |
564 | 564 | |
565 | - if ( isset( $_COOKIE['comment_author_url_' . COOKIEHASH] ) ) { |
|
565 | + if (isset($_COOKIE['comment_author_url_'.COOKIEHASH])) { |
|
566 | 566 | /** |
567 | 567 | * Filter the comment author's URL cookie before it is set. |
568 | 568 | * |
@@ -573,7 +573,7 @@ discard block |
||
573 | 573 | * |
574 | 574 | * @param string $author_url_cookie The comment author URL cookie. |
575 | 575 | */ |
576 | - $comment_author_url = apply_filters( 'pre_comment_author_url', $_COOKIE['comment_author_url_' . COOKIEHASH] ); |
|
576 | + $comment_author_url = apply_filters('pre_comment_author_url', $_COOKIE['comment_author_url_'.COOKIEHASH]); |
|
577 | 577 | $comment_author_url = wp_unslash($comment_author_url); |
578 | 578 | $_COOKIE['comment_author_url_'.COOKIEHASH] = $comment_author_url; |
579 | 579 | } |
@@ -589,29 +589,29 @@ discard block |
||
589 | 589 | * @param array $commentdata Contains information on the comment |
590 | 590 | * @return int|string Signifies the approval status (0|1|'spam') |
591 | 591 | */ |
592 | -function wp_allow_comment( $commentdata ) { |
|
592 | +function wp_allow_comment($commentdata) { |
|
593 | 593 | global $wpdb; |
594 | 594 | |
595 | 595 | // Simple duplicate check |
596 | 596 | // expected_slashed ($comment_post_ID, $comment_author, $comment_author_email, $comment_content) |
597 | 597 | $dupe = $wpdb->prepare( |
598 | 598 | "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_parent = %s AND comment_approved != 'trash' AND ( comment_author = %s ", |
599 | - wp_unslash( $commentdata['comment_post_ID'] ), |
|
600 | - wp_unslash( $commentdata['comment_parent'] ), |
|
601 | - wp_unslash( $commentdata['comment_author'] ) |
|
599 | + wp_unslash($commentdata['comment_post_ID']), |
|
600 | + wp_unslash($commentdata['comment_parent']), |
|
601 | + wp_unslash($commentdata['comment_author']) |
|
602 | 602 | ); |
603 | - if ( $commentdata['comment_author_email'] ) { |
|
603 | + if ($commentdata['comment_author_email']) { |
|
604 | 604 | $dupe .= $wpdb->prepare( |
605 | 605 | "OR comment_author_email = %s ", |
606 | - wp_unslash( $commentdata['comment_author_email'] ) |
|
606 | + wp_unslash($commentdata['comment_author_email']) |
|
607 | 607 | ); |
608 | 608 | } |
609 | 609 | $dupe .= $wpdb->prepare( |
610 | 610 | ") AND comment_content = %s LIMIT 1", |
611 | - wp_unslash( $commentdata['comment_content'] ) |
|
611 | + wp_unslash($commentdata['comment_content']) |
|
612 | 612 | ); |
613 | 613 | |
614 | - $dupe_id = $wpdb->get_var( $dupe ); |
|
614 | + $dupe_id = $wpdb->get_var($dupe); |
|
615 | 615 | |
616 | 616 | /** |
617 | 617 | * Filters the ID, if any, of the duplicate comment found when creating a new comment. |
@@ -623,9 +623,9 @@ discard block |
||
623 | 623 | * @param int $dupe_id ID of the comment identified as a duplicate. |
624 | 624 | * @param array $commentdata Data for the comment being created. |
625 | 625 | */ |
626 | - $dupe_id = apply_filters( 'duplicate_comment_id', $dupe_id, $commentdata ); |
|
626 | + $dupe_id = apply_filters('duplicate_comment_id', $dupe_id, $commentdata); |
|
627 | 627 | |
628 | - if ( $dupe_id ) { |
|
628 | + if ($dupe_id) { |
|
629 | 629 | /** |
630 | 630 | * Fires immediately after a duplicate comment is detected. |
631 | 631 | * |
@@ -633,11 +633,11 @@ discard block |
||
633 | 633 | * |
634 | 634 | * @param array $commentdata Comment data. |
635 | 635 | */ |
636 | - do_action( 'comment_duplicate_trigger', $commentdata ); |
|
637 | - if ( defined( 'DOING_AJAX' ) ) { |
|
638 | - die( __('Duplicate comment detected; it looks as though you’ve already said that!') ); |
|
636 | + do_action('comment_duplicate_trigger', $commentdata); |
|
637 | + if (defined('DOING_AJAX')) { |
|
638 | + die(__('Duplicate comment detected; it looks as though you’ve already said that!')); |
|
639 | 639 | } |
640 | - wp_die( __( 'Duplicate comment detected; it looks as though you’ve already said that!' ), 409 ); |
|
640 | + wp_die(__('Duplicate comment detected; it looks as though you’ve already said that!'), 409); |
|
641 | 641 | } |
642 | 642 | |
643 | 643 | /** |
@@ -658,20 +658,20 @@ discard block |
||
658 | 658 | $commentdata['comment_date_gmt'] |
659 | 659 | ); |
660 | 660 | |
661 | - if ( ! empty( $commentdata['user_id'] ) ) { |
|
662 | - $user = get_userdata( $commentdata['user_id'] ); |
|
663 | - $post_author = $wpdb->get_var( $wpdb->prepare( |
|
661 | + if ( ! empty($commentdata['user_id'])) { |
|
662 | + $user = get_userdata($commentdata['user_id']); |
|
663 | + $post_author = $wpdb->get_var($wpdb->prepare( |
|
664 | 664 | "SELECT post_author FROM $wpdb->posts WHERE ID = %d LIMIT 1", |
665 | 665 | $commentdata['comment_post_ID'] |
666 | - ) ); |
|
666 | + )); |
|
667 | 667 | } |
668 | 668 | |
669 | - if ( isset( $user ) && ( $commentdata['user_id'] == $post_author || $user->has_cap( 'moderate_comments' ) ) ) { |
|
669 | + if (isset($user) && ($commentdata['user_id'] == $post_author || $user->has_cap('moderate_comments'))) { |
|
670 | 670 | // The author and the admins get respect. |
671 | 671 | $approved = 1; |
672 | 672 | } else { |
673 | 673 | // Everyone else's comments will be checked. |
674 | - if ( check_comment( |
|
674 | + if (check_comment( |
|
675 | 675 | $commentdata['comment_author'], |
676 | 676 | $commentdata['comment_author_email'], |
677 | 677 | $commentdata['comment_author_url'], |
@@ -679,20 +679,20 @@ discard block |
||
679 | 679 | $commentdata['comment_author_IP'], |
680 | 680 | $commentdata['comment_agent'], |
681 | 681 | $commentdata['comment_type'] |
682 | - ) ) { |
|
682 | + )) { |
|
683 | 683 | $approved = 1; |
684 | 684 | } else { |
685 | 685 | $approved = 0; |
686 | 686 | } |
687 | 687 | |
688 | - if ( wp_blacklist_check( |
|
688 | + if (wp_blacklist_check( |
|
689 | 689 | $commentdata['comment_author'], |
690 | 690 | $commentdata['comment_author_email'], |
691 | 691 | $commentdata['comment_author_url'], |
692 | 692 | $commentdata['comment_content'], |
693 | 693 | $commentdata['comment_author_IP'], |
694 | 694 | $commentdata['comment_agent'] |
695 | - ) ) { |
|
695 | + )) { |
|
696 | 696 | $approved = EMPTY_TRASH_DAYS ? 'trash' : 'spam'; |
697 | 697 | } |
698 | 698 | } |
@@ -705,7 +705,7 @@ discard block |
||
705 | 705 | * @param bool|string $approved The approval status. Accepts 1, 0, or 'spam'. |
706 | 706 | * @param array $commentdata Comment data. |
707 | 707 | */ |
708 | - $approved = apply_filters( 'pre_comment_approved', $approved, $commentdata ); |
|
708 | + $approved = apply_filters('pre_comment_approved', $approved, $commentdata); |
|
709 | 709 | return $approved; |
710 | 710 | } |
711 | 711 | |
@@ -723,15 +723,15 @@ discard block |
||
723 | 723 | * @param string $email Comment author email address. |
724 | 724 | * @param string $date MySQL time string. |
725 | 725 | */ |
726 | -function check_comment_flood_db( $ip, $email, $date ) { |
|
726 | +function check_comment_flood_db($ip, $email, $date) { |
|
727 | 727 | global $wpdb; |
728 | 728 | // don't throttle admins or moderators |
729 | - if ( current_user_can( 'manage_options' ) || current_user_can( 'moderate_comments' ) ) { |
|
729 | + if (current_user_can('manage_options') || current_user_can('moderate_comments')) { |
|
730 | 730 | return; |
731 | 731 | } |
732 | - $hour_ago = gmdate( 'Y-m-d H:i:s', time() - HOUR_IN_SECONDS ); |
|
732 | + $hour_ago = gmdate('Y-m-d H:i:s', time() - HOUR_IN_SECONDS); |
|
733 | 733 | |
734 | - if ( is_user_logged_in() ) { |
|
734 | + if (is_user_logged_in()) { |
|
735 | 735 | $user = get_current_user_id(); |
736 | 736 | $check_column = '`user_id`'; |
737 | 737 | } else { |
@@ -745,8 +745,8 @@ discard block |
||
745 | 745 | $user, |
746 | 746 | |
747 | 747 | ); |
748 | - $lasttime = $wpdb->get_var( $sql ); |
|
749 | - if ( $lasttime ) { |
|
748 | + $lasttime = $wpdb->get_var($sql); |
|
749 | + if ($lasttime) { |
|
750 | 750 | $time_lastcomment = mysql2date('U', $lasttime, false); |
751 | 751 | $time_newcomment = mysql2date('U', $date, false); |
752 | 752 | /** |
@@ -758,8 +758,8 @@ discard block |
||
758 | 758 | * @param int $time_lastcomment Timestamp of when the last comment was posted. |
759 | 759 | * @param int $time_newcomment Timestamp of when the new comment was posted. |
760 | 760 | */ |
761 | - $flood_die = apply_filters( 'comment_flood_filter', false, $time_lastcomment, $time_newcomment ); |
|
762 | - if ( $flood_die ) { |
|
761 | + $flood_die = apply_filters('comment_flood_filter', false, $time_lastcomment, $time_newcomment); |
|
762 | + if ($flood_die) { |
|
763 | 763 | /** |
764 | 764 | * Fires before the comment flood message is triggered. |
765 | 765 | * |
@@ -768,12 +768,12 @@ discard block |
||
768 | 768 | * @param int $time_lastcomment Timestamp of when the last comment was posted. |
769 | 769 | * @param int $time_newcomment Timestamp of when the new comment was posted. |
770 | 770 | */ |
771 | - do_action( 'comment_flood_trigger', $time_lastcomment, $time_newcomment ); |
|
771 | + do_action('comment_flood_trigger', $time_lastcomment, $time_newcomment); |
|
772 | 772 | |
773 | - if ( defined('DOING_AJAX') ) |
|
774 | - die( __('You are posting comments too quickly. Slow down.') ); |
|
773 | + if (defined('DOING_AJAX')) |
|
774 | + die(__('You are posting comments too quickly. Slow down.')); |
|
775 | 775 | |
776 | - wp_die( __( 'You are posting comments too quickly. Slow down.' ), 429 ); |
|
776 | + wp_die(__('You are posting comments too quickly. Slow down.'), 429); |
|
777 | 777 | } |
778 | 778 | } |
779 | 779 | } |
@@ -789,12 +789,12 @@ discard block |
||
789 | 789 | function separate_comments(&$comments) { |
790 | 790 | $comments_by_type = array('comment' => array(), 'trackback' => array(), 'pingback' => array(), 'pings' => array()); |
791 | 791 | $count = count($comments); |
792 | - for ( $i = 0; $i < $count; $i++ ) { |
|
792 | + for ($i = 0; $i < $count; $i++) { |
|
793 | 793 | $type = $comments[$i]->comment_type; |
794 | - if ( empty($type) ) |
|
794 | + if (empty($type)) |
|
795 | 795 | $type = 'comment'; |
796 | 796 | $comments_by_type[$type][] = &$comments[$i]; |
797 | - if ( 'trackback' == $type || 'pingback' == $type ) |
|
797 | + if ('trackback' == $type || 'pingback' == $type) |
|
798 | 798 | $comments_by_type['pings'][] = &$comments[$i]; |
799 | 799 | } |
800 | 800 | |
@@ -815,37 +815,37 @@ discard block |
||
815 | 815 | * @param bool $threaded Optional control over flat or threaded comments. |
816 | 816 | * @return int Number of comment pages. |
817 | 817 | */ |
818 | -function get_comment_pages_count( $comments = null, $per_page = null, $threaded = null ) { |
|
818 | +function get_comment_pages_count($comments = null, $per_page = null, $threaded = null) { |
|
819 | 819 | global $wp_query; |
820 | 820 | |
821 | - if ( null === $comments && null === $per_page && null === $threaded && !empty($wp_query->max_num_comment_pages) ) |
|
821 | + if (null === $comments && null === $per_page && null === $threaded && ! empty($wp_query->max_num_comment_pages)) |
|
822 | 822 | return $wp_query->max_num_comment_pages; |
823 | 823 | |
824 | - if ( ( ! $comments || ! is_array( $comments ) ) && ! empty( $wp_query->comments ) ) |
|
824 | + if (( ! $comments || ! is_array($comments)) && ! empty($wp_query->comments)) |
|
825 | 825 | $comments = $wp_query->comments; |
826 | 826 | |
827 | - if ( empty($comments) ) |
|
827 | + if (empty($comments)) |
|
828 | 828 | return 0; |
829 | 829 | |
830 | - if ( ! get_option( 'page_comments' ) ) { |
|
830 | + if ( ! get_option('page_comments')) { |
|
831 | 831 | return 1; |
832 | 832 | } |
833 | 833 | |
834 | - if ( !isset($per_page) ) |
|
834 | + if ( ! isset($per_page)) |
|
835 | 835 | $per_page = (int) get_query_var('comments_per_page'); |
836 | - if ( 0 === $per_page ) |
|
836 | + if (0 === $per_page) |
|
837 | 837 | $per_page = (int) get_option('comments_per_page'); |
838 | - if ( 0 === $per_page ) |
|
838 | + if (0 === $per_page) |
|
839 | 839 | return 1; |
840 | 840 | |
841 | - if ( !isset($threaded) ) |
|
841 | + if ( ! isset($threaded)) |
|
842 | 842 | $threaded = get_option('thread_comments'); |
843 | 843 | |
844 | - if ( $threaded ) { |
|
844 | + if ($threaded) { |
|
845 | 845 | $walker = new Walker_Comment; |
846 | - $count = ceil( $walker->get_number_of_root_elements( $comments ) / $per_page ); |
|
846 | + $count = ceil($walker->get_number_of_root_elements($comments) / $per_page); |
|
847 | 847 | } else { |
848 | - $count = ceil( count( $comments ) / $per_page ); |
|
848 | + $count = ceil(count($comments) / $per_page); |
|
849 | 849 | } |
850 | 850 | |
851 | 851 | return $count; |
@@ -871,49 +871,49 @@ discard block |
||
871 | 871 | * } * |
872 | 872 | * @return int|null Comment page number or null on error. |
873 | 873 | */ |
874 | -function get_page_of_comment( $comment_ID, $args = array() ) { |
|
874 | +function get_page_of_comment($comment_ID, $args = array()) { |
|
875 | 875 | global $wpdb; |
876 | 876 | |
877 | 877 | $page = null; |
878 | 878 | |
879 | - if ( !$comment = get_comment( $comment_ID ) ) |
|
879 | + if ( ! $comment = get_comment($comment_ID)) |
|
880 | 880 | return; |
881 | 881 | |
882 | - $defaults = array( 'type' => 'all', 'page' => '', 'per_page' => '', 'max_depth' => '' ); |
|
883 | - $args = wp_parse_args( $args, $defaults ); |
|
882 | + $defaults = array('type' => 'all', 'page' => '', 'per_page' => '', 'max_depth' => ''); |
|
883 | + $args = wp_parse_args($args, $defaults); |
|
884 | 884 | $original_args = $args; |
885 | 885 | |
886 | 886 | // Order of precedence: 1. `$args['per_page']`, 2. 'comments_per_page' query_var, 3. 'comments_per_page' option. |
887 | - if ( get_option( 'page_comments' ) ) { |
|
888 | - if ( '' === $args['per_page'] ) { |
|
889 | - $args['per_page'] = get_query_var( 'comments_per_page' ); |
|
887 | + if (get_option('page_comments')) { |
|
888 | + if ('' === $args['per_page']) { |
|
889 | + $args['per_page'] = get_query_var('comments_per_page'); |
|
890 | 890 | } |
891 | 891 | |
892 | - if ( '' === $args['per_page'] ) { |
|
893 | - $args['per_page'] = get_option( 'comments_per_page' ); |
|
892 | + if ('' === $args['per_page']) { |
|
893 | + $args['per_page'] = get_option('comments_per_page'); |
|
894 | 894 | } |
895 | 895 | } |
896 | 896 | |
897 | - if ( empty($args['per_page']) ) { |
|
897 | + if (empty($args['per_page'])) { |
|
898 | 898 | $args['per_page'] = 0; |
899 | 899 | $args['page'] = 0; |
900 | 900 | } |
901 | 901 | |
902 | - if ( $args['per_page'] < 1 ) { |
|
902 | + if ($args['per_page'] < 1) { |
|
903 | 903 | $page = 1; |
904 | 904 | } |
905 | 905 | |
906 | - if ( null === $page ) { |
|
907 | - if ( '' === $args['max_depth'] ) { |
|
908 | - if ( get_option('thread_comments') ) |
|
906 | + if (null === $page) { |
|
907 | + if ('' === $args['max_depth']) { |
|
908 | + if (get_option('thread_comments')) |
|
909 | 909 | $args['max_depth'] = get_option('thread_comments_depth'); |
910 | 910 | else |
911 | 911 | $args['max_depth'] = -1; |
912 | 912 | } |
913 | 913 | |
914 | 914 | // Find this comment's top level parent if threading is enabled |
915 | - if ( $args['max_depth'] > 1 && 0 != $comment->comment_parent ) |
|
916 | - return get_page_of_comment( $comment->comment_parent, $args ); |
|
915 | + if ($args['max_depth'] > 1 && 0 != $comment->comment_parent) |
|
916 | + return get_page_of_comment($comment->comment_parent, $args); |
|
917 | 917 | |
918 | 918 | $comment_args = array( |
919 | 919 | 'type' => $args['type'], |
@@ -931,15 +931,15 @@ discard block |
||
931 | 931 | ); |
932 | 932 | |
933 | 933 | $comment_query = new WP_Comment_Query(); |
934 | - $older_comment_count = $comment_query->query( $comment_args ); |
|
934 | + $older_comment_count = $comment_query->query($comment_args); |
|
935 | 935 | |
936 | 936 | // No older comments? Then it's page #1. |
937 | - if ( 0 == $older_comment_count ) { |
|
937 | + if (0 == $older_comment_count) { |
|
938 | 938 | $page = 1; |
939 | 939 | |
940 | 940 | // Divide comments older than this one by comments per page to get this comment's page number |
941 | 941 | } else { |
942 | - $page = ceil( ( $older_comment_count + 1 ) / $args['per_page'] ); |
|
942 | + $page = ceil(($older_comment_count + 1) / $args['per_page']); |
|
943 | 943 | } |
944 | 944 | } |
945 | 945 | |
@@ -968,7 +968,7 @@ discard block |
||
968 | 968 | * @type int $max_depth Maximum comment threading depth allowed. |
969 | 969 | * } |
970 | 970 | */ |
971 | - return apply_filters( 'get_page_of_comment', (int) $page, $args, $original_args ); |
|
971 | + return apply_filters('get_page_of_comment', (int) $page, $args, $original_args); |
|
972 | 972 | } |
973 | 973 | |
974 | 974 | /** |
@@ -990,28 +990,28 @@ discard block |
||
990 | 990 | 'comment_content' => 65525, |
991 | 991 | ); |
992 | 992 | |
993 | - if ( $wpdb->is_mysql ) { |
|
994 | - foreach ( $lengths as $column => $length ) { |
|
995 | - $col_length = $wpdb->get_col_length( $wpdb->comments, $column ); |
|
993 | + if ($wpdb->is_mysql) { |
|
994 | + foreach ($lengths as $column => $length) { |
|
995 | + $col_length = $wpdb->get_col_length($wpdb->comments, $column); |
|
996 | 996 | $max_length = 0; |
997 | 997 | |
998 | 998 | // No point if we can't get the DB column lengths |
999 | - if ( is_wp_error( $col_length ) ) { |
|
999 | + if (is_wp_error($col_length)) { |
|
1000 | 1000 | break; |
1001 | 1001 | } |
1002 | 1002 | |
1003 | - if ( ! is_array( $col_length ) && (int) $col_length > 0 ) { |
|
1003 | + if ( ! is_array($col_length) && (int) $col_length > 0) { |
|
1004 | 1004 | $max_length = (int) $col_length; |
1005 | - } elseif ( is_array( $col_length ) && isset( $col_length['length'] ) && intval( $col_length['length'] ) > 0 ) { |
|
1005 | + } elseif (is_array($col_length) && isset($col_length['length']) && intval($col_length['length']) > 0) { |
|
1006 | 1006 | $max_length = (int) $col_length['length']; |
1007 | 1007 | |
1008 | - if ( ! empty( $col_length['type'] ) && 'byte' === $col_length['type'] ) { |
|
1008 | + if ( ! empty($col_length['type']) && 'byte' === $col_length['type']) { |
|
1009 | 1009 | $max_length = $max_length - 10; |
1010 | 1010 | } |
1011 | 1011 | } |
1012 | 1012 | |
1013 | - if ( $max_length > 0 ) { |
|
1014 | - $lengths[ $column ] = $max_length; |
|
1013 | + if ($max_length > 0) { |
|
1014 | + $lengths[$column] = $max_length; |
|
1015 | 1015 | } |
1016 | 1016 | } |
1017 | 1017 | } |
@@ -1023,7 +1023,7 @@ discard block |
||
1023 | 1023 | * |
1024 | 1024 | * @param array $lengths Associative array `'field_name' => 'maximum length'`. |
1025 | 1025 | */ |
1026 | - return apply_filters( 'wp_get_comment_fields_max_lengths', $lengths ); |
|
1026 | + return apply_filters('wp_get_comment_fields_max_lengths', $lengths); |
|
1027 | 1027 | } |
1028 | 1028 | |
1029 | 1029 | /** |
@@ -1052,18 +1052,18 @@ discard block |
||
1052 | 1052 | * @param string $user_ip Comment author's IP address. |
1053 | 1053 | * @param string $user_agent Comment author's browser user agent. |
1054 | 1054 | */ |
1055 | - do_action( 'wp_blacklist_check', $author, $email, $url, $comment, $user_ip, $user_agent ); |
|
1055 | + do_action('wp_blacklist_check', $author, $email, $url, $comment, $user_ip, $user_agent); |
|
1056 | 1056 | |
1057 | - $mod_keys = trim( get_option('blacklist_keys') ); |
|
1058 | - if ( '' == $mod_keys ) |
|
1057 | + $mod_keys = trim(get_option('blacklist_keys')); |
|
1058 | + if ('' == $mod_keys) |
|
1059 | 1059 | return false; // If moderation keys are empty |
1060 | - $words = explode("\n", $mod_keys ); |
|
1060 | + $words = explode("\n", $mod_keys); |
|
1061 | 1061 | |
1062 | - foreach ( (array) $words as $word ) { |
|
1062 | + foreach ((array) $words as $word) { |
|
1063 | 1063 | $word = trim($word); |
1064 | 1064 | |
1065 | 1065 | // Skip empty lines |
1066 | - if ( empty($word) ) { continue; } |
|
1066 | + if (empty($word)) { continue; } |
|
1067 | 1067 | |
1068 | 1068 | // Do some escaping magic so that '#' chars in the |
1069 | 1069 | // spam words don't break things: |
@@ -1099,7 +1099,7 @@ discard block |
||
1099 | 1099 | * @param int $post_id Optional. Post ID. |
1100 | 1100 | * @return object|array Comment stats. |
1101 | 1101 | */ |
1102 | -function wp_count_comments( $post_id = 0 ) { |
|
1102 | +function wp_count_comments($post_id = 0) { |
|
1103 | 1103 | $post_id = (int) $post_id; |
1104 | 1104 | |
1105 | 1105 | /** |
@@ -1110,22 +1110,22 @@ discard block |
||
1110 | 1110 | * @param array $count An empty array. |
1111 | 1111 | * @param int $post_id The post ID. |
1112 | 1112 | */ |
1113 | - $filtered = apply_filters( 'wp_count_comments', array(), $post_id ); |
|
1114 | - if ( ! empty( $filtered ) ) { |
|
1113 | + $filtered = apply_filters('wp_count_comments', array(), $post_id); |
|
1114 | + if ( ! empty($filtered)) { |
|
1115 | 1115 | return $filtered; |
1116 | 1116 | } |
1117 | 1117 | |
1118 | - $count = wp_cache_get( "comments-{$post_id}", 'counts' ); |
|
1119 | - if ( false !== $count ) { |
|
1118 | + $count = wp_cache_get("comments-{$post_id}", 'counts'); |
|
1119 | + if (false !== $count) { |
|
1120 | 1120 | return $count; |
1121 | 1121 | } |
1122 | 1122 | |
1123 | - $stats = get_comment_count( $post_id ); |
|
1123 | + $stats = get_comment_count($post_id); |
|
1124 | 1124 | $stats['moderated'] = $stats['awaiting_moderation']; |
1125 | - unset( $stats['awaiting_moderation'] ); |
|
1125 | + unset($stats['awaiting_moderation']); |
|
1126 | 1126 | |
1127 | 1127 | $stats_object = (object) $stats; |
1128 | - wp_cache_set( "comments-{$post_id}", $stats_object, 'counts' ); |
|
1128 | + wp_cache_set("comments-{$post_id}", $stats_object, 'counts'); |
|
1129 | 1129 | |
1130 | 1130 | return $stats_object; |
1131 | 1131 | } |
@@ -1149,10 +1149,10 @@ discard block |
||
1149 | 1149 | */ |
1150 | 1150 | function wp_delete_comment($comment_id, $force_delete = false) { |
1151 | 1151 | global $wpdb; |
1152 | - if (!$comment = get_comment($comment_id)) |
|
1152 | + if ( ! $comment = get_comment($comment_id)) |
|
1153 | 1153 | return false; |
1154 | 1154 | |
1155 | - if ( !$force_delete && EMPTY_TRASH_DAYS && !in_array( wp_get_comment_status( $comment ), array( 'trash', 'spam' ) ) ) |
|
1155 | + if ( ! $force_delete && EMPTY_TRASH_DAYS && ! in_array(wp_get_comment_status($comment), array('trash', 'spam'))) |
|
1156 | 1156 | return wp_trash_comment($comment_id); |
1157 | 1157 | |
1158 | 1158 | /** |
@@ -1162,21 +1162,21 @@ discard block |
||
1162 | 1162 | * |
1163 | 1163 | * @param int $comment_id The comment ID. |
1164 | 1164 | */ |
1165 | - do_action( 'delete_comment', $comment->comment_ID ); |
|
1165 | + do_action('delete_comment', $comment->comment_ID); |
|
1166 | 1166 | |
1167 | 1167 | // Move children up a level. |
1168 | - $children = $wpdb->get_col( $wpdb->prepare("SELECT comment_ID FROM $wpdb->comments WHERE comment_parent = %d", $comment->comment_ID) ); |
|
1169 | - if ( !empty($children) ) { |
|
1168 | + $children = $wpdb->get_col($wpdb->prepare("SELECT comment_ID FROM $wpdb->comments WHERE comment_parent = %d", $comment->comment_ID)); |
|
1169 | + if ( ! empty($children)) { |
|
1170 | 1170 | $wpdb->update($wpdb->comments, array('comment_parent' => $comment->comment_parent), array('comment_parent' => $comment->comment_ID)); |
1171 | 1171 | clean_comment_cache($children); |
1172 | 1172 | } |
1173 | 1173 | |
1174 | 1174 | // Delete metadata |
1175 | - $meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->commentmeta WHERE comment_id = %d", $comment->comment_ID ) ); |
|
1176 | - foreach ( $meta_ids as $mid ) |
|
1177 | - delete_metadata_by_mid( 'comment', $mid ); |
|
1175 | + $meta_ids = $wpdb->get_col($wpdb->prepare("SELECT meta_id FROM $wpdb->commentmeta WHERE comment_id = %d", $comment->comment_ID)); |
|
1176 | + foreach ($meta_ids as $mid) |
|
1177 | + delete_metadata_by_mid('comment', $mid); |
|
1178 | 1178 | |
1179 | - if ( ! $wpdb->delete( $wpdb->comments, array( 'comment_ID' => $comment->comment_ID ) ) ) |
|
1179 | + if ( ! $wpdb->delete($wpdb->comments, array('comment_ID' => $comment->comment_ID))) |
|
1180 | 1180 | return false; |
1181 | 1181 | |
1182 | 1182 | /** |
@@ -1186,16 +1186,16 @@ discard block |
||
1186 | 1186 | * |
1187 | 1187 | * @param int $comment_id The comment ID. |
1188 | 1188 | */ |
1189 | - do_action( 'deleted_comment', $comment->comment_ID ); |
|
1189 | + do_action('deleted_comment', $comment->comment_ID); |
|
1190 | 1190 | |
1191 | 1191 | $post_id = $comment->comment_post_ID; |
1192 | - if ( $post_id && $comment->comment_approved == 1 ) |
|
1192 | + if ($post_id && $comment->comment_approved == 1) |
|
1193 | 1193 | wp_update_comment_count($post_id); |
1194 | 1194 | |
1195 | - clean_comment_cache( $comment->comment_ID ); |
|
1195 | + clean_comment_cache($comment->comment_ID); |
|
1196 | 1196 | |
1197 | 1197 | /** This action is documented in wp-includes/comment.php */ |
1198 | - do_action( 'wp_set_comment_status', $comment->comment_ID, 'delete' ); |
|
1198 | + do_action('wp_set_comment_status', $comment->comment_ID, 'delete'); |
|
1199 | 1199 | |
1200 | 1200 | wp_transition_comment_status('delete', $comment->comment_approved, $comment); |
1201 | 1201 | return true; |
@@ -1212,10 +1212,10 @@ discard block |
||
1212 | 1212 | * @return bool True on success, false on failure. |
1213 | 1213 | */ |
1214 | 1214 | function wp_trash_comment($comment_id) { |
1215 | - if ( !EMPTY_TRASH_DAYS ) |
|
1215 | + if ( ! EMPTY_TRASH_DAYS) |
|
1216 | 1216 | return wp_delete_comment($comment_id, true); |
1217 | 1217 | |
1218 | - if ( !$comment = get_comment($comment_id) ) |
|
1218 | + if ( ! $comment = get_comment($comment_id)) |
|
1219 | 1219 | return false; |
1220 | 1220 | |
1221 | 1221 | /** |
@@ -1225,13 +1225,13 @@ discard block |
||
1225 | 1225 | * |
1226 | 1226 | * @param int $comment_id The comment ID. |
1227 | 1227 | */ |
1228 | - do_action( 'trash_comment', $comment->comment_ID ); |
|
1228 | + do_action('trash_comment', $comment->comment_ID); |
|
1229 | 1229 | |
1230 | - if ( wp_set_comment_status( $comment, 'trash' ) ) { |
|
1231 | - delete_comment_meta( $comment->comment_ID, '_wp_trash_meta_status' ); |
|
1232 | - delete_comment_meta( $comment->comment_ID, '_wp_trash_meta_time' ); |
|
1233 | - add_comment_meta( $comment->comment_ID, '_wp_trash_meta_status', $comment->comment_approved ); |
|
1234 | - add_comment_meta( $comment->comment_ID, '_wp_trash_meta_time', time() ); |
|
1230 | + if (wp_set_comment_status($comment, 'trash')) { |
|
1231 | + delete_comment_meta($comment->comment_ID, '_wp_trash_meta_status'); |
|
1232 | + delete_comment_meta($comment->comment_ID, '_wp_trash_meta_time'); |
|
1233 | + add_comment_meta($comment->comment_ID, '_wp_trash_meta_status', $comment->comment_approved); |
|
1234 | + add_comment_meta($comment->comment_ID, '_wp_trash_meta_time', time()); |
|
1235 | 1235 | |
1236 | 1236 | /** |
1237 | 1237 | * Fires immediately after a comment is sent to Trash. |
@@ -1240,7 +1240,7 @@ discard block |
||
1240 | 1240 | * |
1241 | 1241 | * @param int $comment_id The comment ID. |
1242 | 1242 | */ |
1243 | - do_action( 'trashed_comment', $comment->comment_ID ); |
|
1243 | + do_action('trashed_comment', $comment->comment_ID); |
|
1244 | 1244 | return true; |
1245 | 1245 | } |
1246 | 1246 | |
@@ -1256,8 +1256,8 @@ discard block |
||
1256 | 1256 | * @return bool True on success, false on failure. |
1257 | 1257 | */ |
1258 | 1258 | function wp_untrash_comment($comment_id) { |
1259 | - $comment = get_comment( $comment_id ); |
|
1260 | - if ( ! $comment ) { |
|
1259 | + $comment = get_comment($comment_id); |
|
1260 | + if ( ! $comment) { |
|
1261 | 1261 | return false; |
1262 | 1262 | } |
1263 | 1263 | |
@@ -1268,15 +1268,15 @@ discard block |
||
1268 | 1268 | * |
1269 | 1269 | * @param int $comment_id The comment ID. |
1270 | 1270 | */ |
1271 | - do_action( 'untrash_comment', $comment->comment_ID ); |
|
1271 | + do_action('untrash_comment', $comment->comment_ID); |
|
1272 | 1272 | |
1273 | - $status = (string) get_comment_meta( $comment->comment_ID, '_wp_trash_meta_status', true ); |
|
1274 | - if ( empty($status) ) |
|
1273 | + $status = (string) get_comment_meta($comment->comment_ID, '_wp_trash_meta_status', true); |
|
1274 | + if (empty($status)) |
|
1275 | 1275 | $status = '0'; |
1276 | 1276 | |
1277 | - if ( wp_set_comment_status( $comment, $status ) ) { |
|
1278 | - delete_comment_meta( $comment->comment_ID, '_wp_trash_meta_time' ); |
|
1279 | - delete_comment_meta( $comment->comment_ID, '_wp_trash_meta_status' ); |
|
1277 | + if (wp_set_comment_status($comment, $status)) { |
|
1278 | + delete_comment_meta($comment->comment_ID, '_wp_trash_meta_time'); |
|
1279 | + delete_comment_meta($comment->comment_ID, '_wp_trash_meta_status'); |
|
1280 | 1280 | /** |
1281 | 1281 | * Fires immediately after a comment is restored from the Trash. |
1282 | 1282 | * |
@@ -1284,7 +1284,7 @@ discard block |
||
1284 | 1284 | * |
1285 | 1285 | * @param int $comment_id The comment ID. |
1286 | 1286 | */ |
1287 | - do_action( 'untrashed_comment', $comment->comment_ID ); |
|
1287 | + do_action('untrashed_comment', $comment->comment_ID); |
|
1288 | 1288 | return true; |
1289 | 1289 | } |
1290 | 1290 | |
@@ -1299,9 +1299,9 @@ discard block |
||
1299 | 1299 | * @param int|WP_Comment $comment_id Comment ID or WP_Comment object. |
1300 | 1300 | * @return bool True on success, false on failure. |
1301 | 1301 | */ |
1302 | -function wp_spam_comment( $comment_id ) { |
|
1303 | - $comment = get_comment( $comment_id ); |
|
1304 | - if ( ! $comment ) { |
|
1302 | +function wp_spam_comment($comment_id) { |
|
1303 | + $comment = get_comment($comment_id); |
|
1304 | + if ( ! $comment) { |
|
1305 | 1305 | return false; |
1306 | 1306 | } |
1307 | 1307 | |
@@ -1312,13 +1312,13 @@ discard block |
||
1312 | 1312 | * |
1313 | 1313 | * @param int $comment_id The comment ID. |
1314 | 1314 | */ |
1315 | - do_action( 'spam_comment', $comment->comment_ID ); |
|
1315 | + do_action('spam_comment', $comment->comment_ID); |
|
1316 | 1316 | |
1317 | - if ( wp_set_comment_status( $comment, 'spam' ) ) { |
|
1318 | - delete_comment_meta( $comment->comment_ID, '_wp_trash_meta_status' ); |
|
1319 | - delete_comment_meta( $comment->comment_ID, '_wp_trash_meta_time' ); |
|
1320 | - add_comment_meta( $comment->comment_ID, '_wp_trash_meta_status', $comment->comment_approved ); |
|
1321 | - add_comment_meta( $comment->comment_ID, '_wp_trash_meta_time', time() ); |
|
1317 | + if (wp_set_comment_status($comment, 'spam')) { |
|
1318 | + delete_comment_meta($comment->comment_ID, '_wp_trash_meta_status'); |
|
1319 | + delete_comment_meta($comment->comment_ID, '_wp_trash_meta_time'); |
|
1320 | + add_comment_meta($comment->comment_ID, '_wp_trash_meta_status', $comment->comment_approved); |
|
1321 | + add_comment_meta($comment->comment_ID, '_wp_trash_meta_time', time()); |
|
1322 | 1322 | /** |
1323 | 1323 | * Fires immediately after a comment is marked as Spam. |
1324 | 1324 | * |
@@ -1326,7 +1326,7 @@ discard block |
||
1326 | 1326 | * |
1327 | 1327 | * @param int $comment_id The comment ID. |
1328 | 1328 | */ |
1329 | - do_action( 'spammed_comment', $comment->comment_ID ); |
|
1329 | + do_action('spammed_comment', $comment->comment_ID); |
|
1330 | 1330 | return true; |
1331 | 1331 | } |
1332 | 1332 | |
@@ -1341,9 +1341,9 @@ discard block |
||
1341 | 1341 | * @param int|WP_Comment $comment_id Comment ID or WP_Comment object. |
1342 | 1342 | * @return bool True on success, false on failure. |
1343 | 1343 | */ |
1344 | -function wp_unspam_comment( $comment_id ) { |
|
1345 | - $comment = get_comment( $comment_id ); |
|
1346 | - if ( ! $comment ) { |
|
1344 | +function wp_unspam_comment($comment_id) { |
|
1345 | + $comment = get_comment($comment_id); |
|
1346 | + if ( ! $comment) { |
|
1347 | 1347 | return false; |
1348 | 1348 | } |
1349 | 1349 | |
@@ -1354,15 +1354,15 @@ discard block |
||
1354 | 1354 | * |
1355 | 1355 | * @param int $comment_id The comment ID. |
1356 | 1356 | */ |
1357 | - do_action( 'unspam_comment', $comment->comment_ID ); |
|
1357 | + do_action('unspam_comment', $comment->comment_ID); |
|
1358 | 1358 | |
1359 | - $status = (string) get_comment_meta( $comment->comment_ID, '_wp_trash_meta_status', true ); |
|
1360 | - if ( empty($status) ) |
|
1359 | + $status = (string) get_comment_meta($comment->comment_ID, '_wp_trash_meta_status', true); |
|
1360 | + if (empty($status)) |
|
1361 | 1361 | $status = '0'; |
1362 | 1362 | |
1363 | - if ( wp_set_comment_status( $comment, $status ) ) { |
|
1364 | - delete_comment_meta( $comment->comment_ID, '_wp_trash_meta_status' ); |
|
1365 | - delete_comment_meta( $comment->comment_ID, '_wp_trash_meta_time' ); |
|
1363 | + if (wp_set_comment_status($comment, $status)) { |
|
1364 | + delete_comment_meta($comment->comment_ID, '_wp_trash_meta_status'); |
|
1365 | + delete_comment_meta($comment->comment_ID, '_wp_trash_meta_time'); |
|
1366 | 1366 | /** |
1367 | 1367 | * Fires immediately after a comment is unmarked as Spam. |
1368 | 1368 | * |
@@ -1370,7 +1370,7 @@ discard block |
||
1370 | 1370 | * |
1371 | 1371 | * @param int $comment_id The comment ID. |
1372 | 1372 | */ |
1373 | - do_action( 'unspammed_comment', $comment->comment_ID ); |
|
1373 | + do_action('unspammed_comment', $comment->comment_ID); |
|
1374 | 1374 | return true; |
1375 | 1375 | } |
1376 | 1376 | |
@@ -1387,20 +1387,20 @@ discard block |
||
1387 | 1387 | */ |
1388 | 1388 | function wp_get_comment_status($comment_id) { |
1389 | 1389 | $comment = get_comment($comment_id); |
1390 | - if ( !$comment ) |
|
1390 | + if ( ! $comment) |
|
1391 | 1391 | return false; |
1392 | 1392 | |
1393 | 1393 | $approved = $comment->comment_approved; |
1394 | 1394 | |
1395 | - if ( $approved == null ) |
|
1395 | + if ($approved == null) |
|
1396 | 1396 | return false; |
1397 | - elseif ( $approved == '1' ) |
|
1397 | + elseif ($approved == '1') |
|
1398 | 1398 | return 'approved'; |
1399 | - elseif ( $approved == '0' ) |
|
1399 | + elseif ($approved == '0') |
|
1400 | 1400 | return 'unapproved'; |
1401 | - elseif ( $approved == 'spam' ) |
|
1401 | + elseif ($approved == 'spam') |
|
1402 | 1402 | return 'spam'; |
1403 | - elseif ( $approved == 'trash' ) |
|
1403 | + elseif ($approved == 'trash') |
|
1404 | 1404 | return 'trash'; |
1405 | 1405 | else |
1406 | 1406 | return false; |
@@ -1438,11 +1438,11 @@ discard block |
||
1438 | 1438 | 1 => 'approved', |
1439 | 1439 | 'approve' => 'approved', // wp_set_comment_status() uses "approve" |
1440 | 1440 | ); |
1441 | - if ( isset($comment_statuses[$new_status]) ) $new_status = $comment_statuses[$new_status]; |
|
1442 | - if ( isset($comment_statuses[$old_status]) ) $old_status = $comment_statuses[$old_status]; |
|
1441 | + if (isset($comment_statuses[$new_status])) $new_status = $comment_statuses[$new_status]; |
|
1442 | + if (isset($comment_statuses[$old_status])) $old_status = $comment_statuses[$old_status]; |
|
1443 | 1443 | |
1444 | 1444 | // Call the hooks |
1445 | - if ( $new_status != $old_status ) { |
|
1445 | + if ($new_status != $old_status) { |
|
1446 | 1446 | /** |
1447 | 1447 | * Fires when the comment status is in transition. |
1448 | 1448 | * |
@@ -1452,7 +1452,7 @@ discard block |
||
1452 | 1452 | * @param int|string $old_status The old comment status. |
1453 | 1453 | * @param object $comment The comment data. |
1454 | 1454 | */ |
1455 | - do_action( 'transition_comment_status', $new_status, $old_status, $comment ); |
|
1455 | + do_action('transition_comment_status', $new_status, $old_status, $comment); |
|
1456 | 1456 | /** |
1457 | 1457 | * Fires when the comment status is in transition from one specific status to another. |
1458 | 1458 | * |
@@ -1463,7 +1463,7 @@ discard block |
||
1463 | 1463 | * |
1464 | 1464 | * @param WP_Comment $comment Comment object. |
1465 | 1465 | */ |
1466 | - do_action( "comment_{$old_status}_to_{$new_status}", $comment ); |
|
1466 | + do_action("comment_{$old_status}_to_{$new_status}", $comment); |
|
1467 | 1467 | } |
1468 | 1468 | /** |
1469 | 1469 | * Fires when the status of a specific comment type is in transition. |
@@ -1479,7 +1479,7 @@ discard block |
||
1479 | 1479 | * @param int $comment_ID The comment ID. |
1480 | 1480 | * @param WP_Comment $comment Comment object. |
1481 | 1481 | */ |
1482 | - do_action( "comment_{$new_status}_{$comment->comment_type}", $comment->comment_ID, $comment ); |
|
1482 | + do_action("comment_{$new_status}_{$comment->comment_type}", $comment->comment_ID, $comment); |
|
1483 | 1483 | } |
1484 | 1484 | |
1485 | 1485 | /** |
@@ -1498,15 +1498,15 @@ discard block |
||
1498 | 1498 | // Cookies should already be sanitized. |
1499 | 1499 | |
1500 | 1500 | $comment_author = ''; |
1501 | - if ( isset($_COOKIE['comment_author_'.COOKIEHASH]) ) |
|
1501 | + if (isset($_COOKIE['comment_author_'.COOKIEHASH])) |
|
1502 | 1502 | $comment_author = $_COOKIE['comment_author_'.COOKIEHASH]; |
1503 | 1503 | |
1504 | 1504 | $comment_author_email = ''; |
1505 | - if ( isset($_COOKIE['comment_author_email_'.COOKIEHASH]) ) |
|
1505 | + if (isset($_COOKIE['comment_author_email_'.COOKIEHASH])) |
|
1506 | 1506 | $comment_author_email = $_COOKIE['comment_author_email_'.COOKIEHASH]; |
1507 | 1507 | |
1508 | 1508 | $comment_author_url = ''; |
1509 | - if ( isset($_COOKIE['comment_author_url_'.COOKIEHASH]) ) |
|
1509 | + if (isset($_COOKIE['comment_author_url_'.COOKIEHASH])) |
|
1510 | 1510 | $comment_author_url = $_COOKIE['comment_author_url_'.COOKIEHASH]; |
1511 | 1511 | |
1512 | 1512 | /** |
@@ -1522,7 +1522,7 @@ discard block |
||
1522 | 1522 | * @type string $comment_author_url The URL address of the `$comment_author`. Default empty. |
1523 | 1523 | * } |
1524 | 1524 | */ |
1525 | - return apply_filters( 'wp_get_current_commenter', compact('comment_author', 'comment_author_email', 'comment_author_url') ); |
|
1525 | + return apply_filters('wp_get_current_commenter', compact('comment_author', 'comment_author_email', 'comment_author_url')); |
|
1526 | 1526 | } |
1527 | 1527 | |
1528 | 1528 | /** |
@@ -1560,44 +1560,44 @@ discard block |
||
1560 | 1560 | * } |
1561 | 1561 | * @return int|false The new comment's ID on success, false on failure. |
1562 | 1562 | */ |
1563 | -function wp_insert_comment( $commentdata ) { |
|
1563 | +function wp_insert_comment($commentdata) { |
|
1564 | 1564 | global $wpdb; |
1565 | - $data = wp_unslash( $commentdata ); |
|
1565 | + $data = wp_unslash($commentdata); |
|
1566 | 1566 | |
1567 | - $comment_author = ! isset( $data['comment_author'] ) ? '' : $data['comment_author']; |
|
1568 | - $comment_author_email = ! isset( $data['comment_author_email'] ) ? '' : $data['comment_author_email']; |
|
1569 | - $comment_author_url = ! isset( $data['comment_author_url'] ) ? '' : $data['comment_author_url']; |
|
1570 | - $comment_author_IP = ! isset( $data['comment_author_IP'] ) ? '' : $data['comment_author_IP']; |
|
1567 | + $comment_author = ! isset($data['comment_author']) ? '' : $data['comment_author']; |
|
1568 | + $comment_author_email = ! isset($data['comment_author_email']) ? '' : $data['comment_author_email']; |
|
1569 | + $comment_author_url = ! isset($data['comment_author_url']) ? '' : $data['comment_author_url']; |
|
1570 | + $comment_author_IP = ! isset($data['comment_author_IP']) ? '' : $data['comment_author_IP']; |
|
1571 | 1571 | |
1572 | - $comment_date = ! isset( $data['comment_date'] ) ? current_time( 'mysql' ) : $data['comment_date']; |
|
1573 | - $comment_date_gmt = ! isset( $data['comment_date_gmt'] ) ? get_gmt_from_date( $comment_date ) : $data['comment_date_gmt']; |
|
1572 | + $comment_date = ! isset($data['comment_date']) ? current_time('mysql') : $data['comment_date']; |
|
1573 | + $comment_date_gmt = ! isset($data['comment_date_gmt']) ? get_gmt_from_date($comment_date) : $data['comment_date_gmt']; |
|
1574 | 1574 | |
1575 | - $comment_post_ID = ! isset( $data['comment_post_ID'] ) ? 0 : $data['comment_post_ID']; |
|
1576 | - $comment_content = ! isset( $data['comment_content'] ) ? '' : $data['comment_content']; |
|
1577 | - $comment_karma = ! isset( $data['comment_karma'] ) ? 0 : $data['comment_karma']; |
|
1578 | - $comment_approved = ! isset( $data['comment_approved'] ) ? 1 : $data['comment_approved']; |
|
1579 | - $comment_agent = ! isset( $data['comment_agent'] ) ? '' : $data['comment_agent']; |
|
1580 | - $comment_type = ! isset( $data['comment_type'] ) ? '' : $data['comment_type']; |
|
1581 | - $comment_parent = ! isset( $data['comment_parent'] ) ? 0 : $data['comment_parent']; |
|
1575 | + $comment_post_ID = ! isset($data['comment_post_ID']) ? 0 : $data['comment_post_ID']; |
|
1576 | + $comment_content = ! isset($data['comment_content']) ? '' : $data['comment_content']; |
|
1577 | + $comment_karma = ! isset($data['comment_karma']) ? 0 : $data['comment_karma']; |
|
1578 | + $comment_approved = ! isset($data['comment_approved']) ? 1 : $data['comment_approved']; |
|
1579 | + $comment_agent = ! isset($data['comment_agent']) ? '' : $data['comment_agent']; |
|
1580 | + $comment_type = ! isset($data['comment_type']) ? '' : $data['comment_type']; |
|
1581 | + $comment_parent = ! isset($data['comment_parent']) ? 0 : $data['comment_parent']; |
|
1582 | 1582 | |
1583 | - $user_id = ! isset( $data['user_id'] ) ? 0 : $data['user_id']; |
|
1583 | + $user_id = ! isset($data['user_id']) ? 0 : $data['user_id']; |
|
1584 | 1584 | |
1585 | - $compacted = compact( 'comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_author_IP', 'comment_date', 'comment_date_gmt', 'comment_content', 'comment_karma', 'comment_approved', 'comment_agent', 'comment_type', 'comment_parent', 'user_id' ); |
|
1586 | - if ( ! $wpdb->insert( $wpdb->comments, $compacted ) ) { |
|
1585 | + $compacted = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_author_IP', 'comment_date', 'comment_date_gmt', 'comment_content', 'comment_karma', 'comment_approved', 'comment_agent', 'comment_type', 'comment_parent', 'user_id'); |
|
1586 | + if ( ! $wpdb->insert($wpdb->comments, $compacted)) { |
|
1587 | 1587 | return false; |
1588 | 1588 | } |
1589 | 1589 | |
1590 | 1590 | $id = (int) $wpdb->insert_id; |
1591 | 1591 | |
1592 | - if ( $comment_approved == 1 ) { |
|
1593 | - wp_update_comment_count( $comment_post_ID ); |
|
1592 | + if ($comment_approved == 1) { |
|
1593 | + wp_update_comment_count($comment_post_ID); |
|
1594 | 1594 | } |
1595 | - $comment = get_comment( $id ); |
|
1595 | + $comment = get_comment($id); |
|
1596 | 1596 | |
1597 | 1597 | // If metadata is provided, store it. |
1598 | - if ( isset( $commentdata['comment_meta'] ) && is_array( $commentdata['comment_meta'] ) ) { |
|
1599 | - foreach ( $commentdata['comment_meta'] as $meta_key => $meta_value ) { |
|
1600 | - add_comment_meta( $comment->comment_ID, $meta_key, $meta_value, true ); |
|
1598 | + if (isset($commentdata['comment_meta']) && is_array($commentdata['comment_meta'])) { |
|
1599 | + foreach ($commentdata['comment_meta'] as $meta_key => $meta_value) { |
|
1600 | + add_comment_meta($comment->comment_ID, $meta_key, $meta_value, true); |
|
1601 | 1601 | } |
1602 | 1602 | } |
1603 | 1603 | |
@@ -1609,9 +1609,9 @@ discard block |
||
1609 | 1609 | * @param int $id The comment ID. |
1610 | 1610 | * @param WP_Comment $comment Comment object. |
1611 | 1611 | */ |
1612 | - do_action( 'wp_insert_comment', $id, $comment ); |
|
1612 | + do_action('wp_insert_comment', $id, $comment); |
|
1613 | 1613 | |
1614 | - wp_cache_set( 'last_changed', microtime(), 'comment' ); |
|
1614 | + wp_cache_set('last_changed', microtime(), 'comment'); |
|
1615 | 1615 | |
1616 | 1616 | return $id; |
1617 | 1617 | } |
@@ -1629,7 +1629,7 @@ discard block |
||
1629 | 1629 | * @return array Parsed comment information. |
1630 | 1630 | */ |
1631 | 1631 | function wp_filter_comment($commentdata) { |
1632 | - if ( isset( $commentdata['user_ID'] ) ) { |
|
1632 | + if (isset($commentdata['user_ID'])) { |
|
1633 | 1633 | /** |
1634 | 1634 | * Filter the comment author's user id before it is set. |
1635 | 1635 | * |
@@ -1640,10 +1640,10 @@ discard block |
||
1640 | 1640 | * |
1641 | 1641 | * @param int $user_ID The comment author's user ID. |
1642 | 1642 | */ |
1643 | - $commentdata['user_id'] = apply_filters( 'pre_user_id', $commentdata['user_ID'] ); |
|
1644 | - } elseif ( isset( $commentdata['user_id'] ) ) { |
|
1643 | + $commentdata['user_id'] = apply_filters('pre_user_id', $commentdata['user_ID']); |
|
1644 | + } elseif (isset($commentdata['user_id'])) { |
|
1645 | 1645 | /** This filter is documented in wp-includes/comment.php */ |
1646 | - $commentdata['user_id'] = apply_filters( 'pre_user_id', $commentdata['user_id'] ); |
|
1646 | + $commentdata['user_id'] = apply_filters('pre_user_id', $commentdata['user_id']); |
|
1647 | 1647 | } |
1648 | 1648 | |
1649 | 1649 | /** |
@@ -1653,9 +1653,9 @@ discard block |
||
1653 | 1653 | * |
1654 | 1654 | * @param string $comment_agent The comment author's browser user agent. |
1655 | 1655 | */ |
1656 | - $commentdata['comment_agent'] = apply_filters( 'pre_comment_user_agent', ( isset( $commentdata['comment_agent'] ) ? $commentdata['comment_agent'] : '' ) ); |
|
1656 | + $commentdata['comment_agent'] = apply_filters('pre_comment_user_agent', (isset($commentdata['comment_agent']) ? $commentdata['comment_agent'] : '')); |
|
1657 | 1657 | /** This filter is documented in wp-includes/comment.php */ |
1658 | - $commentdata['comment_author'] = apply_filters( 'pre_comment_author_name', $commentdata['comment_author'] ); |
|
1658 | + $commentdata['comment_author'] = apply_filters('pre_comment_author_name', $commentdata['comment_author']); |
|
1659 | 1659 | /** |
1660 | 1660 | * Filter the comment content before it is set. |
1661 | 1661 | * |
@@ -1663,7 +1663,7 @@ discard block |
||
1663 | 1663 | * |
1664 | 1664 | * @param string $comment_content The comment content. |
1665 | 1665 | */ |
1666 | - $commentdata['comment_content'] = apply_filters( 'pre_comment_content', $commentdata['comment_content'] ); |
|
1666 | + $commentdata['comment_content'] = apply_filters('pre_comment_content', $commentdata['comment_content']); |
|
1667 | 1667 | /** |
1668 | 1668 | * Filter the comment author's IP before it is set. |
1669 | 1669 | * |
@@ -1671,11 +1671,11 @@ discard block |
||
1671 | 1671 | * |
1672 | 1672 | * @param string $comment_author_ip The comment author's IP. |
1673 | 1673 | */ |
1674 | - $commentdata['comment_author_IP'] = apply_filters( 'pre_comment_user_ip', $commentdata['comment_author_IP'] ); |
|
1674 | + $commentdata['comment_author_IP'] = apply_filters('pre_comment_user_ip', $commentdata['comment_author_IP']); |
|
1675 | 1675 | /** This filter is documented in wp-includes/comment.php */ |
1676 | - $commentdata['comment_author_url'] = apply_filters( 'pre_comment_author_url', $commentdata['comment_author_url'] ); |
|
1676 | + $commentdata['comment_author_url'] = apply_filters('pre_comment_author_url', $commentdata['comment_author_url']); |
|
1677 | 1677 | /** This filter is documented in wp-includes/comment.php */ |
1678 | - $commentdata['comment_author_email'] = apply_filters( 'pre_comment_author_email', $commentdata['comment_author_email'] ); |
|
1678 | + $commentdata['comment_author_email'] = apply_filters('pre_comment_author_email', $commentdata['comment_author_email']); |
|
1679 | 1679 | $commentdata['filtered'] = true; |
1680 | 1680 | return $commentdata; |
1681 | 1681 | } |
@@ -1691,9 +1691,9 @@ discard block |
||
1691 | 1691 | * @return bool Whether comment should be blocked. |
1692 | 1692 | */ |
1693 | 1693 | function wp_throttle_comment_flood($block, $time_lastcomment, $time_newcomment) { |
1694 | - if ( $block ) // a plugin has already blocked... we'll let that decision stand |
|
1694 | + if ($block) // a plugin has already blocked... we'll let that decision stand |
|
1695 | 1695 | return $block; |
1696 | - if ( ($time_newcomment - $time_lastcomment) < 15 ) |
|
1696 | + if (($time_newcomment - $time_lastcomment) < 15) |
|
1697 | 1697 | return true; |
1698 | 1698 | return false; |
1699 | 1699 | } |
@@ -1737,14 +1737,14 @@ discard block |
||
1737 | 1737 | * } |
1738 | 1738 | * @return int|false The ID of the comment on success, false on failure. |
1739 | 1739 | */ |
1740 | -function wp_new_comment( $commentdata ) { |
|
1740 | +function wp_new_comment($commentdata) { |
|
1741 | 1741 | global $wpdb; |
1742 | 1742 | |
1743 | - if ( isset( $commentdata['user_ID'] ) ) { |
|
1743 | + if (isset($commentdata['user_ID'])) { |
|
1744 | 1744 | $commentdata['user_id'] = $commentdata['user_ID'] = (int) $commentdata['user_ID']; |
1745 | 1745 | } |
1746 | 1746 | |
1747 | - $prefiltered_user_id = ( isset( $commentdata['user_id'] ) ) ? (int) $commentdata['user_id'] : 0; |
|
1747 | + $prefiltered_user_id = (isset($commentdata['user_id'])) ? (int) $commentdata['user_id'] : 0; |
|
1748 | 1748 | |
1749 | 1749 | /** |
1750 | 1750 | * Filter a comment's data before it is sanitized and inserted into the database. |
@@ -1753,35 +1753,35 @@ discard block |
||
1753 | 1753 | * |
1754 | 1754 | * @param array $commentdata Comment data. |
1755 | 1755 | */ |
1756 | - $commentdata = apply_filters( 'preprocess_comment', $commentdata ); |
|
1756 | + $commentdata = apply_filters('preprocess_comment', $commentdata); |
|
1757 | 1757 | |
1758 | 1758 | $commentdata['comment_post_ID'] = (int) $commentdata['comment_post_ID']; |
1759 | - if ( isset( $commentdata['user_ID'] ) && $prefiltered_user_id !== (int) $commentdata['user_ID'] ) { |
|
1759 | + if (isset($commentdata['user_ID']) && $prefiltered_user_id !== (int) $commentdata['user_ID']) { |
|
1760 | 1760 | $commentdata['user_id'] = $commentdata['user_ID'] = (int) $commentdata['user_ID']; |
1761 | - } elseif ( isset( $commentdata['user_id'] ) ) { |
|
1761 | + } elseif (isset($commentdata['user_id'])) { |
|
1762 | 1762 | $commentdata['user_id'] = (int) $commentdata['user_id']; |
1763 | 1763 | } |
1764 | 1764 | |
1765 | 1765 | $commentdata['comment_parent'] = isset($commentdata['comment_parent']) ? absint($commentdata['comment_parent']) : 0; |
1766 | - $parent_status = ( 0 < $commentdata['comment_parent'] ) ? wp_get_comment_status($commentdata['comment_parent']) : ''; |
|
1767 | - $commentdata['comment_parent'] = ( 'approved' == $parent_status || 'unapproved' == $parent_status ) ? $commentdata['comment_parent'] : 0; |
|
1766 | + $parent_status = (0 < $commentdata['comment_parent']) ? wp_get_comment_status($commentdata['comment_parent']) : ''; |
|
1767 | + $commentdata['comment_parent'] = ('approved' == $parent_status || 'unapproved' == $parent_status) ? $commentdata['comment_parent'] : 0; |
|
1768 | 1768 | |
1769 | - if ( ! isset( $commentdata['comment_author_IP'] ) ) { |
|
1769 | + if ( ! isset($commentdata['comment_author_IP'])) { |
|
1770 | 1770 | $commentdata['comment_author_IP'] = $_SERVER['REMOTE_ADDR']; |
1771 | 1771 | } |
1772 | - $commentdata['comment_author_IP'] = preg_replace( '/[^0-9a-fA-F:., ]/', '', $commentdata['comment_author_IP'] ); |
|
1772 | + $commentdata['comment_author_IP'] = preg_replace('/[^0-9a-fA-F:., ]/', '', $commentdata['comment_author_IP']); |
|
1773 | 1773 | |
1774 | - if ( ! isset( $commentdata['comment_agent'] ) ) { |
|
1775 | - $commentdata['comment_agent'] = isset( $_SERVER['HTTP_USER_AGENT'] ) ? $_SERVER['HTTP_USER_AGENT']: ''; |
|
1774 | + if ( ! isset($commentdata['comment_agent'])) { |
|
1775 | + $commentdata['comment_agent'] = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ''; |
|
1776 | 1776 | } |
1777 | - $commentdata['comment_agent'] = substr( $commentdata['comment_agent'], 0, 254 ); |
|
1777 | + $commentdata['comment_agent'] = substr($commentdata['comment_agent'], 0, 254); |
|
1778 | 1778 | |
1779 | - if ( empty( $commentdata['comment_date'] ) ) { |
|
1779 | + if (empty($commentdata['comment_date'])) { |
|
1780 | 1780 | $commentdata['comment_date'] = current_time('mysql'); |
1781 | 1781 | } |
1782 | 1782 | |
1783 | - if ( empty( $commentdata['comment_date_gmt'] ) ) { |
|
1784 | - $commentdata['comment_date_gmt'] = current_time( 'mysql', 1 ); |
|
1783 | + if (empty($commentdata['comment_date_gmt'])) { |
|
1784 | + $commentdata['comment_date_gmt'] = current_time('mysql', 1); |
|
1785 | 1785 | } |
1786 | 1786 | |
1787 | 1787 | $commentdata = wp_filter_comment($commentdata); |
@@ -1789,21 +1789,21 @@ discard block |
||
1789 | 1789 | $commentdata['comment_approved'] = wp_allow_comment($commentdata); |
1790 | 1790 | |
1791 | 1791 | $comment_ID = wp_insert_comment($commentdata); |
1792 | - if ( ! $comment_ID ) { |
|
1793 | - $fields = array( 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content' ); |
|
1792 | + if ( ! $comment_ID) { |
|
1793 | + $fields = array('comment_author', 'comment_author_email', 'comment_author_url', 'comment_content'); |
|
1794 | 1794 | |
1795 | - foreach ( $fields as $field ) { |
|
1796 | - if ( isset( $commentdata[ $field ] ) ) { |
|
1797 | - $commentdata[ $field ] = $wpdb->strip_invalid_text_for_column( $wpdb->comments, $field, $commentdata[ $field ] ); |
|
1795 | + foreach ($fields as $field) { |
|
1796 | + if (isset($commentdata[$field])) { |
|
1797 | + $commentdata[$field] = $wpdb->strip_invalid_text_for_column($wpdb->comments, $field, $commentdata[$field]); |
|
1798 | 1798 | } |
1799 | 1799 | } |
1800 | 1800 | |
1801 | - $commentdata = wp_filter_comment( $commentdata ); |
|
1801 | + $commentdata = wp_filter_comment($commentdata); |
|
1802 | 1802 | |
1803 | - $commentdata['comment_approved'] = wp_allow_comment( $commentdata ); |
|
1803 | + $commentdata['comment_approved'] = wp_allow_comment($commentdata); |
|
1804 | 1804 | |
1805 | - $comment_ID = wp_insert_comment( $commentdata ); |
|
1806 | - if ( ! $comment_ID ) { |
|
1805 | + $comment_ID = wp_insert_comment($commentdata); |
|
1806 | + if ( ! $comment_ID) { |
|
1807 | 1807 | return false; |
1808 | 1808 | } |
1809 | 1809 | } |
@@ -1818,7 +1818,7 @@ discard block |
||
1818 | 1818 | * @param int|string $comment_approved 1 if the comment is approved, 0 if not, 'spam' if spam. |
1819 | 1819 | * @param array $commentdata Comment data. |
1820 | 1820 | */ |
1821 | - do_action( 'comment_post', $comment_ID, $commentdata['comment_approved'], $commentdata ); |
|
1821 | + do_action('comment_post', $comment_ID, $commentdata['comment_approved'], $commentdata); |
|
1822 | 1822 | |
1823 | 1823 | return $comment_ID; |
1824 | 1824 | } |
@@ -1831,20 +1831,20 @@ discard block |
||
1831 | 1831 | * @param int $comment_ID ID of the comment. |
1832 | 1832 | * @return bool True on success, false on failure. |
1833 | 1833 | */ |
1834 | -function wp_new_comment_notify_moderator( $comment_ID ) { |
|
1835 | - $comment = get_comment( $comment_ID ); |
|
1834 | +function wp_new_comment_notify_moderator($comment_ID) { |
|
1835 | + $comment = get_comment($comment_ID); |
|
1836 | 1836 | |
1837 | 1837 | // Only send notifications for pending comments. |
1838 | - $maybe_notify = ( '0' == $comment->comment_approved ); |
|
1838 | + $maybe_notify = ('0' == $comment->comment_approved); |
|
1839 | 1839 | |
1840 | 1840 | /** This filter is documented in wp-includes/comment.php */ |
1841 | - $maybe_notify = apply_filters( 'notify_moderator', $maybe_notify, $comment_ID ); |
|
1841 | + $maybe_notify = apply_filters('notify_moderator', $maybe_notify, $comment_ID); |
|
1842 | 1842 | |
1843 | - if ( ! $maybe_notify ) { |
|
1843 | + if ( ! $maybe_notify) { |
|
1844 | 1844 | return false; |
1845 | 1845 | } |
1846 | 1846 | |
1847 | - return wp_notify_moderator( $comment_ID ); |
|
1847 | + return wp_notify_moderator($comment_ID); |
|
1848 | 1848 | } |
1849 | 1849 | |
1850 | 1850 | /** |
@@ -1858,10 +1858,10 @@ discard block |
||
1858 | 1858 | * @param int $comment_ID Comment ID. |
1859 | 1859 | * @return bool True on success, false on failure. |
1860 | 1860 | */ |
1861 | -function wp_new_comment_notify_postauthor( $comment_ID ) { |
|
1862 | - $comment = get_comment( $comment_ID ); |
|
1861 | +function wp_new_comment_notify_postauthor($comment_ID) { |
|
1862 | + $comment = get_comment($comment_ID); |
|
1863 | 1863 | |
1864 | - $maybe_notify = get_option( 'comments_notify' ); |
|
1864 | + $maybe_notify = get_option('comments_notify'); |
|
1865 | 1865 | |
1866 | 1866 | /** |
1867 | 1867 | * Filter whether to send the post author new comment notification emails, |
@@ -1872,22 +1872,22 @@ discard block |
||
1872 | 1872 | * @param bool $maybe_notify Whether to notify the post author about the new comment. |
1873 | 1873 | * @param int $comment_ID The ID of the comment for the notification. |
1874 | 1874 | */ |
1875 | - $maybe_notify = apply_filters( 'notify_post_author', $maybe_notify, $comment_ID ); |
|
1875 | + $maybe_notify = apply_filters('notify_post_author', $maybe_notify, $comment_ID); |
|
1876 | 1876 | |
1877 | 1877 | /* |
1878 | 1878 | * wp_notify_postauthor() checks if notifying the author of their own comment. |
1879 | 1879 | * By default, it won't, but filters can override this. |
1880 | 1880 | */ |
1881 | - if ( ! $maybe_notify ) { |
|
1881 | + if ( ! $maybe_notify) { |
|
1882 | 1882 | return false; |
1883 | 1883 | } |
1884 | 1884 | |
1885 | 1885 | // Only send notifications for approved comments. |
1886 | - if ( ! isset( $comment->comment_approved ) || '1' != $comment->comment_approved ) { |
|
1886 | + if ( ! isset($comment->comment_approved) || '1' != $comment->comment_approved) { |
|
1887 | 1887 | return false; |
1888 | 1888 | } |
1889 | 1889 | |
1890 | - return wp_notify_postauthor( $comment_ID ); |
|
1890 | + return wp_notify_postauthor($comment_ID); |
|
1891 | 1891 | } |
1892 | 1892 | |
1893 | 1893 | /** |
@@ -1908,7 +1908,7 @@ discard block |
||
1908 | 1908 | function wp_set_comment_status($comment_id, $comment_status, $wp_error = false) { |
1909 | 1909 | global $wpdb; |
1910 | 1910 | |
1911 | - switch ( $comment_status ) { |
|
1911 | + switch ($comment_status) { |
|
1912 | 1912 | case 'hold': |
1913 | 1913 | case '0': |
1914 | 1914 | $status = '0'; |
@@ -1916,7 +1916,7 @@ discard block |
||
1916 | 1916 | case 'approve': |
1917 | 1917 | case '1': |
1918 | 1918 | $status = '1'; |
1919 | - add_action( 'wp_set_comment_status', 'wp_new_comment_notify_postauthor' ); |
|
1919 | + add_action('wp_set_comment_status', 'wp_new_comment_notify_postauthor'); |
|
1920 | 1920 | break; |
1921 | 1921 | case 'spam': |
1922 | 1922 | $status = 'spam'; |
@@ -1930,16 +1930,16 @@ discard block |
||
1930 | 1930 | |
1931 | 1931 | $comment_old = clone get_comment($comment_id); |
1932 | 1932 | |
1933 | - if ( !$wpdb->update( $wpdb->comments, array('comment_approved' => $status), array( 'comment_ID' => $comment_old->comment_ID ) ) ) { |
|
1934 | - if ( $wp_error ) |
|
1933 | + if ( ! $wpdb->update($wpdb->comments, array('comment_approved' => $status), array('comment_ID' => $comment_old->comment_ID))) { |
|
1934 | + if ($wp_error) |
|
1935 | 1935 | return new WP_Error('db_update_error', __('Could not update comment status'), $wpdb->last_error); |
1936 | 1936 | else |
1937 | 1937 | return false; |
1938 | 1938 | } |
1939 | 1939 | |
1940 | - clean_comment_cache( $comment_old->comment_ID ); |
|
1940 | + clean_comment_cache($comment_old->comment_ID); |
|
1941 | 1941 | |
1942 | - $comment = get_comment( $comment_old->comment_ID ); |
|
1942 | + $comment = get_comment($comment_old->comment_ID); |
|
1943 | 1943 | |
1944 | 1944 | /** |
1945 | 1945 | * Fires immediately before transitioning a comment's status from one to another |
@@ -1951,7 +1951,7 @@ discard block |
||
1951 | 1951 | * @param string|bool $comment_status Current comment status. Possible values include |
1952 | 1952 | * 'hold', 'approve', 'spam', 'trash', or false. |
1953 | 1953 | */ |
1954 | - do_action( 'wp_set_comment_status', $comment->comment_ID, $comment_status ); |
|
1954 | + do_action('wp_set_comment_status', $comment->comment_ID, $comment_status); |
|
1955 | 1955 | |
1956 | 1956 | wp_transition_comment_status($comment_status, $comment_old->comment_approved, $comment); |
1957 | 1957 | |
@@ -1977,12 +1977,12 @@ discard block |
||
1977 | 1977 | |
1978 | 1978 | // First, get all of the original fields |
1979 | 1979 | $comment = get_comment($commentarr['comment_ID'], ARRAY_A); |
1980 | - if ( empty( $comment ) ) { |
|
1980 | + if (empty($comment)) { |
|
1981 | 1981 | return 0; |
1982 | 1982 | } |
1983 | 1983 | |
1984 | 1984 | // Make sure that the comment post ID is valid (if specified). |
1985 | - if ( ! empty( $commentarr['comment_post_ID'] ) && ! get_post( $commentarr['comment_post_ID'] ) ) { |
|
1985 | + if ( ! empty($commentarr['comment_post_ID']) && ! get_post($commentarr['comment_post_ID'])) { |
|
1986 | 1986 | return 0; |
1987 | 1987 | } |
1988 | 1988 | |
@@ -1994,10 +1994,10 @@ discard block |
||
1994 | 1994 | // Merge old and new fields with new fields overwriting old ones. |
1995 | 1995 | $commentarr = array_merge($comment, $commentarr); |
1996 | 1996 | |
1997 | - $commentarr = wp_filter_comment( $commentarr ); |
|
1997 | + $commentarr = wp_filter_comment($commentarr); |
|
1998 | 1998 | |
1999 | 1999 | // Now extract the merged array. |
2000 | - $data = wp_unslash( $commentarr ); |
|
2000 | + $data = wp_unslash($commentarr); |
|
2001 | 2001 | |
2002 | 2002 | /** |
2003 | 2003 | * Filter the comment content before it is updated in the database. |
@@ -2006,26 +2006,26 @@ discard block |
||
2006 | 2006 | * |
2007 | 2007 | * @param string $comment_content The comment data. |
2008 | 2008 | */ |
2009 | - $data['comment_content'] = apply_filters( 'comment_save_pre', $data['comment_content'] ); |
|
2009 | + $data['comment_content'] = apply_filters('comment_save_pre', $data['comment_content']); |
|
2010 | 2010 | |
2011 | - $data['comment_date_gmt'] = get_gmt_from_date( $data['comment_date'] ); |
|
2011 | + $data['comment_date_gmt'] = get_gmt_from_date($data['comment_date']); |
|
2012 | 2012 | |
2013 | - if ( ! isset( $data['comment_approved'] ) ) { |
|
2013 | + if ( ! isset($data['comment_approved'])) { |
|
2014 | 2014 | $data['comment_approved'] = 1; |
2015 | - } elseif ( 'hold' == $data['comment_approved'] ) { |
|
2015 | + } elseif ('hold' == $data['comment_approved']) { |
|
2016 | 2016 | $data['comment_approved'] = 0; |
2017 | - } elseif ( 'approve' == $data['comment_approved'] ) { |
|
2017 | + } elseif ('approve' == $data['comment_approved']) { |
|
2018 | 2018 | $data['comment_approved'] = 1; |
2019 | 2019 | } |
2020 | 2020 | |
2021 | 2021 | $comment_ID = $data['comment_ID']; |
2022 | 2022 | $comment_post_ID = $data['comment_post_ID']; |
2023 | - $keys = array( 'comment_post_ID', 'comment_content', 'comment_author', 'comment_author_email', 'comment_approved', 'comment_karma', 'comment_author_url', 'comment_date', 'comment_date_gmt', 'comment_type', 'comment_parent', 'user_id', 'comment_agent', 'comment_author_IP' ); |
|
2024 | - $data = wp_array_slice_assoc( $data, $keys ); |
|
2025 | - $rval = $wpdb->update( $wpdb->comments, $data, compact( 'comment_ID' ) ); |
|
2023 | + $keys = array('comment_post_ID', 'comment_content', 'comment_author', 'comment_author_email', 'comment_approved', 'comment_karma', 'comment_author_url', 'comment_date', 'comment_date_gmt', 'comment_type', 'comment_parent', 'user_id', 'comment_agent', 'comment_author_IP'); |
|
2024 | + $data = wp_array_slice_assoc($data, $keys); |
|
2025 | + $rval = $wpdb->update($wpdb->comments, $data, compact('comment_ID')); |
|
2026 | 2026 | |
2027 | - clean_comment_cache( $comment_ID ); |
|
2028 | - wp_update_comment_count( $comment_post_ID ); |
|
2027 | + clean_comment_cache($comment_ID); |
|
2028 | + wp_update_comment_count($comment_post_ID); |
|
2029 | 2029 | /** |
2030 | 2030 | * Fires immediately after a comment is updated in the database. |
2031 | 2031 | * |
@@ -2035,7 +2035,7 @@ discard block |
||
2035 | 2035 | * |
2036 | 2036 | * @param int $comment_ID The comment ID. |
2037 | 2037 | */ |
2038 | - do_action( 'edit_comment', $comment_ID ); |
|
2038 | + do_action('edit_comment', $comment_ID); |
|
2039 | 2039 | $comment = get_comment($comment_ID); |
2040 | 2040 | wp_transition_comment_status($comment->comment_approved, $old_status, $comment); |
2041 | 2041 | return $rval; |
@@ -2055,14 +2055,14 @@ discard block |
||
2055 | 2055 | * @param bool $defer |
2056 | 2056 | * @return bool |
2057 | 2057 | */ |
2058 | -function wp_defer_comment_counting($defer=null) { |
|
2058 | +function wp_defer_comment_counting($defer = null) { |
|
2059 | 2059 | static $_defer = false; |
2060 | 2060 | |
2061 | - if ( is_bool($defer) ) { |
|
2061 | + if (is_bool($defer)) { |
|
2062 | 2062 | $_defer = $defer; |
2063 | 2063 | // flush any deferred counts |
2064 | - if ( !$defer ) |
|
2065 | - wp_update_comment_count( null, true ); |
|
2064 | + if ( ! $defer) |
|
2065 | + wp_update_comment_count(null, true); |
|
2066 | 2066 | } |
2067 | 2067 | |
2068 | 2068 | return $_defer; |
@@ -2090,26 +2090,26 @@ discard block |
||
2090 | 2090 | * @return bool|void True on success, false on failure or if post with ID does |
2091 | 2091 | * not exist. |
2092 | 2092 | */ |
2093 | -function wp_update_comment_count($post_id, $do_deferred=false) { |
|
2093 | +function wp_update_comment_count($post_id, $do_deferred = false) { |
|
2094 | 2094 | static $_deferred = array(); |
2095 | 2095 | |
2096 | - if ( empty( $post_id ) && ! $do_deferred ) { |
|
2096 | + if (empty($post_id) && ! $do_deferred) { |
|
2097 | 2097 | return false; |
2098 | 2098 | } |
2099 | 2099 | |
2100 | - if ( $do_deferred ) { |
|
2100 | + if ($do_deferred) { |
|
2101 | 2101 | $_deferred = array_unique($_deferred); |
2102 | - foreach ( $_deferred as $i => $_post_id ) { |
|
2102 | + foreach ($_deferred as $i => $_post_id) { |
|
2103 | 2103 | wp_update_comment_count_now($_post_id); |
2104 | - unset( $_deferred[$i] ); /** @todo Move this outside of the foreach and reset $_deferred to an array instead */ |
|
2104 | + unset($_deferred[$i]); /** @todo Move this outside of the foreach and reset $_deferred to an array instead */ |
|
2105 | 2105 | } |
2106 | 2106 | } |
2107 | 2107 | |
2108 | - if ( wp_defer_comment_counting() ) { |
|
2108 | + if (wp_defer_comment_counting()) { |
|
2109 | 2109 | $_deferred[] = $post_id; |
2110 | 2110 | return true; |
2111 | 2111 | } |
2112 | - elseif ( $post_id ) { |
|
2112 | + elseif ($post_id) { |
|
2113 | 2113 | return wp_update_comment_count_now($post_id); |
2114 | 2114 | } |
2115 | 2115 | |
@@ -2128,13 +2128,13 @@ discard block |
||
2128 | 2128 | function wp_update_comment_count_now($post_id) { |
2129 | 2129 | global $wpdb; |
2130 | 2130 | $post_id = (int) $post_id; |
2131 | - if ( !$post_id ) |
|
2131 | + if ( ! $post_id) |
|
2132 | 2132 | return false; |
2133 | 2133 | |
2134 | - wp_cache_delete( 'comments-0', 'counts' ); |
|
2135 | - wp_cache_delete( "comments-{$post_id}", 'counts' ); |
|
2134 | + wp_cache_delete('comments-0', 'counts'); |
|
2135 | + wp_cache_delete("comments-{$post_id}", 'counts'); |
|
2136 | 2136 | |
2137 | - if ( !$post = get_post($post_id) ) |
|
2137 | + if ( ! $post = get_post($post_id)) |
|
2138 | 2138 | return false; |
2139 | 2139 | |
2140 | 2140 | $old = (int) $post->comment_count; |
@@ -2148,17 +2148,17 @@ discard block |
||
2148 | 2148 | * @param int $old The old comment count. |
2149 | 2149 | * @param int $post_id Post ID. |
2150 | 2150 | */ |
2151 | - $new = apply_filters( 'pre_wp_update_comment_count_now', null, $old, $post_id ); |
|
2151 | + $new = apply_filters('pre_wp_update_comment_count_now', null, $old, $post_id); |
|
2152 | 2152 | |
2153 | - if ( is_null( $new ) ) { |
|
2154 | - $new = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved = '1'", $post_id ) ); |
|
2153 | + if (is_null($new)) { |
|
2154 | + $new = (int) $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved = '1'", $post_id)); |
|
2155 | 2155 | } else { |
2156 | 2156 | $new = (int) $new; |
2157 | 2157 | } |
2158 | 2158 | |
2159 | - $wpdb->update( $wpdb->posts, array('comment_count' => $new), array('ID' => $post_id) ); |
|
2159 | + $wpdb->update($wpdb->posts, array('comment_count' => $new), array('ID' => $post_id)); |
|
2160 | 2160 | |
2161 | - clean_post_cache( $post ); |
|
2161 | + clean_post_cache($post); |
|
2162 | 2162 | |
2163 | 2163 | /** |
2164 | 2164 | * Fires immediately after a post's comment count is updated in the database. |
@@ -2169,9 +2169,9 @@ discard block |
||
2169 | 2169 | * @param int $new The new comment count. |
2170 | 2170 | * @param int $old The old comment count. |
2171 | 2171 | */ |
2172 | - do_action( 'wp_update_comment_count', $post_id, $new, $old ); |
|
2172 | + do_action('wp_update_comment_count', $post_id, $new, $old); |
|
2173 | 2173 | /** This action is documented in wp-includes/post.php */ |
2174 | - do_action( 'edit_post', $post_id, $post ); |
|
2174 | + do_action('edit_post', $post_id, $post); |
|
2175 | 2175 | |
2176 | 2176 | return true; |
2177 | 2177 | } |
@@ -2193,9 +2193,9 @@ discard block |
||
2193 | 2193 | * @param int $deprecated Not Used. |
2194 | 2194 | * @return false|string False on failure, string containing URI on success. |
2195 | 2195 | */ |
2196 | -function discover_pingback_server_uri( $url, $deprecated = '' ) { |
|
2197 | - if ( !empty( $deprecated ) ) |
|
2198 | - _deprecated_argument( __FUNCTION__, '2.7' ); |
|
2196 | +function discover_pingback_server_uri($url, $deprecated = '') { |
|
2197 | + if ( ! empty($deprecated)) |
|
2198 | + _deprecated_argument(__FUNCTION__, '2.7'); |
|
2199 | 2199 | |
2200 | 2200 | $pingback_str_dquote = 'rel="pingback"'; |
2201 | 2201 | $pingback_str_squote = 'rel=\'pingback\''; |
@@ -2203,47 +2203,47 @@ discard block |
||
2203 | 2203 | /** @todo Should use Filter Extension or custom preg_match instead. */ |
2204 | 2204 | $parsed_url = parse_url($url); |
2205 | 2205 | |
2206 | - if ( ! isset( $parsed_url['host'] ) ) // Not a URL. This should never happen. |
|
2206 | + if ( ! isset($parsed_url['host'])) // Not a URL. This should never happen. |
|
2207 | 2207 | return false; |
2208 | 2208 | |
2209 | 2209 | //Do not search for a pingback server on our own uploads |
2210 | 2210 | $uploads_dir = wp_get_upload_dir(); |
2211 | - if ( 0 === strpos($url, $uploads_dir['baseurl']) ) |
|
2211 | + if (0 === strpos($url, $uploads_dir['baseurl'])) |
|
2212 | 2212 | return false; |
2213 | 2213 | |
2214 | - $response = wp_safe_remote_head( $url, array( 'timeout' => 2, 'httpversion' => '1.0' ) ); |
|
2214 | + $response = wp_safe_remote_head($url, array('timeout' => 2, 'httpversion' => '1.0')); |
|
2215 | 2215 | |
2216 | - if ( is_wp_error( $response ) ) |
|
2216 | + if (is_wp_error($response)) |
|
2217 | 2217 | return false; |
2218 | 2218 | |
2219 | - if ( wp_remote_retrieve_header( $response, 'x-pingback' ) ) |
|
2220 | - return wp_remote_retrieve_header( $response, 'x-pingback' ); |
|
2219 | + if (wp_remote_retrieve_header($response, 'x-pingback')) |
|
2220 | + return wp_remote_retrieve_header($response, 'x-pingback'); |
|
2221 | 2221 | |
2222 | 2222 | // Not an (x)html, sgml, or xml page, no use going further. |
2223 | - if ( preg_match('#(image|audio|video|model)/#is', wp_remote_retrieve_header( $response, 'content-type' )) ) |
|
2223 | + if (preg_match('#(image|audio|video|model)/#is', wp_remote_retrieve_header($response, 'content-type'))) |
|
2224 | 2224 | return false; |
2225 | 2225 | |
2226 | 2226 | // Now do a GET since we're going to look in the html headers (and we're sure it's not a binary file) |
2227 | - $response = wp_safe_remote_get( $url, array( 'timeout' => 2, 'httpversion' => '1.0' ) ); |
|
2227 | + $response = wp_safe_remote_get($url, array('timeout' => 2, 'httpversion' => '1.0')); |
|
2228 | 2228 | |
2229 | - if ( is_wp_error( $response ) ) |
|
2229 | + if (is_wp_error($response)) |
|
2230 | 2230 | return false; |
2231 | 2231 | |
2232 | - $contents = wp_remote_retrieve_body( $response ); |
|
2232 | + $contents = wp_remote_retrieve_body($response); |
|
2233 | 2233 | |
2234 | 2234 | $pingback_link_offset_dquote = strpos($contents, $pingback_str_dquote); |
2235 | 2235 | $pingback_link_offset_squote = strpos($contents, $pingback_str_squote); |
2236 | - if ( $pingback_link_offset_dquote || $pingback_link_offset_squote ) { |
|
2236 | + if ($pingback_link_offset_dquote || $pingback_link_offset_squote) { |
|
2237 | 2237 | $quote = ($pingback_link_offset_dquote) ? '"' : '\''; |
2238 | - $pingback_link_offset = ($quote=='"') ? $pingback_link_offset_dquote : $pingback_link_offset_squote; |
|
2238 | + $pingback_link_offset = ($quote == '"') ? $pingback_link_offset_dquote : $pingback_link_offset_squote; |
|
2239 | 2239 | $pingback_href_pos = @strpos($contents, 'href=', $pingback_link_offset); |
2240 | - $pingback_href_start = $pingback_href_pos+6; |
|
2240 | + $pingback_href_start = $pingback_href_pos + 6; |
|
2241 | 2241 | $pingback_href_end = @strpos($contents, $quote, $pingback_href_start); |
2242 | 2242 | $pingback_server_url_len = $pingback_href_end - $pingback_href_start; |
2243 | 2243 | $pingback_server_url = substr($contents, $pingback_href_start, $pingback_server_url_len); |
2244 | 2244 | |
2245 | 2245 | // We may find rel="pingback" but an incomplete pingback URL |
2246 | - if ( $pingback_server_url_len > 0 ) { // We got it! |
|
2246 | + if ($pingback_server_url_len > 0) { // We got it! |
|
2247 | 2247 | return $pingback_server_url; |
2248 | 2248 | } |
2249 | 2249 | } |
@@ -2263,20 +2263,20 @@ discard block |
||
2263 | 2263 | |
2264 | 2264 | // Do pingbacks |
2265 | 2265 | while ($ping = $wpdb->get_row("SELECT ID, post_content, meta_id FROM {$wpdb->posts}, {$wpdb->postmeta} WHERE {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id AND {$wpdb->postmeta}.meta_key = '_pingme' LIMIT 1")) { |
2266 | - delete_metadata_by_mid( 'post', $ping->meta_id ); |
|
2267 | - pingback( $ping->post_content, $ping->ID ); |
|
2266 | + delete_metadata_by_mid('post', $ping->meta_id); |
|
2267 | + pingback($ping->post_content, $ping->ID); |
|
2268 | 2268 | } |
2269 | 2269 | |
2270 | 2270 | // Do Enclosures |
2271 | 2271 | while ($enclosure = $wpdb->get_row("SELECT ID, post_content, meta_id FROM {$wpdb->posts}, {$wpdb->postmeta} WHERE {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id AND {$wpdb->postmeta}.meta_key = '_encloseme' LIMIT 1")) { |
2272 | - delete_metadata_by_mid( 'post', $enclosure->meta_id ); |
|
2273 | - do_enclose( $enclosure->post_content, $enclosure->ID ); |
|
2272 | + delete_metadata_by_mid('post', $enclosure->meta_id); |
|
2273 | + do_enclose($enclosure->post_content, $enclosure->ID); |
|
2274 | 2274 | } |
2275 | 2275 | |
2276 | 2276 | // Do Trackbacks |
2277 | 2277 | $trackbacks = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE to_ping <> '' AND post_status = 'publish'"); |
2278 | - if ( is_array($trackbacks) ) |
|
2279 | - foreach ( $trackbacks as $trackback ) |
|
2278 | + if (is_array($trackbacks)) |
|
2279 | + foreach ($trackbacks as $trackback) |
|
2280 | 2280 | do_trackbacks($trackback); |
2281 | 2281 | |
2282 | 2282 | //Do Update Services/Generic Pings |
@@ -2295,37 +2295,37 @@ discard block |
||
2295 | 2295 | function do_trackbacks($post_id) { |
2296 | 2296 | global $wpdb; |
2297 | 2297 | |
2298 | - $post = get_post( $post_id ); |
|
2298 | + $post = get_post($post_id); |
|
2299 | 2299 | $to_ping = get_to_ping($post_id); |
2300 | 2300 | $pinged = get_pung($post_id); |
2301 | - if ( empty($to_ping) ) { |
|
2302 | - $wpdb->update($wpdb->posts, array('to_ping' => ''), array('ID' => $post_id) ); |
|
2301 | + if (empty($to_ping)) { |
|
2302 | + $wpdb->update($wpdb->posts, array('to_ping' => ''), array('ID' => $post_id)); |
|
2303 | 2303 | return; |
2304 | 2304 | } |
2305 | 2305 | |
2306 | - if ( empty($post->post_excerpt) ) { |
|
2306 | + if (empty($post->post_excerpt)) { |
|
2307 | 2307 | /** This filter is documented in wp-includes/post-template.php */ |
2308 | - $excerpt = apply_filters( 'the_content', $post->post_content, $post->ID ); |
|
2308 | + $excerpt = apply_filters('the_content', $post->post_content, $post->ID); |
|
2309 | 2309 | } else { |
2310 | 2310 | /** This filter is documented in wp-includes/post-template.php */ |
2311 | - $excerpt = apply_filters( 'the_excerpt', $post->post_excerpt ); |
|
2311 | + $excerpt = apply_filters('the_excerpt', $post->post_excerpt); |
|
2312 | 2312 | } |
2313 | 2313 | |
2314 | 2314 | $excerpt = str_replace(']]>', ']]>', $excerpt); |
2315 | 2315 | $excerpt = wp_html_excerpt($excerpt, 252, '…'); |
2316 | 2316 | |
2317 | 2317 | /** This filter is documented in wp-includes/post-template.php */ |
2318 | - $post_title = apply_filters( 'the_title', $post->post_title, $post->ID ); |
|
2318 | + $post_title = apply_filters('the_title', $post->post_title, $post->ID); |
|
2319 | 2319 | $post_title = strip_tags($post_title); |
2320 | 2320 | |
2321 | - if ( $to_ping ) { |
|
2322 | - foreach ( (array) $to_ping as $tb_ping ) { |
|
2321 | + if ($to_ping) { |
|
2322 | + foreach ((array) $to_ping as $tb_ping) { |
|
2323 | 2323 | $tb_ping = trim($tb_ping); |
2324 | - if ( !in_array($tb_ping, $pinged) ) { |
|
2324 | + if ( ! in_array($tb_ping, $pinged)) { |
|
2325 | 2325 | trackback($tb_ping, $post_title, $excerpt, $post_id); |
2326 | 2326 | $pinged[] = $tb_ping; |
2327 | 2327 | } else { |
2328 | - $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET to_ping = TRIM(REPLACE(to_ping, %s, '')) WHERE ID = %d", $tb_ping, $post_id) ); |
|
2328 | + $wpdb->query($wpdb->prepare("UPDATE $wpdb->posts SET to_ping = TRIM(REPLACE(to_ping, %s, '')) WHERE ID = %d", $tb_ping, $post_id)); |
|
2329 | 2329 | } |
2330 | 2330 | } |
2331 | 2331 | } |
@@ -2339,13 +2339,13 @@ discard block |
||
2339 | 2339 | * @param int $post_id Post ID. |
2340 | 2340 | * @return int Same as Post ID from parameter |
2341 | 2341 | */ |
2342 | -function generic_ping( $post_id = 0 ) { |
|
2342 | +function generic_ping($post_id = 0) { |
|
2343 | 2343 | $services = get_option('ping_sites'); |
2344 | 2344 | |
2345 | 2345 | $services = explode("\n", $services); |
2346 | - foreach ( (array) $services as $service ) { |
|
2346 | + foreach ((array) $services as $service) { |
|
2347 | 2347 | $service = trim($service); |
2348 | - if ( '' != $service ) |
|
2348 | + if ('' != $service) |
|
2349 | 2349 | weblog_ping($service); |
2350 | 2350 | } |
2351 | 2351 | |
@@ -2364,8 +2364,8 @@ discard block |
||
2364 | 2364 | */ |
2365 | 2365 | function pingback($content, $post_ID) { |
2366 | 2366 | global $wp_version; |
2367 | - include_once(ABSPATH . WPINC . '/class-IXR.php'); |
|
2368 | - include_once(ABSPATH . WPINC . '/class-wp-http-ixr-client.php'); |
|
2367 | + include_once(ABSPATH.WPINC.'/class-IXR.php'); |
|
2368 | + include_once(ABSPATH.WPINC.'/class-wp-http-ixr-client.php'); |
|
2369 | 2369 | |
2370 | 2370 | // original code by Mort (http://mort.mine.nu:8080) |
2371 | 2371 | $post_links = array(); |
@@ -2374,7 +2374,7 @@ discard block |
||
2374 | 2374 | |
2375 | 2375 | // Step 1 |
2376 | 2376 | // Parsing the post, external links (if any) are stored in the $post_links array |
2377 | - $post_links_temp = wp_extract_urls( $content ); |
|
2377 | + $post_links_temp = wp_extract_urls($content); |
|
2378 | 2378 | |
2379 | 2379 | // Step 2. |
2380 | 2380 | // Walking thru the links array |
@@ -2385,19 +2385,19 @@ discard block |
||
2385 | 2385 | // http://dummy-weblog.org/post.php |
2386 | 2386 | // We don't wanna ping first and second types, even if they have a valid <link/> |
2387 | 2387 | |
2388 | - foreach ( (array) $post_links_temp as $link_test ) : |
|
2389 | - if ( !in_array($link_test, $pung) && (url_to_postid($link_test) != $post_ID) // If we haven't pung it already and it isn't a link to itself |
|
2390 | - && !is_local_attachment($link_test) ) : // Also, let's never ping local attachments. |
|
2391 | - if ( $test = @parse_url($link_test) ) { |
|
2392 | - if ( isset($test['query']) ) |
|
2388 | + foreach ((array) $post_links_temp as $link_test) : |
|
2389 | + if ( ! in_array($link_test, $pung) && (url_to_postid($link_test) != $post_ID) // If we haven't pung it already and it isn't a link to itself |
|
2390 | + && ! is_local_attachment($link_test)) : // Also, let's never ping local attachments. |
|
2391 | + if ($test = @parse_url($link_test)) { |
|
2392 | + if (isset($test['query'])) |
|
2393 | 2393 | $post_links[] = $link_test; |
2394 | - elseif ( isset( $test['path'] ) && ( $test['path'] != '/' ) && ( $test['path'] != '' ) ) |
|
2394 | + elseif (isset($test['path']) && ($test['path'] != '/') && ($test['path'] != '')) |
|
2395 | 2395 | $post_links[] = $link_test; |
2396 | 2396 | } |
2397 | 2397 | endif; |
2398 | 2398 | endforeach; |
2399 | 2399 | |
2400 | - $post_links = array_unique( $post_links ); |
|
2400 | + $post_links = array_unique($post_links); |
|
2401 | 2401 | /** |
2402 | 2402 | * Fires just before pinging back links found in a post. |
2403 | 2403 | * |
@@ -2407,13 +2407,13 @@ discard block |
||
2407 | 2407 | * @param array &$pung Whether a link has already been pinged, passed by reference. |
2408 | 2408 | * @param int $post_ID The post ID. |
2409 | 2409 | */ |
2410 | - do_action_ref_array( 'pre_ping', array( &$post_links, &$pung, $post_ID ) ); |
|
2410 | + do_action_ref_array('pre_ping', array(&$post_links, &$pung, $post_ID)); |
|
2411 | 2411 | |
2412 | - foreach ( (array) $post_links as $pagelinkedto ) { |
|
2413 | - $pingback_server_url = discover_pingback_server_uri( $pagelinkedto ); |
|
2412 | + foreach ((array) $post_links as $pagelinkedto) { |
|
2413 | + $pingback_server_url = discover_pingback_server_uri($pagelinkedto); |
|
2414 | 2414 | |
2415 | - if ( $pingback_server_url ) { |
|
2416 | - @ set_time_limit( 60 ); |
|
2415 | + if ($pingback_server_url) { |
|
2416 | + @ set_time_limit(60); |
|
2417 | 2417 | // Now, the RPC call |
2418 | 2418 | $pagelinkedfrom = get_permalink($post_ID); |
2419 | 2419 | |
@@ -2432,12 +2432,12 @@ discard block |
||
2432 | 2432 | * @param string $pagelinkedto URL of page linked to. |
2433 | 2433 | * @param string $pagelinkedfrom URL of page linked from. |
2434 | 2434 | */ |
2435 | - $client->useragent = apply_filters( 'pingback_useragent', $client->useragent . ' -- WordPress/' . $wp_version, $client->useragent, $pingback_server_url, $pagelinkedto, $pagelinkedfrom ); |
|
2435 | + $client->useragent = apply_filters('pingback_useragent', $client->useragent.' -- WordPress/'.$wp_version, $client->useragent, $pingback_server_url, $pagelinkedto, $pagelinkedfrom); |
|
2436 | 2436 | // when set to true, this outputs debug messages by itself |
2437 | 2437 | $client->debug = false; |
2438 | 2438 | |
2439 | - if ( $client->query('pingback.ping', $pagelinkedfrom, $pagelinkedto) || ( isset($client->error->code) && 48 == $client->error->code ) ) // Already registered |
|
2440 | - add_ping( $post_ID, $pagelinkedto ); |
|
2439 | + if ($client->query('pingback.ping', $pagelinkedfrom, $pagelinkedto) || (isset($client->error->code) && 48 == $client->error->code)) // Already registered |
|
2440 | + add_ping($post_ID, $pagelinkedto); |
|
2441 | 2441 | } |
2442 | 2442 | } |
2443 | 2443 | } |
@@ -2451,7 +2451,7 @@ discard block |
||
2451 | 2451 | * @return mixed Empty string if blog is not public, returns $sites, if site is public. |
2452 | 2452 | */ |
2453 | 2453 | function privacy_ping_filter($sites) { |
2454 | - if ( '0' != get_option('blog_public') ) |
|
2454 | + if ('0' != get_option('blog_public')) |
|
2455 | 2455 | return $sites; |
2456 | 2456 | else |
2457 | 2457 | return ''; |
@@ -2475,7 +2475,7 @@ discard block |
||
2475 | 2475 | function trackback($trackback_url, $title, $excerpt, $ID) { |
2476 | 2476 | global $wpdb; |
2477 | 2477 | |
2478 | - if ( empty($trackback_url) ) |
|
2478 | + if (empty($trackback_url)) |
|
2479 | 2479 | return; |
2480 | 2480 | |
2481 | 2481 | $options = array(); |
@@ -2487,13 +2487,13 @@ discard block |
||
2487 | 2487 | 'excerpt' => $excerpt |
2488 | 2488 | ); |
2489 | 2489 | |
2490 | - $response = wp_safe_remote_post( $trackback_url, $options ); |
|
2490 | + $response = wp_safe_remote_post($trackback_url, $options); |
|
2491 | 2491 | |
2492 | - if ( is_wp_error( $response ) ) |
|
2492 | + if (is_wp_error($response)) |
|
2493 | 2493 | return; |
2494 | 2494 | |
2495 | - $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET pinged = CONCAT(pinged, '\n', %s) WHERE ID = %d", $trackback_url, $ID) ); |
|
2496 | - return $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET to_ping = TRIM(REPLACE(to_ping, %s, '')) WHERE ID = %d", $trackback_url, $ID) ); |
|
2495 | + $wpdb->query($wpdb->prepare("UPDATE $wpdb->posts SET pinged = CONCAT(pinged, '\n', %s) WHERE ID = %d", $trackback_url, $ID)); |
|
2496 | + return $wpdb->query($wpdb->prepare("UPDATE $wpdb->posts SET to_ping = TRIM(REPLACE(to_ping, %s, '')) WHERE ID = %d", $trackback_url, $ID)); |
|
2497 | 2497 | } |
2498 | 2498 | |
2499 | 2499 | /** |
@@ -2508,18 +2508,18 @@ discard block |
||
2508 | 2508 | */ |
2509 | 2509 | function weblog_ping($server = '', $path = '') { |
2510 | 2510 | global $wp_version; |
2511 | - include_once(ABSPATH . WPINC . '/class-IXR.php'); |
|
2512 | - include_once(ABSPATH . WPINC . '/class-wp-http-ixr-client.php'); |
|
2511 | + include_once(ABSPATH.WPINC.'/class-IXR.php'); |
|
2512 | + include_once(ABSPATH.WPINC.'/class-wp-http-ixr-client.php'); |
|
2513 | 2513 | |
2514 | 2514 | // using a timeout of 3 seconds should be enough to cover slow servers |
2515 | - $client = new WP_HTTP_IXR_Client($server, ((!strlen(trim($path)) || ('/' == $path)) ? false : $path)); |
|
2515 | + $client = new WP_HTTP_IXR_Client($server, (( ! strlen(trim($path)) || ('/' == $path)) ? false : $path)); |
|
2516 | 2516 | $client->timeout = 3; |
2517 | 2517 | $client->useragent .= ' -- WordPress/'.$wp_version; |
2518 | 2518 | |
2519 | 2519 | // when set to true, this outputs debug messages by itself |
2520 | 2520 | $client->debug = false; |
2521 | - $home = trailingslashit( home_url() ); |
|
2522 | - if ( !$client->query('weblogUpdates.extendedPing', get_option('blogname'), $home, get_bloginfo('rss2_url') ) ) // then try a normal ping |
|
2521 | + $home = trailingslashit(home_url()); |
|
2522 | + if ( ! $client->query('weblogUpdates.extendedPing', get_option('blogname'), $home, get_bloginfo('rss2_url'))) // then try a normal ping |
|
2523 | 2523 | $client->query('weblogUpdates.ping', get_option('blogname'), $home); |
2524 | 2524 | } |
2525 | 2525 | |
@@ -2532,8 +2532,8 @@ discard block |
||
2532 | 2532 | * @param string $source_uri |
2533 | 2533 | * @return string |
2534 | 2534 | */ |
2535 | -function pingback_ping_source_uri( $source_uri ) { |
|
2536 | - return (string) wp_http_validate_url( $source_uri ); |
|
2535 | +function pingback_ping_source_uri($source_uri) { |
|
2536 | + return (string) wp_http_validate_url($source_uri); |
|
2537 | 2537 | } |
2538 | 2538 | |
2539 | 2539 | /** |
@@ -2548,10 +2548,10 @@ discard block |
||
2548 | 2548 | * @param IXR_Error $ixr_error |
2549 | 2549 | * @return IXR_Error |
2550 | 2550 | */ |
2551 | -function xmlrpc_pingback_error( $ixr_error ) { |
|
2552 | - if ( $ixr_error->code === 48 ) |
|
2551 | +function xmlrpc_pingback_error($ixr_error) { |
|
2552 | + if ($ixr_error->code === 48) |
|
2553 | 2553 | return $ixr_error; |
2554 | - return new IXR_Error( 0, '' ); |
|
2554 | + return new IXR_Error(0, ''); |
|
2555 | 2555 | } |
2556 | 2556 | |
2557 | 2557 | // |
@@ -2566,8 +2566,8 @@ discard block |
||
2566 | 2566 | * @param int|array $ids Comment ID or an array of comment IDs to remove from cache. |
2567 | 2567 | */ |
2568 | 2568 | function clean_comment_cache($ids) { |
2569 | - foreach ( (array) $ids as $id ) { |
|
2570 | - wp_cache_delete( $id, 'comment' ); |
|
2569 | + foreach ((array) $ids as $id) { |
|
2570 | + wp_cache_delete($id, 'comment'); |
|
2571 | 2571 | |
2572 | 2572 | /** |
2573 | 2573 | * Fires immediately after a comment has been removed from the object cache. |
@@ -2576,10 +2576,10 @@ discard block |
||
2576 | 2576 | * |
2577 | 2577 | * @param int $id Comment ID. |
2578 | 2578 | */ |
2579 | - do_action( 'clean_comment_cache', $id ); |
|
2579 | + do_action('clean_comment_cache', $id); |
|
2580 | 2580 | } |
2581 | 2581 | |
2582 | - wp_cache_set( 'last_changed', microtime(), 'comment' ); |
|
2582 | + wp_cache_set('last_changed', microtime(), 'comment'); |
|
2583 | 2583 | } |
2584 | 2584 | |
2585 | 2585 | /** |
@@ -2595,17 +2595,17 @@ discard block |
||
2595 | 2595 | * @param array $comments Array of comment row objects |
2596 | 2596 | * @param bool $update_meta_cache Whether to update commentmeta cache. Default true. |
2597 | 2597 | */ |
2598 | -function update_comment_cache( $comments, $update_meta_cache = true ) { |
|
2599 | - foreach ( (array) $comments as $comment ) |
|
2598 | +function update_comment_cache($comments, $update_meta_cache = true) { |
|
2599 | + foreach ((array) $comments as $comment) |
|
2600 | 2600 | wp_cache_add($comment->comment_ID, $comment, 'comment'); |
2601 | 2601 | |
2602 | - if ( $update_meta_cache ) { |
|
2602 | + if ($update_meta_cache) { |
|
2603 | 2603 | // Avoid `wp_list_pluck()` in case `$comments` is passed by reference. |
2604 | 2604 | $comment_ids = array(); |
2605 | - foreach ( $comments as $comment ) { |
|
2605 | + foreach ($comments as $comment) { |
|
2606 | 2606 | $comment_ids[] = $comment->comment_ID; |
2607 | 2607 | } |
2608 | - update_meta_cache( 'comment', $comment_ids ); |
|
2608 | + update_meta_cache('comment', $comment_ids); |
|
2609 | 2609 | } |
2610 | 2610 | } |
2611 | 2611 | |
@@ -2621,14 +2621,14 @@ discard block |
||
2621 | 2621 | * @param array $comment_ids Array of comment IDs. |
2622 | 2622 | * @param bool $update_meta_cache Optional. Whether to update the meta cache. Default true. |
2623 | 2623 | */ |
2624 | -function _prime_comment_caches( $comment_ids, $update_meta_cache = true ) { |
|
2624 | +function _prime_comment_caches($comment_ids, $update_meta_cache = true) { |
|
2625 | 2625 | global $wpdb; |
2626 | 2626 | |
2627 | - $non_cached_ids = _get_non_cached_ids( $comment_ids, 'comment' ); |
|
2628 | - if ( !empty( $non_cached_ids ) ) { |
|
2629 | - $fresh_comments = $wpdb->get_results( sprintf( "SELECT $wpdb->comments.* FROM $wpdb->comments WHERE comment_ID IN (%s)", join( ",", array_map( 'intval', $non_cached_ids ) ) ) ); |
|
2627 | + $non_cached_ids = _get_non_cached_ids($comment_ids, 'comment'); |
|
2628 | + if ( ! empty($non_cached_ids)) { |
|
2629 | + $fresh_comments = $wpdb->get_results(sprintf("SELECT $wpdb->comments.* FROM $wpdb->comments WHERE comment_ID IN (%s)", join(",", array_map('intval', $non_cached_ids)))); |
|
2630 | 2630 | |
2631 | - update_comment_cache( $fresh_comments, $update_meta_cache ); |
|
2631 | + update_comment_cache($fresh_comments, $update_meta_cache); |
|
2632 | 2632 | } |
2633 | 2633 | } |
2634 | 2634 | |
@@ -2646,8 +2646,8 @@ discard block |
||
2646 | 2646 | * @param WP_Query $query Query object. |
2647 | 2647 | * @return array |
2648 | 2648 | */ |
2649 | -function _close_comments_for_old_posts( $posts, $query ) { |
|
2650 | - if ( empty( $posts ) || ! $query->is_singular() || ! get_option( 'close_comments_for_old_posts' ) ) |
|
2649 | +function _close_comments_for_old_posts($posts, $query) { |
|
2650 | + if (empty($posts) || ! $query->is_singular() || ! get_option('close_comments_for_old_posts')) |
|
2651 | 2651 | return $posts; |
2652 | 2652 | |
2653 | 2653 | /** |
@@ -2657,15 +2657,15 @@ discard block |
||
2657 | 2657 | * |
2658 | 2658 | * @param array $post_types An array of registered post types. Default array with 'post'. |
2659 | 2659 | */ |
2660 | - $post_types = apply_filters( 'close_comments_for_post_types', array( 'post' ) ); |
|
2661 | - if ( ! in_array( $posts[0]->post_type, $post_types ) ) |
|
2660 | + $post_types = apply_filters('close_comments_for_post_types', array('post')); |
|
2661 | + if ( ! in_array($posts[0]->post_type, $post_types)) |
|
2662 | 2662 | return $posts; |
2663 | 2663 | |
2664 | - $days_old = (int) get_option( 'close_comments_days_old' ); |
|
2665 | - if ( ! $days_old ) |
|
2664 | + $days_old = (int) get_option('close_comments_days_old'); |
|
2665 | + if ( ! $days_old) |
|
2666 | 2666 | return $posts; |
2667 | 2667 | |
2668 | - if ( time() - strtotime( $posts[0]->post_date_gmt ) > ( $days_old * DAY_IN_SECONDS ) ) { |
|
2668 | + if (time() - strtotime($posts[0]->post_date_gmt) > ($days_old * DAY_IN_SECONDS)) { |
|
2669 | 2669 | $posts[0]->comment_status = 'closed'; |
2670 | 2670 | $posts[0]->ping_status = 'closed'; |
2671 | 2671 | } |
@@ -2683,30 +2683,30 @@ discard block |
||
2683 | 2683 | * @param int $post_id Post ID |
2684 | 2684 | * @return bool $open |
2685 | 2685 | */ |
2686 | -function _close_comments_for_old_post( $open, $post_id ) { |
|
2687 | - if ( ! $open ) |
|
2686 | +function _close_comments_for_old_post($open, $post_id) { |
|
2687 | + if ( ! $open) |
|
2688 | 2688 | return $open; |
2689 | 2689 | |
2690 | - if ( !get_option('close_comments_for_old_posts') ) |
|
2690 | + if ( ! get_option('close_comments_for_old_posts')) |
|
2691 | 2691 | return $open; |
2692 | 2692 | |
2693 | 2693 | $days_old = (int) get_option('close_comments_days_old'); |
2694 | - if ( !$days_old ) |
|
2694 | + if ( ! $days_old) |
|
2695 | 2695 | return $open; |
2696 | 2696 | |
2697 | 2697 | $post = get_post($post_id); |
2698 | 2698 | |
2699 | 2699 | /** This filter is documented in wp-includes/comment.php */ |
2700 | - $post_types = apply_filters( 'close_comments_for_post_types', array( 'post' ) ); |
|
2701 | - if ( ! in_array( $post->post_type, $post_types ) ) |
|
2700 | + $post_types = apply_filters('close_comments_for_post_types', array('post')); |
|
2701 | + if ( ! in_array($post->post_type, $post_types)) |
|
2702 | 2702 | return $open; |
2703 | 2703 | |
2704 | 2704 | // Undated drafts should not show up as comments closed. |
2705 | - if ( '0000-00-00 00:00:00' === $post->post_date_gmt ) { |
|
2705 | + if ('0000-00-00 00:00:00' === $post->post_date_gmt) { |
|
2706 | 2706 | return $open; |
2707 | 2707 | } |
2708 | 2708 | |
2709 | - if ( time() - strtotime( $post->post_date_gmt ) > ( $days_old * DAY_IN_SECONDS ) ) |
|
2709 | + if (time() - strtotime($post->post_date_gmt) > ($days_old * DAY_IN_SECONDS)) |
|
2710 | 2710 | return false; |
2711 | 2711 | |
2712 | 2712 | return $open; |
@@ -2733,36 +2733,36 @@ discard block |
||
2733 | 2733 | * } |
2734 | 2734 | * @return WP_Comment|WP_Error A WP_Comment object on success, a WP_Error object on failure. |
2735 | 2735 | */ |
2736 | -function wp_handle_comment_submission( $comment_data ) { |
|
2736 | +function wp_handle_comment_submission($comment_data) { |
|
2737 | 2737 | |
2738 | 2738 | $comment_post_ID = $comment_parent = 0; |
2739 | 2739 | $comment_author = $comment_author_email = $comment_author_url = $comment_content = $_wp_unfiltered_html_comment = null; |
2740 | 2740 | |
2741 | - if ( isset( $comment_data['comment_post_ID'] ) ) { |
|
2741 | + if (isset($comment_data['comment_post_ID'])) { |
|
2742 | 2742 | $comment_post_ID = (int) $comment_data['comment_post_ID']; |
2743 | 2743 | } |
2744 | - if ( isset( $comment_data['author'] ) && is_string( $comment_data['author'] ) ) { |
|
2745 | - $comment_author = trim( strip_tags( $comment_data['author'] ) ); |
|
2744 | + if (isset($comment_data['author']) && is_string($comment_data['author'])) { |
|
2745 | + $comment_author = trim(strip_tags($comment_data['author'])); |
|
2746 | 2746 | } |
2747 | - if ( isset( $comment_data['email'] ) && is_string( $comment_data['email'] ) ) { |
|
2748 | - $comment_author_email = trim( $comment_data['email'] ); |
|
2747 | + if (isset($comment_data['email']) && is_string($comment_data['email'])) { |
|
2748 | + $comment_author_email = trim($comment_data['email']); |
|
2749 | 2749 | } |
2750 | - if ( isset( $comment_data['url'] ) && is_string( $comment_data['url'] ) ) { |
|
2751 | - $comment_author_url = trim( $comment_data['url'] ); |
|
2750 | + if (isset($comment_data['url']) && is_string($comment_data['url'])) { |
|
2751 | + $comment_author_url = trim($comment_data['url']); |
|
2752 | 2752 | } |
2753 | - if ( isset( $comment_data['comment'] ) && is_string( $comment_data['comment'] ) ) { |
|
2754 | - $comment_content = trim( $comment_data['comment'] ); |
|
2753 | + if (isset($comment_data['comment']) && is_string($comment_data['comment'])) { |
|
2754 | + $comment_content = trim($comment_data['comment']); |
|
2755 | 2755 | } |
2756 | - if ( isset( $comment_data['comment_parent'] ) ) { |
|
2757 | - $comment_parent = absint( $comment_data['comment_parent'] ); |
|
2756 | + if (isset($comment_data['comment_parent'])) { |
|
2757 | + $comment_parent = absint($comment_data['comment_parent']); |
|
2758 | 2758 | } |
2759 | - if ( isset( $comment_data['_wp_unfiltered_html_comment'] ) && is_string( $comment_data['_wp_unfiltered_html_comment'] ) ) { |
|
2760 | - $_wp_unfiltered_html_comment = trim( $comment_data['_wp_unfiltered_html_comment'] ); |
|
2759 | + if (isset($comment_data['_wp_unfiltered_html_comment']) && is_string($comment_data['_wp_unfiltered_html_comment'])) { |
|
2760 | + $_wp_unfiltered_html_comment = trim($comment_data['_wp_unfiltered_html_comment']); |
|
2761 | 2761 | } |
2762 | 2762 | |
2763 | - $post = get_post( $comment_post_ID ); |
|
2763 | + $post = get_post($comment_post_ID); |
|
2764 | 2764 | |
2765 | - if ( empty( $post->comment_status ) ) { |
|
2765 | + if (empty($post->comment_status)) { |
|
2766 | 2766 | |
2767 | 2767 | /** |
2768 | 2768 | * Fires when a comment is attempted on a post that does not exist. |
@@ -2771,22 +2771,22 @@ discard block |
||
2771 | 2771 | * |
2772 | 2772 | * @param int $comment_post_ID Post ID. |
2773 | 2773 | */ |
2774 | - do_action( 'comment_id_not_found', $comment_post_ID ); |
|
2774 | + do_action('comment_id_not_found', $comment_post_ID); |
|
2775 | 2775 | |
2776 | - return new WP_Error( 'comment_id_not_found' ); |
|
2776 | + return new WP_Error('comment_id_not_found'); |
|
2777 | 2777 | |
2778 | 2778 | } |
2779 | 2779 | |
2780 | 2780 | // get_post_status() will get the parent status for attachments. |
2781 | - $status = get_post_status( $post ); |
|
2781 | + $status = get_post_status($post); |
|
2782 | 2782 | |
2783 | - if ( ( 'private' == $status ) && ! current_user_can( 'read_post', $comment_post_ID ) ) { |
|
2784 | - return new WP_Error( 'comment_id_not_found' ); |
|
2783 | + if (('private' == $status) && ! current_user_can('read_post', $comment_post_ID)) { |
|
2784 | + return new WP_Error('comment_id_not_found'); |
|
2785 | 2785 | } |
2786 | 2786 | |
2787 | - $status_obj = get_post_status_object( $status ); |
|
2787 | + $status_obj = get_post_status_object($status); |
|
2788 | 2788 | |
2789 | - if ( ! comments_open( $comment_post_ID ) ) { |
|
2789 | + if ( ! comments_open($comment_post_ID)) { |
|
2790 | 2790 | |
2791 | 2791 | /** |
2792 | 2792 | * Fires when a comment is attempted on a post that has comments closed. |
@@ -2795,11 +2795,11 @@ discard block |
||
2795 | 2795 | * |
2796 | 2796 | * @param int $comment_post_ID Post ID. |
2797 | 2797 | */ |
2798 | - do_action( 'comment_closed', $comment_post_ID ); |
|
2798 | + do_action('comment_closed', $comment_post_ID); |
|
2799 | 2799 | |
2800 | - return new WP_Error( 'comment_closed', __( 'Sorry, comments are closed for this item.' ), 403 ); |
|
2800 | + return new WP_Error('comment_closed', __('Sorry, comments are closed for this item.'), 403); |
|
2801 | 2801 | |
2802 | - } elseif ( 'trash' == $status ) { |
|
2802 | + } elseif ('trash' == $status) { |
|
2803 | 2803 | |
2804 | 2804 | /** |
2805 | 2805 | * Fires when a comment is attempted on a trashed post. |
@@ -2808,11 +2808,11 @@ discard block |
||
2808 | 2808 | * |
2809 | 2809 | * @param int $comment_post_ID Post ID. |
2810 | 2810 | */ |
2811 | - do_action( 'comment_on_trash', $comment_post_ID ); |
|
2811 | + do_action('comment_on_trash', $comment_post_ID); |
|
2812 | 2812 | |
2813 | - return new WP_Error( 'comment_on_trash' ); |
|
2813 | + return new WP_Error('comment_on_trash'); |
|
2814 | 2814 | |
2815 | - } elseif ( ! $status_obj->public && ! $status_obj->private ) { |
|
2815 | + } elseif ( ! $status_obj->public && ! $status_obj->private) { |
|
2816 | 2816 | |
2817 | 2817 | /** |
2818 | 2818 | * Fires when a comment is attempted on a post in draft mode. |
@@ -2821,11 +2821,11 @@ discard block |
||
2821 | 2821 | * |
2822 | 2822 | * @param int $comment_post_ID Post ID. |
2823 | 2823 | */ |
2824 | - do_action( 'comment_on_draft', $comment_post_ID ); |
|
2824 | + do_action('comment_on_draft', $comment_post_ID); |
|
2825 | 2825 | |
2826 | - return new WP_Error( 'comment_on_draft' ); |
|
2826 | + return new WP_Error('comment_on_draft'); |
|
2827 | 2827 | |
2828 | - } elseif ( post_password_required( $comment_post_ID ) ) { |
|
2828 | + } elseif (post_password_required($comment_post_ID)) { |
|
2829 | 2829 | |
2830 | 2830 | /** |
2831 | 2831 | * Fires when a comment is attempted on a password-protected post. |
@@ -2834,9 +2834,9 @@ discard block |
||
2834 | 2834 | * |
2835 | 2835 | * @param int $comment_post_ID Post ID. |
2836 | 2836 | */ |
2837 | - do_action( 'comment_on_password_protected', $comment_post_ID ); |
|
2837 | + do_action('comment_on_password_protected', $comment_post_ID); |
|
2838 | 2838 | |
2839 | - return new WP_Error( 'comment_on_password_protected' ); |
|
2839 | + return new WP_Error('comment_on_password_protected'); |
|
2840 | 2840 | |
2841 | 2841 | } else { |
2842 | 2842 | |
@@ -2847,61 +2847,61 @@ discard block |
||
2847 | 2847 | * |
2848 | 2848 | * @param int $comment_post_ID Post ID. |
2849 | 2849 | */ |
2850 | - do_action( 'pre_comment_on_post', $comment_post_ID ); |
|
2850 | + do_action('pre_comment_on_post', $comment_post_ID); |
|
2851 | 2851 | |
2852 | 2852 | } |
2853 | 2853 | |
2854 | 2854 | // If the user is logged in |
2855 | 2855 | $user = wp_get_current_user(); |
2856 | - if ( $user->exists() ) { |
|
2857 | - if ( empty( $user->display_name ) ) { |
|
2858 | - $user->display_name=$user->user_login; |
|
2856 | + if ($user->exists()) { |
|
2857 | + if (empty($user->display_name)) { |
|
2858 | + $user->display_name = $user->user_login; |
|
2859 | 2859 | } |
2860 | 2860 | $comment_author = $user->display_name; |
2861 | 2861 | $comment_author_email = $user->user_email; |
2862 | 2862 | $comment_author_url = $user->user_url; |
2863 | 2863 | $user_ID = $user->ID; |
2864 | - if ( current_user_can( 'unfiltered_html' ) ) { |
|
2865 | - if ( ! isset( $comment_data['_wp_unfiltered_html_comment'] ) |
|
2866 | - || ! wp_verify_nonce( $comment_data['_wp_unfiltered_html_comment'], 'unfiltered-html-comment_' . $comment_post_ID ) |
|
2864 | + if (current_user_can('unfiltered_html')) { |
|
2865 | + if ( ! isset($comment_data['_wp_unfiltered_html_comment']) |
|
2866 | + || ! wp_verify_nonce($comment_data['_wp_unfiltered_html_comment'], 'unfiltered-html-comment_'.$comment_post_ID) |
|
2867 | 2867 | ) { |
2868 | 2868 | kses_remove_filters(); // start with a clean slate |
2869 | 2869 | kses_init_filters(); // set up the filters |
2870 | 2870 | } |
2871 | 2871 | } |
2872 | 2872 | } else { |
2873 | - if ( get_option( 'comment_registration' ) ) { |
|
2874 | - return new WP_Error( 'not_logged_in', __( 'Sorry, you must be logged in to post a comment.' ), 403 ); |
|
2873 | + if (get_option('comment_registration')) { |
|
2874 | + return new WP_Error('not_logged_in', __('Sorry, you must be logged in to post a comment.'), 403); |
|
2875 | 2875 | } |
2876 | 2876 | } |
2877 | 2877 | |
2878 | 2878 | $comment_type = ''; |
2879 | 2879 | $max_lengths = wp_get_comment_fields_max_lengths(); |
2880 | 2880 | |
2881 | - if ( get_option( 'require_name_email' ) && ! $user->exists() ) { |
|
2882 | - if ( 6 > strlen( $comment_author_email ) || '' == $comment_author ) { |
|
2883 | - return new WP_Error( 'require_name_email', __( '<strong>ERROR</strong>: please fill the required fields (name, email).' ), 200 ); |
|
2884 | - } elseif ( ! is_email( $comment_author_email ) ) { |
|
2885 | - return new WP_Error( 'require_valid_email', __( '<strong>ERROR</strong>: please enter a valid email address.' ), 200 ); |
|
2881 | + if (get_option('require_name_email') && ! $user->exists()) { |
|
2882 | + if (6 > strlen($comment_author_email) || '' == $comment_author) { |
|
2883 | + return new WP_Error('require_name_email', __('<strong>ERROR</strong>: please fill the required fields (name, email).'), 200); |
|
2884 | + } elseif ( ! is_email($comment_author_email)) { |
|
2885 | + return new WP_Error('require_valid_email', __('<strong>ERROR</strong>: please enter a valid email address.'), 200); |
|
2886 | 2886 | } |
2887 | 2887 | } |
2888 | 2888 | |
2889 | - if ( isset( $comment_author ) && $max_lengths['comment_author'] < mb_strlen( $comment_author, '8bit' ) ) { |
|
2890 | - return new WP_Error( 'comment_author_column_length', __( '<strong>ERROR</strong>: your name is too long.' ), 200 ); |
|
2889 | + if (isset($comment_author) && $max_lengths['comment_author'] < mb_strlen($comment_author, '8bit')) { |
|
2890 | + return new WP_Error('comment_author_column_length', __('<strong>ERROR</strong>: your name is too long.'), 200); |
|
2891 | 2891 | } |
2892 | 2892 | |
2893 | - if ( isset( $comment_author_email ) && $max_lengths['comment_author_email'] < strlen( $comment_author_email ) ) { |
|
2894 | - return new WP_Error( 'comment_author_email_column_length', __( '<strong>ERROR</strong>: your email address is too long.' ), 200 ); |
|
2893 | + if (isset($comment_author_email) && $max_lengths['comment_author_email'] < strlen($comment_author_email)) { |
|
2894 | + return new WP_Error('comment_author_email_column_length', __('<strong>ERROR</strong>: your email address is too long.'), 200); |
|
2895 | 2895 | } |
2896 | 2896 | |
2897 | - if ( isset( $comment_author_url ) && $max_lengths['comment_author_url'] < strlen( $comment_author_url ) ) { |
|
2898 | - return new WP_Error( 'comment_author_url_column_length', __( '<strong>ERROR</strong>: your url is too long.' ), 200 ); |
|
2897 | + if (isset($comment_author_url) && $max_lengths['comment_author_url'] < strlen($comment_author_url)) { |
|
2898 | + return new WP_Error('comment_author_url_column_length', __('<strong>ERROR</strong>: your url is too long.'), 200); |
|
2899 | 2899 | } |
2900 | 2900 | |
2901 | - if ( '' == $comment_content ) { |
|
2902 | - return new WP_Error( 'require_valid_comment', __( '<strong>ERROR</strong>: please type a comment.' ), 200 ); |
|
2903 | - } elseif ( $max_lengths['comment_content'] < mb_strlen( $comment_content, '8bit' ) ) { |
|
2904 | - return new WP_Error( 'comment_content_column_length', __( '<strong>ERROR</strong>: your comment is too long.' ), 200 ); |
|
2901 | + if ('' == $comment_content) { |
|
2902 | + return new WP_Error('require_valid_comment', __('<strong>ERROR</strong>: please type a comment.'), 200); |
|
2903 | + } elseif ($max_lengths['comment_content'] < mb_strlen($comment_content, '8bit')) { |
|
2904 | + return new WP_Error('comment_content_column_length', __('<strong>ERROR</strong>: your comment is too long.'), 200); |
|
2905 | 2905 | } |
2906 | 2906 | |
2907 | 2907 | $commentdata = compact( |
@@ -2915,11 +2915,11 @@ discard block |
||
2915 | 2915 | 'user_ID' |
2916 | 2916 | ); |
2917 | 2917 | |
2918 | - $comment_id = wp_new_comment( wp_slash( $commentdata ) ); |
|
2919 | - if ( ! $comment_id ) { |
|
2920 | - return new WP_Error( 'comment_save_error', __( '<strong>ERROR</strong>: The comment could not be saved. Please try again later.' ), 500 ); |
|
2918 | + $comment_id = wp_new_comment(wp_slash($commentdata)); |
|
2919 | + if ( ! $comment_id) { |
|
2920 | + return new WP_Error('comment_save_error', __('<strong>ERROR</strong>: The comment could not be saved. Please try again later.'), 500); |
|
2921 | 2921 | } |
2922 | 2922 | |
2923 | - return get_comment( $comment_id ); |
|
2923 | + return get_comment($comment_id); |
|
2924 | 2924 | |
2925 | 2925 | } |
@@ -40,8 +40,9 @@ discard block |
||
40 | 40 | global $wpdb; |
41 | 41 | |
42 | 42 | // If manual moderation is enabled, skip all checks and return false. |
43 | - if ( 1 == get_option('comment_moderation') ) |
|
44 | - return false; |
|
43 | + if ( 1 == get_option('comment_moderation') ) { |
|
44 | + return false; |
|
45 | + } |
|
45 | 46 | |
46 | 47 | /** This filter is documented in wp-includes/comment-template.php */ |
47 | 48 | $comment = apply_filters( 'comment_text', $comment ); |
@@ -64,8 +65,9 @@ discard block |
||
64 | 65 | * If the number of links in the comment exceeds the allowed amount, |
65 | 66 | * fail the check by returning false. |
66 | 67 | */ |
67 | - if ( $num_links >= $max_links ) |
|
68 | - return false; |
|
68 | + if ( $num_links >= $max_links ) { |
|
69 | + return false; |
|
70 | + } |
|
69 | 71 | } |
70 | 72 | |
71 | 73 | $mod_keys = trim(get_option('moderation_keys')); |
@@ -78,8 +80,9 @@ discard block |
||
78 | 80 | $word = trim($word); |
79 | 81 | |
80 | 82 | // Skip empty lines. |
81 | - if ( empty($word) ) |
|
82 | - continue; |
|
83 | + if ( empty($word) ) { |
|
84 | + continue; |
|
85 | + } |
|
83 | 86 | |
84 | 87 | /* |
85 | 88 | * Do some escaping magic so that '#' (number of) characters in the spam |
@@ -92,12 +95,24 @@ discard block |
||
92 | 95 | * fail the check for the given field by returning false. |
93 | 96 | */ |
94 | 97 | $pattern = "#$word#i"; |
95 | - if ( preg_match($pattern, $author) ) return false; |
|
96 | - if ( preg_match($pattern, $email) ) return false; |
|
97 | - if ( preg_match($pattern, $url) ) return false; |
|
98 | - if ( preg_match($pattern, $comment) ) return false; |
|
99 | - if ( preg_match($pattern, $user_ip) ) return false; |
|
100 | - if ( preg_match($pattern, $user_agent) ) return false; |
|
98 | + if ( preg_match($pattern, $author) ) { |
|
99 | + return false; |
|
100 | + } |
|
101 | + if ( preg_match($pattern, $email) ) { |
|
102 | + return false; |
|
103 | + } |
|
104 | + if ( preg_match($pattern, $url) ) { |
|
105 | + return false; |
|
106 | + } |
|
107 | + if ( preg_match($pattern, $comment) ) { |
|
108 | + return false; |
|
109 | + } |
|
110 | + if ( preg_match($pattern, $user_ip) ) { |
|
111 | + return false; |
|
112 | + } |
|
113 | + if ( preg_match($pattern, $user_agent) ) { |
|
114 | + return false; |
|
115 | + } |
|
101 | 116 | } |
102 | 117 | } |
103 | 118 | |
@@ -113,10 +128,11 @@ discard block |
||
113 | 128 | // expected_slashed ($author, $email) |
114 | 129 | $ok_to_comment = $wpdb->get_var("SELECT comment_approved FROM $wpdb->comments WHERE comment_author = '$author' AND comment_author_email = '$email' and comment_approved = '1' LIMIT 1"); |
115 | 130 | if ( ( 1 == $ok_to_comment ) && |
116 | - ( empty($mod_keys) || false === strpos( $email, $mod_keys) ) ) |
|
117 | - return true; |
|
118 | - else |
|
119 | - return false; |
|
131 | + ( empty($mod_keys) || false === strpos( $email, $mod_keys) ) ) { |
|
132 | + return true; |
|
133 | + } else { |
|
134 | + return false; |
|
135 | + } |
|
120 | 136 | } else { |
121 | 137 | return false; |
122 | 138 | } |
@@ -299,8 +315,9 @@ discard block |
||
299 | 315 | global $wpdb; |
300 | 316 | static $cache_lastcommentmodified = array(); |
301 | 317 | |
302 | - if ( isset($cache_lastcommentmodified[$timezone]) ) |
|
303 | - return $cache_lastcommentmodified[$timezone]; |
|
318 | + if ( isset($cache_lastcommentmodified[$timezone]) ) { |
|
319 | + return $cache_lastcommentmodified[$timezone]; |
|
320 | + } |
|
304 | 321 | |
305 | 322 | $add_seconds_server = date('Z'); |
306 | 323 | |
@@ -502,8 +519,9 @@ discard block |
||
502 | 519 | * @since 3.4.0 |
503 | 520 | */ |
504 | 521 | function wp_set_comment_cookies($comment, $user) { |
505 | - if ( $user->exists() ) |
|
506 | - return; |
|
522 | + if ( $user->exists() ) { |
|
523 | + return; |
|
524 | + } |
|
507 | 525 | |
508 | 526 | /** |
509 | 527 | * Filter the lifetime of the comment cookie in seconds. |
@@ -770,8 +788,9 @@ discard block |
||
770 | 788 | */ |
771 | 789 | do_action( 'comment_flood_trigger', $time_lastcomment, $time_newcomment ); |
772 | 790 | |
773 | - if ( defined('DOING_AJAX') ) |
|
774 | - die( __('You are posting comments too quickly. Slow down.') ); |
|
791 | + if ( defined('DOING_AJAX') ) { |
|
792 | + die( __('You are posting comments too quickly. Slow down.') ); |
|
793 | + } |
|
775 | 794 | |
776 | 795 | wp_die( __( 'You are posting comments too quickly. Slow down.' ), 429 ); |
777 | 796 | } |
@@ -791,11 +810,13 @@ discard block |
||
791 | 810 | $count = count($comments); |
792 | 811 | for ( $i = 0; $i < $count; $i++ ) { |
793 | 812 | $type = $comments[$i]->comment_type; |
794 | - if ( empty($type) ) |
|
795 | - $type = 'comment'; |
|
813 | + if ( empty($type) ) { |
|
814 | + $type = 'comment'; |
|
815 | + } |
|
796 | 816 | $comments_by_type[$type][] = &$comments[$i]; |
797 | - if ( 'trackback' == $type || 'pingback' == $type ) |
|
798 | - $comments_by_type['pings'][] = &$comments[$i]; |
|
817 | + if ( 'trackback' == $type || 'pingback' == $type ) { |
|
818 | + $comments_by_type['pings'][] = &$comments[$i]; |
|
819 | + } |
|
799 | 820 | } |
800 | 821 | |
801 | 822 | return $comments_by_type; |
@@ -818,28 +839,35 @@ discard block |
||
818 | 839 | function get_comment_pages_count( $comments = null, $per_page = null, $threaded = null ) { |
819 | 840 | global $wp_query; |
820 | 841 | |
821 | - if ( null === $comments && null === $per_page && null === $threaded && !empty($wp_query->max_num_comment_pages) ) |
|
822 | - return $wp_query->max_num_comment_pages; |
|
842 | + if ( null === $comments && null === $per_page && null === $threaded && !empty($wp_query->max_num_comment_pages) ) { |
|
843 | + return $wp_query->max_num_comment_pages; |
|
844 | + } |
|
823 | 845 | |
824 | - if ( ( ! $comments || ! is_array( $comments ) ) && ! empty( $wp_query->comments ) ) |
|
825 | - $comments = $wp_query->comments; |
|
846 | + if ( ( ! $comments || ! is_array( $comments ) ) && ! empty( $wp_query->comments ) ) { |
|
847 | + $comments = $wp_query->comments; |
|
848 | + } |
|
826 | 849 | |
827 | - if ( empty($comments) ) |
|
828 | - return 0; |
|
850 | + if ( empty($comments) ) { |
|
851 | + return 0; |
|
852 | + } |
|
829 | 853 | |
830 | 854 | if ( ! get_option( 'page_comments' ) ) { |
831 | 855 | return 1; |
832 | 856 | } |
833 | 857 | |
834 | - if ( !isset($per_page) ) |
|
835 | - $per_page = (int) get_query_var('comments_per_page'); |
|
836 | - if ( 0 === $per_page ) |
|
837 | - $per_page = (int) get_option('comments_per_page'); |
|
838 | - if ( 0 === $per_page ) |
|
839 | - return 1; |
|
858 | + if ( !isset($per_page) ) { |
|
859 | + $per_page = (int) get_query_var('comments_per_page'); |
|
860 | + } |
|
861 | + if ( 0 === $per_page ) { |
|
862 | + $per_page = (int) get_option('comments_per_page'); |
|
863 | + } |
|
864 | + if ( 0 === $per_page ) { |
|
865 | + return 1; |
|
866 | + } |
|
840 | 867 | |
841 | - if ( !isset($threaded) ) |
|
842 | - $threaded = get_option('thread_comments'); |
|
868 | + if ( !isset($threaded) ) { |
|
869 | + $threaded = get_option('thread_comments'); |
|
870 | + } |
|
843 | 871 | |
844 | 872 | if ( $threaded ) { |
845 | 873 | $walker = new Walker_Comment; |
@@ -876,8 +904,9 @@ discard block |
||
876 | 904 | |
877 | 905 | $page = null; |
878 | 906 | |
879 | - if ( !$comment = get_comment( $comment_ID ) ) |
|
880 | - return; |
|
907 | + if ( !$comment = get_comment( $comment_ID ) ) { |
|
908 | + return; |
|
909 | + } |
|
881 | 910 | |
882 | 911 | $defaults = array( 'type' => 'all', 'page' => '', 'per_page' => '', 'max_depth' => '' ); |
883 | 912 | $args = wp_parse_args( $args, $defaults ); |
@@ -905,15 +934,17 @@ discard block |
||
905 | 934 | |
906 | 935 | if ( null === $page ) { |
907 | 936 | if ( '' === $args['max_depth'] ) { |
908 | - if ( get_option('thread_comments') ) |
|
909 | - $args['max_depth'] = get_option('thread_comments_depth'); |
|
910 | - else |
|
911 | - $args['max_depth'] = -1; |
|
937 | + if ( get_option('thread_comments') ) { |
|
938 | + $args['max_depth'] = get_option('thread_comments_depth'); |
|
939 | + } else { |
|
940 | + $args['max_depth'] = -1; |
|
941 | + } |
|
912 | 942 | } |
913 | 943 | |
914 | 944 | // Find this comment's top level parent if threading is enabled |
915 | - if ( $args['max_depth'] > 1 && 0 != $comment->comment_parent ) |
|
916 | - return get_page_of_comment( $comment->comment_parent, $args ); |
|
945 | + if ( $args['max_depth'] > 1 && 0 != $comment->comment_parent ) { |
|
946 | + return get_page_of_comment( $comment->comment_parent, $args ); |
|
947 | + } |
|
917 | 948 | |
918 | 949 | $comment_args = array( |
919 | 950 | 'type' => $args['type'], |
@@ -1055,8 +1086,10 @@ discard block |
||
1055 | 1086 | do_action( 'wp_blacklist_check', $author, $email, $url, $comment, $user_ip, $user_agent ); |
1056 | 1087 | |
1057 | 1088 | $mod_keys = trim( get_option('blacklist_keys') ); |
1058 | - if ( '' == $mod_keys ) |
|
1059 | - return false; // If moderation keys are empty |
|
1089 | + if ( '' == $mod_keys ) { |
|
1090 | + return false; |
|
1091 | + } |
|
1092 | + // If moderation keys are empty |
|
1060 | 1093 | $words = explode("\n", $mod_keys ); |
1061 | 1094 | |
1062 | 1095 | foreach ( (array) $words as $word ) { |
@@ -1077,8 +1110,9 @@ discard block |
||
1077 | 1110 | || preg_match($pattern, $comment) |
1078 | 1111 | || preg_match($pattern, $user_ip) |
1079 | 1112 | || preg_match($pattern, $user_agent) |
1080 | - ) |
|
1081 | - return true; |
|
1113 | + ) { |
|
1114 | + return true; |
|
1115 | + } |
|
1082 | 1116 | } |
1083 | 1117 | return false; |
1084 | 1118 | } |
@@ -1149,11 +1183,13 @@ discard block |
||
1149 | 1183 | */ |
1150 | 1184 | function wp_delete_comment($comment_id, $force_delete = false) { |
1151 | 1185 | global $wpdb; |
1152 | - if (!$comment = get_comment($comment_id)) |
|
1153 | - return false; |
|
1186 | + if (!$comment = get_comment($comment_id)) { |
|
1187 | + return false; |
|
1188 | + } |
|
1154 | 1189 | |
1155 | - if ( !$force_delete && EMPTY_TRASH_DAYS && !in_array( wp_get_comment_status( $comment ), array( 'trash', 'spam' ) ) ) |
|
1156 | - return wp_trash_comment($comment_id); |
|
1190 | + if ( !$force_delete && EMPTY_TRASH_DAYS && !in_array( wp_get_comment_status( $comment ), array( 'trash', 'spam' ) ) ) { |
|
1191 | + return wp_trash_comment($comment_id); |
|
1192 | + } |
|
1157 | 1193 | |
1158 | 1194 | /** |
1159 | 1195 | * Fires immediately before a comment is deleted from the database. |
@@ -1173,11 +1209,13 @@ discard block |
||
1173 | 1209 | |
1174 | 1210 | // Delete metadata |
1175 | 1211 | $meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->commentmeta WHERE comment_id = %d", $comment->comment_ID ) ); |
1176 | - foreach ( $meta_ids as $mid ) |
|
1177 | - delete_metadata_by_mid( 'comment', $mid ); |
|
1212 | + foreach ( $meta_ids as $mid ) { |
|
1213 | + delete_metadata_by_mid( 'comment', $mid ); |
|
1214 | + } |
|
1178 | 1215 | |
1179 | - if ( ! $wpdb->delete( $wpdb->comments, array( 'comment_ID' => $comment->comment_ID ) ) ) |
|
1180 | - return false; |
|
1216 | + if ( ! $wpdb->delete( $wpdb->comments, array( 'comment_ID' => $comment->comment_ID ) ) ) { |
|
1217 | + return false; |
|
1218 | + } |
|
1181 | 1219 | |
1182 | 1220 | /** |
1183 | 1221 | * Fires immediately after a comment is deleted from the database. |
@@ -1189,8 +1227,9 @@ discard block |
||
1189 | 1227 | do_action( 'deleted_comment', $comment->comment_ID ); |
1190 | 1228 | |
1191 | 1229 | $post_id = $comment->comment_post_ID; |
1192 | - if ( $post_id && $comment->comment_approved == 1 ) |
|
1193 | - wp_update_comment_count($post_id); |
|
1230 | + if ( $post_id && $comment->comment_approved == 1 ) { |
|
1231 | + wp_update_comment_count($post_id); |
|
1232 | + } |
|
1194 | 1233 | |
1195 | 1234 | clean_comment_cache( $comment->comment_ID ); |
1196 | 1235 | |
@@ -1212,11 +1251,13 @@ discard block |
||
1212 | 1251 | * @return bool True on success, false on failure. |
1213 | 1252 | */ |
1214 | 1253 | function wp_trash_comment($comment_id) { |
1215 | - if ( !EMPTY_TRASH_DAYS ) |
|
1216 | - return wp_delete_comment($comment_id, true); |
|
1254 | + if ( !EMPTY_TRASH_DAYS ) { |
|
1255 | + return wp_delete_comment($comment_id, true); |
|
1256 | + } |
|
1217 | 1257 | |
1218 | - if ( !$comment = get_comment($comment_id) ) |
|
1219 | - return false; |
|
1258 | + if ( !$comment = get_comment($comment_id) ) { |
|
1259 | + return false; |
|
1260 | + } |
|
1220 | 1261 | |
1221 | 1262 | /** |
1222 | 1263 | * Fires immediately before a comment is sent to the Trash. |
@@ -1271,8 +1312,9 @@ discard block |
||
1271 | 1312 | do_action( 'untrash_comment', $comment->comment_ID ); |
1272 | 1313 | |
1273 | 1314 | $status = (string) get_comment_meta( $comment->comment_ID, '_wp_trash_meta_status', true ); |
1274 | - if ( empty($status) ) |
|
1275 | - $status = '0'; |
|
1315 | + if ( empty($status) ) { |
|
1316 | + $status = '0'; |
|
1317 | + } |
|
1276 | 1318 | |
1277 | 1319 | if ( wp_set_comment_status( $comment, $status ) ) { |
1278 | 1320 | delete_comment_meta( $comment->comment_ID, '_wp_trash_meta_time' ); |
@@ -1357,8 +1399,9 @@ discard block |
||
1357 | 1399 | do_action( 'unspam_comment', $comment->comment_ID ); |
1358 | 1400 | |
1359 | 1401 | $status = (string) get_comment_meta( $comment->comment_ID, '_wp_trash_meta_status', true ); |
1360 | - if ( empty($status) ) |
|
1361 | - $status = '0'; |
|
1402 | + if ( empty($status) ) { |
|
1403 | + $status = '0'; |
|
1404 | + } |
|
1362 | 1405 | |
1363 | 1406 | if ( wp_set_comment_status( $comment, $status ) ) { |
1364 | 1407 | delete_comment_meta( $comment->comment_ID, '_wp_trash_meta_status' ); |
@@ -1387,24 +1430,26 @@ discard block |
||
1387 | 1430 | */ |
1388 | 1431 | function wp_get_comment_status($comment_id) { |
1389 | 1432 | $comment = get_comment($comment_id); |
1390 | - if ( !$comment ) |
|
1391 | - return false; |
|
1433 | + if ( !$comment ) { |
|
1434 | + return false; |
|
1435 | + } |
|
1392 | 1436 | |
1393 | 1437 | $approved = $comment->comment_approved; |
1394 | 1438 | |
1395 | - if ( $approved == null ) |
|
1396 | - return false; |
|
1397 | - elseif ( $approved == '1' ) |
|
1398 | - return 'approved'; |
|
1399 | - elseif ( $approved == '0' ) |
|
1400 | - return 'unapproved'; |
|
1401 | - elseif ( $approved == 'spam' ) |
|
1402 | - return 'spam'; |
|
1403 | - elseif ( $approved == 'trash' ) |
|
1404 | - return 'trash'; |
|
1405 | - else |
|
1406 | - return false; |
|
1407 | -} |
|
1439 | + if ( $approved == null ) { |
|
1440 | + return false; |
|
1441 | + } elseif ( $approved == '1' ) { |
|
1442 | + return 'approved'; |
|
1443 | + } elseif ( $approved == '0' ) { |
|
1444 | + return 'unapproved'; |
|
1445 | + } elseif ( $approved == 'spam' ) { |
|
1446 | + return 'spam'; |
|
1447 | + } elseif ( $approved == 'trash' ) { |
|
1448 | + return 'trash'; |
|
1449 | + } else { |
|
1450 | + return false; |
|
1451 | + } |
|
1452 | + } |
|
1408 | 1453 | |
1409 | 1454 | /** |
1410 | 1455 | * Call hooks for when a comment status transition occurs. |
@@ -1438,8 +1483,12 @@ discard block |
||
1438 | 1483 | 1 => 'approved', |
1439 | 1484 | 'approve' => 'approved', // wp_set_comment_status() uses "approve" |
1440 | 1485 | ); |
1441 | - if ( isset($comment_statuses[$new_status]) ) $new_status = $comment_statuses[$new_status]; |
|
1442 | - if ( isset($comment_statuses[$old_status]) ) $old_status = $comment_statuses[$old_status]; |
|
1486 | + if ( isset($comment_statuses[$new_status]) ) { |
|
1487 | + $new_status = $comment_statuses[$new_status]; |
|
1488 | + } |
|
1489 | + if ( isset($comment_statuses[$old_status]) ) { |
|
1490 | + $old_status = $comment_statuses[$old_status]; |
|
1491 | + } |
|
1443 | 1492 | |
1444 | 1493 | // Call the hooks |
1445 | 1494 | if ( $new_status != $old_status ) { |
@@ -1498,16 +1547,19 @@ discard block |
||
1498 | 1547 | // Cookies should already be sanitized. |
1499 | 1548 | |
1500 | 1549 | $comment_author = ''; |
1501 | - if ( isset($_COOKIE['comment_author_'.COOKIEHASH]) ) |
|
1502 | - $comment_author = $_COOKIE['comment_author_'.COOKIEHASH]; |
|
1550 | + if ( isset($_COOKIE['comment_author_'.COOKIEHASH]) ) { |
|
1551 | + $comment_author = $_COOKIE['comment_author_'.COOKIEHASH]; |
|
1552 | + } |
|
1503 | 1553 | |
1504 | 1554 | $comment_author_email = ''; |
1505 | - if ( isset($_COOKIE['comment_author_email_'.COOKIEHASH]) ) |
|
1506 | - $comment_author_email = $_COOKIE['comment_author_email_'.COOKIEHASH]; |
|
1555 | + if ( isset($_COOKIE['comment_author_email_'.COOKIEHASH]) ) { |
|
1556 | + $comment_author_email = $_COOKIE['comment_author_email_'.COOKIEHASH]; |
|
1557 | + } |
|
1507 | 1558 | |
1508 | 1559 | $comment_author_url = ''; |
1509 | - if ( isset($_COOKIE['comment_author_url_'.COOKIEHASH]) ) |
|
1510 | - $comment_author_url = $_COOKIE['comment_author_url_'.COOKIEHASH]; |
|
1560 | + if ( isset($_COOKIE['comment_author_url_'.COOKIEHASH]) ) { |
|
1561 | + $comment_author_url = $_COOKIE['comment_author_url_'.COOKIEHASH]; |
|
1562 | + } |
|
1511 | 1563 | |
1512 | 1564 | /** |
1513 | 1565 | * Filter the current commenter's name, email, and URL. |
@@ -1691,10 +1743,13 @@ discard block |
||
1691 | 1743 | * @return bool Whether comment should be blocked. |
1692 | 1744 | */ |
1693 | 1745 | function wp_throttle_comment_flood($block, $time_lastcomment, $time_newcomment) { |
1694 | - if ( $block ) // a plugin has already blocked... we'll let that decision stand |
|
1746 | + if ( $block ) { |
|
1747 | + // a plugin has already blocked... we'll let that decision stand |
|
1695 | 1748 | return $block; |
1696 | - if ( ($time_newcomment - $time_lastcomment) < 15 ) |
|
1697 | - return true; |
|
1749 | + } |
|
1750 | + if ( ($time_newcomment - $time_lastcomment) < 15 ) { |
|
1751 | + return true; |
|
1752 | + } |
|
1698 | 1753 | return false; |
1699 | 1754 | } |
1700 | 1755 | |
@@ -1931,10 +1986,11 @@ discard block |
||
1931 | 1986 | $comment_old = clone get_comment($comment_id); |
1932 | 1987 | |
1933 | 1988 | if ( !$wpdb->update( $wpdb->comments, array('comment_approved' => $status), array( 'comment_ID' => $comment_old->comment_ID ) ) ) { |
1934 | - if ( $wp_error ) |
|
1935 | - return new WP_Error('db_update_error', __('Could not update comment status'), $wpdb->last_error); |
|
1936 | - else |
|
1937 | - return false; |
|
1989 | + if ( $wp_error ) { |
|
1990 | + return new WP_Error('db_update_error', __('Could not update comment status'), $wpdb->last_error); |
|
1991 | + } else { |
|
1992 | + return false; |
|
1993 | + } |
|
1938 | 1994 | } |
1939 | 1995 | |
1940 | 1996 | clean_comment_cache( $comment_old->comment_ID ); |
@@ -2061,8 +2117,9 @@ discard block |
||
2061 | 2117 | if ( is_bool($defer) ) { |
2062 | 2118 | $_defer = $defer; |
2063 | 2119 | // flush any deferred counts |
2064 | - if ( !$defer ) |
|
2065 | - wp_update_comment_count( null, true ); |
|
2120 | + if ( !$defer ) { |
|
2121 | + wp_update_comment_count( null, true ); |
|
2122 | + } |
|
2066 | 2123 | } |
2067 | 2124 | |
2068 | 2125 | return $_defer; |
@@ -2108,8 +2165,7 @@ discard block |
||
2108 | 2165 | if ( wp_defer_comment_counting() ) { |
2109 | 2166 | $_deferred[] = $post_id; |
2110 | 2167 | return true; |
2111 | - } |
|
2112 | - elseif ( $post_id ) { |
|
2168 | + } elseif ( $post_id ) { |
|
2113 | 2169 | return wp_update_comment_count_now($post_id); |
2114 | 2170 | } |
2115 | 2171 | |
@@ -2128,14 +2184,16 @@ discard block |
||
2128 | 2184 | function wp_update_comment_count_now($post_id) { |
2129 | 2185 | global $wpdb; |
2130 | 2186 | $post_id = (int) $post_id; |
2131 | - if ( !$post_id ) |
|
2132 | - return false; |
|
2187 | + if ( !$post_id ) { |
|
2188 | + return false; |
|
2189 | + } |
|
2133 | 2190 | |
2134 | 2191 | wp_cache_delete( 'comments-0', 'counts' ); |
2135 | 2192 | wp_cache_delete( "comments-{$post_id}", 'counts' ); |
2136 | 2193 | |
2137 | - if ( !$post = get_post($post_id) ) |
|
2138 | - return false; |
|
2194 | + if ( !$post = get_post($post_id) ) { |
|
2195 | + return false; |
|
2196 | + } |
|
2139 | 2197 | |
2140 | 2198 | $old = (int) $post->comment_count; |
2141 | 2199 | |
@@ -2194,8 +2252,9 @@ discard block |
||
2194 | 2252 | * @return false|string False on failure, string containing URI on success. |
2195 | 2253 | */ |
2196 | 2254 | function discover_pingback_server_uri( $url, $deprecated = '' ) { |
2197 | - if ( !empty( $deprecated ) ) |
|
2198 | - _deprecated_argument( __FUNCTION__, '2.7' ); |
|
2255 | + if ( !empty( $deprecated ) ) { |
|
2256 | + _deprecated_argument( __FUNCTION__, '2.7' ); |
|
2257 | + } |
|
2199 | 2258 | |
2200 | 2259 | $pingback_str_dquote = 'rel="pingback"'; |
2201 | 2260 | $pingback_str_squote = 'rel=\'pingback\''; |
@@ -2203,31 +2262,38 @@ discard block |
||
2203 | 2262 | /** @todo Should use Filter Extension or custom preg_match instead. */ |
2204 | 2263 | $parsed_url = parse_url($url); |
2205 | 2264 | |
2206 | - if ( ! isset( $parsed_url['host'] ) ) // Not a URL. This should never happen. |
|
2265 | + if ( ! isset( $parsed_url['host'] ) ) { |
|
2266 | + // Not a URL. This should never happen. |
|
2207 | 2267 | return false; |
2268 | + } |
|
2208 | 2269 | |
2209 | 2270 | //Do not search for a pingback server on our own uploads |
2210 | 2271 | $uploads_dir = wp_get_upload_dir(); |
2211 | - if ( 0 === strpos($url, $uploads_dir['baseurl']) ) |
|
2212 | - return false; |
|
2272 | + if ( 0 === strpos($url, $uploads_dir['baseurl']) ) { |
|
2273 | + return false; |
|
2274 | + } |
|
2213 | 2275 | |
2214 | 2276 | $response = wp_safe_remote_head( $url, array( 'timeout' => 2, 'httpversion' => '1.0' ) ); |
2215 | 2277 | |
2216 | - if ( is_wp_error( $response ) ) |
|
2217 | - return false; |
|
2278 | + if ( is_wp_error( $response ) ) { |
|
2279 | + return false; |
|
2280 | + } |
|
2218 | 2281 | |
2219 | - if ( wp_remote_retrieve_header( $response, 'x-pingback' ) ) |
|
2220 | - return wp_remote_retrieve_header( $response, 'x-pingback' ); |
|
2282 | + if ( wp_remote_retrieve_header( $response, 'x-pingback' ) ) { |
|
2283 | + return wp_remote_retrieve_header( $response, 'x-pingback' ); |
|
2284 | + } |
|
2221 | 2285 | |
2222 | 2286 | // Not an (x)html, sgml, or xml page, no use going further. |
2223 | - if ( preg_match('#(image|audio|video|model)/#is', wp_remote_retrieve_header( $response, 'content-type' )) ) |
|
2224 | - return false; |
|
2287 | + if ( preg_match('#(image|audio|video|model)/#is', wp_remote_retrieve_header( $response, 'content-type' )) ) { |
|
2288 | + return false; |
|
2289 | + } |
|
2225 | 2290 | |
2226 | 2291 | // Now do a GET since we're going to look in the html headers (and we're sure it's not a binary file) |
2227 | 2292 | $response = wp_safe_remote_get( $url, array( 'timeout' => 2, 'httpversion' => '1.0' ) ); |
2228 | 2293 | |
2229 | - if ( is_wp_error( $response ) ) |
|
2230 | - return false; |
|
2294 | + if ( is_wp_error( $response ) ) { |
|
2295 | + return false; |
|
2296 | + } |
|
2231 | 2297 | |
2232 | 2298 | $contents = wp_remote_retrieve_body( $response ); |
2233 | 2299 | |
@@ -2275,9 +2341,10 @@ discard block |
||
2275 | 2341 | |
2276 | 2342 | // Do Trackbacks |
2277 | 2343 | $trackbacks = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE to_ping <> '' AND post_status = 'publish'"); |
2278 | - if ( is_array($trackbacks) ) |
|
2279 | - foreach ( $trackbacks as $trackback ) |
|
2344 | + if ( is_array($trackbacks) ) { |
|
2345 | + foreach ( $trackbacks as $trackback ) |
|
2280 | 2346 | do_trackbacks($trackback); |
2347 | + } |
|
2281 | 2348 | |
2282 | 2349 | //Do Update Services/Generic Pings |
2283 | 2350 | generic_ping(); |
@@ -2345,8 +2412,9 @@ discard block |
||
2345 | 2412 | $services = explode("\n", $services); |
2346 | 2413 | foreach ( (array) $services as $service ) { |
2347 | 2414 | $service = trim($service); |
2348 | - if ( '' != $service ) |
|
2349 | - weblog_ping($service); |
|
2415 | + if ( '' != $service ) { |
|
2416 | + weblog_ping($service); |
|
2417 | + } |
|
2350 | 2418 | } |
2351 | 2419 | |
2352 | 2420 | return $post_id; |
@@ -2389,10 +2457,11 @@ discard block |
||
2389 | 2457 | if ( !in_array($link_test, $pung) && (url_to_postid($link_test) != $post_ID) // If we haven't pung it already and it isn't a link to itself |
2390 | 2458 | && !is_local_attachment($link_test) ) : // Also, let's never ping local attachments. |
2391 | 2459 | if ( $test = @parse_url($link_test) ) { |
2392 | - if ( isset($test['query']) ) |
|
2393 | - $post_links[] = $link_test; |
|
2394 | - elseif ( isset( $test['path'] ) && ( $test['path'] != '/' ) && ( $test['path'] != '' ) ) |
|
2395 | - $post_links[] = $link_test; |
|
2460 | + if ( isset($test['query']) ) { |
|
2461 | + $post_links[] = $link_test; |
|
2462 | + } elseif ( isset( $test['path'] ) && ( $test['path'] != '/' ) && ( $test['path'] != '' ) ) { |
|
2463 | + $post_links[] = $link_test; |
|
2464 | + } |
|
2396 | 2465 | } |
2397 | 2466 | endif; |
2398 | 2467 | endforeach; |
@@ -2436,8 +2505,10 @@ discard block |
||
2436 | 2505 | // when set to true, this outputs debug messages by itself |
2437 | 2506 | $client->debug = false; |
2438 | 2507 | |
2439 | - if ( $client->query('pingback.ping', $pagelinkedfrom, $pagelinkedto) || ( isset($client->error->code) && 48 == $client->error->code ) ) // Already registered |
|
2508 | + if ( $client->query('pingback.ping', $pagelinkedfrom, $pagelinkedto) || ( isset($client->error->code) && 48 == $client->error->code ) ) { |
|
2509 | + // Already registered |
|
2440 | 2510 | add_ping( $post_ID, $pagelinkedto ); |
2511 | + } |
|
2441 | 2512 | } |
2442 | 2513 | } |
2443 | 2514 | } |
@@ -2451,11 +2522,12 @@ discard block |
||
2451 | 2522 | * @return mixed Empty string if blog is not public, returns $sites, if site is public. |
2452 | 2523 | */ |
2453 | 2524 | function privacy_ping_filter($sites) { |
2454 | - if ( '0' != get_option('blog_public') ) |
|
2455 | - return $sites; |
|
2456 | - else |
|
2457 | - return ''; |
|
2458 | -} |
|
2525 | + if ( '0' != get_option('blog_public') ) { |
|
2526 | + return $sites; |
|
2527 | + } else { |
|
2528 | + return ''; |
|
2529 | + } |
|
2530 | + } |
|
2459 | 2531 | |
2460 | 2532 | /** |
2461 | 2533 | * Send a Trackback. |
@@ -2475,8 +2547,9 @@ discard block |
||
2475 | 2547 | function trackback($trackback_url, $title, $excerpt, $ID) { |
2476 | 2548 | global $wpdb; |
2477 | 2549 | |
2478 | - if ( empty($trackback_url) ) |
|
2479 | - return; |
|
2550 | + if ( empty($trackback_url) ) { |
|
2551 | + return; |
|
2552 | + } |
|
2480 | 2553 | |
2481 | 2554 | $options = array(); |
2482 | 2555 | $options['timeout'] = 10; |
@@ -2489,8 +2562,9 @@ discard block |
||
2489 | 2562 | |
2490 | 2563 | $response = wp_safe_remote_post( $trackback_url, $options ); |
2491 | 2564 | |
2492 | - if ( is_wp_error( $response ) ) |
|
2493 | - return; |
|
2565 | + if ( is_wp_error( $response ) ) { |
|
2566 | + return; |
|
2567 | + } |
|
2494 | 2568 | |
2495 | 2569 | $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET pinged = CONCAT(pinged, '\n', %s) WHERE ID = %d", $trackback_url, $ID) ); |
2496 | 2570 | return $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET to_ping = TRIM(REPLACE(to_ping, %s, '')) WHERE ID = %d", $trackback_url, $ID) ); |
@@ -2519,9 +2593,11 @@ discard block |
||
2519 | 2593 | // when set to true, this outputs debug messages by itself |
2520 | 2594 | $client->debug = false; |
2521 | 2595 | $home = trailingslashit( home_url() ); |
2522 | - if ( !$client->query('weblogUpdates.extendedPing', get_option('blogname'), $home, get_bloginfo('rss2_url') ) ) // then try a normal ping |
|
2596 | + if ( !$client->query('weblogUpdates.extendedPing', get_option('blogname'), $home, get_bloginfo('rss2_url') ) ) { |
|
2597 | + // then try a normal ping |
|
2523 | 2598 | $client->query('weblogUpdates.ping', get_option('blogname'), $home); |
2524 | -} |
|
2599 | + } |
|
2600 | + } |
|
2525 | 2601 | |
2526 | 2602 | /** |
2527 | 2603 | * Default filter attached to pingback_ping_source_uri to validate the pingback's Source URI |
@@ -2549,8 +2625,9 @@ discard block |
||
2549 | 2625 | * @return IXR_Error |
2550 | 2626 | */ |
2551 | 2627 | function xmlrpc_pingback_error( $ixr_error ) { |
2552 | - if ( $ixr_error->code === 48 ) |
|
2553 | - return $ixr_error; |
|
2628 | + if ( $ixr_error->code === 48 ) { |
|
2629 | + return $ixr_error; |
|
2630 | + } |
|
2554 | 2631 | return new IXR_Error( 0, '' ); |
2555 | 2632 | } |
2556 | 2633 | |
@@ -2596,8 +2673,9 @@ discard block |
||
2596 | 2673 | * @param bool $update_meta_cache Whether to update commentmeta cache. Default true. |
2597 | 2674 | */ |
2598 | 2675 | function update_comment_cache( $comments, $update_meta_cache = true ) { |
2599 | - foreach ( (array) $comments as $comment ) |
|
2600 | - wp_cache_add($comment->comment_ID, $comment, 'comment'); |
|
2676 | + foreach ( (array) $comments as $comment ) { |
|
2677 | + wp_cache_add($comment->comment_ID, $comment, 'comment'); |
|
2678 | + } |
|
2601 | 2679 | |
2602 | 2680 | if ( $update_meta_cache ) { |
2603 | 2681 | // Avoid `wp_list_pluck()` in case `$comments` is passed by reference. |
@@ -2647,8 +2725,9 @@ discard block |
||
2647 | 2725 | * @return array |
2648 | 2726 | */ |
2649 | 2727 | function _close_comments_for_old_posts( $posts, $query ) { |
2650 | - if ( empty( $posts ) || ! $query->is_singular() || ! get_option( 'close_comments_for_old_posts' ) ) |
|
2651 | - return $posts; |
|
2728 | + if ( empty( $posts ) || ! $query->is_singular() || ! get_option( 'close_comments_for_old_posts' ) ) { |
|
2729 | + return $posts; |
|
2730 | + } |
|
2652 | 2731 | |
2653 | 2732 | /** |
2654 | 2733 | * Filter the list of post types to automatically close comments for. |
@@ -2658,12 +2737,14 @@ discard block |
||
2658 | 2737 | * @param array $post_types An array of registered post types. Default array with 'post'. |
2659 | 2738 | */ |
2660 | 2739 | $post_types = apply_filters( 'close_comments_for_post_types', array( 'post' ) ); |
2661 | - if ( ! in_array( $posts[0]->post_type, $post_types ) ) |
|
2662 | - return $posts; |
|
2740 | + if ( ! in_array( $posts[0]->post_type, $post_types ) ) { |
|
2741 | + return $posts; |
|
2742 | + } |
|
2663 | 2743 | |
2664 | 2744 | $days_old = (int) get_option( 'close_comments_days_old' ); |
2665 | - if ( ! $days_old ) |
|
2666 | - return $posts; |
|
2745 | + if ( ! $days_old ) { |
|
2746 | + return $posts; |
|
2747 | + } |
|
2667 | 2748 | |
2668 | 2749 | if ( time() - strtotime( $posts[0]->post_date_gmt ) > ( $days_old * DAY_IN_SECONDS ) ) { |
2669 | 2750 | $posts[0]->comment_status = 'closed'; |
@@ -2684,30 +2765,35 @@ discard block |
||
2684 | 2765 | * @return bool $open |
2685 | 2766 | */ |
2686 | 2767 | function _close_comments_for_old_post( $open, $post_id ) { |
2687 | - if ( ! $open ) |
|
2688 | - return $open; |
|
2768 | + if ( ! $open ) { |
|
2769 | + return $open; |
|
2770 | + } |
|
2689 | 2771 | |
2690 | - if ( !get_option('close_comments_for_old_posts') ) |
|
2691 | - return $open; |
|
2772 | + if ( !get_option('close_comments_for_old_posts') ) { |
|
2773 | + return $open; |
|
2774 | + } |
|
2692 | 2775 | |
2693 | 2776 | $days_old = (int) get_option('close_comments_days_old'); |
2694 | - if ( !$days_old ) |
|
2695 | - return $open; |
|
2777 | + if ( !$days_old ) { |
|
2778 | + return $open; |
|
2779 | + } |
|
2696 | 2780 | |
2697 | 2781 | $post = get_post($post_id); |
2698 | 2782 | |
2699 | 2783 | /** This filter is documented in wp-includes/comment.php */ |
2700 | 2784 | $post_types = apply_filters( 'close_comments_for_post_types', array( 'post' ) ); |
2701 | - if ( ! in_array( $post->post_type, $post_types ) ) |
|
2702 | - return $open; |
|
2785 | + if ( ! in_array( $post->post_type, $post_types ) ) { |
|
2786 | + return $open; |
|
2787 | + } |
|
2703 | 2788 | |
2704 | 2789 | // Undated drafts should not show up as comments closed. |
2705 | 2790 | if ( '0000-00-00 00:00:00' === $post->post_date_gmt ) { |
2706 | 2791 | return $open; |
2707 | 2792 | } |
2708 | 2793 | |
2709 | - if ( time() - strtotime( $post->post_date_gmt ) > ( $days_old * DAY_IN_SECONDS ) ) |
|
2710 | - return false; |
|
2794 | + if ( time() - strtotime( $post->post_date_gmt ) > ( $days_old * DAY_IN_SECONDS ) ) { |
|
2795 | + return false; |
|
2796 | + } |
|
2711 | 2797 | |
2712 | 2798 | return $open; |
2713 | 2799 | } |