Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.