Completed
Push — add/twentynineteen-compat ( 865e9a...81bca9 )
by
unknown
35:16 queued 24:48
created

twentynineteen.php ➔ twentynineteen_override_post_thumbnail()   C

Complexity

Conditions 13
Paths 128

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 13
nc 128
nop 1
dl 0
loc 21
rs 6.3833
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
 * Jetpack Compatibility File
4
 * See: http://jetpack.com/
5
 */
6
7
function twentynineteen_jetpack_setup() {
8
9
	/**
10
 	 * Add theme support for Infinite Scroll.
11
	 */
12
 	add_theme_support( 'infinite-scroll', array(
13
	 	'type'      => 'click',
14
 		'container' => 'main',
15
 		'render'    => 'twentynineteen_infinite_scroll_render',
16
 		'footer'    => 'page',
17
 	) );
18
19
 	/**
0 ignored issues
show
Coding Style introduced by
There is some trailing whitespace on this line which should be avoided as per coding-style.
Loading history...
20
	 * Add theme support for Responsive Videos.
21
	 */
22
	add_theme_support( 'jetpack-responsive-videos' );
23
24
	/**
25
	 * Add theme support for geo-location.
26
	 */
27
	add_theme_support( 'jetpack-geo-location' );
28
29
	/**
30
	 * Add theme support for Content Options.
31
	 */
32
	add_theme_support( 'jetpack-content-options', array(
33
		'blog-display' => 'content', // the default setting of the theme: 'content', 'excerpt' or array( 'content', 'excerpt' ) for themes mixing both display.
34
    	'post-details' => array(
35
			'stylesheet' => 'twentynineteen-style',
36
			'date'       => '.posted-on',
37
			'categories' => '.cat-links',
38
			'tags'       => '.tags-links',
39
			'author'     => '.byline',
40
			'comment'    => '.comments-link',
41
		),
42
		'featured-images'    => array(
43
			'archive'  => true,
44
			'post'     => true,
45
			'page'     => true,
46
		),
47
	) );
48
}
49
add_action( 'after_setup_theme', 'twentynineteen_jetpack_setup' );
50
51
/**
52
 * Custom render function for Infinite Scroll.
53
 */
54
function twentynineteen_infinite_scroll_render() {
55
	while ( have_posts() ) {
56
		the_post();
57
		get_template_part( 'template-parts/content/content' );
58
	}
59
}
60
61 View Code Duplication
function twentynineteen_init_jetpack() {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
62
	/**
63
	 * Add our compat CSS file for Infinite Scroll and custom widget stylings and such.
64
	 * Set the version equal to filemtime for development builds, and the JETPACK__VERSION for production
65
	 * or skip it entirely for wpcom.
66
	 */
67
	if ( ! is_admin() ) {
68
		$version = false;
69
		if ( method_exists( 'Jetpack', 'is_development_version' ) ) {
70
			$version = Jetpack::is_development_version() ? filemtime( plugin_dir_path( __FILE__ ) . 'twentynineteen.css' ) : JETPACK__VERSION;
71
		}
72
		wp_enqueue_style( 'twentynineteen-jetpack', plugins_url( 'twentynineteen.css', __FILE__ ), array(), $version );
73
		wp_style_add_data( 'twentynineteen-jetpack', 'rtl', 'replace' );
74
	}
75
}
76
add_action( 'init', 'twentynineteen_init_jetpack' );
77
78
/**
79
 * Alter gallery widget default width.
80
 */
81
function twentynineteen_gallery_widget_content_width( $width ) {
82
	return 390;
83
}
84
add_filter( 'gallery_widget_content_width', 'twentynineteen_gallery_widget_content_width' );
85
86
/**
87
 * Alter featured-image default visibility for content-options.
88
 */
89
function twentynineteen_override_post_thumbnail( $width ) {
90
	$options         = get_theme_support( 'jetpack-content-options' );
91
	$featured_images = ( ! empty( $options[0]['featured-images'] ) ) ? $options[0]['featured-images'] : null;
92
93
	$settings = array(
94
		'post-default' => ( isset( $featured_images['post-default'] ) && false === $featured_images['post-default'] ) ? '' : 1,
95
		'page-default' => ( isset( $featured_images['page-default'] ) && false === $featured_images['page-default'] ) ? '' : 1,
96
	);
97
98
	$settings = array_merge( $settings, array(
99
		'post-option'  => get_option( 'jetpack_content_featured_images_post', $settings['post-default'] ),
100
		'page-option'  => get_option( 'jetpack_content_featured_images_page', $settings['page-default'] ),
101
	) );
102
103
	if ( ( ! $settings['post-option'] && is_single() )
104
	|| ( ! $settings['page-option'] && is_singular() && is_page() ) ) {
105
		return false;
106
	} else {
107
		return ! post_password_required() && ! is_attachment() && has_post_thumbnail();
108
	}
109
}
110
add_filter( 'twentynineteen_can_show_post_thumbnail', 'twentynineteen_override_post_thumbnail', 10, 2 );
111