Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save michaeluno/b8df5e5796980fcec8ad to your computer and use it in GitHub Desktop.
Save michaeluno/b8df5e5796980fcec8ad to your computer and use it in GitHub Desktop.
Restores the global $post variable in the admin area as some plugins modify it.
<?php
/*
Plugin Name: Patch - Admin Page Framework Global Post Variable
Description: Restores the global $post variable in the admin area as some plugins modify it.
*/
class Patch_AdminPageFramework_GlobalPostVariable {
public function __construct() {
if ( ! is_admin() ) {
return;
}
$this->storeGlobalPostVariable();
add_action(
'current_screen',
array( $this, 'restoreGlobalPostVariable' ),
1
);
}
static public $post;
public function storeGlobalPostVariable() {
global $post;
self::$post = $post;
}
public function restoreGlobalPostVariable() {
global $post;
$post = self::$post;
}
}
new Patch_AdminPageFramework_GlobalPostVariable;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment