forbidden(); } public function register_routes(): void { register_rest_route( $this->namespace, '/examples', array( array( 'methods' => 'GET', 'callback' => array( $this, 'index' ), 'permission_callback' => array( $this, 'can_administer' ), ), ) ); register_rest_route( $this->namespace, '/examples/restore', array( array( 'methods' => 'POST', 'callback' => array( $this, 'restore' ), 'permission_callback' => array( $this, 'can_administer' ), ), ) ); } /** * How many examples of each kind are present, and how many are missing. * * @param WP_REST_Request $request The request. */ public function index( WP_REST_Request $request ): WP_REST_Response|WP_Error { unset( $request ); return $this->ok( $this->seeder->status() ); } /** * Put back everything that is missing. * * Answers with the fresh status as well as the counts, so the panel never has to make a second * request to redraw itself, and so "restored 0" is visibly the same thing as "nothing missing" * rather than looking like a failure. * * @param WP_REST_Request $request The request. */ public function restore( WP_REST_Request $request ): WP_REST_Response|WP_Error { unset( $request ); $restored = $this->seeder->restore(); return $this->ok( array( 'restored' => $restored, 'total' => array_sum( $restored ), 'status' => $this->seeder->status(), ) ); } }