settings = $settings ?? new SettingsStore(); $this->enableMap = $enableMap; } /** * Get module id. * * @return string The result. */ public function getId(): string { return 'metadata'; } /** * Get human-readable name. * * @return string The result. */ public function getName(): string { return __( 'Metadata Engine', 'rankkernel' ); } /** * Module priority. * * @return int The result. */ public function getPriority(): int { return 10; } /** * Dependencies. * * @return string[] The result. */ public function dependsOn(): array { return []; } /** * Whether the module is enabled (delegates to shared map if injected). * * @return bool The result. */ public function isEnabled(): bool { if ( null !== $this->enabledCache ) { return $this->enabledCache; } if ( null !== $this->enableMap ) { $this->enabledCache = $this->enableMap->isEnabled( 'metadata' ); return $this->enabledCache; } $map = get_option( 'rankkernel_modules', [] ); if ( ! is_array( $map ) ) { $map = []; } // Support both associative map and indexed list (activation seed is list). if ( array_key_exists( 'metadata', $map ) ) { $this->enabledCache = (bool) $map['metadata']; } else { $this->enabledCache = in_array( 'metadata', $map, true ); } return $this->enabledCache; } /** * Register meta keys (no hooks yet). */ public function register(): void { register_meta( 'post', '_rankkernel_meta_data', [ 'type' => 'object', 'single' => true, 'show_in_rest' => [ 'schema' => MetaPayload::restSchema(), ], 'sanitize_callback' => [ MetaPayload::class, 'sanitize' ], 'auth_callback' => static fn ( mixed $value, string $meta_key, int $object_id ): bool => current_user_can( 'edit_post', $object_id ), ] ); // Term payload = post shape minus post-only fields (schema module not needed here). register_meta( 'term', '_rankkernel_term_data', [ 'type' => 'object', 'single' => true, 'show_in_rest' => [ 'schema' => MetaPayload::restSchema(), ], 'sanitize_callback' => [ MetaPayload::class, 'sanitize' ], 'auth_callback' => static fn ( mixed $value, string $meta_key, int $object_id ): bool => current_user_can( 'edit_term', $object_id ), ] ); // Per-user prefs (module-off notices, AI prefs later); permissive schema. register_meta( 'user', '_rankkernel_user_prefs', [ 'type' => 'object', 'single' => true, 'show_in_rest' => [ 'schema' => MetaPayload::userPrefsSchema(), ], 'sanitize_callback' => [ MetaPayload::class, 'sanitize' ], 'auth_callback' => static fn ( mixed $value, string $meta_key, int $object_id ): bool => current_user_can( 'edit_user', $object_id ), ] ); } /** * Boot hooks (only if enabled, caller enforces). */ public function boot(): void { $renderer = new HeadRenderer( $this->settings ); $renderer->boot(); // Scalar noindex flags stay in agreement with payloads no matter // which path wrote them: classic editor, REST, or programmatic. add_action( 'added_post_meta', [ NoindexFlag::class, 'onPostMetaWrite' ], 10, 4 ); add_action( 'updated_post_meta', [ NoindexFlag::class, 'onPostMetaWrite' ], 10, 4 ); add_action( 'deleted_post_meta', [ NoindexFlag::class, 'onPostMetaDelete' ], 10, 4 ); add_action( 'added_term_meta', [ NoindexFlag::class, 'onTermMetaWrite' ], 10, 4 ); add_action( 'updated_term_meta', [ NoindexFlag::class, 'onTermMetaWrite' ], 10, 4 ); add_action( 'deleted_term_meta', [ NoindexFlag::class, 'onTermMetaDelete' ], 10, 4 ); } }