Edit File by line
/home/barbar84/www/wp-inclu...
File: sitemaps.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Sitemaps: Public functions
[2] Fix | Delete
*
[3] Fix | Delete
* This file contains a variety of public functions developers can use to interact with
[4] Fix | Delete
* the XML Sitemaps API.
[5] Fix | Delete
*
[6] Fix | Delete
* @package WordPress
[7] Fix | Delete
* @subpackage Sitemaps
[8] Fix | Delete
* @since 5.5.0
[9] Fix | Delete
*/
[10] Fix | Delete
[11] Fix | Delete
/**
[12] Fix | Delete
* Retrieves the current Sitemaps server instance.
[13] Fix | Delete
*
[14] Fix | Delete
* @since 5.5.0
[15] Fix | Delete
*
[16] Fix | Delete
* @global WP_Sitemaps $wp_sitemaps Global Core Sitemaps instance.
[17] Fix | Delete
*
[18] Fix | Delete
* @return WP_Sitemaps Sitemaps instance.
[19] Fix | Delete
*/
[20] Fix | Delete
function wp_sitemaps_get_server() {
[21] Fix | Delete
global $wp_sitemaps;
[22] Fix | Delete
[23] Fix | Delete
// If there isn't a global instance, set and bootstrap the sitemaps system.
[24] Fix | Delete
if ( empty( $wp_sitemaps ) ) {
[25] Fix | Delete
$wp_sitemaps = new WP_Sitemaps();
[26] Fix | Delete
$wp_sitemaps->init();
[27] Fix | Delete
[28] Fix | Delete
/**
[29] Fix | Delete
* Fires when initializing the Sitemaps object.
[30] Fix | Delete
*
[31] Fix | Delete
* Additional sitemaps should be registered on this hook.
[32] Fix | Delete
*
[33] Fix | Delete
* @since 5.5.0
[34] Fix | Delete
*
[35] Fix | Delete
* @param WP_Sitemaps $wp_sitemaps Sitemaps object.
[36] Fix | Delete
*/
[37] Fix | Delete
do_action( 'wp_sitemaps_init', $wp_sitemaps );
[38] Fix | Delete
}
[39] Fix | Delete
[40] Fix | Delete
return $wp_sitemaps;
[41] Fix | Delete
}
[42] Fix | Delete
[43] Fix | Delete
/**
[44] Fix | Delete
* Gets an array of sitemap providers.
[45] Fix | Delete
*
[46] Fix | Delete
* @since 5.5.0
[47] Fix | Delete
*
[48] Fix | Delete
* @return WP_Sitemaps_Provider[] Array of sitemap providers.
[49] Fix | Delete
*/
[50] Fix | Delete
function wp_get_sitemap_providers() {
[51] Fix | Delete
$sitemaps = wp_sitemaps_get_server();
[52] Fix | Delete
return $sitemaps->registry->get_providers();
[53] Fix | Delete
}
[54] Fix | Delete
[55] Fix | Delete
/**
[56] Fix | Delete
* Registers a new sitemap provider.
[57] Fix | Delete
*
[58] Fix | Delete
* @since 5.5.0
[59] Fix | Delete
*
[60] Fix | Delete
* @param string $name Unique name for the sitemap provider.
[61] Fix | Delete
* @param WP_Sitemaps_Provider $provider The `Sitemaps_Provider` instance implementing the sitemap.
[62] Fix | Delete
* @return bool Whether the sitemap was added.
[63] Fix | Delete
*/
[64] Fix | Delete
function wp_register_sitemap_provider( $name, WP_Sitemaps_Provider $provider ) {
[65] Fix | Delete
$sitemaps = wp_sitemaps_get_server();
[66] Fix | Delete
return $sitemaps->registry->add_provider( $name, $provider );
[67] Fix | Delete
}
[68] Fix | Delete
[69] Fix | Delete
/**
[70] Fix | Delete
* Gets the maximum number of URLs for a sitemap.
[71] Fix | Delete
*
[72] Fix | Delete
* @since 5.5.0
[73] Fix | Delete
*
[74] Fix | Delete
* @param string $object_type Object type for sitemap to be filtered (e.g. 'post', 'term', 'user').
[75] Fix | Delete
* @return int The maximum number of URLs.
[76] Fix | Delete
*/
[77] Fix | Delete
function wp_sitemaps_get_max_urls( $object_type ) {
[78] Fix | Delete
/**
[79] Fix | Delete
* Filters the maximum number of URLs displayed on a sitemap.
[80] Fix | Delete
*
[81] Fix | Delete
* @since 5.5.0
[82] Fix | Delete
*
[83] Fix | Delete
* @param int $max_urls The maximum number of URLs included in a sitemap. Default 2000.
[84] Fix | Delete
* @param string $object_type Object type for sitemap to be filtered (e.g. 'post', 'term', 'user').
[85] Fix | Delete
*/
[86] Fix | Delete
return apply_filters( 'wp_sitemaps_max_urls', 2000, $object_type );
[87] Fix | Delete
}
[88] Fix | Delete
[89] Fix | Delete
/**
[90] Fix | Delete
* Retrieves the full URL for a sitemap.
[91] Fix | Delete
*
[92] Fix | Delete
* @since 5.5.1
[93] Fix | Delete
*
[94] Fix | Delete
* @param string $name The sitemap name.
[95] Fix | Delete
* @param string $subtype_name The sitemap subtype name. Default empty string.
[96] Fix | Delete
* @param int $page The page of the sitemap. Default 1.
[97] Fix | Delete
* @return string|false The sitemap URL or false if the sitemap doesn't exist.
[98] Fix | Delete
*/
[99] Fix | Delete
function get_sitemap_url( $name, $subtype_name = '', $page = 1 ) {
[100] Fix | Delete
$sitemaps = wp_sitemaps_get_server();
[101] Fix | Delete
if ( ! $sitemaps ) {
[102] Fix | Delete
return false;
[103] Fix | Delete
}
[104] Fix | Delete
[105] Fix | Delete
if ( 'index' === $name ) {
[106] Fix | Delete
return $sitemaps->index->get_index_url();
[107] Fix | Delete
}
[108] Fix | Delete
[109] Fix | Delete
$provider = $sitemaps->registry->get_provider( $name );
[110] Fix | Delete
if ( ! $provider ) {
[111] Fix | Delete
return false;
[112] Fix | Delete
}
[113] Fix | Delete
[114] Fix | Delete
if ( $subtype_name && ! in_array( $subtype_name, array_keys( $provider->get_object_subtypes() ), true ) ) {
[115] Fix | Delete
return false;
[116] Fix | Delete
}
[117] Fix | Delete
[118] Fix | Delete
$page = absint( $page );
[119] Fix | Delete
if ( 0 >= $page ) {
[120] Fix | Delete
$page = 1;
[121] Fix | Delete
}
[122] Fix | Delete
return $provider->get_sitemap_url( $subtype_name, $page );
[123] Fix | Delete
}
[124] Fix | Delete
[125] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function