name = $action;
$this->depth = 0;
$this->messages = array();
$this->subActions = array();
}
public function addMessage($message) {
$this->subActions[] = $message;
}
static function on_action() {
global $wp_current_filter;
$action = current_filter();
// ignore some actions
switch($action) {
case 'gettext':
case 'gettext_with_context':
return;
};
$instance = new BE_MCH_ACTUNV_class($action);
$instance->depth = count($wp_current_filter);
self::$dicActions[$action] = $instance;
self::$actions[] = $instance;
if ($instance->depth > 1) {
$previousAction = $wp_current_filter[$instance->depth - 2];
if (isset(self::$dicActions[$previousAction])) {
self::$dicActions[$previousAction]->subActions[] = $instance;
array_pop(self::$actions);
}
}
}
static function print_actions($actions) {
foreach($actions as $a => $action) {
if ($action instanceof BE_MCH_ACTUNV_class) {
echo(sprintf(
$action->name == null
? '
%1$s'
: '%1$s'
, htmlspecialchars($action->name)
, $action->depth
));
} else {
echo(sprintf(
'%1$s'
, htmlspecialchars($action)
));
}
if (count($action->subActions) > 0) {
echo('');
self::print_actions($action->subActions);
echo('
');
}
echo('');
}
}
static function on_shutdown() {
if (is_admin()) {
echo('');
self::print_actions(self::$actions);
echo('
');
} else {
// Comment node
echo('');
}
}
static function add_message($action, $message) {
if (isset(self::$dicActions[$action])) {
self::$dicActions[$action]->addMessage($message);
} else {
$instance = new BE_MCH_ACTUNV_class(
$action == null
? ''
: '[' . $action . ']'
);
$instance->addMessage($message);
self::$actions[] = $instance;
}
}
}
class BE_MCH_ACTUNV_messenger {
private $message;
public function __construct($message) {
$action = current_filter();
// echo($message);
BE_MCH_ACTUNV_class::add_message($action, $message);
}
}
add_action( 'all', array('BE_MCH_ACTUNV_class', 'on_action'), 0);
add_action( 'shutdown', array('BE_MCH_ACTUNV_class', 'on_shutdown'), 9999);