Automattic /
jetpack
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 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 | /** |
||
| 9 | * Allow featured images to be displayed at all times for specific CPTs. |
||
| 10 | * |
||
| 11 | * @module theme-tools |
||
| 12 | * |
||
| 13 | * @since 9.1.0 |
||
| 14 | * |
||
| 15 | * @param array $excluded_post_types Array of excluded post types. |
||
| 16 | */ |
||
| 17 | $excluded_post_types = apply_filters( |
||
| 18 | 'jetpack_content_options_featured_image_exclude_cpt', |
||
| 19 | array( 'jp_pay_product' ) |
||
| 20 | ); |
||
| 21 | |||
| 22 | // Automatically return metadata for specific post types, when we don't want to hide the Featured Image. |
||
| 23 | if ( in_array( get_post_type( $object_id ), $excluded_post_types, true ) ) { |
||
| 24 | return $metadata; |
||
| 25 | } |
||
| 26 | |||
| 27 | // Return false if the archive option or singular option is unticked. |
||
| 28 | if ( |
||
| 29 | ( true === $opts['archive'] |
||
| 30 | && ( is_home() || is_archive() || is_search() ) |
||
| 31 | && ! jetpack_is_shop_page() |
||
| 32 | && ! $opts['archive-option'] |
||
| 33 | && ( isset( $meta_key ) |
||
| 34 | && '_thumbnail_id' === $meta_key ) |
||
| 35 | && in_the_loop() |
||
| 36 | ) |
||
| 37 | || ( true === $opts['post'] |
||
| 38 | && is_single() |
||
| 39 | && ! jetpack_is_product() |
||
| 40 | && ! $opts['post-option'] |
||
| 41 | && ( isset( $meta_key ) |
||
| 42 | && '_thumbnail_id' === $meta_key ) |
||
| 43 | && in_the_loop() |
||
| 44 | ) |
||
| 45 | || ( true === $opts['page'] |
||
| 46 | && is_singular() |
||
| 47 | && is_page() |
||
| 48 | && ! $opts['page-option'] |
||
| 49 | && ( isset( $meta_key ) |
||
| 50 | && '_thumbnail_id' === $meta_key ) |
||
| 51 | && in_the_loop() |
||
| 52 | ) |
||
| 53 | || ( true === $opts['portfolio'] |
||
| 54 | && post_type_exists( 'jetpack-portfolio' ) |
||
| 55 | && is_singular( 'jetpack-portfolio' ) |
||
| 56 | && ! $opts['portfolio-option'] |
||
| 57 | && ( isset( $meta_key ) |
||
| 58 | && '_thumbnail_id' === $meta_key ) |
||
| 59 | && in_the_loop() |
||
| 60 | ) |
||
| 61 | ) { |
||
| 62 | return false; |
||
| 63 | } else { |
||
| 64 | return $metadata; |
||
| 65 | } |
||
| 66 | } |
||
| 67 | add_filter( 'get_post_metadata', 'jetpack_featured_images_remove_post_thumbnail', true, 4 ); |
||
|
0 ignored issues
–
show
|
|||
| 68 | |||
| 69 | /** |
||
| 70 | * Check if we are in a WooCommerce Product in order to exclude it from the is_single check. |
||
| 71 | */ |
||
| 72 | function jetpack_is_product() { |
||
| 73 | return ( function_exists( 'is_product' ) ) ? is_product() : false; |
||
| 74 | } |
||
| 75 | |||
| 76 | /** |
||
| 77 | * Check if we are in a WooCommerce Shop in order to exclude it from the is_archive check. |
||
| 78 | */ |
||
| 79 | function jetpack_is_shop_page() { |
||
| 80 | // Check if WooCommerce is active first. |
||
| 81 | if ( ! class_exists( 'WooCommerce' ) ) { |
||
| 82 | return false; |
||
| 83 | } |
||
| 84 | |||
| 85 | global $wp_query; |
||
| 86 | |||
| 87 | $front_page_id = get_option( 'page_on_front' ); |
||
| 88 | $current_page_id = $wp_query->get( 'page_id' ); |
||
| 89 | $is_static_front_page = 'page' === get_option( 'show_on_front' ); |
||
| 90 | |||
| 91 | if ( $is_static_front_page && $front_page_id === $current_page_id ) { |
||
| 92 | $is_shop_page = ( $current_page_id === wc_get_page_id( 'shop' ) ) ? true : false; |
||
| 93 | } else { |
||
| 94 | $is_shop_page = is_shop(); |
||
| 95 | } |
||
| 96 | |||
| 97 | return $is_shop_page; |
||
| 98 | } |
||
| 99 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: