Baki
Baki

Reputation: 1

how to redirect Wordpress 404 page through function()

I want to change a role in my wordpress plugin.

            if ( is_admin() && ! is_user_logged_in() && ! defined( 'DOING_AJAX' ) && $pagenow !== 'admin-post.php' ) {
            wp_die( __( 'This has been disabled', 'wp-hide-login' ), 403 );
        }

        $request = parse_url( $_SERVER['REQUEST_URI'] );

When my plugin get the action, Wordpress shows "This has been disabled" under WP default (admin-post.php) page. But i need when my function get assign it's redirect to 404 page.

As like as "This has been disabled" > http://www.example.com/404

Upvotes: 0

Views: 10704

Answers (1)

Amit Gaud
Amit Gaud

Reputation: 766

<?php
 if ( is_admin() && ! is_user_logged_in() && ! defined( 'DOING_AJAX' ) && $pagenow !== 'admin-post.php' ) 
      {
             global $wp_query;
            $wp_query->set_404();
            status_header( 404 );
            get_template_part( 404 ); exit();
        }

?>

Upvotes: 7

Related Questions