Merged in feature/314-dev-dev01 (pull request #24)

auto-patch  314-dev-dev01-2024-01-25T04_09_02

* auto-patch  314-dev-dev01-2024-01-25T04_09_02
This commit is contained in:
Tony Volpe
2024-01-25 04:11:47 +00:00
parent 6b67473553
commit 68dbe860e9
540 changed files with 3445 additions and 2131 deletions

View File

@@ -17,7 +17,7 @@ class WPSEO_Sitemaps {
*
* @var string
*/
const SITEMAP_INDEX_TYPE = '1';
public const SITEMAP_INDEX_TYPE = '1';
/**
* Content of the sitemap to output.
@@ -115,6 +115,8 @@ class WPSEO_Sitemaps {
* Initialize sitemap providers classes.
*
* @since 5.3
*
* @return void
*/
public function init_sitemaps_providers() {
@@ -135,6 +137,8 @@ class WPSEO_Sitemaps {
/**
* Check the current request URI, if we can determine it's probably an XML sitemap, kill loading the widgets.
*
* @return void
*/
public function reduce_query_load() {
if ( ! isset( $_SERVER['REQUEST_URI'] ) ) {
@@ -153,11 +157,13 @@ class WPSEO_Sitemaps {
* @param string $name The name of the sitemap.
* @param callback $building_function Function to build your sitemap.
* @param string $rewrite Optional. Regular expression to match your sitemap with.
*
* @return void
*/
public function register_sitemap( $name, $building_function, $rewrite = '' ) {
add_action( 'wpseo_do_sitemap_' . $name, $building_function );
if ( ! empty( $rewrite ) ) {
add_rewrite_rule( $rewrite, 'index.php?sitemap=' . $name, 'top' );
if ( $rewrite ) {
Yoast_Dynamic_Rewrites::instance()->add_rule( $rewrite, 'index.php?sitemap=' . $name, 'top' );
}
}
@@ -169,11 +175,13 @@ class WPSEO_Sitemaps {
* @param string $name The name of the XSL file.
* @param callback $building_function Function to build your XSL file.
* @param string $rewrite Optional. Regular expression to match your sitemap with.
*
* @return void
*/
public function register_xsl( $name, $building_function, $rewrite = '' ) {
add_action( 'wpseo_xsl_' . $name, $building_function );
if ( ! empty( $rewrite ) ) {
add_rewrite_rule( $rewrite, 'index.php?yoast-sitemap-xsl=' . $name, 'top' );
if ( $rewrite ) {
Yoast_Dynamic_Rewrites::instance()->add_rule( $rewrite, 'index.php?yoast-sitemap-xsl=' . $name, 'top' );
}
}
@@ -182,6 +190,8 @@ class WPSEO_Sitemaps {
* in a one-off process.
*
* @param int $current_page The part that should be generated.
*
* @return void
*/
public function set_n( $current_page ) {
if ( is_scalar( $current_page ) && intval( $current_page ) > 0 ) {
@@ -193,6 +203,8 @@ class WPSEO_Sitemaps {
* Set the sitemap content to display after you have generated it.
*
* @param string $sitemap The generated sitemap to output.
*
* @return void
*/
public function set_sitemap( $sitemap ) {
$this->sitemap = $sitemap;
@@ -202,6 +214,8 @@ class WPSEO_Sitemaps {
* Set as true to make the request 404. Used stop the display of empty sitemaps or invalid requests.
*
* @param bool $is_bad Is this a bad request. True or false.
*
* @return void
*/
public function set_bad_sitemap( $is_bad ) {
$this->bad_sitemap = (bool) $is_bad;
@@ -211,6 +225,8 @@ class WPSEO_Sitemaps {
* Prevent stupid plugins from running shutdown scripts when we're obviously not outputting HTML.
*
* @since 1.4.16
*
* @return void
*/
public function sitemap_close() {
remove_all_actions( 'wp_footer' );
@@ -220,7 +236,9 @@ class WPSEO_Sitemaps {
/**
* Hijack requests for potential sitemaps and XSL files.
*
* @param \WP_Query $query Main query instance.
* @param WP_Query $query Main query instance.
*
* @return void
*/
public function redirect( $query ) {
@@ -332,6 +350,8 @@ class WPSEO_Sitemaps {
* Sets $bad_sitemap if this isn't for the root sitemap, a post type or taxonomy.
*
* @param string $type The requested sitemap's identifier.
*
* @return void
*/
public function build_sitemap( $type ) {
@@ -382,6 +402,8 @@ class WPSEO_Sitemaps {
/**
* Build the root sitemap (example.com/sitemap_index.xml) which lists sub-sitemaps for other content types.
*
* @return void
*/
public function build_root_map() {
@@ -415,6 +437,8 @@ class WPSEO_Sitemaps {
* @since 1.4.13
*
* @param string $type Type to output.
*
* @return void
*/
public function xsl_output( $type ) {
@@ -445,6 +469,8 @@ class WPSEO_Sitemaps {
/**
* Spit out the generated sitemap.
*
* @return void
*/
public function output() {
$this->send_headers();
@@ -499,18 +525,41 @@ class WPSEO_Sitemaps {
if ( ! empty( $post_type_names ) ) {
$post_statuses = array_map( 'esc_sql', self::get_post_statuses() );
$replacements = array_merge(
[
'post_type',
'post_modified_gmt',
'date',
$wpdb->posts,
'post_status',
],
$post_statuses,
[ 'post_type' ],
array_keys( $post_type_names ),
[
'post_type',
'date',
]
);
$sql = "
SELECT post_type, MAX(post_modified_gmt) AS date
FROM $wpdb->posts
WHERE post_status IN ('" . implode( "','", $post_statuses ) . "')
AND post_type IN ('" . implode( "','", $post_type_names ) . "')
GROUP BY post_type
ORDER BY date DESC
";
//phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- We need to use a direct query here.
//phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching -- Reason: No relevant caches.
$dates = $wpdb->get_results(
//phpcs:disable WordPress.DB.PreparedSQLPlaceholders -- %i placeholder is still not recognized.
$wpdb->prepare(
'
SELECT %i, MAX(%i) AS %i
FROM %i
WHERE %i IN (' . implode( ', ', array_fill( 0, count( $post_statuses ), '%s' ) ) . ')
AND %i IN (' . implode( ', ', array_fill( 0, count( $post_type_names ), '%s' ) ) . ')
GROUP BY %i
ORDER BY %i DESC
',
$replacements
)
);
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery -- They are prepared on the lines above and a direct query is required.
foreach ( $wpdb->get_results( $sql ) as $obj ) {
foreach ( $dates as $obj ) {
$post_type_dates[ $obj->post_type ] = $obj->date;
}
}
@@ -592,6 +641,8 @@ class WPSEO_Sitemaps {
/**
* Sends all the required HTTP Headers.
*
* @return void
*/
private function send_headers() {
if ( headers_sent() ) {