public function simpleRedirect()
    {
        global $wp;
        if (!$request = $wp->request) {
            return;
        }
        $currentSlug = add_query_arg(array(), $request);
        $post = get_page_by_title($currentSlug, 'OBJECT', 'custom-short-link');

        if (!$post) {
            return;
        }

        $fields = get_fields($post->ID);
        $redirectTo = null;

        // Find redirect url
        switch ($fields['custom_short_links_redirect_url_type']) {
            case 'external':
                $redirectTo = $fields['custom_short_links_redirect_to_external'];
                break;

            case 'internal':
                $redirectTo = $fields['custom_short_links_redirect_to_internal'];
                break;
        }

        // Make redirect with selected method
        switch ($fields['custom_short_links_redirect_method']) {
            case 'meta':
                add_action('wp_head', function () use ($fields, $redirectTo) {
                    echo '<meta http-equiv="refresh" content="' . $fields['custom_short_links_timeout'] . ';URL=' . $redirectTo . '">';
                });
                break;

            // 301 or 302
            default:
                wp_redirect($redirectTo, intval($fields['custom_short_links_redirect_method']));
                break;
        }
    }
public function simpleRedirect()
    {
        global $wp;
        if (!$request = $wp->request) {
            return;
        }
        $currentSlug = add_query_arg(array(), $request);
        $post = get_page_by_title($currentSlug, 'OBJECT', 'custom-short-link');

        if (!$post) {
            return;
        }

        $fields = get_fields($post->ID);
        $redirectTo = null;

        // Find redirect url
        switch ($fields['custom_short_links_redirect_url_type']) {
            case 'external':
                $redirectTo = $fields['custom_short_links_redirect_to_external'];
                break;

            case 'internal':
                $redirectTo = $fields['custom_short_links_redirect_to_internal'];
                break;
        }

        // Make redirect with selected method
        switch ($fields['custom_short_links_redirect_method']) {
            case 'meta':
                add_action('wp_head', function () use ($fields, $redirectTo) {
                    echo '<meta http-equiv="refresh" content="' . $fields['custom_short_links_timeout'] . ';URL=' . $redirectTo . '">';
                });
                break;

            // 301 or 302
            default:
                wp_redirect($redirectTo, intval($fields['custom_short_links_redirect_method']));
                break;
        }
    }
public function simpleRedirect ( ) { global $ wp ; if ( ! $ request = $ wp -> request ) { return ; } $ currentSlug = add_query_arg ( array ( ) , $ request ) ; $ post = get_page_by_title ( $ currentSlug , 'OBJECT' , 'custom-short-link' ) ; if ( ! $ post ) { return ; } $ fields = get_fields ( $ post -> ID ) ; $ redirectTo = null ; // Find redirect url switch ( $ fields [ 'custom_short_links_redirect_url_type' ] ) { case 'external' : $ redirectTo = $ fields [ 'custom_short_links_redirect_to_external' ] ; break ; case 'internal' : $ redirectTo = $ fields [ 'custom_short_links_redirect_to_internal' ] ; break ; } // Make redirect with selected method switch ( $ fields [ 'custom_short_links_redirect_method' ] ) { case 'meta' : add_action ( 'wp_head' , function ( ) use ( $ fields , $ redirectTo ) { echo '<meta http-equiv="refresh" content="' . $ fields [ 'custom_short_links_timeout' ] . ';URL=' . $ redirectTo . '">' ; } ) ; break ; // 301 or 302 default : wp_redirect ( $ redirectTo , intval ( $ fields [ 'custom_short_links_redirect_method' ] ) ) ; break ; } }
Make a simple PHP redirect to the target page
@return void
Make a simple PHP redirect to the target page