| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace RenzoJohnson\Blocks\WooCommerce; |
| 6 |
|
| 7 |
\defined( 'ABSPATH' ) || exit; |
| 8 |
|
| 9 |
/** Resolves the WooCommerce pages shared by sitemap and robots guards. */ |
| 10 |
final class WooPages { |
| 11 |
|
| 12 |
/** |
| 13 |
* @param array<int, string> $slugs WooCommerce page slugs. |
| 14 |
* @return array<int, int> |
| 15 |
*/ |
| 16 |
public static function guarded_ids( array $slugs ): array { |
| 17 |
$ids = array(); |
| 18 |
|
| 19 |
foreach ( $slugs as $slug ) { |
| 20 |
// wc_get_page_id() returns -1 when the page is not configured. |
| 21 |
$id = (int) \wc_get_page_id( $slug ); |
| 22 |
|
| 23 |
if ( $id > 0 ) { |
| 24 |
$ids[] = $id; |
| 25 |
} |
| 26 |
} |
| 27 |
|
| 28 |
/** |
| 29 |
* Filter the WooCommerce page IDs treated as non-indexable. |
| 30 |
* |
| 31 |
* @param array<int, int> $ids Page IDs. |
| 32 |
*/ |
| 33 |
$filtered = \apply_filters( 'blocks_woo_guarded_page_ids', $ids ); |
| 34 |
|
| 35 |
if ( ! \is_array( $filtered ) ) { |
| 36 |
return $ids; |
| 37 |
} |
| 38 |
|
| 39 |
return \array_values( \array_unique( \array_filter( \array_map( '\intval', $filtered ), static fn ( int $id ): bool => $id > 0 ) ) ); |
| 40 |
} |
| 41 |
} |
| 42 |
|