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