| 1 |
<?php |
| 2 |
/** |
| 3 |
* Shared MetaSync helper functions. |
| 4 |
* |
| 5 |
* Always loaded (in all request contexts: admin, REST, MCP, AJAX) so that the |
| 6 |
* custom/LPS page detection rule lives in exactly one place and every SEO |
| 7 |
* surface applies the same exclusion without copy-paste drift. |
| 8 |
* |
| 9 |
* @package Search_Atlas |
| 10 |
*/ |
| 11 |
|
| 12 |
if (!defined('ABSPATH')) { |
| 13 |
exit; |
| 14 |
} |
| 15 |
|
| 16 |
if (!function_exists('metasync_is_custom_or_lps_page')) { |
| 17 |
/** |
| 18 |
* Determine whether a post is a MetaSync-built custom page that ships its own |
| 19 |
* complete, self-contained SEO (Custom HTML pages and LPS-imported pages). |
| 20 |
* |
| 21 |
* These pages already include a full SEO head (title, meta description, OG, |
| 22 |
* Twitter, JSON-LD schema) generated by LPS, so OTTO must not run on them — |
| 23 |
* otherwise it injects/overwrites SEO from a different/older OTTO project and |
| 24 |
* produces a page with two contradictory SEO identities (WP-440). |
| 25 |
* |
| 26 |
* @param int $post_id Post ID to inspect. |
| 27 |
* @return bool True when the post carries any custom-page / LPS marker. |
| 28 |
*/ |
| 29 |
function metasync_is_custom_or_lps_page($post_id){ |
| 30 |
$post_id = (int) $post_id; |
| 31 |
if ($post_id <= 0 || !class_exists('Metasync_Custom_Pages')) { |
| 32 |
return false; |
| 33 |
} |
| 34 |
|
| 35 |
if (get_post_meta($post_id, Metasync_Custom_Pages::META_IS_CUSTOM_HTML_PAGE, true) === '1') { |
| 36 |
return true; |
| 37 |
} |
| 38 |
if (!empty(get_post_meta($post_id, Metasync_Custom_Pages::META_LPS_IMPORT, true))) { |
| 39 |
return true; |
| 40 |
} |
| 41 |
if (!empty(get_post_meta($post_id, Metasync_Custom_Pages::META_CREATED_VIA_API, true))) { |
| 42 |
return true; |
| 43 |
} |
| 44 |
|
| 45 |
return false; |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
if (!function_exists('metasync_get_custom_page_exclusion_meta_query')) { |
| 50 |
/** |
| 51 |
* Build a WP_Query meta_query fragment that excludes custom/LPS pages. |
| 52 |
* |
| 53 |
* When AND-combined with any query, this drops posts whose |
| 54 |
* _metasync_is_custom_html_page marker is set to '1' while keeping all |
| 55 |
* WordPress-managed posts (where the key is absent or set to anything else). |
| 56 |
* |
| 57 |
* @return array meta_query fragment. |
| 58 |
*/ |
| 59 |
function metasync_get_custom_page_exclusion_meta_query(){ |
| 60 |
return array( |
| 61 |
'relation' => 'OR', |
| 62 |
array( |
| 63 |
'key' => '_metasync_is_custom_html_page', |
| 64 |
'compare' => 'NOT EXISTS', |
| 65 |
), |
| 66 |
array( |
| 67 |
'key' => '_metasync_is_custom_html_page', |
| 68 |
'value' => '1', |
| 69 |
'compare' => '!=', |
| 70 |
), |
| 71 |
); |
| 72 |
} |
| 73 |
} |
| 74 |
|