
Product
/Security News
Introducing Socket Calm: A Syntax Highlighting Theme for VS Code, Vim, and Neovim
Socket Calm is a free, open source syntax highlighting theme for VS Code, Vim, and Neovim, inspired by Socket's design system.
truongwp/wp-redirect-with-error
Advanced tools
Handle error when redirecting to other URL in WordPress.
This class handles the error when redirecting to other URL in WordPress. Use simple URL parameter and nonce, don't use SESSION or COOKIE which not advised in WordPress.
Just include file class-truongwp-redirect-with-error.php in your theme or plugin or use Composer to install.
composer require "truongwp/wp-redirect-with-error=*"
Then create a function to store class instance globally.
<?php
function prefix_redirect_error() {
static $errors = null;
if ( ! $errors ) {
$errors = new Truongwp_Redirect_With_Error();
}
return $errors;
}
You need to register all errors you use. This can be done by register_error() method.
<?php
function prefix_redirect_error() {
static $errors = null;
if ( ! $errors ) {
$errors = new Truongwp_Redirect_With_Error();
}
$errors->register_error( 'error-1', 'This is error 1' );
$errors->register_error( 'error-2', 'This is error 2' );
$errors->register_error( 'error-3', 'This is error 3' );
return $errors;
}
To pass error to redirect URL. Instead of:
<?php
wp_redirect( $url );
You need:
<?php
$new_url = prefix_redirect_error()->add_error( $url, 'error-2' );
wp_redirect( $new_url );
To display error, use this code:
<?php
prefix_redirect_error()->show_error();
To display only specific error, pass error code to show_error() method:
<?php
prefix_redirect_error()->show_error( 'error-1' );
To change markup of error when displaying, use set_template() method:
<?php
function prefix_redirect_error() {
static $errors = null;
if ( ! $errors ) {
$errors = new Truongwp_Redirect_With_Error();
}
$errors->register_error( 'error-1', 'This is error 1' );
$errors->register_error( 'error-2', 'This is error 2' );
$errors->register_error( 'error-3', 'This is error 3' );
// Set new error markup.
$errors->set_template( '<p class="error error-%1$s">%2$s</p>' );
return $errors;
}
You can also change some other value, read the code and comments in class-truongwp-redirect-with-error.php file.``
Contributor: @truongwp
Bug reports or Pull requests are welcome.
FAQs
Handle error when redirecting to other URL in WordPress.
We found that truongwp/wp-redirect-with-error demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.

Product
/Security News
Socket Calm is a free, open source syntax highlighting theme for VS Code, Vim, and Neovim, inspired by Socket's design system.

Product
Fix critical RubyGems vulnerabilities without upgrading dependencies. Free security patches are now available with more ways to install and deploy them.

Threat Research
/Security News
Socket researchers uncovered 13 malicious NuGet packages linked to fake developer job assessments, DLL side-loading, credential theft, and GitHub-based malware.