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