Changeset 3470035
- Timestamp:
- 02/26/2026 08:56:20 AM (5 weeks ago)
- Location:
- rank-authority/trunk
- Files:
-
- 2 edited
-
rank-authority.php (modified) (8 diffs)
-
readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
rank-authority/trunk/rank-authority.php
r3470015 r3470035 4 4 * Plugin URI: https://rankauthority.com/plugins/rankauthority 5 5 * Description: Secure API connector to publish posts / overwrite posts from the RA Dashboard to WordPress. Token reset now available to all administrators. 6 * Version: 1.0.2 06 * Version: 1.0.21 7 7 * Author: Rank Authority 8 8 * Author URI: https://rankauthority.com … … 1541 1541 $schema_data = $this->replace_schema_logo($schema_data); 1542 1542 } 1543 1544 // Replace mainEntityOfPage.@id with actual post permalink 1545 $permalink = get_permalink($post_id); 1546 if (is_string($schema_data) && strpos($schema_data, '<script') === false) { 1547 $decoded = json_decode($schema_data, true); 1548 if (json_last_error() === JSON_ERROR_NONE && is_array($decoded)) { 1549 $schema_data = $this->replace_schema_main_entity_of_page($decoded, $permalink); 1550 } 1551 } elseif (is_array($schema_data)) { 1552 $schema_data = $this->replace_schema_main_entity_of_page($schema_data, $permalink); 1553 } 1543 1554 1544 1555 // Check if schema is HTML string with script tags (multiple schemas) … … 1590 1601 $permalink = get_permalink($post_id); 1591 1602 1592 // Return response compatible with Xano expectations1593 return[1603 // Build response with final schema when schema was stored 1604 $response = [ 1594 1605 'success' => true, 1595 1606 'post_id' => $post_id, … … 1598 1609 'ID' => $post_id // Xano compatibility 1599 1610 ]; 1611 if (!empty($params['schema'])) { 1612 $stored_schema = get_post_meta($post_id, '_rank_authority_schema', true); 1613 $schema_type = get_post_meta($post_id, '_rank_authority_schema_type', true); 1614 if ($stored_schema) { 1615 if ($schema_type === 'json') { 1616 $decoded = json_decode($stored_schema, true); 1617 $response['schema'] = json_last_error() === JSON_ERROR_NONE ? $decoded : $stored_schema; 1618 } else { 1619 $response['schema'] = $stored_schema; 1620 } 1621 } 1622 } 1623 return $response; 1600 1624 } 1601 1625 … … 1734 1758 } elseif (is_array($schema_data)) { 1735 1759 $schema_data = $this->replace_schema_logo($schema_data); 1760 } 1761 1762 // Replace mainEntityOfPage.@id with actual post permalink 1763 $permalink = get_permalink($updated_id); 1764 if (is_string($schema_data) && strpos($schema_data, '<script') === false) { 1765 $decoded = json_decode($schema_data, true); 1766 if (json_last_error() === JSON_ERROR_NONE && is_array($decoded)) { 1767 $schema_data = $this->replace_schema_main_entity_of_page($decoded, $permalink); 1768 } 1769 } elseif (is_array($schema_data)) { 1770 $schema_data = $this->replace_schema_main_entity_of_page($schema_data, $permalink); 1736 1771 } 1737 1772 … … 1792 1827 $permalink = get_permalink($updated_id); 1793 1828 1794 return[1829 $response = [ 1795 1830 'success' => true, 1796 1831 'post_id' => $updated_id, … … 1799 1834 'ID' => $updated_id // Xano compatibility 1800 1835 ]; 1836 if (isset($params['schema']) && !empty($params['schema'])) { 1837 $stored_schema = get_post_meta($updated_id, '_rank_authority_schema', true); 1838 $schema_type = get_post_meta($updated_id, '_rank_authority_schema_type', true); 1839 if ($stored_schema) { 1840 if ($schema_type === 'json') { 1841 $decoded = json_decode($stored_schema, true); 1842 $response['schema'] = json_last_error() === JSON_ERROR_NONE ? $decoded : $stored_schema; 1843 } else { 1844 $response['schema'] = $stored_schema; 1845 } 1846 } 1847 } 1848 return $response; 1801 1849 } 1802 1850 … … 1990 2038 1991 2039 /** 2040 * Replace schema mainEntityOfPage.@id with actual post permalink. 2041 * 2042 * @param array $schema_data Schema (modified in place) 2043 * @param string $permalink Post URL 2044 * @return array Modified schema 2045 */ 2046 private function replace_schema_main_entity_of_page($schema_data, $permalink) { 2047 if (empty($permalink) || !is_array($schema_data)) { 2048 return $schema_data; 2049 } 2050 2051 $replace_in_node = function (&$node) use ($permalink, &$replace_in_node) { 2052 if (!is_array($node)) { 2053 return; 2054 } 2055 if (isset($node['mainEntityOfPage'])) { 2056 $mep = &$node['mainEntityOfPage']; 2057 if (is_array($mep) && isset($mep['@id'])) { 2058 $mep['@id'] = $permalink; 2059 } elseif (is_string($mep)) { 2060 $node['mainEntityOfPage'] = $permalink; 2061 } 2062 } 2063 if (isset($node['@graph']) && is_array($node['@graph'])) { 2064 foreach ($node['@graph'] as &$item) { 2065 $replace_in_node($item); 2066 } 2067 } 2068 foreach ($node as $key => &$value) { 2069 if ($key !== '@graph' && is_array($value)) { 2070 $replace_in_node($value); 2071 } 2072 } 2073 }; 2074 2075 $replace_in_node($schema_data); 2076 return $schema_data; 2077 } 2078 2079 /** 1992 2080 * Get WordPress site logo URL and dimensions (from Customizer). 1993 2081 * -
rank-authority/trunk/readme.txt
r3470015 r3470035 5 5 Tested up to: 6.9 6 6 Requires PHP: 7.4 7 Stable tag: 1.0.2 07 Stable tag: 1.0.21 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 137 137 138 138 == Changelog == 139 140 = 1.0.21 = 141 * Schema mainEntityOfPage.@id now replaced with actual published post URL 142 * Publish and update post API responses now include final schema (JSON) in response 143 * Ensures schema references the correct permalink for SEO and rich results 139 144 140 145 = 1.0.20 = … … 270 275 == Upgrade Notice == 271 276 277 = 1.0.21 = 278 Schema mainEntityOfPage now uses actual post URL. API responses include the final schema for verification. 279 272 280 = 1.0.20 = 273 281 Schema enhancements: placeholder images are now replaced with actual uploaded URLs, and publisher logo uses your WordPress site logo when available.
Note: See TracChangeset
for help on using the changeset viewer.