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