Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/jetpack/modules/infinite...
File: infinity.php
<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
[0] Fix | Delete
[1] Fix | Delete
// phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed -- TODO: Move classes to appropriately-named class files.
[2] Fix | Delete
[3] Fix | Delete
use Automattic\Jetpack\Assets;
[4] Fix | Delete
[5] Fix | Delete
/*
[6] Fix | Delete
Plugin Name: The Neverending Home Page.
[7] Fix | Delete
Plugin URI: https://automattic.com/
[8] Fix | Delete
Description: Adds infinite scrolling support to the front-end blog post view for themes, pulling the next set of posts automatically into view when the reader approaches the bottom of the page.
[9] Fix | Delete
Version: 1.1
[10] Fix | Delete
Author: Automattic
[11] Fix | Delete
Author URI: https://automattic.com/
[12] Fix | Delete
License: GNU General Public License v2 or later
[13] Fix | Delete
License URI: https://www.gnu.org/licenses/gpl-2.0.html
[14] Fix | Delete
Text Domain: jetpack
[15] Fix | Delete
*/
[16] Fix | Delete
[17] Fix | Delete
/**
[18] Fix | Delete
* Class: The_Neverending_Home_Page relies on add_theme_support, expects specific
[19] Fix | Delete
* styling from each theme; including fixed footer.
[20] Fix | Delete
*
[21] Fix | Delete
* @phan-constructor-used-for-side-effects
[22] Fix | Delete
*/
[23] Fix | Delete
class The_Neverending_Home_Page {
[24] Fix | Delete
/**
[25] Fix | Delete
* Maximum allowed number of posts per page in $_REQUEST.
[26] Fix | Delete
*/
[27] Fix | Delete
const MAX_ALLOWED_POSTS_PER_PAGE_ΙΝ_REQUEST = 5000;
[28] Fix | Delete
[29] Fix | Delete
/**
[30] Fix | Delete
* Register actions and filters, plus parse IS settings
[31] Fix | Delete
*
[32] Fix | Delete
* @uses add_action, add_filter, self::get_settings
[33] Fix | Delete
*/
[34] Fix | Delete
public function __construct() {
[35] Fix | Delete
add_action( 'pre_get_posts', array( $this, 'posts_per_page_query' ) );
[36] Fix | Delete
add_action( 'admin_init', array( $this, 'settings_api_init' ) );
[37] Fix | Delete
add_action( 'template_redirect', array( $this, 'action_template_redirect' ) );
[38] Fix | Delete
add_action( 'customize_preview_init', array( $this, 'init_customizer_assets' ) );
[39] Fix | Delete
add_action( 'template_redirect', array( $this, 'ajax_response' ) );
[40] Fix | Delete
add_action( 'custom_ajax_infinite_scroll', array( $this, 'query' ) );
[41] Fix | Delete
add_filter( 'infinite_scroll_query_args', array( $this, 'inject_query_args' ) );
[42] Fix | Delete
add_filter( 'infinite_scroll_allowed_vars', array( $this, 'allowed_query_vars' ) );
[43] Fix | Delete
add_action( 'the_post', array( $this, 'preserve_more_tag' ) );
[44] Fix | Delete
add_action( 'wp_footer', array( $this, 'footer' ) );
[45] Fix | Delete
add_filter( 'infinite_scroll_additional_scripts', array( $this, 'add_mejs_config' ) );
[46] Fix | Delete
[47] Fix | Delete
// Plugin compatibility
[48] Fix | Delete
add_filter( 'grunion_contact_form_redirect_url', array( $this, 'filter_grunion_redirect_url' ) );
[49] Fix | Delete
[50] Fix | Delete
// AMP compatibility
[51] Fix | Delete
// needs to happen after parse_query so that Jetpack_AMP_Support::is_amp_request() is ready.
[52] Fix | Delete
add_action( 'wp', array( $this, 'amp_load_hooks' ) );
[53] Fix | Delete
[54] Fix | Delete
// Parse IS settings from theme
[55] Fix | Delete
self::get_settings();
[56] Fix | Delete
}
[57] Fix | Delete
[58] Fix | Delete
/**
[59] Fix | Delete
* Initialize our static variables
[60] Fix | Delete
*/
[61] Fix | Delete
[62] Fix | Delete
/**
[63] Fix | Delete
* The time.
[64] Fix | Delete
*
[65] Fix | Delete
* @var null - I don't think this is used?
[66] Fix | Delete
*/
[67] Fix | Delete
public static $the_time = null;
[68] Fix | Delete
[69] Fix | Delete
/**
[70] Fix | Delete
* Settings.
[71] Fix | Delete
*
[72] Fix | Delete
* Don't access directly, instead use self::get_settings().
[73] Fix | Delete
*
[74] Fix | Delete
* @var array
[75] Fix | Delete
*/
[76] Fix | Delete
public static $settings = null;
[77] Fix | Delete
[78] Fix | Delete
/**
[79] Fix | Delete
* The enabled option name.
[80] Fix | Delete
*
[81] Fix | Delete
* @var string
[82] Fix | Delete
*/
[83] Fix | Delete
public static $option_name_enabled = 'infinite_scroll';
[84] Fix | Delete
[85] Fix | Delete
/**
[86] Fix | Delete
* Parse IS settings provided by theme
[87] Fix | Delete
*
[88] Fix | Delete
* @uses get_theme_support, infinite_scroll_has_footer_widgets, sanitize_title, add_action, get_option, wp_parse_args, is_active_sidebar
[89] Fix | Delete
* @return object
[90] Fix | Delete
*/
[91] Fix | Delete
public static function get_settings() {
[92] Fix | Delete
$defaults = array(
[93] Fix | Delete
'type' => 'scroll', // scroll | click
[94] Fix | Delete
'requested_type' => 'scroll', // store the original type for use when logic overrides it
[95] Fix | Delete
'footer_widgets' => false, // true | false | sidebar_id | array of sidebar_ids -- last two are checked with is_active_sidebar
[96] Fix | Delete
'container' => 'content', // container html id
[97] Fix | Delete
'wrapper' => true, // true | false | html class -- the html class.
[98] Fix | Delete
'render' => false, // optional function, otherwise the `content` template part will be used
[99] Fix | Delete
'footer' => true, // boolean to enable or disable the infinite footer | string to provide an html id to derive footer width from
[100] Fix | Delete
'footer_callback' => false, // function to be called to render the IS footer, in place of the default
[101] Fix | Delete
'posts_per_page' => false, // phpcs:ignore WordPress.WP.PostsPerPage.posts_per_page_posts_per_page -- int | false to set based on IS type
[102] Fix | Delete
'click_handle' => true, // boolean to enable or disable rendering the click handler div. If type is click and this is false, page must include its own trigger with the HTML ID `infinite-handle`.
[103] Fix | Delete
);
[104] Fix | Delete
[105] Fix | Delete
if ( self::$settings === null ) {
[106] Fix | Delete
$css_pattern = '#[^A-Z\d\-_]#i';
[107] Fix | Delete
[108] Fix | Delete
$settings = $defaults;
[109] Fix | Delete
// Validate settings passed through add_theme_support()
[110] Fix | Delete
$_settings = get_theme_support( 'infinite-scroll' );
[111] Fix | Delete
[112] Fix | Delete
if ( is_array( $_settings ) ) {
[113] Fix | Delete
// Preferred implementation, where theme provides an array of options
[114] Fix | Delete
if ( isset( $_settings[0] ) && is_array( $_settings[0] ) ) {
[115] Fix | Delete
foreach ( $_settings[0] as $key => $value ) {
[116] Fix | Delete
switch ( $key ) {
[117] Fix | Delete
case 'type':
[118] Fix | Delete
if ( in_array( $value, array( 'scroll', 'click' ), true ) ) {
[119] Fix | Delete
$settings['requested_type'] = $value;
[120] Fix | Delete
$settings[ $key ] = $settings['requested_type'];
[121] Fix | Delete
}
[122] Fix | Delete
[123] Fix | Delete
break;
[124] Fix | Delete
[125] Fix | Delete
case 'footer_widgets':
[126] Fix | Delete
if ( is_string( $value ) ) {
[127] Fix | Delete
$settings[ $key ] = sanitize_title( $value );
[128] Fix | Delete
} elseif ( is_array( $value ) ) {
[129] Fix | Delete
$settings[ $key ] = array_map( 'sanitize_title', $value );
[130] Fix | Delete
} elseif ( is_bool( $value ) ) {
[131] Fix | Delete
$settings[ $key ] = $value;
[132] Fix | Delete
}
[133] Fix | Delete
[134] Fix | Delete
break;
[135] Fix | Delete
[136] Fix | Delete
case 'container':
[137] Fix | Delete
case 'wrapper':
[138] Fix | Delete
if ( 'wrapper' === $key && is_bool( $value ) ) {
[139] Fix | Delete
$settings[ $key ] = $value;
[140] Fix | Delete
} else {
[141] Fix | Delete
$value = preg_replace( $css_pattern, '', $value );
[142] Fix | Delete
[143] Fix | Delete
if ( ! empty( $value ) ) {
[144] Fix | Delete
$settings[ $key ] = $value;
[145] Fix | Delete
}
[146] Fix | Delete
}
[147] Fix | Delete
[148] Fix | Delete
break;
[149] Fix | Delete
[150] Fix | Delete
case 'render':
[151] Fix | Delete
if ( false !== $value && is_callable( $value ) ) {
[152] Fix | Delete
$settings[ $key ] = $value;
[153] Fix | Delete
}
[154] Fix | Delete
[155] Fix | Delete
break;
[156] Fix | Delete
[157] Fix | Delete
case 'footer':
[158] Fix | Delete
if ( is_bool( $value ) ) {
[159] Fix | Delete
$settings[ $key ] = $value;
[160] Fix | Delete
} elseif ( is_string( $value ) ) {
[161] Fix | Delete
$value = preg_replace( $css_pattern, '', $value );
[162] Fix | Delete
[163] Fix | Delete
if ( ! empty( $value ) ) {
[164] Fix | Delete
$settings[ $key ] = $value;
[165] Fix | Delete
}
[166] Fix | Delete
}
[167] Fix | Delete
[168] Fix | Delete
break;
[169] Fix | Delete
[170] Fix | Delete
case 'footer_callback':
[171] Fix | Delete
if ( is_callable( $value ) ) {
[172] Fix | Delete
$settings[ $key ] = $value;
[173] Fix | Delete
} else {
[174] Fix | Delete
$settings[ $key ] = false;
[175] Fix | Delete
}
[176] Fix | Delete
[177] Fix | Delete
break;
[178] Fix | Delete
[179] Fix | Delete
case 'posts_per_page':
[180] Fix | Delete
if ( is_numeric( $value ) ) {
[181] Fix | Delete
$settings[ $key ] = (int) $value;
[182] Fix | Delete
}
[183] Fix | Delete
[184] Fix | Delete
break;
[185] Fix | Delete
[186] Fix | Delete
case 'click_handle':
[187] Fix | Delete
if ( is_bool( $value ) ) {
[188] Fix | Delete
$settings[ $key ] = $value;
[189] Fix | Delete
}
[190] Fix | Delete
[191] Fix | Delete
break;
[192] Fix | Delete
[193] Fix | Delete
default:
[194] Fix | Delete
break;
[195] Fix | Delete
}
[196] Fix | Delete
}
[197] Fix | Delete
} elseif ( is_string( $_settings[0] ) ) {
[198] Fix | Delete
// Checks below are for backwards compatibility
[199] Fix | Delete
[200] Fix | Delete
// Container to append new posts to
[201] Fix | Delete
$settings['container'] = preg_replace( $css_pattern, '', $_settings[0] );
[202] Fix | Delete
[203] Fix | Delete
// Wrap IS elements?
[204] Fix | Delete
if ( isset( $_settings[1] ) ) {
[205] Fix | Delete
$settings['wrapper'] = (bool) $_settings[1];
[206] Fix | Delete
}
[207] Fix | Delete
}
[208] Fix | Delete
}
[209] Fix | Delete
[210] Fix | Delete
// Always ensure all values are present in the final array
[211] Fix | Delete
$settings = wp_parse_args( $settings, $defaults );
[212] Fix | Delete
[213] Fix | Delete
// Check if a legacy `infinite_scroll_has_footer_widgets()` function is defined and override the footer_widgets parameter's value.
[214] Fix | Delete
// Otherwise, if a widget area ID or array of IDs was provided in the footer_widgets parameter, check if any contains any widgets.
[215] Fix | Delete
// It is safe to use `is_active_sidebar()` before the sidebar is registered as this function doesn't check for a sidebar's existence when determining if it contains any widgets.
[216] Fix | Delete
if ( function_exists( 'infinite_scroll_has_footer_widgets' ) ) {
[217] Fix | Delete
// @phan-suppress-next-line PhanUndeclaredFunction -- Checked above. See also https://github.com/phan/phan/issues/1204.
[218] Fix | Delete
$settings['footer_widgets'] = (bool) infinite_scroll_has_footer_widgets();
[219] Fix | Delete
} elseif ( is_array( $settings['footer_widgets'] ) ) {
[220] Fix | Delete
$sidebar_ids = $settings['footer_widgets'];
[221] Fix | Delete
$settings['footer_widgets'] = false;
[222] Fix | Delete
[223] Fix | Delete
foreach ( $sidebar_ids as $sidebar_id ) {
[224] Fix | Delete
if ( is_active_sidebar( $sidebar_id ) ) {
[225] Fix | Delete
$settings['footer_widgets'] = true;
[226] Fix | Delete
break;
[227] Fix | Delete
}
[228] Fix | Delete
}
[229] Fix | Delete
[230] Fix | Delete
unset( $sidebar_ids );
[231] Fix | Delete
unset( $sidebar_id );
[232] Fix | Delete
} elseif ( is_string( $settings['footer_widgets'] ) ) {
[233] Fix | Delete
$settings['footer_widgets'] = (bool) is_active_sidebar( $settings['footer_widgets'] );
[234] Fix | Delete
}
[235] Fix | Delete
[236] Fix | Delete
/**
[237] Fix | Delete
* Filter Infinite Scroll's `footer_widgets` parameter.
[238] Fix | Delete
*
[239] Fix | Delete
* @module infinite-scroll
[240] Fix | Delete
*
[241] Fix | Delete
* @since 2.0.0
[242] Fix | Delete
*
[243] Fix | Delete
* @param bool $settings['footer_widgets'] Does the current theme have Footer Widgets.
[244] Fix | Delete
*/
[245] Fix | Delete
$settings['footer_widgets'] = apply_filters( 'infinite_scroll_has_footer_widgets', $settings['footer_widgets'] );
[246] Fix | Delete
[247] Fix | Delete
// Finally, after all of the sidebar checks and filtering, ensure that a boolean value is present, otherwise set to default of `false`.
[248] Fix | Delete
if ( ! is_bool( $settings['footer_widgets'] ) ) {
[249] Fix | Delete
$settings['footer_widgets'] = false;
[250] Fix | Delete
}
[251] Fix | Delete
[252] Fix | Delete
// Ensure that IS is enabled and no footer widgets exist if the IS type isn't already "click".
[253] Fix | Delete
if ( 'click' !== $settings['type'] ) {
[254] Fix | Delete
// Check the setting status
[255] Fix | Delete
$disabled = '' === get_option( self::$option_name_enabled ) ? true : false;
[256] Fix | Delete
[257] Fix | Delete
// Footer content or Reading option check
[258] Fix | Delete
if ( $settings['footer_widgets'] || $disabled ) {
[259] Fix | Delete
$settings['type'] = 'click';
[260] Fix | Delete
}
[261] Fix | Delete
}
[262] Fix | Delete
[263] Fix | Delete
// Force display of the click handler and attendant bits when the type isn't `click`
[264] Fix | Delete
if ( 'click' !== $settings['type'] ) {
[265] Fix | Delete
$settings['click_handle'] = true;
[266] Fix | Delete
}
[267] Fix | Delete
[268] Fix | Delete
// Store final settings in a class static to avoid reparsing
[269] Fix | Delete
self::$settings = $settings;
[270] Fix | Delete
}
[271] Fix | Delete
[272] Fix | Delete
/**
[273] Fix | Delete
* Filter the array of Infinite Scroll settings.
[274] Fix | Delete
*
[275] Fix | Delete
* @module infinite-scroll
[276] Fix | Delete
*
[277] Fix | Delete
* @since 2.0.0
[278] Fix | Delete
*
[279] Fix | Delete
* @param array $settings Array of Infinite Scroll settings.
[280] Fix | Delete
*/
[281] Fix | Delete
$filtered_settings = apply_filters( 'infinite_scroll_settings', self::$settings );
[282] Fix | Delete
[283] Fix | Delete
// Ensure all properties are still set.
[284] Fix | Delete
return (object) wp_parse_args( $filtered_settings, $defaults );
[285] Fix | Delete
}
[286] Fix | Delete
[287] Fix | Delete
/**
[288] Fix | Delete
* Number of posts per page.
[289] Fix | Delete
*
[290] Fix | Delete
* @uses self::wp_query, self::get_settings, apply_filters
[291] Fix | Delete
* @return int
[292] Fix | Delete
*/
[293] Fix | Delete
public static function posts_per_page() {
[294] Fix | Delete
$settings = self::get_settings();
[295] Fix | Delete
$posts_per_page = $settings->posts_per_page ? $settings->posts_per_page : self::wp_query()->get( 'posts_per_page' );
[296] Fix | Delete
$posts_per_page_core_option = get_option( 'posts_per_page' );
[297] Fix | Delete
[298] Fix | Delete
// If Infinite Scroll is set to click, and if the site owner changed posts_per_page, let's use that.
[299] Fix | Delete
if (
[300] Fix | Delete
'click' === $settings->type
[301] Fix | Delete
&& ( '10' !== $posts_per_page_core_option )
[302] Fix | Delete
) {
[303] Fix | Delete
$posts_per_page = $posts_per_page_core_option;
[304] Fix | Delete
}
[305] Fix | Delete
[306] Fix | Delete
// Take JS query into consideration here.
[307] Fix | Delete
$posts_per_page_in_request = isset( $_REQUEST['query_args']['posts_per_page'] ) ? (int) $_REQUEST['query_args']['posts_per_page'] : 0; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
[308] Fix | Delete
if ( $posts_per_page_in_request > 0 &&
[309] Fix | Delete
self::MAX_ALLOWED_POSTS_PER_PAGE_ΙΝ_REQUEST >= $posts_per_page_in_request
[310] Fix | Delete
) {
[311] Fix | Delete
$posts_per_page = $posts_per_page_in_request;
[312] Fix | Delete
}
[313] Fix | Delete
[314] Fix | Delete
/**
[315] Fix | Delete
* Filter the number of posts per page.
[316] Fix | Delete
*
[317] Fix | Delete
* @module infinite-scroll
[318] Fix | Delete
*
[319] Fix | Delete
* @since 6.0.0
[320] Fix | Delete
*
[321] Fix | Delete
* @param int $posts_per_page The number of posts to display per page.
[322] Fix | Delete
*/
[323] Fix | Delete
return (int) apply_filters( 'infinite_scroll_posts_per_page', $posts_per_page );
[324] Fix | Delete
}
[325] Fix | Delete
[326] Fix | Delete
/**
[327] Fix | Delete
* Retrieve the query used with Infinite Scroll
[328] Fix | Delete
*
[329] Fix | Delete
* @global $wp_the_query
[330] Fix | Delete
* @uses apply_filters
[331] Fix | Delete
* @return object
[332] Fix | Delete
*/
[333] Fix | Delete
public static function wp_query() {
[334] Fix | Delete
global $wp_the_query;
[335] Fix | Delete
/**
[336] Fix | Delete
* Filter the Infinite Scroll query object.
[337] Fix | Delete
*
[338] Fix | Delete
* @module infinite-scroll
[339] Fix | Delete
*
[340] Fix | Delete
* @since 2.2.1
[341] Fix | Delete
*
[342] Fix | Delete
* @param WP_Query $wp_the_query WP Query.
[343] Fix | Delete
*/
[344] Fix | Delete
return apply_filters( 'infinite_scroll_query_object', $wp_the_query );
[345] Fix | Delete
}
[346] Fix | Delete
[347] Fix | Delete
/**
[348] Fix | Delete
* Has infinite scroll been triggered?
[349] Fix | Delete
*/
[350] Fix | Delete
public static function got_infinity() {
[351] Fix | Delete
/**
[352] Fix | Delete
* Filter the parameter used to check if Infinite Scroll has been triggered.
[353] Fix | Delete
*
[354] Fix | Delete
* @module infinite-scroll
[355] Fix | Delete
*
[356] Fix | Delete
* @since 3.9.0
[357] Fix | Delete
*
[358] Fix | Delete
* @param bool isset( $_GET[ 'infinity' ] ) Return true if the "infinity" parameter is set.
[359] Fix | Delete
*/
[360] Fix | Delete
return apply_filters( 'infinite_scroll_got_infinity', isset( $_GET['infinity'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- no changes made to the site.
[361] Fix | Delete
}
[362] Fix | Delete
[363] Fix | Delete
/**
[364] Fix | Delete
* Is this guaranteed to be the last batch of posts?
[365] Fix | Delete
*/
[366] Fix | Delete
public static function is_last_batch() {
[367] Fix | Delete
/**
[368] Fix | Delete
* Override whether or not this is the last batch for a request
[369] Fix | Delete
*
[370] Fix | Delete
* @module infinite-scroll
[371] Fix | Delete
*
[372] Fix | Delete
* @since 4.8.0
[373] Fix | Delete
*
[374] Fix | Delete
* @param bool|null null Bool if value should be overridden, null to determine from query
[375] Fix | Delete
* @param object self::wp_query() WP_Query object for current request
[376] Fix | Delete
* @param object self::get_settings() Infinite Scroll settings
[377] Fix | Delete
*/
[378] Fix | Delete
$override = apply_filters( 'infinite_scroll_is_last_batch', null, self::wp_query(), self::get_settings() ); // phpcs:ignore WordPress.WP.ClassNameCase.Incorrect -- False positive.
[379] Fix | Delete
if ( is_bool( $override ) ) {
[380] Fix | Delete
return $override;
[381] Fix | Delete
}
[382] Fix | Delete
[383] Fix | Delete
$entries = (int) self::wp_query()->found_posts;
[384] Fix | Delete
$posts_per_page = self::posts_per_page();
[385] Fix | Delete
[386] Fix | Delete
// This is to cope with an issue in certain themes or setups where posts are returned but found_posts is 0.
[387] Fix | Delete
if ( 0 === $entries ) {
[388] Fix | Delete
return (bool) ( ! is_countable( self::wp_query()->posts ) || ( count( self::wp_query()->posts ) < $posts_per_page ) );
[389] Fix | Delete
}
[390] Fix | Delete
$paged = max( 1, (int) self::wp_query()->get( 'paged' ) );
[391] Fix | Delete
[392] Fix | Delete
// Are there enough posts for more than the first page?
[393] Fix | Delete
if ( $entries <= $posts_per_page ) {
[394] Fix | Delete
return true;
[395] Fix | Delete
}
[396] Fix | Delete
[397] Fix | Delete
// Calculate entries left after a certain number of pages
[398] Fix | Delete
if ( $paged && $paged > 1 ) {
[399] Fix | Delete
$entries -= $posts_per_page * $paged;
[400] Fix | Delete
}
[401] Fix | Delete
[402] Fix | Delete
// Are there some entries left to display?
[403] Fix | Delete
return $entries <= 0;
[404] Fix | Delete
}
[405] Fix | Delete
[406] Fix | Delete
/**
[407] Fix | Delete
* The more tag will be ignored by default if the blog page isn't our homepage.
[408] Fix | Delete
* Let's force the $more global to false.
[409] Fix | Delete
*
[410] Fix | Delete
* @param array $array - the_post array.
[411] Fix | Delete
* @return array
[412] Fix | Delete
*/
[413] Fix | Delete
public function preserve_more_tag( $array ) {
[414] Fix | Delete
global $more;
[415] Fix | Delete
[416] Fix | Delete
if ( self::got_infinity() ) {
[417] Fix | Delete
$more = 0; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited -- 0 = show content up to the more tag. Add more link.
[418] Fix | Delete
}
[419] Fix | Delete
[420] Fix | Delete
return $array;
[421] Fix | Delete
}
[422] Fix | Delete
[423] Fix | Delete
/**
[424] Fix | Delete
* Add a checkbox field to Settings > Reading
[425] Fix | Delete
* for enabling infinite scroll.
[426] Fix | Delete
*
[427] Fix | Delete
* Only show if the current theme supports infinity.
[428] Fix | Delete
*
[429] Fix | Delete
* @uses current_theme_supports, add_settings_field, __, register_setting
[430] Fix | Delete
* @action admin_init
[431] Fix | Delete
* @return null
[432] Fix | Delete
*/
[433] Fix | Delete
public function settings_api_init() {
[434] Fix | Delete
if ( ! current_theme_supports( 'infinite-scroll' ) ) {
[435] Fix | Delete
return;
[436] Fix | Delete
}
[437] Fix | Delete
[438] Fix | Delete
// Add the setting field [infinite_scroll] and place it in Settings > Reading
[439] Fix | Delete
add_settings_field( self::$option_name_enabled, '<span id="infinite-scroll-options">' . esc_html__( 'Infinite Scroll Behavior', 'jetpack' ) . '</span>', array( $this, 'infinite_setting_html' ), 'reading' );
[440] Fix | Delete
register_setting( 'reading', self::$option_name_enabled, 'esc_attr' );
[441] Fix | Delete
}
[442] Fix | Delete
[443] Fix | Delete
/**
[444] Fix | Delete
* HTML code to display a checkbox true/false option
[445] Fix | Delete
* for the infinite_scroll setting.
[446] Fix | Delete
*/
[447] Fix | Delete
public function infinite_setting_html() {
[448] Fix | Delete
$settings = self::get_settings();
[449] Fix | Delete
[450] Fix | Delete
// If the blog has footer widgets, show a notice instead of the checkbox
[451] Fix | Delete
if ( $settings->footer_widgets || 'click' === $settings->requested_type ) {
[452] Fix | Delete
echo '<label><em>' . esc_html__( 'We&rsquo;ve changed this option to a click-to-scroll version for you since you have footer widgets in Appearance &rarr; Widgets, or your theme uses click-to-scroll as the default behavior.', 'jetpack' ) . '</em></label>';
[453] Fix | Delete
} else {
[454] Fix | Delete
echo '<label><input name="infinite_scroll" type="checkbox" value="1" ' . checked( 1, '' !== get_option( self::$option_name_enabled ), false ) . ' /> ' . esc_html__( 'Check to load posts as you scroll. Uncheck to show clickable button to load posts', 'jetpack' ) . '</label>';
[455] Fix | Delete
// translators: the number of posts to show on each page load.
[456] Fix | Delete
echo '<p class="description">' . esc_html( sprintf( _n( 'Shows %s post on each load.', 'Shows %s posts on each load.', self::posts_per_page(), 'jetpack' ), number_format_i18n( self::posts_per_page() ) ) ) . '</p>';
[457] Fix | Delete
}
[458] Fix | Delete
}
[459] Fix | Delete
[460] Fix | Delete
/**
[461] Fix | Delete
* Does the legwork to determine whether the feature is enabled.
[462] Fix | Delete
*
[463] Fix | Delete
* @uses current_theme_supports, self::archive_supports_infinity, self::get_settings, add_filter, wp_enqueue_script, plugins_url, wp_enqueue_style, add_action
[464] Fix | Delete
* @action template_redirect
[465] Fix | Delete
* @return null
[466] Fix | Delete
*/
[467] Fix | Delete
public function action_template_redirect() {
[468] Fix | Delete
// Check that we support infinite scroll, and are on the home page.
[469] Fix | Delete
if ( ! current_theme_supports( 'infinite-scroll' ) || ! self::archive_supports_infinity() ) {
[470] Fix | Delete
return;
[471] Fix | Delete
}
[472] Fix | Delete
[473] Fix | Delete
$id = self::get_settings()->container;
[474] Fix | Delete
[475] Fix | Delete
// Check that we have an id.
[476] Fix | Delete
if ( empty( $id ) ) {
[477] Fix | Delete
return;
[478] Fix | Delete
}
[479] Fix | Delete
[480] Fix | Delete
// AMP infinite scroll functionality will start on amp_load_hooks().
[481] Fix | Delete
if ( class_exists( 'Jetpack_AMP_Support' ) && Jetpack_AMP_Support::is_amp_request() ) {
[482] Fix | Delete
return;
[483] Fix | Delete
}
[484] Fix | Delete
[485] Fix | Delete
// Add our scripts.
[486] Fix | Delete
wp_register_script(
[487] Fix | Delete
'the-neverending-homepage',
[488] Fix | Delete
Assets::get_file_url_for_environment(
[489] Fix | Delete
'_inc/build/infinite-scroll/infinity.min.js',
[490] Fix | Delete
'modules/infinite-scroll/infinity.js'
[491] Fix | Delete
),
[492] Fix | Delete
array(),
[493] Fix | Delete
JETPACK__VERSION . '-is5.0.1', // Added for ability to cachebust on WP.com.
[494] Fix | Delete
true
[495] Fix | Delete
);
[496] Fix | Delete
[497] Fix | Delete
// Add our default styles.
[498] Fix | Delete
wp_register_style( 'the-neverending-homepage', plugins_url( 'infinity.css', __FILE__ ), array(), '20140422' );
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function