0 ) { // array of arguments passed to this function $arg_list = func_get_args(); // set backtrace key based on WordPress version number global $wp_version; $backtrack_key = 3; if ( $wp_version < 4.7 ) { $backtrack_key = 1; } // backtrace args key is always 0 $backtrack_args_key = 0; foreach ( $arg_list as $arg_value ) { // build backtrace info $backtrace = debug_backtrace(); // path to file do_action( 'php_console_log' ) was used in $backtrace_array['file'] = $backtrace[$backtrack_key]['file']; // line number do_action( 'php_console_log' ) was used on $backtrace_array['line'] = $backtrace[$backtrack_key]['line']; // args passed in with do_action( 'php_console_log' ) $backtrace_array['args'] = $backtrace[$backtrack_args_key]['args']; // add each argument to the global $php_console_log_array $php_console_log_array[] = $backtrace_array; } } } /** * @info Custom action that is called by end user to log info to web console. * @since 1.0.0 */ add_action( 'php_console_log', 'php_console_log' ); /** * @func php_console_log_load_first() * * Make sure PHP Console Log plugin is loaded first so * do_action('php_console_log' ) can be used in other plugins. Runs when a * plugin is activated and deactivated. Option "active_plugins" order in the * options table of the database can be changed by other plugins after this * runs. Any plugin that loads before PHP Console Log will not be able to use * this plugin's features. * * @since 1.0.0 * */ function php_console_log_load_first() { // get active_plugins row from options table if ( $plugins = get_option( 'active_plugins' ) ) { // if PHP Console Log plugin is not the first element in active_plugins array if ( $key = array_search( PHP_CONSOLE_LOG_PLUGIN_BASENAME, $plugins ) ) { // make PHP Console Log plugin first in active_plugins array array_splice( $plugins, $key, 1 ); array_unshift( $plugins, PHP_CONSOLE_LOG_PLUGIN_BASENAME ); // update active_plugins row in options table update_option( 'active_plugins', $plugins ); } } } /** * @info Set PHP Console Log as first plugin to load when any plugin is * activated or deactivated. * @since 1.0.0 */ add_action( 'activated_plugin', 'php_console_log_load_first' ); add_action( 'deactivated_plugin', 'php_console_log_load_first' );