d3ddbb8933
- hivepress-social-links stores each link as hp_{name} (hp_facebook, not
hp_facebook_url) and lets admins enable links separately for listings
and vendors; the hardcoded 7 *_url vendor keys never matched real meta
- Read hp_listing_social_links / hp_vendor_social_links and register each
enabled link on its own post type, so custom links (e.g. line_oa) work
- dev34 check: meta holds hp_instagram / hp_website, and zero *_url keys
Verify: vendor/bin/phpunit --filter HivePressSocialLinksAdapterTest;
addon unit 156 OK, integration 57 OK
PR: PR-010
117 lines
3.2 KiB
PHP
117 lines
3.2 KiB
PHP
<?php
|
|
/**
|
|
* Social Links adapter — `hivepress-social-links`.
|
|
*
|
|
* The addon adds one attribute per social link the admin enables, separately
|
|
* for listings (`hp_listing_social_links`) and vendors (`hp_vendor_social_links`).
|
|
* Each attribute is stored in postmeta as `hp_{name}` (e.g. `hp_facebook`).
|
|
*
|
|
* Display-only — never used in search/filter — so the right zone is Cold
|
|
* (object cache + JSON blob fallback): one blob per post replaces one
|
|
* postmeta lookup per link on every 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;
|
|
|
|
/**
|
|
* 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 the enabled social link fields to the Cold zone.
|
|
*
|
|
* @param TMDO_Schema_Registry $registry Schema registry singleton.
|
|
*/
|
|
public function on_register_fields( TMDO_Schema_Registry $registry ): void {
|
|
$fields = array();
|
|
foreach ( $this->enabled_meta_keys() as $post_type => $keys ) {
|
|
foreach ( $keys as $key ) {
|
|
$fields[] = array(
|
|
'post_type' => $post_type,
|
|
'meta_key' => $key,
|
|
'zone' => 'cold',
|
|
'cache_group' => 'wpdo_cold_' . $post_type,
|
|
'cache_ttl' => HOUR_IN_SECONDS,
|
|
);
|
|
}
|
|
}
|
|
$registry->register_many( $this->plugin_slug(), $fields );
|
|
}
|
|
|
|
/**
|
|
* Meta keys of the social links enabled in the addon settings.
|
|
*
|
|
* @return array<string, array<int, string>> post_type => meta keys.
|
|
*/
|
|
private function enabled_meta_keys(): array {
|
|
$keys = array();
|
|
foreach ( array( 'listing', 'vendor' ) as $model ) {
|
|
foreach ( (array) get_option( 'hp_' . $model . '_social_links', array() ) as $name ) {
|
|
$name = sanitize_key( (string) $name );
|
|
if ( '' !== $name ) {
|
|
$keys[ 'hp_' . $model ][] = 'hp_' . $name;
|
|
}
|
|
}
|
|
}
|
|
return $keys;
|
|
}
|
|
|
|
/**
|
|
* 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', array_sum( array_map( 'count', $this->enabled_meta_keys() ) ) ),
|
|
);
|
|
}
|
|
|
|
/**
|
|
* 8-D self-score.
|
|
*/
|
|
public function suitability_score(): array {
|
|
return $this->compose_score( array() );
|
|
}
|
|
}
|
|
|
|
} // end if ( ! class_exists )
|