\d+)/remote-reply', array( array( 'methods' => WP_REST_Server::READABLE, 'callback' => array( self::class, 'remote_reply_get' ), 'permission_callback' => '__return_true', 'args' => array( 'resource' => array( 'required' => true, 'sanitize_callback' => 'sanitize_text_field', ), ), ), ) ); } /** * Endpoint for remote follow UI/Block * * @param WP_REST_Request $request The request object. * * @return void|string The URL to the remote follow page */ public static function remote_reply_get( WP_REST_Request $request ) { $resource = $request->get_param( 'resource' ); $comment_id = $request->get_param( 'comment_id' ); $comment = get_comment( $comment_id ); if ( ! $comment ) { return new WP_Error( 'activitypub_comment_not_found', __( 'Comment not found', 'activitypub' ), array( 'status' => 404 ) ); } $is_local = Comment_Utils::is_local( $comment ); if ( $is_local ) { return new WP_Error( 'activitypub_local_only_comment', __( 'Comment is local only', 'activitypub' ), array( 'status' => 403 ) ); } $template = Webfinger_Utils::get_remote_follow_endpoint( $resource ); if ( is_wp_error( $template ) ) { return $template; } $resource = \get_comment_meta( $comment_id, 'source_id', true ); if ( ! $resource ) { $resource = Comment_Utils::generate_id( $comment ); } $url = str_replace( '{uri}', $resource, $template ); return new WP_REST_Response( array( 'url' => $url ), 200 ); } }