Skip to content

Instantly share code, notes, and snippets.

@Rarst
Last active October 4, 2017 14:14
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Rarst/2901b0d89d4fc0a1d96c to your computer and use it in GitHub Desktop.
Save Rarst/2901b0d89d4fc0a1d96c 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