AnsPress_Rewrite::shortlink()

Description #

Handles shortlink redirects.

Changelog #

VersionDescription
unknownunknown
4.1.6Introduced.

Source #

File: includes/rewrite.php

	public static function shortlink() {
		global $wp_query;
		$page = get_query_var( 'ap_page' );

		if ( empty( $page ) || 'shortlink' !== $page ) {
			return;
		}

		$post_id = ap_isset_post_value( 'ap_q', ap_isset_post_value( 'ap_a', false ) );
		$post_id = ap_isset_post_value( 'ap_p', $post_id );

		// Post redirect.
		if ( $post_id ) {
			$permalink = get_permalink( $post_id );
			wp_redirect( $permalink, 302 ); // phpcs:ignore WordPress.Security.SafeRedirect.wp_redirect_wp_redirect
			exit;
		}

		// Comment redirect.
		if ( ap_isset_post_value( 'ap_c', false ) ) {
			$permalink = get_comment_link( ap_isset_post_value( 'ap_c' ) );
			wp_redirect( $permalink, 302 ); // phpcs:ignore WordPress.Security.SafeRedirect.wp_redirect_wp_redirect
			exit;
		}

		// User redirect.
		if ( ap_isset_post_value( 'ap_u', false ) ) {
			$permalink = ap_user_link( ap_isset_post_value( 'ap_u' ), ap_isset_post_value( 'sub' ) );
			wp_redirect( $permalink, 302 ); // phpcs:ignore WordPress.Security.SafeRedirect.wp_redirect_wp_redirect
			exit;
		}
	}

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Add your comment