wp_safe_redirect example

exit;
        }

        if ( $wp_list_table->current_action() && ! empty( $_REQUEST['users'] ) ) {
            $screen   = get_current_screen()->id;
            $sendback = wp_get_referer();
            $user_ids = array_map( 'intval', (array) $_REQUEST['users'] );

            /** This action is documented in wp-admin/edit.php */
            $sendback = apply_filters( "handle_bulk_actions-{$screen}", $sendback$wp_list_table->current_action()$user_ids ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
            wp_safe_redirect( $sendback );
            exit;
        }

        $wp_list_table->prepare_items();
        $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' );

        if ( $pagenum > $total_pages && $total_pages > 0 ) {
            wp_redirect( add_query_arg( 'paged', $total_pages ) );
            exit;
        }

        
return;
        }

        if ( isset( $_POST['remove-background'] ) ) {
            // @todo Uploaded files are not removed here.             check_admin_referer( 'custom-background-remove', '_wpnonce-custom-background-remove' );

            set_theme_mod( 'background_image', '' );
            set_theme_mod( 'background_image_thumb', '' );

            $this->updated = true;
            wp_safe_redirect( $_POST['_wp_http_referer'] );
            return;
        }

        if ( isset( $_POST['background-preset'] ) ) {
            check_admin_referer( 'custom-background' );

            if ( in_array( $_POST['background-preset'], array( 'default', 'fill', 'fit', 'repeat', 'custom' ), true ) ) {
                $preset = $_POST['background-preset'];
            } else {
                $preset = 'default';
            }

            
$comment_status,
                $delete_time
            )
        );
        $doaction       = 'delete';
    } elseif ( isset( $_REQUEST['delete_comments'] ) ) {
        $comment_ids = $_REQUEST['delete_comments'];
        $doaction    = $_REQUEST['action'];
    } elseif ( isset( $_REQUEST['ids'] ) ) {
        $comment_ids = array_map( 'absint', explode( ',', $_REQUEST['ids'] ) );
    } elseif ( wp_get_referer() ) {
        wp_safe_redirect( wp_get_referer() );
        exit;
    }

    $approved   = 0;
    $unapproved = 0;
    $spammed    = 0;
    $unspammed  = 0;
    $trashed    = 0;
    $untrashed  = 0;
    $deleted    = 0;

    

                $referer = apply_filters( "handle_network_bulk_actions-{$screen}", $referer$action$themes$id ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores             } else {
                $action = 'error';
                $n      = 'none';
            }
    }

    update_option( 'allowedthemes', $allowed_themes );
    restore_current_blog();

    wp_safe_redirect(
        add_query_arg(
            array(
                'id'    => $id,
                $action => $n,
            ),
            $referer
        )
    );
    exit;
}



        if ( isset( $_POST['action'] ) && $_POST['action'] == 'enter-key' ) {
            self::enter_api_key();
        }
    }

    public static function init_hooks() {
        // The standalone stats page was removed in 3.0 for an all-in-one config and stats page.         // Redirect any links that might have been bookmarked or in browser history.         if ( isset( $_GET['page'] ) && 'akismet-stats-display' == $_GET['page'] ) {
            wp_safe_redirect( esc_url_raw( self::get_page_url( 'stats' ) ), 301 );
            die;
        }

        self::$initiated = true;

        add_action( 'admin_init', array( 'Akismet_Admin', 'admin_init' ) );
        add_action( 'admin_menu', array( 'Akismet_Admin', 'admin_menu' ), 5 ); # Priority 5, so it's called before Jetpack's admin_menu.         add_action( 'admin_notices', array( 'Akismet_Admin', 'display_notice' ) );
        add_action( 'admin_enqueue_scripts', array( 'Akismet_Admin', 'load_resources' ) );
        add_action( 'activity_box_end', array( 'Akismet_Admin', 'dashboard_stats' ) );
        add_action( 'rightnow_end', array( 'Akismet_Admin', 'rightnow_stats' ) );
        
/** * Filters the location URI to send the commenter after posting. * * @since 2.0.5 * * @param string $location The 'redirect_to' URI sent via $_POST. * @param WP_Comment $comment Comment object. */
$location = apply_filters( 'comment_post_redirect', $location$comment );

wp_safe_redirect( $location );
exit;

            check_admin_referer( 'bulk-users' );
            $userids = $_REQUEST['users'];

            /** This action is documented in wp-admin/network/site-themes.php */
            $referer = apply_filters( 'handle_network_bulk_actions-' . get_current_screen()->id, $referer$action$userids$id ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
            $update = $action;
            break;
    }

    wp_safe_redirect( add_query_arg( 'update', $update$referer ) );
    exit;
}

restore_current_blog();

if ( isset( $_GET['action'] ) && 'update-site' === $_GET['action'] ) {
    wp_safe_redirect( $referer );
    exit;
}

add_screen_option( 'per_page' );

break;
    }

    update_user_meta( $user->ID, $option$value );

    $url = remove_query_arg( array( 'pagenum', 'apage', 'paged' )wp_get_referer() );

    if ( isset( $_POST['mode'] ) ) {
        $url = add_query_arg( array( 'mode' => $_POST['mode'] )$url );
    }

    wp_safe_redirect( $url );
    exit;
}

/** * Checks if rewrite rule for WordPress already exists in the IIS 7+ configuration file. * * @since 2.8.0 * * @param string $filename The file path to the configuration file. * @return bool */


/** Make sure that the WordPress bootstrap has run before continuing. */
require __DIR__ . '/wp-load.php';

