1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Jetpack Compatibility File |
4
|
|
|
* See: https://jetpack.com/ |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
View Code Duplication |
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
|
|
|
/** |
|
|
|
|
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' => array( 'content', 'excerpt' ), |
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() { |
|
|
|
|
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
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Adds custom classes to the array of body classes. |
114
|
|
|
* |
115
|
|
|
* @param array $classes Classes for the body element. |
116
|
|
|
* @return array |
117
|
|
|
*/ |
118
|
|
|
function twentynineteen_jetpack_body_classes( $classes ) { |
119
|
|
|
// Adds a class if we're in the Customizer |
120
|
|
|
if ( is_customize_preview() ) : |
121
|
|
|
$classes[] = 'twentynineteen-customizer'; |
122
|
|
|
endif; |
123
|
|
|
|
124
|
|
|
return $classes; |
125
|
|
|
} |
126
|
|
|
add_filter( 'body_class', 'twentynineteen_jetpack_body_classes' ); |
127
|
|
|
|
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.