Completed
Push — gm-17/payment-widget ( cb2702...55e70e )
by
unknown
13:32 queued 03:19
created

featured-images.php ➔ jetpack_featured_images_remove_post_thumbnail()   D

Complexity

Conditions 31
Paths 3

Size

Total Lines 47
Code Lines 35

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 31
eloc 35
nc 3
nop 4
dl 0
loc 47
rs 4.6677
c 0
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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
			&& ! $opts['archive-option']
18
			&& ( isset( $meta_key )
19
			&& '_thumbnail_id' === $meta_key )
20
			&& in_the_loop()
21
		)
22
		|| ( true === $opts['post']
23
			&& is_single()
24
			&& ! jetpack_is_product()
25
			&& ! $opts['post-option']
26
			&& ( isset( $meta_key )
27
			&& '_thumbnail_id' === $meta_key )
28
			&& in_the_loop()
29
		)
30
		|| ( true === $opts['page']
31
			&& is_singular()
32
			&& is_page()
33
			&& ! $opts['page-option']
34
			&& ( isset( $meta_key )
35
			&& '_thumbnail_id' === $meta_key )
36
			&& in_the_loop()
37
		)
38
		|| ( true === $opts['portfolio']
39
			&& post_type_exists( 'jetpack-portfolio' )
40
			&& is_singular( 'jetpack-portfolio' )
41
			&& ! $opts['portfolio-option']
42
			&& ( isset( $meta_key )
43
			&& '_thumbnail_id' === $meta_key )
44
			&& in_the_loop()
45
		)
46
	) {
47
		return false;
48
	} else {
49
		return $metadata;
50
	}
51
}
52
add_filter( 'get_post_metadata', 'jetpack_featured_images_remove_post_thumbnail', true, 4 );
53
54
/**
55
 * Check if we are in a WooCommerce Product in order to exclude it from the is_single check.
56
 */
57
function jetpack_is_product() {
58
	return ( function_exists( 'is_product' ) ) ? is_product() : false;
59
}
60