// Redirect to HTTPS login if forced to use SSL. if ( force_ssl_admin() && ! is_ssl() ) {
    if ( str_starts_with( $_SERVER['REQUEST_URI'], 'http' ) ) {
        wp_safe_redirect( set_url_scheme( $_SERVER['REQUEST_URI'], 'https' ) );
        exit;
    } else {
        wp_safe_redirect( 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
        exit;
    }
}

/** * Outputs the login page header. * * @since 2.1.0 * * @global string $error Login error message set by deprecated pluggable wp_login() function * or plugins replacing it. * @global bool|string $interim_login Whether interim login modal is being displayed. String 'success' * upon successful login. * @global string $action The action that brought the visitor to the login page. * * @param string $title Optional. WordPress login Page title to display in the `<title>` element. * Default 'Log In'. * @param string $message Optional. Message to display in header. Default empty. * @param WP_Error $wp_error Optional. The error to pass. Default is a WP_Error instance. */

    public function handle_exit_recovery_mode() {
        $redirect_to = wp_get_referer();

        // Safety check in case referrer returns false.         if ( ! $redirect_to ) {
            $redirect_to = is_user_logged_in() ? admin_url() : home_url();
        }

        if ( ! $this->is_active() ) {
            wp_safe_redirect( $redirect_to );
            die;
        }

        if ( ! isset( $_GET['action'] ) || self::EXIT_ACTION !== $_GET['action'] ) {
            return;
        }

        if ( ! isset( $_GET['_wpnonce'] ) || ! wp_verify_nonce( $_GET['_wpnonce'], self::EXIT_ACTION ) ) {
            wp_die( __( 'Exit recovery mode link expired.' ), 403 );
        }

        
exit;

    case 'toggle-custom-fields':
        check_admin_referer( 'toggle-custom-fields', 'toggle-custom-fields-nonce' );

        $current_user_id = get_current_user_id();
        if ( $current_user_id ) {
            $enable_custom_fields = (bool) get_user_meta( $current_user_id, 'enable_custom_fields', true );
            update_user_meta( $current_user_id, 'enable_custom_fields', ! $enable_custom_fields );
        }

        wp_safe_redirect( wp_get_referer() );
        exit;

    default:
        /** * Fires for a given custom post action request. * * The dynamic portion of the hook name, `$action`, refers to the custom post action. * * @since 4.6.0 * * @param int $post_id Post ID sent with the request. */
exit;
        default:
            if ( isset( $_POST['checked'] ) ) {
                check_admin_referer( 'bulk-plugins' );

                $screen   = get_current_screen()->id;
                $sendback = wp_get_referer();
                $plugins  = isset( $_POST['checked'] ) ? (array) wp_unslash( $_POST['checked'] ) : array();

                /** This action is documented in wp-admin/edit.php */
                $sendback = apply_filters( "handle_bulk_actions-{$screen}", $sendback$action$plugins ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores                 wp_safe_redirect( $sendback );
                exit;
            }
            break;
    }
}

$wp_list_table->prepare_items();

wp_enqueue_script( 'plugin-install' );
add_thickbox();

$_SERVER['REQUEST_URI'] = remove_query_arg( $temp_args$_SERVER['REQUEST_URI'] );
$referer                = remove_query_arg( $temp_argswp_get_referer() );

if ( $action ) {
    switch ( $action ) {
        case 'enable':
            check_admin_referer( 'enable-theme_' . $_GET['theme'] );
            WP_Theme::network_enable_theme( $_GET['theme'] );
            if ( ! str_contains( $referer, '/network/themes.php' ) ) {
                wp_redirect( network_admin_url( 'themes.php?enabled=1' ) );
            } else {
                wp_safe_redirect( add_query_arg( 'enabled', 1, $referer ) );
            }
            exit;
        case 'disable':
            check_admin_referer( 'disable-theme_' . $_GET['theme'] );
            WP_Theme::network_disable_theme( $_GET['theme'] );
            wp_safe_redirect( add_query_arg( 'disabled', '1', $referer ) );
            exit;
        case 'enable-selected':
            check_admin_referer( 'bulk-themes' );
            $themes = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array();
            if ( empty( $themes ) ) {
                

    public function redirect_sitemapxml( $bypass$query ) {
        // If a plugin has already utilized the pre_handle_404 function, return without action to avoid conflicts.         if ( $bypass ) {
            return $bypass;
        }

        // 'pagename' is for most permalink types, name is for when the %postname% is used as a top-level field.         if ( 'sitemap-xml' === $query->get( 'pagename' )
            || 'sitemap-xml' === $query->get( 'name' )
        ) {
            wp_safe_redirect( $this->index->get_index_url() );
            exit();
        }

        return $bypass;
    }

    /** * Adds the sitemap index to robots.txt. * * @since 5.5.0 * * @param string $output robots.txt output. * @param bool $is_public Whether the site is public. * @return string The robots.txt output. */
 elseif ( ! empty( $_GET['key'] ) ) {
    $key = $_GET['key'];
} elseif ( ! empty( $_POST['key'] ) ) {
    $key = $_POST['key'];
}

if ( $key ) {
    $redirect_url = remove_query_arg( 'key' );

    if ( remove_query_arg( false ) !== $redirect_url ) {
        setcookie( $activate_cookie$key, 0, $activate_path, COOKIE_DOMAIN, is_ssl(), true );
        wp_safe_redirect( $redirect_url );
        exit;
    } else {
        $result = wpmu_activate_signup( $key );
    }
}

if ( null === $result && isset( $_COOKIE[ $activate_cookie ] ) ) {
    $key    = $_COOKIE[ $activate_cookie ];
    $result = wpmu_activate_signup( $key );
    setcookie( $activate_cookie, ' ', time() - YEAR_IN_SECONDS, $activate_path, COOKIE_DOMAIN, is_ssl(), true );
}

Home | Imprint | This part of the site doesn't use cookies.