Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/jetpack/modules/theme-to.../compat
File: twentytwenty.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Jetpack Compatibility File
[2] Fix | Delete
* See: https://jetpack.com/
[3] Fix | Delete
*
[4] Fix | Delete
* @package automattic/jetpack
[5] Fix | Delete
*/
[6] Fix | Delete
[7] Fix | Delete
if ( ! defined( 'ABSPATH' ) ) {
[8] Fix | Delete
exit( 0 );
[9] Fix | Delete
}
[10] Fix | Delete
[11] Fix | Delete
/**
[12] Fix | Delete
* Add Jetpack extra functionality to Twenty Twenty.
[13] Fix | Delete
*
[14] Fix | Delete
* See: https://jetpack.com/support/infinite-scroll/
[15] Fix | Delete
* See: https://jetpack.com/support/responsive-videos/
[16] Fix | Delete
* See: https://jetpack.com/support/content-options/
[17] Fix | Delete
*/
[18] Fix | Delete
function twentytwenty_jetpack_setup() {
[19] Fix | Delete
/**
[20] Fix | Delete
* Add theme support for Infinite Scroll.
[21] Fix | Delete
*/
[22] Fix | Delete
add_theme_support(
[23] Fix | Delete
'infinite-scroll',
[24] Fix | Delete
array(
[25] Fix | Delete
'type' => 'click',
[26] Fix | Delete
'container' => 'site-content',
[27] Fix | Delete
'render' => 'twentytwenty_infinite_scroll_render',
[28] Fix | Delete
'footer' => 'site-content',
[29] Fix | Delete
'footer_widgets' => array(
[30] Fix | Delete
'sidebar-1',
[31] Fix | Delete
'sidebar-2',
[32] Fix | Delete
),
[33] Fix | Delete
)
[34] Fix | Delete
);
[35] Fix | Delete
}
[36] Fix | Delete
add_action( 'after_setup_theme', 'twentytwenty_jetpack_setup' );
[37] Fix | Delete
[38] Fix | Delete
/**
[39] Fix | Delete
* Custom render function for Infinite Scroll.
[40] Fix | Delete
*/
[41] Fix | Delete
function twentytwenty_infinite_scroll_render() {
[42] Fix | Delete
while ( have_posts() ) {
[43] Fix | Delete
echo '<hr class="post-separator styled-separator is-style-wide section-inner" aria-hidden="true" />';
[44] Fix | Delete
the_post();
[45] Fix | Delete
get_template_part( 'template-parts/content', get_post_type() );
[46] Fix | Delete
}
[47] Fix | Delete
}
[48] Fix | Delete
[49] Fix | Delete
/**
[50] Fix | Delete
* Remove Sharing buttons and Likes from excerpts that are used as intro on single post views.
[51] Fix | Delete
*/
[52] Fix | Delete
function twentytwenty_no_sharing_on_excerpts() {
[53] Fix | Delete
if ( is_single() ) {
[54] Fix | Delete
// Remove sharing buttons.
[55] Fix | Delete
remove_filter( 'the_excerpt', 'sharing_display', 19 );
[56] Fix | Delete
[57] Fix | Delete
// Remove Likes.
[58] Fix | Delete
if ( class_exists( 'Jetpack_Likes' ) ) {
[59] Fix | Delete
remove_filter( 'the_excerpt', array( Jetpack_Likes::init(), 'post_likes' ), 30 );
[60] Fix | Delete
}
[61] Fix | Delete
}
[62] Fix | Delete
}
[63] Fix | Delete
add_action( 'loop_start', 'twentytwenty_no_sharing_on_excerpts' );
[64] Fix | Delete
[65] Fix | Delete
/**
[66] Fix | Delete
* We do not need to display the Likes Heading here.
[67] Fix | Delete
*
[68] Fix | Delete
* @param string $heading Headline structure.
[69] Fix | Delete
* @param string $title Title.
[70] Fix | Delete
* @param string $module Module name.
[71] Fix | Delete
*/
[72] Fix | Delete
function twentytwenty_no_likes_heading( $heading, $title, $module ) {
[73] Fix | Delete
if ( 'likes' === $module ) {
[74] Fix | Delete
return '';
[75] Fix | Delete
}
[76] Fix | Delete
[77] Fix | Delete
return $heading;
[78] Fix | Delete
}
[79] Fix | Delete
add_filter( 'jetpack_sharing_headline_html', 'twentytwenty_no_likes_heading', 10, 3 );
[80] Fix | Delete
[81] Fix | Delete
/**
[82] Fix | Delete
* Disable Ads in post excerpts, that are used as intro on single post views.
[83] Fix | Delete
*/
[84] Fix | Delete
add_filter( 'wordads_excerpt_disable', '__return_true' );
[85] Fix | Delete
[86] Fix | Delete
/**
[87] Fix | Delete
* Add our compat CSS file for Infinite Scroll and custom widget stylings and such.
[88] Fix | Delete
* Set the version equal to filemtime for development builds, and the JETPACK__VERSION for production
[89] Fix | Delete
* or skip it entirely for wpcom.
[90] Fix | Delete
*/
[91] Fix | Delete
function twentytwenty_enqueue_jetpack_style() {
[92] Fix | Delete
$version = Jetpack::is_development_version()
[93] Fix | Delete
? filemtime( JETPACK__PLUGIN_DIR . 'modules/theme-tools/compat/twentytwenty.css' )
[94] Fix | Delete
: JETPACK__VERSION;
[95] Fix | Delete
[96] Fix | Delete
wp_enqueue_style( 'twentytwenty-jetpack', plugins_url( 'twentytwenty.css', __FILE__ ), array(), $version );
[97] Fix | Delete
wp_style_add_data( 'twentytwenty-jetpack', 'rtl', 'replace' );
[98] Fix | Delete
}
[99] Fix | Delete
add_action( 'wp_enqueue_scripts', 'twentytwenty_enqueue_jetpack_style' );
[100] Fix | Delete
[101] Fix | Delete
/**
[102] Fix | Delete
* Add inline custom CSS with custom accent color if there is any set.
[103] Fix | Delete
*/
[104] Fix | Delete
function twentytwenty_infinity_accent_color_css() {
[105] Fix | Delete
$color_info = get_theme_mod( 'accent_accessible_colors' );
[106] Fix | Delete
[107] Fix | Delete
// Bail early if no custom color was set.
[108] Fix | Delete
if (
[109] Fix | Delete
'custom' !== get_theme_mod( 'accent_hue_active' )
[110] Fix | Delete
|| empty( $color_info )
[111] Fix | Delete
) {
[112] Fix | Delete
return;
[113] Fix | Delete
}
[114] Fix | Delete
[115] Fix | Delete
$custom_css = sprintf(
[116] Fix | Delete
'
[117] Fix | Delete
.infinite-scroll #site-content #infinite-handle span button,
[118] Fix | Delete
.infinite-scroll #site-content #infinite-handle span button:hover,
[119] Fix | Delete
.infinite-scroll #site-content #infinite-handle span button:focus {
[120] Fix | Delete
background: %1$s;
[121] Fix | Delete
color: %2$s;
[122] Fix | Delete
}
[123] Fix | Delete
#site-content .entry-content div.sharedaddy h3.sd-title,
[124] Fix | Delete
#site-content .entry-content h3.sd-title,
[125] Fix | Delete
#site-content .entry-content #jp-relatedposts h3.jp-relatedposts-headline {
[126] Fix | Delete
color: %3$s;
[127] Fix | Delete
}
[128] Fix | Delete
',
[129] Fix | Delete
$color_info['content']['accent'],
[130] Fix | Delete
$color_info['content']['background'] ?? '#fff',
[131] Fix | Delete
$color_info['content']['secondary']
[132] Fix | Delete
);
[133] Fix | Delete
[134] Fix | Delete
// Add our custom style to the existing Twenty Twenty CSS compat file.
[135] Fix | Delete
wp_add_inline_style( 'twentytwenty-jetpack', $custom_css );
[136] Fix | Delete
}
[137] Fix | Delete
add_action( 'wp_enqueue_scripts', 'twentytwenty_infinity_accent_color_css' );
[138] Fix | Delete
[139] Fix | Delete
/**
[140] Fix | Delete
* Load AMP theme specific hooks for infinite scroll.
[141] Fix | Delete
*
[142] Fix | Delete
* @return void
[143] Fix | Delete
*/
[144] Fix | Delete
function amp_twentytwenty_infinite_scroll_render_hooks() {
[145] Fix | Delete
add_filter( 'jetpack_amp_infinite_footers', 'twentytwenty_amp_infinite_footers', 10, 2 );
[146] Fix | Delete
add_filter( 'jetpack_amp_infinite_output', 'twentytwenty_amp_infinite_output' );
[147] Fix | Delete
add_filter( 'jetpack_amp_infinite_separator', 'twentytwenty_amp_infinite_separator' );
[148] Fix | Delete
add_filter( 'jetpack_amp_infinite_older_posts', 'twentytwenty_amp_infinite_older_posts' );
[149] Fix | Delete
}
[150] Fix | Delete
[151] Fix | Delete
/**
[152] Fix | Delete
* Get the theme specific footers.
[153] Fix | Delete
*
[154] Fix | Delete
* @param array $footers The footers of the themes.
[155] Fix | Delete
* @param string $buffer Contents of the output buffer.
[156] Fix | Delete
*
[157] Fix | Delete
* @return mixed
[158] Fix | Delete
*/
[159] Fix | Delete
function twentytwenty_amp_infinite_footers( $footers, $buffer ) {
[160] Fix | Delete
// Collect the footer wrapper.
[161] Fix | Delete
preg_match(
[162] Fix | Delete
'/<div class="footer-nav-widgets-wrapper.*<!-- .footer-nav-widgets-wrapper -->/s',
[163] Fix | Delete
$buffer,
[164] Fix | Delete
$footer
[165] Fix | Delete
);
[166] Fix | Delete
$footers[] = reset( $footer );
[167] Fix | Delete
[168] Fix | Delete
// Collect the footer wrapper.
[169] Fix | Delete
preg_match(
[170] Fix | Delete
'/<footer id="site-footer".*<!-- #site-footer -->/s',
[171] Fix | Delete
$buffer,
[172] Fix | Delete
$footer
[173] Fix | Delete
);
[174] Fix | Delete
$footers[] = reset( $footer );
[175] Fix | Delete
[176] Fix | Delete
return $footers;
[177] Fix | Delete
}
[178] Fix | Delete
[179] Fix | Delete
/**
[180] Fix | Delete
* Hide and remove various elements from next page load.
[181] Fix | Delete
*
[182] Fix | Delete
* @param string $buffer Contents of the output buffer.
[183] Fix | Delete
*
[184] Fix | Delete
* @return string
[185] Fix | Delete
*/
[186] Fix | Delete
function twentytwenty_amp_infinite_output( $buffer ) {
[187] Fix | Delete
// Hide site header on next page load.
[188] Fix | Delete
$buffer = preg_replace(
[189] Fix | Delete
'/id="site-header"/',
[190] Fix | Delete
'$0 next-page-hide',
[191] Fix | Delete
$buffer
[192] Fix | Delete
);
[193] Fix | Delete
[194] Fix | Delete
// Hide pagination on next page load.
[195] Fix | Delete
$buffer = preg_replace(
[196] Fix | Delete
'/class=".*pagination-wrapper.*"/',
[197] Fix | Delete
'$0 next-page-hide hidden',
[198] Fix | Delete
$buffer
[199] Fix | Delete
);
[200] Fix | Delete
[201] Fix | Delete
// Remove the footer as it will be added back to amp next page footer.
[202] Fix | Delete
$buffer = preg_replace(
[203] Fix | Delete
'/<div class="footer-nav-widgets-wrapper.*<!-- .footer-nav-widgets-wrapper -->/s',
[204] Fix | Delete
'',
[205] Fix | Delete
$buffer
[206] Fix | Delete
);
[207] Fix | Delete
[208] Fix | Delete
// Remove the footer as it will be added back to amp next page footer.
[209] Fix | Delete
$buffer = preg_replace(
[210] Fix | Delete
'/<footer id="site-footer".*<!-- #site-footer -->/s',
[211] Fix | Delete
'',
[212] Fix | Delete
$buffer
[213] Fix | Delete
);
[214] Fix | Delete
[215] Fix | Delete
return $buffer;
[216] Fix | Delete
}
[217] Fix | Delete
[218] Fix | Delete
/**
[219] Fix | Delete
* Filter the AMP infinite scroll separator
[220] Fix | Delete
*
[221] Fix | Delete
* @return string
[222] Fix | Delete
*/
[223] Fix | Delete
function twentytwenty_amp_infinite_separator() {
[224] Fix | Delete
ob_start();
[225] Fix | Delete
?>
[226] Fix | Delete
<hr class="post-separator styled-separator is-style-wide section-inner" aria-hidden="true">
[227] Fix | Delete
<?php
[228] Fix | Delete
return ob_get_clean();
[229] Fix | Delete
}
[230] Fix | Delete
[231] Fix | Delete
/**
[232] Fix | Delete
* Filter the AMP infinite scroll older posts button
[233] Fix | Delete
*
[234] Fix | Delete
* @return string
[235] Fix | Delete
*/
[236] Fix | Delete
function twentytwenty_amp_infinite_older_posts() {
[237] Fix | Delete
ob_start();
[238] Fix | Delete
?>
[239] Fix | Delete
<div id="infinite-handle" class="read-more-button-wrap">
[240] Fix | Delete
<span>
[241] Fix | Delete
<a href="{{url}}" class="more-link" rel="amphtml">
[242] Fix | Delete
<span class="faux-button">
[243] Fix | Delete
<?php esc_html_e( 'Older posts', 'jetpack' ); ?>
[244] Fix | Delete
</span>
[245] Fix | Delete
</a>
[246] Fix | Delete
</span>
[247] Fix | Delete
</div>
[248] Fix | Delete
<?php
[249] Fix | Delete
return ob_get_clean();
[250] Fix | Delete
}
[251] Fix | Delete
[252] Fix | Delete
[253] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function