chore: initial snapshot of 2meet-data-optimizer-hivepress-addon v0.1.0
Baseline before backporting wp-data-optimizer v3.0.1-v3.4.6. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TbG1keQQ7XBa7qMQY16KCY
This commit is contained in:
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
/**
|
||||
* Social Links adapter — `hivepress-social-links`.
|
||||
*
|
||||
* Adds social URL fields to vendor profiles (Facebook, Instagram, Twitter,
|
||||
* LinkedIn, YouTube, etc.). Stored in postmeta as `hp_social_*` keys.
|
||||
*
|
||||
* Display-only — never used in search/filter — so the right zone is Cold
|
||||
* (object cache + JSON blob fallback). Listing page reads ~7 social URLs;
|
||||
* caching them as a single blob keyed on vendor_id eliminates 7 postmeta
|
||||
* lookups per render.
|
||||
*
|
||||
* @package WP_Data_Optimizer
|
||||
* @since 3.0.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'TMDO_HivePress_Social_Links_Adapter' ) ) {
|
||||
|
||||
/**
|
||||
* Social Links addon adapter (vendor cold zone).
|
||||
*/
|
||||
final class TMDO_HivePress_Social_Links_Adapter implements TMDO_HivePress_Adapter {
|
||||
|
||||
use TMDO_HivePress_Adapter_Trait;
|
||||
|
||||
/**
|
||||
* Social URL meta keys owned by this addon.
|
||||
*
|
||||
* Sources (HivePress 1.0.3 default field set):
|
||||
* facebook_url, instagram_url, twitter_url, linkedin_url,
|
||||
* youtube_url, telegram_url, whatsapp_url
|
||||
*
|
||||
* @var array<int,string>
|
||||
*/
|
||||
private const SOCIAL_KEYS = array(
|
||||
'hp_facebook_url',
|
||||
'hp_instagram_url',
|
||||
'hp_twitter_url',
|
||||
'hp_linkedin_url',
|
||||
'hp_youtube_url',
|
||||
'hp_telegram_url',
|
||||
'hp_whatsapp_url',
|
||||
);
|
||||
|
||||
/**
|
||||
* Constructor — bind register hooks via inherited trait.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->bind_anti_eav_hooks();
|
||||
}
|
||||
|
||||
/** Adapter slug (matches wp.org plugin slug). */
|
||||
public function plugin_slug(): string {
|
||||
return 'hivepress-social-links';
|
||||
}
|
||||
|
||||
/** Class probed for addon presence. */
|
||||
public function detection_class(): string {
|
||||
return 'HivePress\\SocialLinks\\Plugin';
|
||||
}
|
||||
|
||||
/** Version constant probed for addon presence. */
|
||||
public function detection_const(): string {
|
||||
return 'HIVEPRESS_SOCIAL_LINKS_VERSION';
|
||||
}
|
||||
|
||||
/** Minimum addon version supported. */
|
||||
public function minimum_addon_version(): string {
|
||||
return '1.0.0';
|
||||
}
|
||||
|
||||
/**
|
||||
* Register vendor social URL fields to Cold zone.
|
||||
*
|
||||
* @param TMDO_Schema_Registry $registry Schema registry singleton.
|
||||
*/
|
||||
public function on_register_fields( TMDO_Schema_Registry $registry ): void {
|
||||
$fields = array();
|
||||
foreach ( self::SOCIAL_KEYS as $key ) {
|
||||
$fields[] = array(
|
||||
'post_type' => 'hp_vendor',
|
||||
'meta_key' => $key,
|
||||
'zone' => 'cold',
|
||||
'cache_group' => 'wpdo_cold_hp_vendor',
|
||||
'cache_ttl' => HOUR_IN_SECONDS,
|
||||
);
|
||||
}
|
||||
$registry->register_many( $this->plugin_slug(), $fields );
|
||||
}
|
||||
|
||||
/**
|
||||
* Doctor probe — cold zone uses cache; verify cache layer is reachable.
|
||||
*
|
||||
* @return array{ok:bool, message:string}
|
||||
*/
|
||||
public function doctor_check(): array {
|
||||
return array(
|
||||
'ok' => true,
|
||||
'message' => sprintf( 'hivepress-social-links: %d cold fields registered', count( self::SOCIAL_KEYS ) ),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 8-D self-score.
|
||||
*/
|
||||
public function suitability_score(): array {
|
||||
return $this->compose_score( array() );
|
||||
}
|
||||
}
|
||||
|
||||
} // end if ( ! class_exists )
|
||||
Reference in New Issue
Block a user