PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.1
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.1
16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 All 504 releases
← All changes | json-endpoints/class.wpcom-json-api-post-v1-1-endpoint.php +17 -112 12.7.316.3-a.1 View file →
@@ -1,6 +1,10 @@
1 1 <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
2 2
3 +if ( ! defined( 'ABSPATH' ) ) {
4 + exit( 0 );
5 +}
6 +
3 7 /**
4 8 * Post v1_1 Endpoint class.
5 9 */
6 10 abstract class WPCOM_JSON_API_Post_v1_1_Endpoint extends WPCOM_JSON_API_Endpoint { // phpcs:ignore PEAR.NamingConventions.ValidClassName.Invalid, Generic.Classes.OpeningBraceSameLine.ContentAfterBrace
@@ -33,8 +37,9 @@
33 37 'auto-draft' => 'The post is a placeholder for a new post.',
34 38 ),
35 39 'sticky' => '(bool) Is the post sticky?',
36 40 'password' => '(string) The plaintext password protecting the post, or, more likely, the empty string if the post is not password protected.',
41 + 'has_password' => '(bool) Whether the post is password protected, regardless of whether the current user can access it.',
37 42 'parent' => "(object>post_reference|false) A reference to the post's parent, if it has one.",
38 43 'type' => "(string) The post's post_type. Post types besides post, page and revision need to be whitelisted using the <code>rest_api_allowed_post_types</code> filter.",
39 44 'discussion' => '(object) Hash of discussion options for the post',
40 45 'likes_enabled' => '(bool) Is the post open to likes?',
@@ -104,13 +109,8 @@
104 109 $GLOBALS['content_width'] = (int) $args['content_width'];
105 110 }
106 111 }
107 112
108 - if ( isset( $_SERVER['HTTP_USER_AGENT'] ) && strpos( wp_unslash( $_SERVER['HTTP_USER_AGENT'] ), 'wp-windows8' ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- we're not using this value and making changes, just checking if it exists.
109 - remove_shortcode( 'gallery', 'gallery_shortcode' );
110 - add_shortcode( 'gallery', array( $this, 'win8_gallery_shortcode' ) );
111 - }
112 -
113 113 // fetch SAL post
114 114 $post = $this->get_sal_post_by( $field, $field_value, $context );
115 115
116 116 if ( is_wp_error( $post ) ) {
@@ -219,8 +219,11 @@
219 219 break;
220 220 case 'password':
221 221 $response[ $key ] = $post->get_password();
222 222 break;
223 + case 'has_password':
224 + $response[ $key ] = $post->get_has_password();
225 + break;
223 226 /** (object|false) */
224 227 case 'parent':
225 228 $response[ $key ] = $post->get_parent();
226 229 break;
@@ -324,8 +327,17 @@
324 327 if ( ! isset( $_REQUEST['meta_fields'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- we're not making any changes to the site.
325 328 return $response;
326 329 }
327 330
331 + // Bail early if we do not have the necessary data.
332 + if (
333 + is_wp_error( $response )
334 + || ! isset( $response['posts'] )
335 + || ! is_array( $response['posts'] )
336 + ) {
337 + return $response;
338 + }
339 +
328 340 // Retrieve an array of field paths, such as: [`autosave.modified`, `autosave.post_ID`]
329 341 $fields = explode( ',', sanitize_text_field( wp_unslash( $_REQUEST['meta_fields'] ) ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- we're not making any changes to the site.
330 342
331 343 foreach ( $response['posts'] as $post ) {
@@ -369,113 +381,6 @@
369 381 switch_to_blog( $blog_id );
370 382 $post = $this->get_post_by( 'ID', $post_id, $context );
371 383 restore_current_blog();
372 384 return $post;
373 - }
374 -
375 - /**
376 - * Win8 Gallery shortcode.
377 - *
378 - * @param array $attr - the attribute.
379 - */
380 - public function win8_gallery_shortcode( $attr ) {
381 - global $post;
382 -
383 - static $instance = 0;
384 - ++$instance;
385 -
386 - // @todo - find out if this is a bug, intentionally unused, or can be removed.
387 - $output = ''; // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
388 -
389 - // We're trusting author input, so let's at least make sure it looks like a valid orderby statement
390 - if ( isset( $attr['orderby'] ) ) {
391 - $attr['orderby'] = sanitize_sql_orderby( $attr['orderby'] );
392 - if ( ! $attr['orderby'] ) {
393 - unset( $attr['orderby'] );
394 - }
395 - }
396 -
397 - $atts = shortcode_atts(
398 - array(
399 - 'order' => 'ASC',
400 - 'orderby' => 'menu_order ID',
401 - 'id' => $post->ID,
402 - 'include' => '',
403 - 'exclude' => '',
404 - 'slideshow' => false,
405 - ),
406 - $attr,
407 - 'gallery'
408 - );
409 - $id = ! empty( $atts['id'] ) ? (int) $atts['id'] : 0;
410 -
411 - // Custom image size and always use it.
412 - add_image_size( 'win8app-column', 480 );
413 - $size = 'win8app-column';
414 -
415 - if ( 'RAND' === $atts['order'] ) {
416 - $orderby = 'none';
417 - } else {
418 - $orderby = $atts['orderby'];
419 - }
420 -
421 - if ( ! empty( $atts['include'] ) ) {
422 - $include = preg_replace( '/[^0-9,]+/', '', $atts['include'] );
423 - $_attachments = get_posts(
424 - array(
425 - 'include' => $include,
426 - 'post_status' => 'inherit',
427 - 'post_type' => 'attachment',
428 - 'post_mime_type' => 'image',
429 - 'order' => $atts['order'],
430 - 'orderby' => $orderby,
431 - )
432 - );
433 - $attachments = array();
434 - foreach ( $_attachments as $key => $val ) {
435 - $attachments[ $val->ID ] = $_attachments[ $key ];
436 - }
437 - } elseif ( ! empty( $atts['exclude'] ) ) {
438 - $exclude = preg_replace( '/[^0-9,]+/', '', $atts['exclude'] );
439 - $attachments = get_children(
440 - array(
441 - 'post_parent' => $id,
442 - 'exclude' => $exclude,
443 - 'post_status' => 'inherit',
444 - 'post_type' => 'attachment',
445 - 'post_mime_type' => 'image',
446 - 'order' => $atts['order'],
447 - 'orderby' => $orderby,
448 - )
449 - );
450 - } else {
451 - $attachments = get_children(
452 - array(
453 - 'post_parent' => $id,
454 - 'post_status' => 'inherit',
455 - 'post_type' => 'attachment',
456 - 'post_mime_type' => 'image',
457 - 'order' => $atts['order'],
458 - 'orderby' => $orderby,
459 - )
460 - );
461 - }
462 -
463 - if ( ! empty( $attachments ) ) {
464 - foreach ( $attachments as $id => $attachment ) {
465 - $link = isset( $attr['link'] ) && 'file' === $attr['link']
466 - ? wp_get_attachment_link( $id, $size, false, false )
467 - : wp_get_attachment_link( $id, $size, true, false );
468 -
469 - // phpcs:disable VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
470 - if ( $captiontag && trim( $attachment->post_excerpt ) ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable
471 - $output .= "<div class='wp-caption aligncenter'>$link
472 - <p class='wp-caption-text'>" . wptexturize( $attachment->post_excerpt ) . '</p>
473 - </div>';
474 - } else {
475 - $output .= $link . ' ';
476 - }
477 - // phpcs:enable VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
478 - }
479 - }
480 385 }
481 386 }