This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.
Astra_Enqueue_Scripts::has_woocommerce_shortcode_in_archive()
Check for WooCommerce shortcodes in archive pages efficiently.
Description
Return
(bool)
Source
File: inc/core/class-astra-enqueue-scripts.php
private static function has_woocommerce_shortcode_in_archive() {
// Access the global $wp_query variable in a Psalm-compliant way.
$wp_query = isset( $GLOBALS['wp_query'] ) ? $GLOBALS['wp_query'] : null;
// If no posts, return false early.
if ( ! $wp_query || empty( $wp_query->posts ) ) {
return false;
}
// Limit the number of posts to check to prevent memory issues.
$posts_to_check = array_slice( $wp_query->posts, 0, 5 ); // Check only first 5 posts.
// Check each post individually instead of concatenating all content.
foreach ( $posts_to_check as $post ) {
if ( ! $post ) {
continue; // Skip if post is empty.
}
if ( self::has_woocommerce_shortcode( $post->post_content ) ) {
return true;
}
}
return false;
}
Expand full source code Collapse full source code View on Trac
Changelog
| Version | Description |
|---|---|
| 4.11.18 | Introduced. |