Last active
September 5, 2024 01:49
-
-
Save Rarst/2901b0d89d4fc0a1d96c to your computer and use it in GitHub Desktop.
Discover where is array global being modified, because WordPress.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Rarst; | |
/** | |
* Discover where is array global being modified, because WordPress. | |
*/ | |
class Global_Sniffer implements \ArrayAccess { | |
protected $name; | |
protected $data; | |
/** | |
* @param string $name | |
* @param array $data | |
*/ | |
public function __construct( $name, array $data = [ ] ) { | |
$this->name = $name; | |
if ( isset( $GLOBALS[ $name ] ) && is_array( $GLOBALS[ $name ] ) ) { | |
$data = $GLOBALS[ $name ]; | |
} | |
$this->data = $data; | |
$GLOBALS[ $name ] = $this; | |
} | |
/** | |
* @inheritdoc | |
*/ | |
public function offsetExists( $offset ) { | |
return isset( $this->data[ $offset ] ); | |
} | |
/** | |
* @inheritdoc | |
*/ | |
public function offsetGet( $offset ) { | |
return $this->data[ $offset ]; | |
} | |
/** | |
* @inheritdoc | |
*/ | |
public function offsetSet( $offset, $value ) { | |
var_dump( $this->name, $offset, $value, wp_debug_backtrace_summary( null, 1, false ) ); | |
$this->data[ $offset ] = $value; | |
} | |
/** | |
* @inheritdoc | |
*/ | |
public function offsetUnset( $offset ) { | |
unset( $this->data[ $offset ] ); | |
} | |
} | |
// Example: | |
// new Global_Sniffer( '_wp_admin_css_colors' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment