$page['status'] ] ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- process() escapes every value. } /** * Does what the link was asked to do and returns the page to show. * * @param string $token Token from the link. * @param bool $posted Whether the link was posted to. Otherwise it was only opened. * @param bool $all Whether the post asks to stop following every request. * @return array{status: int, title: string, html: string} */ public static function process( string $token, bool $posted, bool $all ): array { $subscription = SubscriptionRepository::find_by_token( $token ); if ( ! $subscription ) { return self::page( 404, __( 'This link no longer works', 'feature-request-system' ), [ self::paragraph( __( 'You may have stopped following this request already.', 'feature-request-system' ) ), self::home_link(), ] ); } // Only a request that anyone can see is named and linked. $request = get_post( $subscription['request_id'] ); $request = $request && 'publish' === $request->post_status ? $request : null; if ( ! $posted ) { return self::ask( $subscription, $request ); } if ( $all ) { SubscriptionRepository::remove_user( $subscription['user_id'] ); Subscriptions::set_automatic( $subscription['user_id'], false ); return self::page( 200, __( 'You no longer follow any request', 'feature-request-system' ), [ self::paragraph( __( 'We will not email you about feature requests again. Voting for a request or suggesting one no longer makes you follow it.', 'feature-request-system' ) ), '
' . wp_kses( sprintf( /* translators: %s: URL of the profile screen. */ __( 'You can still follow a request with the button on its page, and change this choice in your profile.', 'feature-request-system' ), esc_url( admin_url( 'profile.php' ) ) ), [ 'a' => [ 'href' => [] ] ] ) . '
', self::home_link(), ] ); } SubscriptionRepository::remove( $subscription['request_id'], $subscription['user_id'] ); return self::page( 200, __( 'You no longer follow this request', 'feature-request-system' ), array_merge( [ self::paragraph( $request /* translators: %s: request title. */ ? sprintf( __( 'We will not email you about "%s" again.', 'feature-request-system' ), self::title( $request ) ) : __( 'We will not email you about this request again.', 'feature-request-system' ) ), ], self::offer_all( $subscription['user_id'], true ), $request ? [ self::link( (string) get_permalink( $request ), __( 'Go to the request', 'feature-request-system' ) ) ] : [] ) ); } /** * Builds the page that asks whether to stop following. * * @param array' . esc_html( $text ) . '
'; } /** * Builds a paragraph with one link. The link does not pass on the address of this page, which holds the secret. * * @param string $url Where the link goes. * @param string $label Link text. */ private static function link( string $url, string $label ): string { return sprintf( '', esc_url( $url ), esc_html( $label ) ); } /** * Builds a paragraph with a link to the site's home page. */ private static function home_link(): string { /* translators: %s: site name. */ return self::link( home_url( '/' ), sprintf( __( 'Go to %s', 'feature-request-system' ), Mailer::plain( (string) get_bloginfo( 'name' ) ) ) ); } /** * Builds a form with one button that posts to a subscription's link. * * @param string $token Token of the subscription. * @param bool $all Whether the button stops following every request. * @param string $label Button text. */ private static function form( string $token, bool $all, string $label ): string { return sprintf( '', esc_url( self::url( $token ) ), $all ? '' : '', esc_html( $label ) ); } /** * Returns a request's title as plain text. * * @param WP_Post $request Request. */ private static function title( WP_Post $request ): string { return Mailer::plain( $request->post_title ); } }