Plugin Directory

Changeset 3485164


Ignore:
Timestamp:
03/17/2026 10:49:46 PM (3 weeks ago)
Author:
rankauthority
Message:

Release 1.0.34: Handle replacing author and publisher.name in plugin

Location:
rank-authority
Files:
9 added
2 edited

Legend:

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

    r3481417 r3485164  
    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.33
     6 * Version: 1.0.34
    77 * Author: Rank Authority
    88 * Author URI: https://rankauthority.com
     
    17361736            }
    17371737
     1738            // Replace schema publisher.name with WordPress site name
     1739            if (is_string($schema_data) && strpos($schema_data, '<script') === false) {
     1740                $decoded = json_decode($schema_data, true);
     1741                if (json_last_error() === JSON_ERROR_NONE && is_array($decoded)) {
     1742                    $schema_data = $this->replace_schema_publisher_name($decoded);
     1743                }
     1744            } elseif (is_array($schema_data)) {
     1745                $schema_data = $this->replace_schema_publisher_name($schema_data);
     1746            }
     1747
     1748            // Replace schema author.name with WordPress post author display name
     1749            if (is_string($schema_data) && strpos($schema_data, '<script') === false) {
     1750                $decoded = json_decode($schema_data, true);
     1751                if (json_last_error() === JSON_ERROR_NONE && is_array($decoded)) {
     1752                    $schema_data = $this->replace_schema_author_name($decoded, $post_id);
     1753                }
     1754            } elseif (is_array($schema_data)) {
     1755                $schema_data = $this->replace_schema_author_name($schema_data, $post_id);
     1756            }
     1757
    17381758            // Replace mainEntityOfPage.@id with actual post permalink
    17391759            $permalink = get_permalink($post_id);
     
    20492069                } elseif (is_array($schema_data)) {
    20502070                    $schema_data = $this->replace_schema_logo($schema_data);
     2071                }
     2072
     2073                // Replace schema publisher.name with WordPress site name
     2074                if (is_string($schema_data) && strpos($schema_data, '<script') === false) {
     2075                    $decoded = json_decode($schema_data, true);
     2076                    if (json_last_error() === JSON_ERROR_NONE && is_array($decoded)) {
     2077                        $schema_data = $this->replace_schema_publisher_name($decoded);
     2078                    }
     2079                } elseif (is_array($schema_data)) {
     2080                    $schema_data = $this->replace_schema_publisher_name($schema_data);
     2081                }
     2082
     2083                // Replace schema author.name with WordPress post author display name
     2084                if (is_string($schema_data) && strpos($schema_data, '<script') === false) {
     2085                    $decoded = json_decode($schema_data, true);
     2086                    if (json_last_error() === JSON_ERROR_NONE && is_array($decoded)) {
     2087                        $schema_data = $this->replace_schema_author_name($decoded, $updated_id);
     2088                    }
     2089                } elseif (is_array($schema_data)) {
     2090                    $schema_data = $this->replace_schema_author_name($schema_data, $updated_id);
    20512091                }
    20522092
     
    24432483
    24442484    /**
     2485     * Replace schema publisher.name with WordPress site name (Settings > General).
     2486     *
     2487     * @param array $schema_data Schema (modified in place)
     2488     * @return array Modified schema
     2489     */
     2490    private function replace_schema_publisher_name($schema_data) {
     2491        $site_name = get_bloginfo('name');
     2492        if (empty($site_name) || !is_array($schema_data)) {
     2493            return $schema_data;
     2494        }
     2495
     2496        $replace_in_node = function (&$node) use ($site_name, &$replace_in_node) {
     2497            if (!is_array($node)) {
     2498                return;
     2499            }
     2500            if (isset($node['publisher']['name'])) {
     2501                $node['publisher']['name'] = $site_name;
     2502            }
     2503            if (isset($node['@graph']) && is_array($node['@graph'])) {
     2504                foreach ($node['@graph'] as &$item) {
     2505                    $replace_in_node($item);
     2506                }
     2507            }
     2508            foreach ($node as $key => &$value) {
     2509                if ($key !== '@graph' && is_array($value)) {
     2510                    $replace_in_node($value);
     2511                }
     2512            }
     2513        };
     2514
     2515        $replace_in_node($schema_data);
     2516        return $schema_data;
     2517    }
     2518
     2519    /**
     2520     * Replace schema author with WordPress post author as Person.
     2521     * Replaces entire author object (object, array, or string) with @type Person.
     2522     *
     2523     * @param array $schema_data Schema (modified in place)
     2524     * @param int $post_id Post ID
     2525     * @return array Modified schema
     2526     */
     2527    private function replace_schema_author_name($schema_data, $post_id) {
     2528        if (!$post_id || !is_array($schema_data)) {
     2529            return $schema_data;
     2530        }
     2531        $post = get_post($post_id);
     2532        if (!$post) {
     2533            return $schema_data;
     2534        }
     2535        $author_name = get_the_author_meta('display_name', $post->post_author);
     2536        if (empty($author_name)) {
     2537            return $schema_data;
     2538        }
     2539
     2540        $wp_author = [
     2541            '@type' => 'Person',
     2542            'name'  => $author_name,
     2543        ];
     2544        $author_url = get_author_posts_url($post->post_author);
     2545        if ($author_url) {
     2546            $wp_author['url'] = $author_url;
     2547        }
     2548
     2549        $replace_in_node = function (&$node) use ($wp_author, &$replace_in_node) {
     2550            if (!is_array($node)) {
     2551                return;
     2552            }
     2553            if (isset($node['author'])) {
     2554                $node['author'] = $wp_author;
     2555            }
     2556            if (isset($node['@graph']) && is_array($node['@graph'])) {
     2557                foreach ($node['@graph'] as &$item) {
     2558                    $replace_in_node($item);
     2559                }
     2560            }
     2561            foreach ($node as $key => &$value) {
     2562                if ($key !== '@graph' && is_array($value)) {
     2563                    $replace_in_node($value);
     2564                }
     2565            }
     2566        };
     2567
     2568        $replace_in_node($schema_data);
     2569        return $schema_data;
     2570    }
     2571
     2572    /**
    24452573     * Upload media from URL via REST API
    24462574     * Endpoint: POST /wp-json/ra/v1/media/upload-from-url
  • rank-authority/trunk/readme.txt

    r3481417 r3485164  
    55Tested up to: 6.9
    66Requires PHP: 7.4
    7 Stable tag: 1.0.33
     7Stable tag: 1.0.34
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    137137
    138138== Changelog ==
     139
     140= 1.0.34 =
     141* Schema publisher.name now replaced with WordPress site name (Settings > General)
     142* Schema author fully replaced with WordPress post author as Person (@type Person, name, url)
     143* Ensures schema uses your site's publisher name and post author for consistent structured data
    139144
    140145= 1.0.33 =
     
    337342== Upgrade Notice ==
    338343
     344= 1.0.34 =
     345Schema enhancements: publisher name and author now use your WordPress site name and post author. Structured data will reflect your site's branding and authorship.
     346
    339347= 1.0.33 =
    340348PUT now clears page builder meta when updating content (Elementor, WPBakery, Divi, etc.) so changes appear on frontend. Response includes builder data for restore; send builder_meta to re-apply. Added post_meta param for custom meta updates.
Note: See TracChangeset for help on using the changeset viewer.