PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 9.8.2
Jetpack – WP Security, Backup, Speed, & Growth v9.8.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 14.1.1 14.2.2 14.3.1 All 501 releases
jetpack / modules / theme-tools / featured-content.php

featured-content.php in Jetpack – WP Security, Backup, Speed, & Growth 9.8.2, at modules/theme-tools/featured-content.php

731 lines 22.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 use Automattic\Jetpack\Constants;
4
5 if ( ! class_exists( 'Featured_Content' ) && isset( $GLOBALS['pagenow'] ) && 'plugins.php' !== $GLOBALS['pagenow'] ) {
6
7 /**
8 * Featured Content.
9 *
10 * This module will allow users to define a subset of posts to be displayed in a
11 * theme-designated featured content area.
12 *
13 * This feature will only be activated for themes that declare that they support
14 * it. This can be done by adding code similar to the following during the
15 * "after_setup_theme" action:
16 *
17 * add_theme_support( 'featured-content', array(
18 * 'filter' => 'mytheme_get_featured_content',
19 * 'max_posts' => 20,
20 * 'post_types' => array( 'post', 'page' ),
21 * ) );
22 *
23 * For maximum compatibility with different methods of posting users will
24 * designate a featured post tag to associate posts with. Since this tag now has
25 * special meaning beyond that of a normal tags, users will have the ability to
26 * hide it from the front-end of their site.
27 */
28 class Featured_Content {
29
30 /**
31 * The maximum number of posts that a Featured Content area can contain. We
32 * define a default value here but themes can override this by defining a
33 * "max_posts" entry in the second parameter passed in the call to
34 * add_theme_support( 'featured-content' ).
35 *
36 * @see Featured_Content::init()
37 */
38 public static $max_posts = 15;
39
40 /**
41 * The registered post types supported by Featured Content. Themes can add
42 * Featured Content support for registered post types by defining a
43 * 'post_types' argument (string|array) in the call to
44 * add_theme_support( 'featured-content' ).
45 *
46 * @see Featured_Content::init()
47 */
48 public static $post_types = array( 'post' );
49
50 /**
51 * The tag that is used to mark featured content. Users can define
52 * a custom tag name that will be stored in this variable.
53 *
54 * @see Featured_Content::hide_featured_term
55 */
56 public static $tag;
57
58 /**
59 * Instantiate.
60 *
61 * All custom functionality will be hooked into the "init" action.
62 */
63 public static function setup() {
64 add_action( 'init', array( __CLASS__, 'init' ), 30 );
65 }
66
67 /**
68 * Conditionally hook into WordPress.
69 *
70 * Themes must declare that they support this module by adding
71 * add_theme_support( 'featured-content' ); during after_setup_theme.
72 *
73 * If no theme support is found there is no need to hook into WordPress. We'll
74 * just return early instead.
75 *
76 * @uses Featured_Content::$max_posts
77 */
78 public static function init() {
79 $theme_support = get_theme_support( 'featured-content' );
80
81 // Return early if theme does not support featured content.
82 if ( ! $theme_support ) {
83 return;
84 }
85
86 /*
87 * An array of named arguments must be passed as the second parameter
88 * of add_theme_support().
89 */
90 if ( ! isset( $theme_support[0] ) ) {
91 return;
92 }
93
94 if ( isset( $theme_support[0]['featured_content_filter'] ) ) {
95 $theme_support[0]['filter'] = $theme_support[0]['featured_content_filter'];
96 unset( $theme_support[0]['featured_content_filter'] );
97 }
98
99 // Return early if "filter" has not been defined.
100 if ( ! isset( $theme_support[0]['filter'] ) ) {
101 return;
102 }
103
104 // Theme can override the number of max posts.
105 if ( isset( $theme_support[0]['max_posts'] ) ) {
106 self::$max_posts = absint( $theme_support[0]['max_posts'] );
107 }
108
109 add_filter( $theme_support[0]['filter'], array( __CLASS__, 'get_featured_posts' ) );
110 add_action( 'customize_register', array( __CLASS__, 'customize_register' ), 9 );
111 add_action( 'admin_init', array( __CLASS__, 'register_setting' ) );
112 add_action( 'save_post', array( __CLASS__, 'delete_transient' ) );
113 add_action( 'delete_post_tag', array( __CLASS__, 'delete_post_tag' ) );
114 add_action( 'customize_controls_enqueue_scripts', array( __CLASS__, 'enqueue_scripts' ) );
115 add_action( 'pre_get_posts', array( __CLASS__, 'pre_get_posts' ) );
116 add_action( 'switch_theme', array( __CLASS__, 'switch_theme' ) );
117 add_action( 'switch_theme', array( __CLASS__, 'delete_transient' ) );
118 add_action( 'wp_loaded', array( __CLASS__, 'wp_loaded' ) );
119 add_action( 'update_option_featured-content', array( __CLASS__, 'flush_post_tag_cache' ), 10, 2 );
120 add_action( 'delete_option_featured-content', array( __CLASS__, 'flush_post_tag_cache' ), 10, 2 );
121 add_action( 'split_shared_term', array( __CLASS__, 'jetpack_update_featured_content_for_split_terms', 10, 4 ) );
122
123 if ( isset( $theme_support[0]['additional_post_types'] ) ) {
124 $theme_support[0]['post_types'] = array_merge( array( 'post' ), (array) $theme_support[0]['additional_post_types'] );
125 unset( $theme_support[0]['additional_post_types'] );
126 }
127
128 // Themes can allow Featured Content pages
129 if ( isset( $theme_support[0]['post_types'] ) ) {
130 self::$post_types = array_merge( self::$post_types, (array) $theme_support[0]['post_types'] );
131 self::$post_types = array_unique( self::$post_types );
132
133 // register post_tag support for each post type
134 foreach ( self::$post_types as $post_type ) {
135 register_taxonomy_for_object_type( 'post_tag', $post_type );
136 }
137 }
138 }
139
140 /**
141 * Hide "featured" tag from the front-end.
142 *
143 * Has to run on wp_loaded so that the preview filters of the customizer
144 * have a chance to alter the value.
145 */
146 public static function wp_loaded() {
147 if ( self::get_setting( 'hide-tag' ) ) {
148 $settings = self::get_setting();
149
150 // This is done before setting filters for get_terms in order to avoid an infinite filter loop
151 self::$tag = get_term_by( 'name', $settings['tag-name'], 'post_tag' );
152
153 add_filter( 'get_terms', array( __CLASS__, 'hide_featured_term' ), 10, 3 );
154 add_filter( 'get_the_terms', array( __CLASS__, 'hide_the_featured_term' ), 10, 3 );
155 }
156 }
157
158 /**
159 * Get featured posts
160 *
161 * This method is not intended to be called directly. Theme developers should
162 * place a filter directly in their theme and then pass its name as a value of
163 * the "filter" key in the array passed as the $args parameter during the call
164 * to: add_theme_support( 'featured-content', $args ).
165 *
166 * @uses Featured_Content::get_featured_post_ids()
167 *
168 * @return array
169 */
170 public static function get_featured_posts() {
171 $post_ids = self::get_featured_post_ids();
172
173 // No need to query if there is are no featured posts.
174 if ( empty( $post_ids ) ) {
175 return array();
176 }
177
178 $featured_posts = get_posts(
179 array(
180 'include' => $post_ids,
181 'posts_per_page' => count( $post_ids ),
182 'post_type' => self::$post_types,
183 'suppress_filters' => false,
184 )
185 );
186
187 return $featured_posts;
188 }
189
190 /**
191 * Get featured post IDs
192 *
193 * This function will return the an array containing the post IDs of all
194 * featured posts.
195 *
196 * Sets the "featured_content_ids" transient.
197 *
198 * @return array Array of post IDs.
199 */
200 public static function get_featured_post_ids() {
201 // Return array of cached results if they exist.
202 $featured_ids = get_transient( 'featured_content_ids' );
203 if ( ! empty( $featured_ids ) ) {
204 return array_map(
205 'absint',
206 /**
207 * Filter the list of Featured Posts IDs.
208 *
209 * @module theme-tools
210 *
211 * @since 2.7.0
212 *
213 * @param array $featured_ids Array of post IDs.
214 */
215 apply_filters( 'featured_content_post_ids', (array) $featured_ids )
216 );
217 }
218
219 $settings = self::get_setting();
220
221 // Return empty array if no tag name is set.
222 $term = get_term_by( 'name', $settings['tag-name'], 'post_tag' );
223 if ( ! $term ) {
224 $term = get_term_by( 'id', $settings['tag-id'], 'post_tag' );
225 }
226 if ( $term ) {
227 $tag = $term->term_id;
228 } else {
229 /** This action is documented in modules/theme-tools/featured-content.php */
230 return apply_filters( 'featured_content_post_ids', array() );
231 }
232
233 // Back compat for installs that have the quantity option still set.
234 $quantity = isset( $settings['quantity'] ) ? $settings['quantity'] : self::$max_posts;
235
236 // Query for featured posts.
237 $featured = get_posts(
238 array(
239 'numberposts' => $quantity,
240 'post_type' => self::$post_types,
241 'suppress_filters' => false,
242 'tax_query' => array(
243 array(
244 'field' => 'term_id',
245 'taxonomy' => 'post_tag',
246 'terms' => $tag,
247 ),
248 ),
249 )
250 );
251
252 // Return empty array if no featured content exists.
253 if ( ! $featured ) {
254 /** This action is documented in modules/theme-tools/featured-content.php */
255 return apply_filters( 'featured_content_post_ids', array() );
256 }
257
258 // Ensure correct format before save/return.
259 $featured_ids = wp_list_pluck( (array) $featured, 'ID' );
260 $featured_ids = array_map( 'absint', $featured_ids );
261
262 set_transient( 'featured_content_ids', $featured_ids );
263
264 /** This action is documented in modules/theme-tools/featured-content.php */
265 return apply_filters( 'featured_content_post_ids', $featured_ids );
266 }
267
268 /**
269 * Delete Transient.
270 *
271 * Hooks in the "save_post" action.
272 *
273 * @see Featured_Content::validate_settings().
274 */
275 public static function delete_transient() {
276 delete_transient( 'featured_content_ids' );
277 }
278
279 /**
280 * Flush the Post Tag relationships cache.
281 *
282 * Hooks in the "update_option_featured-content" action.
283 */
284 public static function flush_post_tag_cache( $prev, $opts ) {
285 if ( ! empty( $opts ) && ! empty( $opts['tag-id'] ) ) {
286 $query = new WP_Query(
287 array(
288 'tag_id' => (int) $opts['tag-id'],
289 'posts_per_page' => -1,
290 )
291 );
292 foreach ( $query->posts as $post ) {
293 wp_cache_delete( $post->ID, 'post_tag_relationships' );
294 }
295 }
296 }
297
298 /**
299 * Exclude featured posts from the blog query when the blog is the front-page,
300 * and user has not checked the "Also display tagged posts outside the Featured Content area" checkbox.
301 *
302 * Filter the home page posts, and remove any featured post ID's from it.
303 * Hooked onto the 'pre_get_posts' action, this changes the parameters of the
304 * query before it gets any posts.
305 *
306 * @uses Featured_Content::get_featured_post_ids();
307 * @uses Featured_Content::get_setting();
308 * @param WP_Query $query
309 * @return WP_Query Possibly modified WP_Query
310 */
311 public static function pre_get_posts( $query ) {
312
313 // Bail if not home or not main query.
314 if ( ! $query->is_home() || ! $query->is_main_query() ) {
315 return;
316 }
317
318 // Bail if the blog page is not the front page.
319 if ( 'posts' !== get_option( 'show_on_front' ) ) {
320 return;
321 }
322
323 $featured = self::get_featured_post_ids();
324
325 // Bail if no featured posts.
326 if ( ! $featured ) {
327 return;
328 }
329
330 $settings = self::get_setting();
331
332 // Bail if the user wants featured posts always displayed.
333 if ( true == $settings['show-all'] ) {
334 return;
335 }
336
337 // We need to respect post ids already in the blocklist.
338 $post__not_in = $query->get( 'post__not_in' );
339
340 if ( ! empty( $post__not_in ) ) {
341 $featured = array_merge( (array) $post__not_in, $featured );
342 $featured = array_unique( $featured );
343 }
344
345 $query->set( 'post__not_in', $featured );
346 }
347
348 /**
349 * Reset tag option when the saved tag is deleted.
350 *
351 * It's important to mention that the transient needs to be deleted, too.
352 * While it may not be obvious by looking at the function alone, the transient
353 * is deleted by Featured_Content::validate_settings().
354 *
355 * Hooks in the "delete_post_tag" action.
356 *
357 * @see Featured_Content::validate_settings().
358 *
359 * @param int $tag_id The term_id of the tag that has been deleted.
360 * @return void
361 */
362 public static function delete_post_tag( $tag_id ) {
363 $settings = self::get_setting();
364
365 if ( empty( $settings['tag-id'] ) || $tag_id != $settings['tag-id'] ) {
366 return;
367 }
368
369 $settings['tag-id'] = 0;
370 $settings = self::validate_settings( $settings );
371 update_option( 'featured-content', $settings );
372 }
373
374 /**
375 * Hide featured tag from displaying when global terms are queried from
376 * the front-end.
377 *
378 * Hooks into the "get_terms" filter.
379 *
380 * @uses Featured_Content::get_setting()
381 *
382 * @param array $terms A list of term objects. This is the return value of get_terms().
383 * @param array $taxonomies An array of taxonomy slugs.
384 * @return array $terms
385 */
386 public static function hide_featured_term( $terms, $taxonomies, $args ) {
387
388 // This filter is only appropriate on the front-end.
389 if ( is_admin() || ( defined( 'REST_REQUEST' ) && REST_REQUEST ) || ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST ) ) {
390 return $terms;
391 }
392
393 // WordPress defines the parameter as `array`, but it passes null if `get_terms( $args )` was called
394 // without a 'taxonomy' in $args.
395 if ( ! is_array( $taxonomies ) ) {
396 return $terms;
397 }
398
399 // We only want to hide the featured tag.
400 if ( ! in_array( 'post_tag', $taxonomies ) ) {
401 return $terms;
402 }
403
404 // Bail if no terms were returned.
405 if ( empty( $terms ) ) {
406 return $terms;
407 }
408
409 // Bail if term objects are unavailable.
410 if ( 'all' != $args['fields'] ) {
411 return $terms;
412 }
413
414 $settings = self::get_setting();
415
416 if ( false !== self::$tag ) {
417 foreach ( $terms as $order => $term ) {
418 if (
419 is_object( $term )
420 && (
421 $settings['tag-id'] === $term->term_id
422 || $settings['tag-name'] === $term->name
423 )
424 ) {
425 unset( $terms[ $order ] );
426 }
427 }
428 }
429
430 return $terms;
431 }
432
433 /**
434 * Hide featured tag from displaying when terms associated with a post object
435 * are queried from the front-end.
436 *
437 * Hooks into the "get_the_terms" filter.
438 *
439 * @uses Featured_Content::get_setting()
440 *
441 * @param array $terms A list of term objects. This is the return value of get_the_terms().
442 * @param int $id The ID field for the post object that terms are associated with.
443 * @param array $taxonomy An array of taxonomy slugs.
444 * @return array $terms
445 */
446 public static function hide_the_featured_term( $terms, $id, $taxonomy ) {
447
448 // This filter is only appropriate on the front-end.
449 if ( is_admin() || ( defined( 'REST_REQUEST' ) && REST_REQUEST ) || ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST ) ) {
450 return $terms;
451 }
452
453 // Make sure we are in the correct taxonomy.
454 if ( 'post_tag' != $taxonomy ) {
455 return $terms;
456 }
457
458 // No terms? Return early!
459 if ( empty( $terms ) ) {
460 return $terms;
461 }
462
463 $settings = self::get_setting();
464 $tag = get_term_by( 'name', $settings['tag-name'], 'post_tag' );
465
466 if ( false !== $tag ) {
467 foreach ( $terms as $order => $term ) {
468 if ( $settings['tag-id'] === $term->term_id || $settings['tag-name'] === $term->name ) {
469 unset( $terms[ $order ] );
470 }
471 }
472 }
473
474 return $terms;
475 }
476
477 /**
478 * Register custom setting on the Settings -> Reading screen.
479 *
480 * @uses Featured_Content::render_form()
481 * @uses Featured_Content::validate_settings()
482 *
483 * @return void
484 */
485 public static function register_setting() {
486 add_settings_field( 'featured-content', __( 'Featured Content', 'jetpack' ), array( __class__, 'render_form' ), 'reading' );
487
488 // Register sanitization callback for the Customizer.
489 register_setting( 'featured-content', 'featured-content', array( __class__, 'validate_settings' ) );
490 }
491
492 /**
493 * Add settings to the Customizer.
494 *
495 * @param WP_Customize_Manager $wp_customize Theme Customizer object.
496 */
497 public static function customize_register( $wp_customize ) {
498 $wp_customize->add_section(
499 'featured_content',
500 array(
501 'title' => esc_html__( 'Featured Content', 'jetpack' ),
502 'description' => sprintf( __( 'Easily feature all posts with the <a href="%1$s">"featured" tag</a> or a tag of your choice. Your theme supports up to %2$s posts in its featured content area.', 'jetpack' ), admin_url( '/edit.php?tag=featured' ), absint( self::$max_posts ) ),
503 'priority' => 130,
504 'theme_supports' => 'featured-content',
505 )
506 );
507
508 /*
509 Add Featured Content settings.
510 *
511 * Sanitization callback registered in Featured_Content::validate_settings().
512 * See https://themeshaper.com/2013/04/29/validation-sanitization-in-customizer/comment-page-1/#comment-12374
513 */
514 $wp_customize->add_setting(
515 'featured-content[tag-name]',
516 array(
517 'type' => 'option',
518 'sanitize_js_callback' => array( __CLASS__, 'delete_transient' ),
519 )
520 );
521 $wp_customize->add_setting(
522 'featured-content[hide-tag]',
523 array(
524 'default' => true,
525 'type' => 'option',
526 'sanitize_js_callback' => array( __CLASS__, 'delete_transient' ),
527 )
528 );
529 $wp_customize->add_setting(
530 'featured-content[show-all]',
531 array(
532 'default' => false,
533 'type' => 'option',
534 'sanitize_js_callback' => array( __CLASS__, 'delete_transient' ),
535 )
536 );
537
538 // Add Featured Content controls.
539 $wp_customize->add_control(
540 'featured-content[tag-name]',
541 array(
542 'label' => esc_html__( 'Tag name', 'jetpack' ),
543 'section' => 'featured_content',
544 'theme_supports' => 'featured-content',
545 'priority' => 20,
546 )
547 );
548 $wp_customize->add_control(
549 'featured-content[hide-tag]',
550 array(
551 'label' => esc_html__( 'Do not display tag in post details and tag clouds.', 'jetpack' ),
552 'section' => 'featured_content',
553 'theme_supports' => 'featured-content',
554 'type' => 'checkbox',
555 'priority' => 30,
556 )
557 );
558 $wp_customize->add_control(
559 'featured-content[show-all]',
560 array(
561 'label' => esc_html__( 'Also display tagged posts outside the Featured Content area.', 'jetpack' ),
562 'section' => 'featured_content',
563 'theme_supports' => 'featured-content',
564 'type' => 'checkbox',
565 'priority' => 40,
566 )
567 );
568 }
569
570 /**
571 * Enqueue the tag suggestion script.
572 */
573 public static function enqueue_scripts() {
574 wp_enqueue_script( 'featured-content-suggest', plugins_url( 'js/suggest.js', __FILE__ ), array( 'suggest' ), '20131022', true );
575 }
576
577 /**
578 * Renders all form fields on the Settings -> Reading screen.
579 */
580 public static function render_form() {
581 printf( __( 'The settings for Featured Content have <a href="%s">moved to Appearance &rarr; Customize</a>.', 'jetpack' ), admin_url( 'customize.php?#accordion-section-featured_content' ) );
582 }
583
584 /**
585 * Get settings
586 *
587 * Get all settings recognized by this module. This function will return all
588 * settings whether or not they have been stored in the database yet. This
589 * ensures that all keys are available at all times.
590 *
591 * In the event that you only require one setting, you may pass its name as the
592 * first parameter to the function and only that value will be returned.
593 *
594 * @param string $key The key of a recognized setting.
595 * @return mixed Array of all settings by default. A single value if passed as first parameter.
596 */
597 public static function get_setting( $key = 'all' ) {
598 $saved = (array) get_option( 'featured-content' );
599
600 /**
601 * Filter Featured Content's default settings.
602 *
603 * @module theme-tools
604 *
605 * @since 2.7.0
606 *
607 * @param array $args {
608 * Array of Featured Content Settings
609 *
610 * @type int hide-tag Default is 1.
611 * @type int tag-id Default is 0.
612 * @type string tag-name Default is empty.
613 * @type int show-all Default is 0.
614 * }
615 */
616 $defaults = apply_filters(
617 'featured_content_default_settings',
618 array(
619 'hide-tag' => 1,
620 'tag-id' => 0,
621 'tag-name' => '',
622 'show-all' => 0,
623 )
624 );
625
626 $options = wp_parse_args( $saved, $defaults );
627 $options = array_intersect_key( $options, $defaults );
628
629 if ( 'all' != $key ) {
630 return isset( $options[ $key ] ) ? $options[ $key ] : false;
631 }
632
633 return $options;
634 }
635
636 /**
637 * Validate settings
638 *
639 * Make sure that all user supplied content is in an expected format before
640 * saving to the database. This function will also delete the transient set in
641 * Featured_Content::get_featured_content().
642 *
643 * @uses Featured_Content::delete_transient()
644 *
645 * @param array $input
646 * @return array $output
647 */
648 public static function validate_settings( $input ) {
649 $output = array();
650
651 if ( empty( $input['tag-name'] ) ) {
652 $output['tag-id'] = 0;
653 } else {
654 $term = get_term_by( 'name', $input['tag-name'], 'post_tag' );
655
656 if ( $term ) {
657 $output['tag-id'] = $term->term_id;
658 } else {
659 $new_tag = wp_create_tag( $input['tag-name'] );
660
661 if ( ! is_wp_error( $new_tag ) && isset( $new_tag['term_id'] ) ) {
662 $output['tag-id'] = $new_tag['term_id'];
663 }
664 }
665
666 $output['tag-name'] = $input['tag-name'];
667 }
668
669 $output['hide-tag'] = isset( $input['hide-tag'] ) && $input['hide-tag'] ? 1 : 0;
670
671 $output['show-all'] = isset( $input['show-all'] ) && $input['show-all'] ? 1 : 0;
672
673 self::delete_transient();
674
675 return $output;
676 }
677
678 /**
679 * Removes the quantity setting from the options array.
680 *
681 * @return void
682 */
683 public static function switch_theme() {
684 $option = (array) get_option( 'featured-content' );
685
686 if ( isset( $option['quantity'] ) ) {
687 unset( $option['quantity'] );
688 update_option( 'featured-content', $option );
689 }
690 }
691
692 public static function jetpack_update_featured_content_for_split_terms( $old_term_id, $new_term_id, $term_taxonomy_id, $taxonomy ) {
693 $featured_content_settings = get_option( 'featured-content', array() );
694
695 // Check to see whether the stored tag ID is the one that's just been split.
696 if ( isset( $featured_content_settings['tag-id'] ) && $old_term_id == $featured_content_settings['tag-id'] && 'post_tag' == $taxonomy ) {
697 // We have a match, so we swap out the old tag ID for the new one and resave the option.
698 $featured_content_settings['tag-id'] = $new_term_id;
699 update_option( 'featured-content', $featured_content_settings );
700 }
701 }
702 }
703
704 /**
705 * Adds the featured content plugin to the set of files for which action
706 * handlers should be copied when the theme context is loaded by the REST API.
707 *
708 * @param array $copy_dirs Copy paths with actions to be copied
709 * @return array Copy paths with featured content plugin
710 */
711 function wpcom_rest_api_featured_content_copy_plugin_actions( $copy_dirs ) {
712 $copy_dirs[] = __FILE__;
713 return $copy_dirs;
714 }
715 add_action( 'restapi_theme_action_copy_dirs', 'wpcom_rest_api_featured_content_copy_plugin_actions' );
716
717 /**
718 * Delayed initialization for API Requests.
719 */
720 function wpcom_rest_request_before_callbacks( $request ) {
721 Featured_Content::init();
722 return $request;
723 }
724
725 if ( Constants::is_true( 'IS_WPCOM' ) && Constants::is_true( 'REST_API_REQUEST' ) ) {
726 add_filter( 'rest_request_before_callbacks', 'wpcom_rest_request_before_callbacks');
727 }
728
729 Featured_Content::setup();
730 } // end if ( ! class_exists( 'Featured_Content' ) && isset( $GLOBALS['pagenow'] ) && 'plugins.php' !== $GLOBALS['pagenow'] ) {
731