Use new code style
This commit is contained in:
@ -10,7 +10,7 @@
|
||||
* @since 2.1.0
|
||||
*/
|
||||
|
||||
use \Rarst\wps\Plugin as Whoops;
|
||||
use Rarst\wps\Plugin as Whoops;
|
||||
|
||||
return;
|
||||
|
||||
@ -19,10 +19,8 @@ return;
|
||||
* or by setting the constant we used to have on previous versions.
|
||||
*/
|
||||
if (isset($_GET['whoops-disable']) || (defined('WP_ULTIMO_DISABLE_WHOOPS') && WP_ULTIMO_DISABLE_WHOOPS)) {
|
||||
|
||||
return;
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
$wu_whoops = new Whoops();
|
||||
|
||||
|
@ -81,8 +81,7 @@ class Toolkit {
|
||||
add_filter('qm/collectors', array($this, 'register_collector_overview'), 1, 2);
|
||||
|
||||
add_filter('qm/outputter/html', array($this, 'add_overview_panel'), 50, 2);
|
||||
|
||||
} // end init;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the default listeners.
|
||||
@ -107,8 +106,7 @@ class Toolkit {
|
||||
$this->listen('save-rest-arguments', array($this, 'save_route_arguments'), 'wu_rest_register_routes_general');
|
||||
|
||||
$this->listen('save-rest-arguments', array($this, 'save_route_arguments'), 'wu_rest_register_routes_with_id');
|
||||
|
||||
} // end register_default_listeners;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save route arguments to files to deal with opcache.
|
||||
@ -128,8 +126,7 @@ class Toolkit {
|
||||
$args = $manager->get_arguments_schema($context === 'update');
|
||||
|
||||
file_put_contents(wu_path("/mpb/data/endpoint/.endpoint-$class_name-$context"), json_encode($args)); // phpcs:ignore
|
||||
|
||||
} // end save_route_arguments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a listener for development purposes.
|
||||
@ -144,35 +141,38 @@ class Toolkit {
|
||||
*/
|
||||
public function listen($hook, $callback, $wp_hook = 'wp_ultimo_load', $order = 1) {
|
||||
|
||||
$this->listeners[$hook] = ($this->listeners[$hook] ?? 0) + 1;
|
||||
$this->listeners[ $hook ] = ($this->listeners[ $hook ] ?? 0) + 1;
|
||||
|
||||
$this->wp_hooks[$wp_hook] = 1;
|
||||
$this->wp_hooks[ $wp_hook ] = 1;
|
||||
|
||||
$action = $this->get_action($hook, $wp_hook);
|
||||
|
||||
$order = $this->get_order($hook, $order);
|
||||
|
||||
add_action($action, function(...$arguments) use ($callback, $action, $order) {
|
||||
add_action(
|
||||
$action,
|
||||
function (...$arguments) use ($callback, $action, $order) {
|
||||
|
||||
$timing_id = sprintf('%s_%s_%s', $action, $this->run + 1, $order);
|
||||
$timing_id = sprintf('%s_%s_%s', $action, $this->run + 1, $order);
|
||||
|
||||
// phpcs:ignore
|
||||
do_action('qm/start', $timing_id);
|
||||
|
||||
$result = call_user_func_array($callback, $arguments);
|
||||
$result = call_user_func_array($callback, $arguments);
|
||||
|
||||
// phpcs:ignore
|
||||
do_action('qm/stop', $timing_id);
|
||||
|
||||
$this->run++;
|
||||
$this->run++;
|
||||
|
||||
return $result;
|
||||
|
||||
}, $order, 100);
|
||||
return $result;
|
||||
},
|
||||
$order,
|
||||
100
|
||||
);
|
||||
|
||||
return $this;
|
||||
|
||||
} // end listen;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets flags for the development environment.
|
||||
@ -197,17 +197,12 @@ class Toolkit {
|
||||
);
|
||||
|
||||
foreach ($configs as $constant_name => $constant_value) {
|
||||
|
||||
if (in_array($constant_name, $allowed_configs, true)) {
|
||||
|
||||
// phpcs:ignore
|
||||
defined($constant_name) === false && define($constant_name, $constant_value);
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end foreach;
|
||||
|
||||
} // end config;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Marks the development environment to finish execution after all listeners are run.
|
||||
@ -220,14 +215,11 @@ class Toolkit {
|
||||
public function die($should_die = true) {
|
||||
|
||||
if ($should_die === true) {
|
||||
|
||||
$should_die = is_admin() ? 'admin_enqueue_scripts' : 'wp_enqueue_scripts';
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
$this->should_die = $should_die;
|
||||
|
||||
} // end die;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run a registered listener.
|
||||
@ -243,20 +235,15 @@ class Toolkit {
|
||||
$listener = wu_request(self::LISTENER_PARAM, 'no-dev-param');
|
||||
|
||||
if ($listener === 'no-dev-param') {
|
||||
|
||||
return current($arguments);
|
||||
|
||||
} elseif ($listener === '') {
|
||||
|
||||
$listener = 'index';
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
$action = $this->get_action($listener, $wp_hook);
|
||||
|
||||
return do_action_ref_array($action, $arguments); // phpcs:ignore
|
||||
|
||||
} // end run_listener;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the sandbox environment.
|
||||
@ -280,26 +267,20 @@ class Toolkit {
|
||||
$toolkit = $this;
|
||||
|
||||
include $dev_file;
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
$wp_hooks = array_keys($this->wp_hooks);
|
||||
|
||||
foreach ($wp_hooks as $wp_hook) {
|
||||
|
||||
add_action($wp_hook, fn(...$arguments) => $this->run_listener($wp_hook, $arguments), 0, 100);
|
||||
|
||||
} // end foreach;
|
||||
}
|
||||
|
||||
add_action('shutdown', array($this, 'setup_query_monitor'));
|
||||
|
||||
if ($this->should_die) {
|
||||
|
||||
$this->dump_and_die(end($wp_hooks));
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end load_sandbox;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Setups the query monitor integration.
|
||||
@ -310,7 +291,6 @@ class Toolkit {
|
||||
public function setup_query_monitor() {
|
||||
|
||||
if (class_exists('\QM_Dispatchers')) {
|
||||
|
||||
// phpcs:ignore
|
||||
do_action('qm/debug', sprintf('Actions with listeners: %s', $this->get_wp_hooks_list()));
|
||||
|
||||
@ -320,23 +300,17 @@ class Toolkit {
|
||||
// phpcs:ignore
|
||||
$dispatcher = \QM_Dispatchers::get('html');
|
||||
|
||||
if (!$dispatcher) {
|
||||
|
||||
if (! $dispatcher) {
|
||||
return;
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
$dispatcher->did_footer = true;
|
||||
|
||||
if ($this->should_die && $this->run) {
|
||||
|
||||
$this->enqueue_scripts($dispatcher);
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end setup_query_monitor;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the collector overview.
|
||||
@ -352,8 +326,7 @@ class Toolkit {
|
||||
$collectors['wp-ultimo'] = new Query_Monitor\Collectors\Collector_Overview();
|
||||
|
||||
return $collectors;
|
||||
|
||||
} // end register_collector_overview;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the overview panel.
|
||||
@ -370,8 +343,7 @@ class Toolkit {
|
||||
$output['wp-ultimo'] = new Query_Monitor\Panel\Overview($collector);
|
||||
|
||||
return $output;
|
||||
|
||||
} // end add_overview_panel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Manually enqueues query monitor and WP Multisite WaaS styles.
|
||||
@ -383,15 +355,16 @@ class Toolkit {
|
||||
*/
|
||||
protected function enqueue_scripts($dispatcher) {
|
||||
|
||||
echo sprintf('<link rel="stylesheet" id="toolkit" href="%s" type="text/css" media="all">', wu_url('inc/development/assets/development.css'));
|
||||
printf('<link rel="stylesheet" id="toolkit" href="%s" type="text/css" media="all">', wu_url('inc/development/assets/development.css'));
|
||||
|
||||
wp_print_styles(array(
|
||||
'wu-admin',
|
||||
));
|
||||
wp_print_styles(
|
||||
array(
|
||||
'wu-admin',
|
||||
)
|
||||
);
|
||||
|
||||
$dispatcher->manually_print_assets(); // phpcs:ignore
|
||||
|
||||
} // end enqueue_scripts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a comma-separated list of listeners.
|
||||
@ -403,8 +376,7 @@ class Toolkit {
|
||||
$listener_names = array_keys($this->listeners);
|
||||
|
||||
return implode(', ', $listener_names);
|
||||
|
||||
} // end get_listeners_list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a comma-separated list of WordPress hooks.
|
||||
@ -416,8 +388,7 @@ class Toolkit {
|
||||
$wp_hook_names = array_keys($this->wp_hooks);
|
||||
|
||||
return implode(', ', $wp_hook_names);
|
||||
|
||||
} // end get_wp_hooks_list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dumps the development content and kill the execution.
|
||||
@ -429,29 +400,27 @@ class Toolkit {
|
||||
*/
|
||||
protected function dump_and_die($hook) {
|
||||
|
||||
add_action($hook, function() use ($hook) {
|
||||
add_action(
|
||||
$hook,
|
||||
function () use ($hook) {
|
||||
|
||||
if (did_action($this->should_die) && $this->run) {
|
||||
if (did_action($this->should_die) && $this->run) {
|
||||
$this->render_listeners_menu();
|
||||
|
||||
$this->render_listeners_menu();
|
||||
do_action('shutdown'); // phpcs:ignore
|
||||
|
||||
do_action('shutdown'); // phpcs:ignore
|
||||
$message = sprintf('Execution killed on %s.', $hook);
|
||||
|
||||
$message = sprintf('Execution killed on %s.', $hook);
|
||||
do_action('qm/info', $message); // phpcs:ignore
|
||||
|
||||
do_action('qm/info', $message); // phpcs:ignore
|
||||
|
||||
die();
|
||||
|
||||
} else {
|
||||
|
||||
return $this->dump_and_die($this->should_die);
|
||||
|
||||
} // end if;
|
||||
|
||||
}, 110);
|
||||
|
||||
} // end dump_and_die;
|
||||
die();
|
||||
} else {
|
||||
return $this->dump_and_die($this->should_die);
|
||||
}
|
||||
},
|
||||
110
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the order of a newly added listener.
|
||||
@ -464,9 +433,8 @@ class Toolkit {
|
||||
*/
|
||||
protected function get_order($hook, $order = 1) {
|
||||
|
||||
return 10 + (absint($this->listeners[$hook]) * $order * 10) + 5;
|
||||
|
||||
} // end get_order;
|
||||
return 10 + (absint($this->listeners[ $hook ]) * $order * 10) + 5;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the action name based on the listener hook and WP action.
|
||||
@ -481,8 +449,7 @@ class Toolkit {
|
||||
$hook = str_replace('-', '_', $hook);
|
||||
|
||||
return sprintf('wu_sandbox_run_%s_%s', $hook, $wp_hook);
|
||||
|
||||
} // end get_action;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the list of listeners with links.
|
||||
@ -496,10 +463,8 @@ class Toolkit {
|
||||
* Make sure we display it only once.
|
||||
*/
|
||||
if ($this->displayed_footer) {
|
||||
|
||||
return;
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
// phpcs:disable
|
||||
echo '
|
||||
@ -509,13 +474,13 @@ class Toolkit {
|
||||
|
||||
foreach (array_keys($this->listeners) as $listener) {
|
||||
|
||||
echo sprintf(
|
||||
'<li><a href="%s">→ Listener "%s"</a></li>',
|
||||
add_query_arg(self::LISTENER_PARAM, $listener),
|
||||
$listener
|
||||
);
|
||||
echo sprintf(
|
||||
'<li><a href="%s">→ Listener "%s"</a></li>',
|
||||
add_query_arg(self::LISTENER_PARAM, $listener),
|
||||
$listener
|
||||
);
|
||||
|
||||
} // end foreach;
|
||||
}
|
||||
|
||||
echo '
|
||||
</ul>
|
||||
@ -523,6 +488,6 @@ class Toolkit {
|
||||
|
||||
$this->displayed_footer = true;
|
||||
|
||||
} // end render_listeners_menu;
|
||||
}
|
||||
|
||||
} // end class Toolkit;
|
||||
}
|
||||
|
@ -35,8 +35,7 @@ class Collector_Overview extends \QM_Collector {
|
||||
public function set_up() {
|
||||
|
||||
parent::set_up();
|
||||
|
||||
} // end set_up;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tear down routines.
|
||||
@ -47,8 +46,7 @@ class Collector_Overview extends \QM_Collector {
|
||||
public function tear_down() {
|
||||
|
||||
parent::tear_down();
|
||||
|
||||
} // end tear_down;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the collection.
|
||||
@ -62,7 +60,5 @@ class Collector_Overview extends \QM_Collector {
|
||||
public function process() {
|
||||
|
||||
$this->data = $_REQUEST;
|
||||
|
||||
} // end process;
|
||||
|
||||
} // end class Collector_Overview;
|
||||
}
|
||||
}
|
||||
|
@ -20,12 +20,12 @@ defined('ABSPATH') || exit;
|
||||
class Overview extends \QM_Output_Html {
|
||||
|
||||
/**
|
||||
* Initializes the panel.
|
||||
*
|
||||
* @since 2.0.11
|
||||
*
|
||||
* @param \QM_Collector $collector The collector associated with the panel.
|
||||
*/
|
||||
* Initializes the panel.
|
||||
*
|
||||
* @since 2.0.11
|
||||
*
|
||||
* @param \QM_Collector $collector The collector associated with the panel.
|
||||
*/
|
||||
public function __construct($collector) {
|
||||
|
||||
parent::__construct($collector);
|
||||
@ -33,8 +33,7 @@ class Overview extends \QM_Output_Html {
|
||||
add_filter('qm/output/menus', array($this, 'admin_menu'), 1000);
|
||||
|
||||
add_filter('qm/output/panel_menus', array($this, 'panel_menu'), 1000);
|
||||
|
||||
} // end __construct;
|
||||
}
|
||||
|
||||
/**
|
||||
* The name of the panel.
|
||||
@ -45,8 +44,7 @@ class Overview extends \QM_Output_Html {
|
||||
public function name() {
|
||||
|
||||
return __('WP Multisite WaaS', 'wp-ultimo');
|
||||
|
||||
} // end name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the contents of the panel.
|
||||
@ -79,8 +77,7 @@ class Overview extends \QM_Output_Html {
|
||||
$data = $this->collector->get_data();
|
||||
|
||||
$this->after_non_tabular_output();
|
||||
|
||||
} // end output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the panel to the admin panel.
|
||||
@ -93,8 +90,7 @@ class Overview extends \QM_Output_Html {
|
||||
public function admin_menu(array $menu) {
|
||||
|
||||
return $menu;
|
||||
|
||||
} // end admin_menu;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a panel menu for the panel.
|
||||
@ -107,14 +103,14 @@ class Overview extends \QM_Output_Html {
|
||||
public function panel_menu(array $menu) {
|
||||
|
||||
$new_menu = array(
|
||||
'wp-ultimo' => $this->menu(array(
|
||||
'title' => esc_html__('WP Multisite WaaS', 'wp-ultimo'),
|
||||
'id' => 'wp-ultimo',
|
||||
)),
|
||||
'wp-ultimo' => $this->menu(
|
||||
array(
|
||||
'title' => esc_html__('WP Multisite WaaS', 'wp-ultimo'),
|
||||
'id' => 'wp-ultimo',
|
||||
)
|
||||
),
|
||||
);
|
||||
|
||||
return $new_menu + $menu;
|
||||
|
||||
} // end panel_menu;
|
||||
|
||||
} // end class Overview;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user