Sin descripción

featured-images.php 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. /**
  3. * The function to prevent for Featured Images to be displayed in a theme.
  4. */
  5. function jetpack_featured_images_remove_post_thumbnail( $metadata, $object_id, $meta_key, $single ) {
  6. $opts = jetpack_featured_images_get_settings();
  7. /**
  8. * Allow featured images to be displayed at all times for specific CPTs.
  9. *
  10. * @module theme-tools
  11. *
  12. * @since 9.1.0
  13. *
  14. * @param array $excluded_post_types Array of excluded post types.
  15. */
  16. $excluded_post_types = apply_filters(
  17. 'jetpack_content_options_featured_image_exclude_cpt',
  18. array( 'jp_pay_product' )
  19. );
  20. // Automatically return metadata for specific post types, when we don't want to hide the Featured Image.
  21. if ( in_array( get_post_type( $object_id ), $excluded_post_types, true ) ) {
  22. return $metadata;
  23. }
  24. // Return false if the archive option or singular option is unticked.
  25. if (
  26. ( true === $opts['archive']
  27. && ( is_home() || is_archive() || is_search() )
  28. && ! jetpack_is_shop_page()
  29. && ! $opts['archive-option']
  30. && ( isset( $meta_key )
  31. && '_thumbnail_id' === $meta_key )
  32. && in_the_loop()
  33. )
  34. || ( true === $opts['post']
  35. && is_single()
  36. && ! jetpack_is_product()
  37. && ! $opts['post-option']
  38. && ( isset( $meta_key )
  39. && '_thumbnail_id' === $meta_key )
  40. && in_the_loop()
  41. )
  42. || ( true === $opts['page']
  43. && is_singular()
  44. && is_page()
  45. && ! $opts['page-option']
  46. && ( isset( $meta_key )
  47. && '_thumbnail_id' === $meta_key )
  48. && in_the_loop()
  49. )
  50. || ( true === $opts['portfolio']
  51. && post_type_exists( 'jetpack-portfolio' )
  52. && is_singular( 'jetpack-portfolio' )
  53. && ! $opts['portfolio-option']
  54. && ( isset( $meta_key )
  55. && '_thumbnail_id' === $meta_key )
  56. && in_the_loop()
  57. )
  58. ) {
  59. return false;
  60. } else {
  61. return $metadata;
  62. }
  63. }
  64. add_filter( 'get_post_metadata', 'jetpack_featured_images_remove_post_thumbnail', true, 4 );
  65. /**
  66. * Check if we are in a WooCommerce Product in order to exclude it from the is_single check.
  67. */
  68. function jetpack_is_product() {
  69. return ( function_exists( 'is_product' ) ) ? is_product() : false;
  70. }
  71. /**
  72. * Check if we are in a WooCommerce Shop in order to exclude it from the is_archive check.
  73. */
  74. function jetpack_is_shop_page() {
  75. // Check if WooCommerce is active first.
  76. if ( ! class_exists( 'WooCommerce' ) ) {
  77. return false;
  78. }
  79. global $wp_query;
  80. $front_page_id = get_option( 'page_on_front' );
  81. $current_page_id = $wp_query->get( 'page_id' );
  82. $is_static_front_page = 'page' === get_option( 'show_on_front' );
  83. if ( $is_static_front_page && $front_page_id === $current_page_id ) {
  84. $is_shop_page = ( $current_page_id === wc_get_page_id( 'shop' ) ) ? true : false;
  85. } else {
  86. $is_shop_page = is_shop();
  87. }
  88. return $is_shop_page;
  89. }