graph_builder = $graph_builder; } public function register(): void { add_action( 'rest_api_init', array( $this, 'register_routes' ) ); } public function register_routes(): void { register_rest_route( self::NAMESPACE, '/graph', array( 'methods' => 'GET', 'callback' => array( $this, 'handle_get_graph' ), 'permission_callback' => array( $this, 'check_permission' ), 'args' => array( 'post_id' => array( 'type' => 'integer', 'required' => true, ), ), ) ); } public function check_permission( \WP_REST_Request $request ): bool { $post_id = (int) $request->get_param( 'post_id' ); return $post_id > 0 && current_user_can( 'edit_post', $post_id ); } public function handle_get_graph( \WP_REST_Request $request ): \WP_REST_Response { $post = get_post( (int) $request->get_param( 'post_id' ) ); if ( ! $post instanceof \WP_Post ) { return new \WP_REST_Response( array( 'message' => __( 'Post not found.', 'acez-seo' ) ), 404 ); } return new \WP_REST_Response( $this->graph_builder->build( $post ), 200 ); } }