1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Jetpack Compatibility File |
4
|
|
|
* See: https://jetpack.com/ |
5
|
|
|
* |
6
|
|
|
* @package Jetpack |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Add Jetpack extra functionality to Twenty Twenty. |
11
|
|
|
* |
12
|
|
|
* See: https://jetpack.com/support/infinite-scroll/ |
13
|
|
|
* See: https://jetpack.com/support/responsive-videos/ |
14
|
|
|
* See: https://jetpack.com/support/content-options/ |
15
|
|
|
*/ |
16
|
|
View Code Duplication |
function twentytwenty_jetpack_setup() { |
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Add theme support for Infinite Scroll. |
19
|
|
|
*/ |
20
|
|
|
add_theme_support( |
21
|
|
|
'infinite-scroll', |
22
|
|
|
array( |
23
|
|
|
'type' => 'click', |
24
|
|
|
'container' => 'site-content', |
25
|
|
|
'render' => 'twentytwenty_infinite_scroll_render', |
26
|
|
|
'footer' => 'site-content', |
27
|
|
|
'footer_widgets' => array( |
28
|
|
|
'sidebar-1', |
29
|
|
|
'sidebar-2', |
30
|
|
|
), |
31
|
|
|
) |
32
|
|
|
); |
33
|
|
|
|
34
|
|
|
// Add theme support for Content Options. |
35
|
|
|
add_theme_support( |
36
|
|
|
'jetpack-content-options', |
37
|
|
|
array( |
38
|
|
|
'post-details' => array( |
39
|
|
|
'stylesheet' => 'twentytwenty-style', |
40
|
|
|
'date' => '.post-date', |
41
|
|
|
'categories' => '.entry-categories', |
42
|
|
|
'tags' => '.post-tags', |
43
|
|
|
'author' => '.post-author', |
44
|
|
|
), |
45
|
|
|
'featured-images' => array( |
46
|
|
|
'archive' => true, |
47
|
|
|
'post' => true, |
48
|
|
|
'page' => true, |
49
|
|
|
'fallback' => false, |
50
|
|
|
), |
51
|
|
|
) |
52
|
|
|
); |
53
|
|
|
|
54
|
|
|
// Social Menu. |
55
|
|
|
add_theme_support( 'jetpack-social-menu', 'svg' ); |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Add theme support for geo-location. |
59
|
|
|
*/ |
60
|
|
|
add_theme_support( 'jetpack-geo-location' ); |
61
|
|
|
} |
62
|
|
|
add_action( 'after_setup_theme', 'twentytwenty_jetpack_setup' ); |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Custom render function for Infinite Scroll. |
66
|
|
|
*/ |
67
|
|
|
function twentytwenty_infinite_scroll_render() { |
68
|
|
|
while ( have_posts() ) { |
69
|
|
|
echo '<hr class="post-separator styled-separator is-style-wide section-inner" aria-hidden="true" />'; |
70
|
|
|
the_post(); |
71
|
|
|
get_template_part( 'template-parts/content', get_post_type() ); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Remove Sharing buttons and Likes from excerpts that are used as intro on single post views. |
77
|
|
|
*/ |
78
|
|
|
function twentytwenty_no_sharing_on_excerpts() { |
79
|
|
|
if ( is_single() ) { |
80
|
|
|
// Remove sharing buttons. |
81
|
|
|
remove_filter( 'the_excerpt', 'sharing_display', 19 ); |
82
|
|
|
|
83
|
|
|
// Remove Likes. |
84
|
|
|
if ( class_exists( 'Jetpack_Likes' ) ) { |
85
|
|
|
remove_filter( 'the_excerpt', array( Jetpack_Likes::init(), 'post_likes' ), 30, 1 ); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
add_action( 'loop_start', 'twentytwenty_no_sharing_on_excerpts' ); |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* We do not need to display the Likes Heading here. |
93
|
|
|
* |
94
|
|
|
* @param string $heading Headline structure. |
95
|
|
|
* @param string $title Title. |
96
|
|
|
* @param string $module Module name. |
97
|
|
|
*/ |
98
|
|
|
function twentytwenty_no_likes_heading( $heading, $title, $module ) { |
99
|
|
|
if ( 'likes' === $module ) { |
100
|
|
|
return ''; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
return $heading; |
104
|
|
|
} |
105
|
|
|
add_filter( 'jetpack_sharing_headline_html', 'twentytwenty_no_likes_heading', 10, 3 ); |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Disable Ads in post excerpts, that are used as intro on single post views. |
109
|
|
|
*/ |
110
|
|
|
add_filter( 'wordads_excerpt_disable', '__return_true' ); |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Add our compat CSS file for Infinite Scroll and custom widget stylings and such. |
114
|
|
|
* Set the version equal to filemtime for development builds, and the JETPACK__VERSION for production |
115
|
|
|
* or skip it entirely for wpcom. |
116
|
|
|
*/ |
117
|
|
|
function twentytwenty_enqueue_jetpack_style() { |
118
|
|
|
$version = Jetpack::is_development_version() |
119
|
|
|
? filemtime( JETPACK__PLUGIN_DIR . 'modules/theme-tools/compat/twentytwenty.css' ) |
120
|
|
|
: JETPACK__VERSION; |
121
|
|
|
|
122
|
|
|
wp_enqueue_style( 'twentytwenty-jetpack', plugins_url( 'twentytwenty.css', __FILE__ ), array(), $version ); |
123
|
|
|
wp_style_add_data( 'twentytwenty-jetpack', 'rtl', 'replace' ); |
124
|
|
|
} |
125
|
|
|
add_action( 'wp_enqueue_scripts', 'twentytwenty_enqueue_jetpack_style' ); |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Add inline custom CSS with custom accent color if there is any set. |
129
|
|
|
*/ |
130
|
|
|
function twentytwenty_infinity_accent_color_css() { |
131
|
|
|
// Bail early if no custom color was set. |
132
|
|
|
if ( |
133
|
|
|
'custom' !== get_theme_mod( 'accent_hue_active' ) |
134
|
|
|
|| empty( get_theme_mod( 'accent_accessible_colors' ) ) |
135
|
|
|
) { |
136
|
|
|
return; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
$color_info = get_theme_mod( 'accent_accessible_colors' ); |
140
|
|
|
$custom_css = sprintf( |
141
|
|
|
' |
142
|
|
|
.infinite-scroll #site-content #infinite-handle span button, |
143
|
|
|
.infinite-scroll #site-content #infinite-handle span button:hover, |
144
|
|
|
.infinite-scroll #site-content #infinite-handle span button:focus { |
145
|
|
|
background: %1$s; |
146
|
|
|
color: %2$s; |
147
|
|
|
} |
148
|
|
|
#site-content .entry-content div.sharedaddy h3.sd-title, |
149
|
|
|
#site-content .entry-content h3.sd-title, |
150
|
|
|
#site-content .entry-content #jp-relatedposts h3.jp-relatedposts-headline { |
151
|
|
|
color: %3$s; |
152
|
|
|
} |
153
|
|
|
', |
154
|
|
|
$color_info['content']['accent'], |
155
|
|
|
$color_info['content']['background'], |
156
|
|
|
$color_info['content']['secondary'] |
157
|
|
|
); |
158
|
|
|
|
159
|
|
|
// Add our custom style to the existing Twenty Twenty CSS compat file. |
160
|
|
|
wp_add_inline_style( 'twentytwenty-jetpack', $custom_css ); |
161
|
|
|
} |
162
|
|
|
add_action( 'wp_enqueue_scripts', 'twentytwenty_infinity_accent_color_css' ); |
163
|
|
|
|
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.