Skip to content

Instantly share code, notes, and snippets.

@leepeterson
Forked from Rarst/class-global-sniffer.php
Created September 5, 2017 02:15
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 leepeterson/53cedcef23389c38302651057250c32c to your computer and use it in GitHub Desktop.
Save leepeterson/53cedcef23389c38302651057250c32c to your computer and use it in GitHub Desktop.
Discover where is array global being modified, because WordPress.
<?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