Completed
Push — fix/murial-studio ( dc6c26...a8f618 )
by
unknown
61:47 queued 55:35
created

twentytwenty.php ➔ twentytwenty_no_sharing_on_excerpts()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 0
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
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
function twentytwenty_jetpack_setup() {
13
	/**
14
	 * Add theme support for Infinite Scroll.
15
	 */
16
	add_theme_support(
17
		'infinite-scroll',
18
		array(
19
			'type'      => 'click',
20
			'container' => 'site-content',
21
			'render'    => 'twentytwenty_infinite_scroll_render',
22
			'footer'    => 'site-content',
23
		)
24
	);
25
26
	/**
27
	 * Add theme support for geo-location.
28
	 */
29
	add_theme_support( 'jetpack-geo-location' );
30
}
31
add_action( 'after_setup_theme', 'twentytwenty_jetpack_setup' );
32
33
/**
34
 * Custom render function for Infinite Scroll.
35
 */
36
function twentytwenty_infinite_scroll_render() {
37
	while ( have_posts() ) {
38
		echo '<hr class="post-separator styled-separator is-style-wide section-inner" aria-hidden="true" />';
39
		the_post();
40
		get_template_part( 'template-parts/content', get_post_type() );
41
	}
42
}
43
44
/**
45
 * Remove Sharing buttons and Likes from excerpts that are used as intro on single post views.
46
 */
47
function twentytwenty_no_sharing_on_excerpts() {
48
	if ( is_single() ) {
49
		// Remove sharing buttons.
50
		remove_filter( 'the_excerpt', 'sharing_display', 19 );
51
52
		// Remove Likes.
53
		if ( class_exists( 'Jetpack_Likes' ) ) {
54
			remove_filter( 'the_excerpt', array( Jetpack_Likes::init(), 'post_likes' ), 30, 1 );
55
		}
56
	}
57
}
58
add_action( 'loop_start', 'twentytwenty_no_sharing_on_excerpts' );
59
60
/**
61
 * We do not need to display the Likes Heading here.
62
 *
63
 * @param string $heading Headline structure.
64
 * @param string $title   Title.
65
 * @param string $module  Module name.
66
 */
67
function twentytwenty_no_likes_heading( $heading, $title, $module ) {
68
	if ( 'likes' === $module ) {
69
		return '';
70
	}
71
72
	return $heading;
73
}
74
add_filter( 'jetpack_sharing_headline_html', 'twentytwenty_no_likes_heading', 10, 3 );
75
76
/**
77
 * Disable Ads in post excerpts, that are used as intro on single post views.
78
 */
79
add_filter( 'wordads_excerpt_disable', '__return_true' );
80
81
/**
82
 * Add our compat CSS file for Infinite Scroll and custom widget stylings and such.
83
 * Set the version equal to filemtime for development builds, and the JETPACK__VERSION for production
84
 * or skip it entirely for wpcom.
85
 */
86
function twentytwenty_enqueue_jetpack_style() {
87
	$version = Jetpack::is_development_version()
88
		? filemtime( JETPACK__PLUGIN_DIR . 'modules/theme-tools/compat/twentytwenty.css' )
89
		: JETPACK__VERSION;
90
91
	wp_enqueue_style( 'twentytwenty-jetpack', plugins_url( 'twentytwenty.css', __FILE__ ), array(), $version );
92
	wp_style_add_data( 'twentytwenty-jetpack', 'rtl', 'replace' );
93
}
94
add_action( 'wp_enqueue_scripts', 'twentytwenty_enqueue_jetpack_style' );
95
96
/**
97
 * Add inline custom CSS with custom accent color if there is any set.
98
 */
99
function twentytwenty_infinity_accent_color_css() {
100
	// Bail early if no custom color was set.
101
	if (
102
		'custom' !== get_theme_mod( 'accent_hue_active' )
103
		|| empty( get_theme_mod( 'accent_accessible_colors' ) )
104
	) {
105
		return;
106
	}
107
108
	$color_info = get_theme_mod( 'accent_accessible_colors' );
109
	$custom_css = sprintf(
110
		'
111
		.infinite-scroll #site-content #infinite-handle span button,
112
		.infinite-scroll #site-content #infinite-handle span button:hover,
113
		.infinite-scroll #site-content #infinite-handle span button:focus {
114
			background: %1$s;
115
			color: %2$s;
116
		}
117
		#site-content .entry-content div.sharedaddy h3.sd-title,
118
		#site-content .entry-content h3.sd-title,
119
		#site-content .entry-content #jp-relatedposts h3.jp-relatedposts-headline {
120
			color: %3$s;
121
		}
122
		',
123
		$color_info['content']['accent'],
124
		$color_info['content']['background'],
125
		$color_info['content']['secondary']
126
	);
127
128
	// Add our custom style to the existing Twenty Twenty CSS compat file.
129
	wp_add_inline_style( 'twentytwenty-jetpack', $custom_css );
130
}
131
add_action( 'wp_enqueue_scripts', 'twentytwenty_infinity_accent_color_css' );
132
133