WP_REST_Server::READABLE, 'callback' => $this->safely( array( $this, 'scan_urls' ) ), 'permission_callback' => array( $this, 'can_manage' ), ) ); register_rest_route( self::NS, '/strings/translate', array( 'methods' => WP_REST_Server::CREATABLE, 'callback' => $this->safely( array( $this, 'translate' ) ), 'permission_callback' => array( $this, 'can_manage' ), 'args' => array( 'lang' => array( 'type' => 'string', 'required' => true, ), 'domain' => array( 'type' => 'string', 'default' => '', ), 'limit' => array( 'type' => 'integer', 'default' => 40, ), ), ) ); } /** Drop strings that no longer apply, then list the pages to open. */ public function scan_urls(): WP_REST_Response { return new WP_REST_Response( array( 'pruned' => $this->translator->prune(), 'urls' => $this->scanner->urls(), ) ); } /** @param WP_REST_Request> $request */ public function translate( WP_REST_Request $request ): WP_REST_Response|WP_Error { $result = $this->translator->machine_translate( (string) $request['lang'], (int) $request['limit'], (string) $request['domain'] ); return $result instanceof WP_Error ? self::fail( $result, 400 ) : new WP_REST_Response( $result ); } }