Plugin Directory

Changeset 3470035


Ignore:
Timestamp:
02/26/2026 08:56:20 AM (5 weeks ago)
Author:
rankauthority
Message:

Update: id canonical / return json

Location:
rank-authority/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • rank-authority/trunk/rank-authority.php

    r3470015 r3470035  
    44 * Plugin URI: https://rankauthority.com/plugins/rankauthority
    55 * 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.20
     6 * Version: 1.0.21
    77 * Author: Rank Authority
    88 * Author URI: https://rankauthority.com
     
    15411541                $schema_data = $this->replace_schema_logo($schema_data);
    15421542            }
     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            }
    15431554           
    15441555            // Check if schema is HTML string with script tags (multiple schemas)
     
    15901601        $permalink = get_permalink($post_id);
    15911602
    1592         // Return response compatible with Xano expectations
    1593         return [
     1603        // Build response with final schema when schema was stored
     1604        $response = [
    15941605            'success' => true,
    15951606            'post_id' => $post_id,
     
    15981609            'ID'      => $post_id     // Xano compatibility
    15991610        ];
     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;
    16001624    }
    16011625
     
    17341758                } elseif (is_array($schema_data)) {
    17351759                    $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);
    17361771                }
    17371772               
     
    17921827        $permalink = get_permalink($updated_id);
    17931828
    1794         return [
     1829        $response = [
    17951830            'success' => true,
    17961831            'post_id' => $updated_id,
     
    17991834            'ID'      => $updated_id  // Xano compatibility
    18001835        ];
     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;
    18011849    }
    18021850
     
    19902038
    19912039    /**
     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    /**
    19922080     * Get WordPress site logo URL and dimensions (from Customizer).
    19932081     *
  • rank-authority/trunk/readme.txt

    r3470015 r3470035  
    55Tested up to: 6.9
    66Requires PHP: 7.4
    7 Stable tag: 1.0.20
     7Stable tag: 1.0.21
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    137137
    138138== 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
    139144
    140145= 1.0.20 =
     
    270275== Upgrade Notice ==
    271276
     277= 1.0.21 =
     278Schema mainEntityOfPage now uses actual post URL. API responses include the final schema for verification.
     279
    272280= 1.0.20 =
    273281Schema 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.