Plugin Directory

Changeset 3443686


Ignore:
Timestamp:
01/21/2026 01:23:09 AM (2 months ago)
Author:
rankauthority
Message:

Update: handle schema when posting

Location:
rank-authority
Files:
6 added
2 edited

Legend:

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

    r3442843 r3443686  
    44 * Plugin URI: https://rankauthority.com/plugins/rankauthority
    55 * Description: Secure API connector to publish posts / overwrite posts from the RA Dashboard to WordPress.
    6  * Version: 1.0.11
     6 * Version: 1.0.12
    77 * Author: Rank Authority
    88 * Author URI: https://rankauthority.com
     
    3232        add_action('rest_api_init', [$this, 'register_routes']);
    3333        add_action('wp_enqueue_scripts', [$this, 'enqueue_seo_scripts']);
     34        add_action('wp_head', [$this, 'output_schema_markup'], 1);
    3435    }
    3536
     
    673674        $website_id = get_option($this->option_website_id);
    674675        $token = get_option($this->option_token);
    675         $plugin_version = get_file_data(__FILE__, array('Version' => 'Version'), false)['Version'] ?? '1.0.11';
     676        $plugin_version = get_file_data(__FILE__, array('Version' => 'Version'), false)['Version'] ?? '1.0.12';
    676677
    677678        ?>
     
    11331134        }
    11341135
     1136        // Set schema if provided
     1137        if (!empty($params['schema'])) {
     1138            $schema_data = $params['schema'];
     1139           
     1140            // If schema is a string, try to decode it as JSON
     1141            if (is_string($schema_data)) {
     1142                $decoded = json_decode($schema_data, true);
     1143                if (json_last_error() === JSON_ERROR_NONE) {
     1144                    $schema_data = $decoded;
     1145                }
     1146            }
     1147           
     1148            // Ensure schema is valid JSON
     1149            if (is_array($schema_data) || is_object($schema_data)) {
     1150                $schema_json = json_encode($schema_data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
     1151               
     1152                // Store schema in post meta for multiple SEO plugins
     1153                // Generic schema storage
     1154                update_post_meta($post_id, '_rank_authority_schema', $schema_json);
     1155               
     1156                // Yoast SEO schema support
     1157                update_post_meta($post_id, '_yoast_wpseo_schema', $schema_json);
     1158               
     1159                // Rank Math schema support
     1160                update_post_meta($post_id, 'rank_math_schema', $schema_json);
     1161               
     1162                // All in One SEO schema support
     1163                update_post_meta($post_id, '_aioseo_schema', $schema_json);
     1164            }
     1165        }
     1166
    11351167        $permalink = get_permalink($post_id);
    11361168
     
    12531285        }
    12541286
     1287        // Update schema if provided
     1288        if (isset($params['schema'])) {
     1289            if (!empty($params['schema'])) {
     1290                $schema_data = $params['schema'];
     1291               
     1292                // If schema is a string, try to decode it as JSON
     1293                if (is_string($schema_data)) {
     1294                    $decoded = json_decode($schema_data, true);
     1295                    if (json_last_error() === JSON_ERROR_NONE) {
     1296                        $schema_data = $decoded;
     1297                    }
     1298                }
     1299               
     1300                // Ensure schema is valid JSON
     1301                if (is_array($schema_data) || is_object($schema_data)) {
     1302                    $schema_json = json_encode($schema_data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
     1303                   
     1304                    // Store schema in post meta for multiple SEO plugins
     1305                    // Generic schema storage
     1306                    update_post_meta($updated_id, '_rank_authority_schema', $schema_json);
     1307                   
     1308                    // Yoast SEO schema support
     1309                    update_post_meta($updated_id, '_yoast_wpseo_schema', $schema_json);
     1310                   
     1311                    // Rank Math schema support
     1312                    update_post_meta($updated_id, 'rank_math_schema', $schema_json);
     1313                   
     1314                    // All in One SEO schema support
     1315                    update_post_meta($updated_id, '_aioseo_schema', $schema_json);
     1316                }
     1317            } else {
     1318                // If schema is empty, delete schema data
     1319                delete_post_meta($updated_id, '_rank_authority_schema');
     1320                delete_post_meta($updated_id, '_yoast_wpseo_schema');
     1321                delete_post_meta($updated_id, 'rank_math_schema');
     1322                delete_post_meta($updated_id, '_aioseo_schema');
     1323            }
     1324        }
     1325
    12551326        $permalink = get_permalink($updated_id);
    12561327
     
    13961467        ];
    13971468    }
     1469
     1470    /**
     1471     * Output schema markup in wp_head
     1472     * Adds JSON-LD structured data to the page head
     1473     */
     1474    public function output_schema_markup() {
     1475        // Only output on single post/page
     1476        if (!is_singular()) {
     1477            return;
     1478        }
     1479
     1480        global $post;
     1481        if (!$post) {
     1482            return;
     1483        }
     1484
     1485        // Get schema from post meta
     1486        $schema_json = get_post_meta($post->ID, '_rank_authority_schema', true);
     1487       
     1488        if (empty($schema_json)) {
     1489            return;
     1490        }
     1491
     1492        // Validate JSON
     1493        $schema_data = json_decode($schema_json, true);
     1494        if (json_last_error() !== JSON_ERROR_NONE) {
     1495            return;
     1496        }
     1497
     1498        // Output JSON-LD script
     1499        echo '<script type="application/ld+json">' . "\n";
     1500        echo wp_json_encode($schema_data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
     1501        echo "\n" . '</script>' . "\n";
     1502    }
    13981503}
    13991504
  • rank-authority/trunk/readme.txt

    r3442843 r3443686  
    55Tested up to: 6.9
    66Requires PHP: 7.4
    7 Stable tag: 1.0.11
     7Stable tag: 1.0.12
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    136136== Changelog ==
    137137
     138= 1.0.12 =
     139* Added support for schema parameter in publish and update post endpoints
     140* Added JSON-LD structured data output in wp_head for SEO
     141* Enhanced schema compatibility with multiple SEO plugins (Yoast SEO, Rank Math, All in One SEO)
     142* Improved structured data support for better search engine visibility
     143
    138144= 1.0.11 =
    139145* Added support for meta_description parameter in publish and update post endpoints
     
    207213== Upgrade Notice ==
    208214
     215= 1.0.12 =
     216Added schema/structured data support - now you can set JSON-LD schema markup via API for better SEO.
     217
    209218= 1.0.11 =
    210219Added SEO metadata support - now you can set meta descriptions and focus keywords via API.
Note: See TracChangeset for help on using the changeset viewer.