featured-images.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. // Automatically return metadata if it's a PayPal product - we don't want to hide the Featured Image.
  8. if ( 'jp_pay_product' === get_post_type( $object_id ) ) {
  9. return $metadata;
  10. }
  11. // Return false if the archive option or singular option is unticked.
  12. if (
  13. ( true === $opts['archive']
  14. && ( is_home() || is_archive() || is_search() )
  15. && ! jetpack_is_shop_page()
  16. && ! $opts['archive-option']
  17. && ( isset( $meta_key )
  18. && '_thumbnail_id' === $meta_key )
  19. && in_the_loop()
  20. )
  21. || ( true === $opts['post']
  22. && is_single()
  23. && ! jetpack_is_product()
  24. && ! $opts['post-option']
  25. && ( isset( $meta_key )
  26. && '_thumbnail_id' === $meta_key )
  27. && in_the_loop()
  28. )
  29. || ( true === $opts['page']
  30. && is_singular()
  31. && is_page()
  32. && ! $opts['page-option']
  33. && ( isset( $meta_key )
  34. && '_thumbnail_id' === $meta_key )
  35. && in_the_loop()
  36. )
  37. || ( true === $opts['portfolio']
  38. && post_type_exists( 'jetpack-portfolio' )
  39. && is_singular( 'jetpack-portfolio' )
  40. && ! $opts['portfolio-option']
  41. && ( isset( $meta_key )
  42. && '_thumbnail_id' === $meta_key )
  43. && in_the_loop()
  44. )
  45. ) {
  46. return false;
  47. } else {
  48. return $metadata;
  49. }
  50. }
  51. add_filter( 'get_post_metadata', 'jetpack_featured_images_remove_post_thumbnail', true, 4 );
  52. /**
  53. * Check if we are in a WooCommerce Product in order to exclude it from the is_single check.
  54. */
  55. function jetpack_is_product() {
  56. return ( function_exists( 'is_product' ) ) ? is_product() : false;
  57. }
  58. /**
  59. * Check if we are in a WooCommerce Shop in order to exclude it from the is_archive check.
  60. */
  61. function jetpack_is_shop_page() {
  62. // Check if WooCommerce is active first.
  63. if ( ! class_exists( 'WooCommerce' ) ) {
  64. return false;
  65. }
  66. global $wp_query;
  67. $front_page_id = get_option( 'page_on_front' );
  68. $current_page_id = $wp_query->get( 'page_id' );
  69. $is_static_front_page = 'page' === get_option( 'show_on_front' );
  70. if ( $is_static_front_page && $front_page_id === $current_page_id ) {
  71. $is_shop_page = ( $current_page_id === wc_get_page_id( 'shop' ) ) ? true : false;
  72. } else {
  73. $is_shop_page = is_shop();
  74. }
  75. return $is_shop_page;
  76. }