enabledCache ) { return $this->enabledCache; } $this->enabledCache = $this->enableMap->isEnabled( 'analysis' ); return $this->enabledCache; } /** * Register the score meta keys, only when the module is on. * * The keys are not exposed in the REST schema, so the editor cannot write * them, and the auth callback ties a write to the edit capability for the * post. The sanitize callback accepts mixed and validates defensively. */ public function register(): void { if ( ! $this->isEnabled() ) { return; } $auth = static fn ( mixed $value, string $meta_key, int $object_id ): bool => current_user_can( 'edit_post', $object_id ); register_meta( 'post', AnalysisScore::META_KEY, [ 'type' => 'object', 'single' => true, 'sanitize_callback' => [ AnalysisScore::class, 'sanitize' ], 'auth_callback' => $auth, ] ); register_meta( 'post', AnalysisScore::SCORE_VALUE_KEY, [ 'type' => 'integer', 'single' => true, 'sanitize_callback' => 'absint', 'auth_callback' => $auth, ] ); } /** * Register hooks, only when the module is on. */ public function boot(): void { if ( ! $this->isEnabled() ) { return; } $controller = $this->controller ?? new AnalysisController(); add_action( 'rest_api_init', [ $controller, 'registerRoutes' ] ); $score = new AnalysisScore(); ( new AnalysisSaveHandler( $score ) )->register(); ( new AnalysisColumn( $score ) )->register(); RecalculateCommand::register( $score ); } }