Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/jetpack/modules/sitemaps
File: sitemap-state.php
<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
[0] Fix | Delete
/**
[1] Fix | Delete
* Abstract sitemap generation state class.
[2] Fix | Delete
*
[3] Fix | Delete
* @package automattic/jetpack
[4] Fix | Delete
* @since 4.8.0
[5] Fix | Delete
* @author Automattic
[6] Fix | Delete
*/
[7] Fix | Delete
[8] Fix | Delete
if ( ! defined( 'ABSPATH' ) ) {
[9] Fix | Delete
exit( 0 );
[10] Fix | Delete
}
[11] Fix | Delete
[12] Fix | Delete
/* Include standard constants and librarian. */
[13] Fix | Delete
require_once __DIR__ . '/sitemap-constants.php';
[14] Fix | Delete
require_once __DIR__ . '/sitemap-librarian.php';
[15] Fix | Delete
[16] Fix | Delete
if ( defined( 'WP_DEBUG' ) && ( true === WP_DEBUG ) ) {
[17] Fix | Delete
require_once __DIR__ . '/sitemap-logger.php';
[18] Fix | Delete
}
[19] Fix | Delete
[20] Fix | Delete
/**
[21] Fix | Delete
* This class provides an interface for storing and retrieving
[22] Fix | Delete
* the state of a sitemap generation phase. Whenever the builder
[23] Fix | Delete
* wants to build a new sitemap page, it uses this class to see
[24] Fix | Delete
* what the current state of the sitemap is. The lock is stored
[25] Fix | Delete
* as a transient with max lifetime of 15 minutes; this way if our
[26] Fix | Delete
* builder times out before unlocking the state, the lock will expire
[27] Fix | Delete
* before the builder tries again.
[28] Fix | Delete
*
[29] Fix | Delete
* @since 4.8.0
[30] Fix | Delete
*/
[31] Fix | Delete
class Jetpack_Sitemap_State {
[32] Fix | Delete
[33] Fix | Delete
/**
[34] Fix | Delete
* Initial state for the sitemap generator.
[35] Fix | Delete
*
[36] Fix | Delete
* @access public
[37] Fix | Delete
* @since 4.8.0
[38] Fix | Delete
*
[39] Fix | Delete
* @param string $type The initial sitemap type.
[40] Fix | Delete
*
[41] Fix | Delete
* @return array $args {
[42] Fix | Delete
* @type string sitemap-type The type of sitemap to be generated.
[43] Fix | Delete
* @type int last-added The largest index to be added to a generated sitemap page.
[44] Fix | Delete
* @type int number The index of the last sitemap to be generated.
[45] Fix | Delete
* @type string last-modified The latest timestamp seen.
[46] Fix | Delete
* @type array max The latest index of each sitemap type seen.
[47] Fix | Delete
* }
[48] Fix | Delete
*/
[49] Fix | Delete
private static function initial( $type = JP_PAGE_SITEMAP_TYPE ) {
[50] Fix | Delete
return array(
[51] Fix | Delete
'sitemap-type' => $type,
[52] Fix | Delete
'last-added' => 0,
[53] Fix | Delete
'number' => 0,
[54] Fix | Delete
'last-modified' => '1970-01-01 00:00:00',
[55] Fix | Delete
'max' => array(),
[56] Fix | Delete
);
[57] Fix | Delete
}
[58] Fix | Delete
[59] Fix | Delete
/**
[60] Fix | Delete
* Reset the sitemap state.
[61] Fix | Delete
*
[62] Fix | Delete
* @param string $type The initial sitemap type.
[63] Fix | Delete
*
[64] Fix | Delete
* @access public
[65] Fix | Delete
* @since 4.8.0
[66] Fix | Delete
*/
[67] Fix | Delete
public static function reset( $type ) {
[68] Fix | Delete
delete_transient( 'jetpack-sitemap-state-lock' );
[69] Fix | Delete
update_option(
[70] Fix | Delete
'jetpack-sitemap-state',
[71] Fix | Delete
self::initial( $type )
[72] Fix | Delete
);
[73] Fix | Delete
}
[74] Fix | Delete
[75] Fix | Delete
/**
[76] Fix | Delete
* Store a sitemap state, and unlock it.
[77] Fix | Delete
*
[78] Fix | Delete
* @access public
[79] Fix | Delete
* @since 4.8.0
[80] Fix | Delete
*
[81] Fix | Delete
* @param array $state Array of the Sitemap state details.
[82] Fix | Delete
* @type string sitemap-type The type of sitemap to be generated.
[83] Fix | Delete
* @type int last-added The largest index to be added to a generated sitemap page.
[84] Fix | Delete
* @type int number The index of the last sitemap to be generated.
[85] Fix | Delete
* @type string last-modified The latest timestamp seen.
[86] Fix | Delete
*/
[87] Fix | Delete
public static function check_in( $state ) {
[88] Fix | Delete
// Get the old max value.
[89] Fix | Delete
$sitemap_old = get_option( 'jetpack-sitemap-state', self::initial() );
[90] Fix | Delete
$state['max'] = $sitemap_old['max'];
[91] Fix | Delete
[92] Fix | Delete
// Update the max value of the current type.
[93] Fix | Delete
$state['max'][ $state['sitemap-type'] ]['number'] = $state['number'];
[94] Fix | Delete
$state['max'][ $state['sitemap-type'] ]['lastmod'] = $state['last-modified'];
[95] Fix | Delete
[96] Fix | Delete
update_option( 'jetpack-sitemap-state', $state );
[97] Fix | Delete
}
[98] Fix | Delete
[99] Fix | Delete
/**
[100] Fix | Delete
* Unlock the sitemap state.
[101] Fix | Delete
*
[102] Fix | Delete
* @access public
[103] Fix | Delete
* @since 4.8.0
[104] Fix | Delete
*/
[105] Fix | Delete
public static function unlock() {
[106] Fix | Delete
delete_transient( 'jetpack-sitemap-state-lock' );
[107] Fix | Delete
}
[108] Fix | Delete
[109] Fix | Delete
/**
[110] Fix | Delete
* Read the stored sitemap state. Returns false if the state is locked.
[111] Fix | Delete
*
[112] Fix | Delete
* @access public
[113] Fix | Delete
* @since 4.8.0
[114] Fix | Delete
*
[115] Fix | Delete
* @return bool|array $args {
[116] Fix | Delete
* @type string sitemap-type The type of sitemap to be generated.
[117] Fix | Delete
* @type int last-added The largest index to be added to a generated sitemap page.
[118] Fix | Delete
* @type int number The index of the last sitemap to be generated.
[119] Fix | Delete
* @type string last-modified The latest timestamp seen.
[120] Fix | Delete
* @type array max The latest index of each sitemap type seen.
[121] Fix | Delete
* }
[122] Fix | Delete
*/
[123] Fix | Delete
public static function check_out() {
[124] Fix | Delete
// See if the state is locked.
[125] Fix | Delete
if ( true === get_transient( 'jetpack-sitemap-state-lock' ) ) {
[126] Fix | Delete
// If it is, return false.
[127] Fix | Delete
return false;
[128] Fix | Delete
} else {
[129] Fix | Delete
// Otherwise, lock the state for 15 minutes and then return it.
[130] Fix | Delete
set_transient( 'jetpack-sitemap-state-lock', true, JP_SITEMAP_LOCK_INTERVAL );
[131] Fix | Delete
return get_option( 'jetpack-sitemap-state', self::initial() );
[132] Fix | Delete
}
[133] Fix | Delete
}
[134] Fix | Delete
[135] Fix | Delete
/**
[136] Fix | Delete
* Delete the stored state and lock.
[137] Fix | Delete
*
[138] Fix | Delete
* @access public
[139] Fix | Delete
* @since 4.8.0
[140] Fix | Delete
*/
[141] Fix | Delete
public static function delete() {
[142] Fix | Delete
delete_transient( 'jetpack-sitemap-state-lock' );
[143] Fix | Delete
delete_option( 'jetpack-sitemap-state' );
[144] Fix | Delete
}
[145] Fix | Delete
}
[146] Fix | Delete
[147] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function