Plugin Directory

Changeset 3482032


Ignore:
Timestamp:
03/13/2026 01:35:53 PM (3 weeks ago)
Author:
floyi
Message:

Release 1.1.0 - Add JSON-LD structured data support for SEO schema markup

Location:
floyi
Files:
26 added
3 edited

Legend:

Unmodified
Added
Removed
  • floyi/trunk/floyi.php

    r3477390 r3482032  
    44 * Plugin URI: https://floyi.com/wordpress-plugin
    55 * Description: Connect your WordPress site to Floyi for seamless content publishing from your topical authority platform.
    6  * Version: 1.0.2
     6 * Version: 1.1.0
    77 * Author: Floyi
    88 * Author URI: https://floyi.com
     
    2323
    2424// Plugin constants
    25 define('FLOYI_CONNECT_VERSION', '1.0.2');
     25define('FLOYI_CONNECT_VERSION', '1.1.0');
    2626define('FLOYI_CONNECT_PLUGIN_DIR', plugin_dir_path(__FILE__));
    2727define('FLOYI_CONNECT_PLUGIN_URL', plugin_dir_url(__FILE__));
     
    100100        // Webhook retry cron
    101101        add_action('floyi_process_webhook_queue', array('Floyi_Webhook_Queue', 'process_queue'));
     102
     103        // Render JSON-LD structured data in page <head>
     104        add_action('wp_head', array(__CLASS__, 'render_json_ld'), 1);
     105
     106        // Expose _floyi_json_ld in the Custom Fields panel so users can view/edit it
     107        add_filter('is_protected_meta', array(__CLASS__, 'unprotect_floyi_meta'), 10, 2);
    102108
    103109        // Track post status changes for Floyi-managed posts
     
    198204        // Text domain loading is handled automatically by WordPress 4.6+
    199205        // for plugins hosted on WordPress.org.
     206
     207        // Register Floyi JSON-LD meta field for REST API access
     208        $post_types = get_post_types(array('public' => true, 'show_in_rest' => true));
     209        foreach ($post_types as $post_type) {
     210            register_post_meta($post_type, '_floyi_json_ld', array(
     211                'show_in_rest'  => true,
     212                'single'        => true,
     213                'type'          => 'string',
     214                'auth_callback' => function () {
     215                    return current_user_can('edit_posts');
     216                },
     217            ));
     218        }
     219    }
     220
     221    /**
     222     * Render Floyi JSON-LD structured data in the page <head>.
     223     *
     224     * Outputs <script type="application/ld+json"> from the _floyi_json_ld
     225     * post meta field. This runs on singular pages (posts, pages, CPTs).
     226     */
     227    public static function render_json_ld() {
     228        if (!is_singular()) {
     229            return;
     230        }
     231
     232        $schema = get_post_meta(get_the_ID(), '_floyi_json_ld', true);
     233        if (!$schema) {
     234            return;
     235        }
     236
     237        // get_post_meta returns the value as stored. The JSON from Floyi contains
     238        // properly escaped inner quotes (e.g. \"deliverable\"). Do NOT wp_unslash()
     239        // as that strips the escaping and breaks json_decode.
     240        $decoded = json_decode($schema);
     241        if (json_last_error() !== JSON_ERROR_NONE || $decoded === null) {
     242            return;
     243        }
     244
     245        // Output each schema as its own <script> tag (Google-recommended approach).
     246        // Single object → one tag. Array of objects → one tag per schema type.
     247        $items = is_array($decoded) ? $decoded : array($decoded);
     248        foreach ($items as $item) {
     249            $clean_json = wp_json_encode($item, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
     250            if ($clean_json) {
     251                echo '<script type="application/ld+json">' . $clean_json . '</script>' . "\n";
     252            }
     253        }
     254    }
     255
     256    /**
     257     * Allow _floyi_json_ld to appear in the Custom Fields panel.
     258     *
     259     * WordPress hides underscore-prefixed meta keys by default. This filter
     260     * makes _floyi_json_ld visible so users can view and edit schema directly
     261     * in the WordPress editor.
     262     *
     263     * @param bool   $protected Whether the meta key is protected.
     264     * @param string $meta_key  The meta key.
     265     * @return bool
     266     */
     267    public static function unprotect_floyi_meta($protected, $meta_key) {
     268        if ($meta_key === '_floyi_json_ld') {
     269            return false;
     270        }
     271        return $protected;
    200272    }
    201273
  • floyi/trunk/includes/class-floyi-publisher.php

    r3477390 r3482032  
    114114        if (!empty($params['meta']) && is_array($params['meta'])) {
    115115            foreach ($params['meta'] as $key => $value) {
    116                 update_post_meta($post_id, sanitize_key($key), $value);
     116                // wp_slash counteracts the wp_unslash that update_post_meta
     117                // applies internally, preserving backslash escaping in JSON strings.
     118                update_post_meta($post_id, sanitize_key($key), wp_slash($value));
    117119            }
    118120        }
     
    212214        if (!empty($params['meta']) && is_array($params['meta'])) {
    213215            foreach ($params['meta'] as $key => $value) {
    214                 update_post_meta($post_id, sanitize_key($key), $value);
     216                // wp_slash counteracts the wp_unslash that update_post_meta
     217                // applies internally, preserving backslash escaping in JSON strings.
     218                update_post_meta($post_id, sanitize_key($key), wp_slash($value));
    215219            }
    216220        }
  • floyi/trunk/readme.txt

    r3477390 r3482032  
    55Tested up to: 6.9
    66Requires PHP: 7.4
    7 Stable tag: 1.0.2
     7Stable tag: 1.1.0
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    125125== Changelog ==
    126126
     127= 1.1.0 =
     128* Added JSON-LD structured data support — Floyi can now push schema markup to WordPress
     129* Schema is rendered in the page head via wp_head hook for SEO and AI search engines
     130* Floyi JSON-LD meta field visible in Custom Fields panel for viewing and manual editing
     131* Registered _floyi_json_ld post meta for all public post types via REST API
     132
    127133= 1.0.2 =
    128134* Preserve link target and rel attributes when publishing from Floyi (fixes "open in new tab" links losing target="_blank" after publishing)
     
    149155== Upgrade Notice ==
    150156
     157= 1.1.0 =
     158Adds JSON-LD structured data support. Floyi can now push Article, FAQ, HowTo, Organization, LocalBusiness, and Breadcrumb schema to your WordPress pages.
     159
    151160= 1.0.2 =
    152161Fixes link attributes (target, rel) being stripped when publishing content to WordPress.
Note: See TracChangeset for help on using the changeset viewer.