Completed
Push — feature/simple-payments ( 6e3ccc...1283b4 )
by
unknown
245:28 queued 229:43
created

featured-images.php ➔ jetpack_featured_images_remove_post_thumbnail()   C

Complexity

Conditions 30
Paths 2

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 30
eloc 9
nc 2
nop 4
dl 0
loc 13
rs 6.981
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
	// Returns false if the archive option or singular option is unticked.
9
	if ( ( true === $opts['archive'] && ( is_home() || is_archive() || is_search() ) && ! $opts['archive-option'] && ( isset( $meta_key ) && '_thumbnail_id' === $meta_key ) && in_the_loop() )
10
		|| ( true === $opts['post'] && is_single() && ! jetpack_is_product() && ! $opts['post-option'] && ( isset( $meta_key ) && '_thumbnail_id' === $meta_key ) && in_the_loop() )
11
		|| ( true === $opts['page'] && is_singular() && is_page() && ! $opts['page-option'] && ( isset( $meta_key ) && '_thumbnail_id' === $meta_key ) && in_the_loop() )
12
		|| ( true === $opts['portfolio'] && post_type_exists( 'jetpack-portfolio' ) && is_singular( 'jetpack-portfolio' ) && ! $opts['portfolio-option'] && ( isset( $meta_key ) && '_thumbnail_id' === $meta_key ) && in_the_loop() ) ) {
13
		return false;
14
	} else {
15
		return $metadata;
16
	}
17
}
18
add_filter( 'get_post_metadata', 'jetpack_featured_images_remove_post_thumbnail', true, 4 );
19
20
/**
21
 * Check if we are in a WooCommerce Product in order to exclude it from the is_single check.
22
 */
23
function jetpack_is_product() {
24
	return ( function_exists( 'is_product' ) ) ? is_product() : false;
25
}
26