Skip to content

Instantly share code, notes, and snippets.

@donmhico
Last active September 24, 2021 17:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save donmhico/bcbcc57042ae25fe11d3dda4dc79c693 to your computer and use it in GitHub Desktop.
Save donmhico/bcbcc57042ae25fe11d3dda4dc79c693 to your computer and use it in GitHub Desktop.
<?php
add_action( 'edit_form_top', 'add_parameters_to_preserve_in_post_form' );
/**
* Add a new input in Post form if 'go-back-to-plugin' is a URL parameter.
*
* @see https://developer.wordpress.org/reference/hooks/edit_form_top/
*
* @return void
*/
function add_parameters_to_preserve_in_post_form() : void {
$back_to_plugin = filter_input( INPUT_GET, 'go-back-to-plugin', FILTER_SANITIZE_STRING );
if ( empty( $back_to_plugin ) || '1' !== $back_to_plugin ) {
return;
}
?>
<input
type="hidden"
id="go-back-to-plugin"
name="go-back-to-plugin"
value="1"
/>
<?php
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment