@@ -6,70 +6,70 @@ |
||
| 6 | 6 | |
| 7 | 7 | class Console |
| 8 | 8 | { |
| 9 | - const ERROR_CODES = array( |
|
| 10 | - E_ERROR => 'Error', // 1 |
|
| 11 | - E_WARNING => 'Warning', // 2 |
|
| 12 | - E_NOTICE => 'Notice', // 8 |
|
| 13 | - E_STRICT => 'Strict', // 2048 |
|
| 14 | - E_DEPRECATED => 'Deprecated', // 8192 |
|
| 15 | - ); |
|
| 9 | + const ERROR_CODES = array( |
|
| 10 | + E_ERROR => 'Error', // 1 |
|
| 11 | + E_WARNING => 'Warning', // 2 |
|
| 12 | + E_NOTICE => 'Notice', // 8 |
|
| 13 | + E_STRICT => 'Strict', // 2048 |
|
| 14 | + E_DEPRECATED => 'Deprecated', // 8192 |
|
| 15 | + ); |
|
| 16 | 16 | |
| 17 | - const MAPPED_ERROR_CODES = array( |
|
| 18 | - 'debug' => 0, |
|
| 19 | - 'info' => 0, |
|
| 20 | - 'notice' => 0, |
|
| 21 | - 'warning' => E_NOTICE, // 8 |
|
| 22 | - 'error' => E_WARNING, // 2 |
|
| 23 | - 'critical' => E_WARNING, // 2 |
|
| 24 | - 'alert' => E_WARNING, // 2 |
|
| 25 | - 'emergency' => E_WARNING, // 2 |
|
| 26 | - ); |
|
| 17 | + const MAPPED_ERROR_CODES = array( |
|
| 18 | + 'debug' => 0, |
|
| 19 | + 'info' => 0, |
|
| 20 | + 'notice' => 0, |
|
| 21 | + 'warning' => E_NOTICE, // 8 |
|
| 22 | + 'error' => E_WARNING, // 2 |
|
| 23 | + 'critical' => E_WARNING, // 2 |
|
| 24 | + 'alert' => E_WARNING, // 2 |
|
| 25 | + 'emergency' => E_WARNING, // 2 |
|
| 26 | + ); |
|
| 27 | 27 | |
| 28 | - public $entries = array(); |
|
| 28 | + public $entries = array(); |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * @param string $message |
|
| 32 | - * @return static |
|
| 33 | - */ |
|
| 34 | - public function store($message, $errno = 0, $location = '') |
|
| 35 | - { |
|
| 36 | - $errname = 'Debug'; |
|
| 37 | - if (array_key_exists($errno, static::MAPPED_ERROR_CODES)) { |
|
| 38 | - $errname = ucfirst($errno); |
|
| 39 | - $errno = static::MAPPED_ERROR_CODES[$errno]; |
|
| 40 | - } elseif (array_key_exists($errno, static::ERROR_CODES)) { |
|
| 41 | - $errname = static::ERROR_CODES[$errno]; |
|
| 42 | - } |
|
| 43 | - $this->entries[] = array( |
|
| 44 | - 'errno' => $errno, |
|
| 45 | - 'message' => $location.$this->normalizeValue($message), |
|
| 46 | - 'name' => sprintf('<span class="glbb-info glbb-%s">%s</span>', strtolower($errname), $errname), |
|
| 47 | - ); |
|
| 48 | - return $this; |
|
| 49 | - } |
|
| 30 | + /** |
|
| 31 | + * @param string $message |
|
| 32 | + * @return static |
|
| 33 | + */ |
|
| 34 | + public function store($message, $errno = 0, $location = '') |
|
| 35 | + { |
|
| 36 | + $errname = 'Debug'; |
|
| 37 | + if (array_key_exists($errno, static::MAPPED_ERROR_CODES)) { |
|
| 38 | + $errname = ucfirst($errno); |
|
| 39 | + $errno = static::MAPPED_ERROR_CODES[$errno]; |
|
| 40 | + } elseif (array_key_exists($errno, static::ERROR_CODES)) { |
|
| 41 | + $errname = static::ERROR_CODES[$errno]; |
|
| 42 | + } |
|
| 43 | + $this->entries[] = array( |
|
| 44 | + 'errno' => $errno, |
|
| 45 | + 'message' => $location.$this->normalizeValue($message), |
|
| 46 | + 'name' => sprintf('<span class="glbb-info glbb-%s">%s</span>', strtolower($errname), $errname), |
|
| 47 | + ); |
|
| 48 | + return $this; |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * @param mixed $value |
|
| 53 | - * @return bool |
|
| 54 | - */ |
|
| 55 | - protected function isObjectOrArray($value) |
|
| 56 | - { |
|
| 57 | - return is_object($value) || is_array($value); |
|
| 58 | - } |
|
| 51 | + /** |
|
| 52 | + * @param mixed $value |
|
| 53 | + * @return bool |
|
| 54 | + */ |
|
| 55 | + protected function isObjectOrArray($value) |
|
| 56 | + { |
|
| 57 | + return is_object($value) || is_array($value); |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * @param mixed $value |
|
| 62 | - * @return string |
|
| 63 | - */ |
|
| 64 | - protected function normalizeValue($value) |
|
| 65 | - { |
|
| 66 | - if ($value instanceof DateTime) { |
|
| 67 | - $value = $value->format('Y-m-d H:i:s'); |
|
| 68 | - } elseif ($this->isObjectOrArray($value)) { |
|
| 69 | - $value = print_r(json_decode(json_encode($value)), true); |
|
| 70 | - } elseif (is_resource($value)) { |
|
| 71 | - $value = (string) $value; |
|
| 72 | - } |
|
| 73 | - return esc_html($value); |
|
| 74 | - } |
|
| 60 | + /** |
|
| 61 | + * @param mixed $value |
|
| 62 | + * @return string |
|
| 63 | + */ |
|
| 64 | + protected function normalizeValue($value) |
|
| 65 | + { |
|
| 66 | + if ($value instanceof DateTime) { |
|
| 67 | + $value = $value->format('Y-m-d H:i:s'); |
|
| 68 | + } elseif ($this->isObjectOrArray($value)) { |
|
| 69 | + $value = print_r(json_decode(json_encode($value)), true); |
|
| 70 | + } elseif (is_resource($value)) { |
|
| 71 | + $value = (string) $value; |
|
| 72 | + } |
|
| 73 | + return esc_html($value); |
|
| 74 | + } |
|
| 75 | 75 | } |
@@ -31,19 +31,19 @@ discard block |
||
| 31 | 31 | * @param string $message |
| 32 | 32 | * @return static |
| 33 | 33 | */ |
| 34 | - public function store($message, $errno = 0, $location = '') |
|
| 34 | + public function store( $message, $errno = 0, $location = '' ) |
|
| 35 | 35 | { |
| 36 | 36 | $errname = 'Debug'; |
| 37 | - if (array_key_exists($errno, static::MAPPED_ERROR_CODES)) { |
|
| 38 | - $errname = ucfirst($errno); |
|
| 39 | - $errno = static::MAPPED_ERROR_CODES[$errno]; |
|
| 40 | - } elseif (array_key_exists($errno, static::ERROR_CODES)) { |
|
| 41 | - $errname = static::ERROR_CODES[$errno]; |
|
| 37 | + if( array_key_exists( $errno, static::MAPPED_ERROR_CODES ) ) { |
|
| 38 | + $errname = ucfirst( $errno ); |
|
| 39 | + $errno = static::MAPPED_ERROR_CODES[ $errno ]; |
|
| 40 | + } elseif( array_key_exists( $errno, static::ERROR_CODES ) ) { |
|
| 41 | + $errname = static::ERROR_CODES[ $errno ]; |
|
| 42 | 42 | } |
| 43 | - $this->entries[] = array( |
|
| 43 | + $this->entries[ ] = array( |
|
| 44 | 44 | 'errno' => $errno, |
| 45 | - 'message' => $location.$this->normalizeValue($message), |
|
| 46 | - 'name' => sprintf('<span class="glbb-info glbb-%s">%s</span>', strtolower($errname), $errname), |
|
| 45 | + 'message' => $location . $this->normalizeValue( $message ), |
|
| 46 | + 'name' => sprintf( '<span class="glbb-info glbb-%s">%s</span>', strtolower( $errname ), $errname ), |
|
| 47 | 47 | ); |
| 48 | 48 | return $this; |
| 49 | 49 | } |
@@ -52,24 +52,24 @@ discard block |
||
| 52 | 52 | * @param mixed $value |
| 53 | 53 | * @return bool |
| 54 | 54 | */ |
| 55 | - protected function isObjectOrArray($value) |
|
| 55 | + protected function isObjectOrArray( $value ) |
|
| 56 | 56 | { |
| 57 | - return is_object($value) || is_array($value); |
|
| 57 | + return is_object( $value ) || is_array( $value ); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | /** |
| 61 | 61 | * @param mixed $value |
| 62 | 62 | * @return string |
| 63 | 63 | */ |
| 64 | - protected function normalizeValue($value) |
|
| 64 | + protected function normalizeValue( $value ) |
|
| 65 | 65 | { |
| 66 | - if ($value instanceof DateTime) { |
|
| 67 | - $value = $value->format('Y-m-d H:i:s'); |
|
| 68 | - } elseif ($this->isObjectOrArray($value)) { |
|
| 69 | - $value = print_r(json_decode(json_encode($value)), true); |
|
| 70 | - } elseif (is_resource($value)) { |
|
| 66 | + if( $value instanceof DateTime ) { |
|
| 67 | + $value = $value->format( 'Y-m-d H:i:s' ); |
|
| 68 | + } elseif( $this->isObjectOrArray( $value ) ) { |
|
| 69 | + $value = print_r( json_decode( json_encode( $value ) ), true ); |
|
| 70 | + } elseif( is_resource( $value ) ) { |
|
| 71 | 71 | $value = (string) $value; |
| 72 | 72 | } |
| 73 | - return esc_html($value); |
|
| 73 | + return esc_html( $value ); |
|
| 74 | 74 | } |
| 75 | 75 | } |
@@ -37,7 +37,8 @@ discard block |
||
| 37 | 37 | if (array_key_exists($errno, static::MAPPED_ERROR_CODES)) { |
| 38 | 38 | $errname = ucfirst($errno); |
| 39 | 39 | $errno = static::MAPPED_ERROR_CODES[$errno]; |
| 40 | - } elseif (array_key_exists($errno, static::ERROR_CODES)) { |
|
| 40 | + } |
|
| 41 | + elseif (array_key_exists($errno, static::ERROR_CODES)) { |
|
| 41 | 42 | $errname = static::ERROR_CODES[$errno]; |
| 42 | 43 | } |
| 43 | 44 | $this->entries[] = array( |
@@ -65,9 +66,11 @@ discard block |
||
| 65 | 66 | { |
| 66 | 67 | if ($value instanceof DateTime) { |
| 67 | 68 | $value = $value->format('Y-m-d H:i:s'); |
| 68 | - } elseif ($this->isObjectOrArray($value)) { |
|
| 69 | + } |
|
| 70 | + elseif ($this->isObjectOrArray($value)) { |
|
| 69 | 71 | $value = print_r(json_decode(json_encode($value)), true); |
| 70 | - } elseif (is_resource($value)) { |
|
| 72 | + } |
|
| 73 | + elseif (is_resource($value)) { |
|
| 71 | 74 | $value = (string) $value; |
| 72 | 75 | } |
| 73 | 76 | return esc_html($value); |
@@ -4,161 +4,161 @@ |
||
| 4 | 4 | |
| 5 | 5 | class SlowActions |
| 6 | 6 | { |
| 7 | - /** |
|
| 8 | - * @var array |
|
| 9 | - */ |
|
| 10 | - protected $flow; |
|
| 11 | - |
|
| 12 | - /** |
|
| 13 | - * This is the time that WordPress takes to execute the all hook. |
|
| 14 | - * @var int |
|
| 15 | - */ |
|
| 16 | - protected $noise = 0; |
|
| 17 | - |
|
| 18 | - /** |
|
| 19 | - * @var int |
|
| 20 | - */ |
|
| 21 | - protected $start = null; |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * @var int |
|
| 25 | - */ |
|
| 26 | - protected $stop = null; |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * @var int |
|
| 30 | - */ |
|
| 31 | - protected $totalActions = 0; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * @var int |
|
| 35 | - */ |
|
| 36 | - protected $totalTime = 0; |
|
| 37 | - |
|
| 38 | - public function __construct() |
|
| 39 | - { |
|
| 40 | - $this->flow = []; |
|
| 41 | - $this->start = microtime(true); |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * @return array |
|
| 46 | - */ |
|
| 47 | - public function getTotalTimeForHook(array $data) |
|
| 48 | - { |
|
| 49 | - $total = 0; |
|
| 50 | - foreach ($data['time'] as $time) { |
|
| 51 | - $total += ($time['stop'] - $time['start']) * 1000; |
|
| 52 | - } |
|
| 53 | - return $total; |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * @return array |
|
| 58 | - */ |
|
| 59 | - public function addCallbacksForAction($action) |
|
| 60 | - { |
|
| 61 | - global $wp_filter; |
|
| 62 | - if (!array_key_exists($action, $this->flow)) { |
|
| 63 | - return; |
|
| 64 | - } |
|
| 65 | - $this->flow[$action]['callbacks_count'] = 0; |
|
| 66 | - foreach ($wp_filter[$action] as $priority => $callbacks) { |
|
| 67 | - if (!array_key_exists($priority, $this->flow[$action]['callbacks'])) { |
|
| 68 | - $this->flow[$action]['callbacks'][$priority] = []; |
|
| 69 | - } |
|
| 70 | - foreach ($callbacks as $callback) { |
|
| 71 | - if (is_array($callback['function']) && 2 == count($callback['function'])) { |
|
| 72 | - list($object, $method) = $callback['function']; |
|
| 73 | - if (is_object($object)) { |
|
| 74 | - $object = get_class($object); |
|
| 75 | - } |
|
| 76 | - $this->flow[$action]['callbacks'][$priority][] = sprintf('%s::%s', $object, $method); |
|
| 77 | - } elseif (is_object($callback['function'])) { |
|
| 78 | - $this->flow[$action]['callbacks'][$priority][] = get_class($callback['function']); |
|
| 79 | - } else { |
|
| 80 | - $this->flow[$action]['callbacks'][$priority][] = $callback['function']; |
|
| 81 | - } |
|
| 82 | - ++$this->flow[$action]['callbacks_count']; |
|
| 83 | - } |
|
| 84 | - } |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * @return array |
|
| 89 | - */ |
|
| 90 | - public function getMeasure() |
|
| 91 | - { |
|
| 92 | - foreach ($this->flow as $action => $data) { |
|
| 93 | - $total = $this->getTotalTimeForHook($data); |
|
| 94 | - $this->flow[$action]['total'] = $total; |
|
| 95 | - $this->totalTime += $total; |
|
| 96 | - $this->totalActions += $data['count']; |
|
| 97 | - $this->addCallbacksForAction($action); |
|
| 98 | - } |
|
| 99 | - uasort($this->flow, [$this, 'sortByTime']); |
|
| 100 | - return $this->flow; |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * @return int |
|
| 105 | - */ |
|
| 106 | - public function getTotalActions() |
|
| 107 | - { |
|
| 108 | - return $this->totalActions; |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * @return int Microseconds |
|
| 113 | - */ |
|
| 114 | - public function getTotalTime() |
|
| 115 | - { |
|
| 116 | - return $this->totalTime; |
|
| 117 | - // $totalNoise = (count($this->timers) - 1) * $this->noise; |
|
| 118 | - // return $this->stop - $this->start - $totalNoise; |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * @param string $name |
|
| 123 | - * @return void |
|
| 124 | - */ |
|
| 125 | - public function startTimer() |
|
| 126 | - { |
|
| 127 | - if (!isset($this->flow[current_filter()])) { |
|
| 128 | - $this->flow[current_filter()] = [ |
|
| 129 | - 'callbacks' => [], |
|
| 130 | - 'count' => 0, |
|
| 131 | - 'stack' => [], |
|
| 132 | - 'time' => [], |
|
| 133 | - ]; |
|
| 134 | - add_action(current_filter(), [$this, 'stopTimer'], 9000); |
|
| 135 | - } |
|
| 136 | - $count = ++$this->flow[current_filter()]['count']; |
|
| 137 | - array_push($this->flow[current_filter()]['stack'], ['start' => microtime(true)]); |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * @param mixed $possibleFilter |
|
| 142 | - * @return mixed |
|
| 143 | - */ |
|
| 144 | - public function stopTimer($possibleFilter = null) |
|
| 145 | - { |
|
| 146 | - $time = array_pop($this->flow[current_filter()]['stack']); |
|
| 147 | - $time['stop'] = microtime(true); |
|
| 148 | - array_push($this->flow[current_filter()]['time'], $time); |
|
| 149 | - return $possibleFilter; |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * @param array $a |
|
| 154 | - * @param array $b |
|
| 155 | - * @return int |
|
| 156 | - */ |
|
| 157 | - protected function sortByTime($a, $b) |
|
| 158 | - { |
|
| 159 | - if ($a['total'] == $b['total']) { |
|
| 160 | - return 0; |
|
| 161 | - } |
|
| 162 | - return ($a['total'] > $b['total']) ? -1 : 1; |
|
| 163 | - } |
|
| 7 | + /** |
|
| 8 | + * @var array |
|
| 9 | + */ |
|
| 10 | + protected $flow; |
|
| 11 | + |
|
| 12 | + /** |
|
| 13 | + * This is the time that WordPress takes to execute the all hook. |
|
| 14 | + * @var int |
|
| 15 | + */ |
|
| 16 | + protected $noise = 0; |
|
| 17 | + |
|
| 18 | + /** |
|
| 19 | + * @var int |
|
| 20 | + */ |
|
| 21 | + protected $start = null; |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * @var int |
|
| 25 | + */ |
|
| 26 | + protected $stop = null; |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * @var int |
|
| 30 | + */ |
|
| 31 | + protected $totalActions = 0; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * @var int |
|
| 35 | + */ |
|
| 36 | + protected $totalTime = 0; |
|
| 37 | + |
|
| 38 | + public function __construct() |
|
| 39 | + { |
|
| 40 | + $this->flow = []; |
|
| 41 | + $this->start = microtime(true); |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * @return array |
|
| 46 | + */ |
|
| 47 | + public function getTotalTimeForHook(array $data) |
|
| 48 | + { |
|
| 49 | + $total = 0; |
|
| 50 | + foreach ($data['time'] as $time) { |
|
| 51 | + $total += ($time['stop'] - $time['start']) * 1000; |
|
| 52 | + } |
|
| 53 | + return $total; |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * @return array |
|
| 58 | + */ |
|
| 59 | + public function addCallbacksForAction($action) |
|
| 60 | + { |
|
| 61 | + global $wp_filter; |
|
| 62 | + if (!array_key_exists($action, $this->flow)) { |
|
| 63 | + return; |
|
| 64 | + } |
|
| 65 | + $this->flow[$action]['callbacks_count'] = 0; |
|
| 66 | + foreach ($wp_filter[$action] as $priority => $callbacks) { |
|
| 67 | + if (!array_key_exists($priority, $this->flow[$action]['callbacks'])) { |
|
| 68 | + $this->flow[$action]['callbacks'][$priority] = []; |
|
| 69 | + } |
|
| 70 | + foreach ($callbacks as $callback) { |
|
| 71 | + if (is_array($callback['function']) && 2 == count($callback['function'])) { |
|
| 72 | + list($object, $method) = $callback['function']; |
|
| 73 | + if (is_object($object)) { |
|
| 74 | + $object = get_class($object); |
|
| 75 | + } |
|
| 76 | + $this->flow[$action]['callbacks'][$priority][] = sprintf('%s::%s', $object, $method); |
|
| 77 | + } elseif (is_object($callback['function'])) { |
|
| 78 | + $this->flow[$action]['callbacks'][$priority][] = get_class($callback['function']); |
|
| 79 | + } else { |
|
| 80 | + $this->flow[$action]['callbacks'][$priority][] = $callback['function']; |
|
| 81 | + } |
|
| 82 | + ++$this->flow[$action]['callbacks_count']; |
|
| 83 | + } |
|
| 84 | + } |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * @return array |
|
| 89 | + */ |
|
| 90 | + public function getMeasure() |
|
| 91 | + { |
|
| 92 | + foreach ($this->flow as $action => $data) { |
|
| 93 | + $total = $this->getTotalTimeForHook($data); |
|
| 94 | + $this->flow[$action]['total'] = $total; |
|
| 95 | + $this->totalTime += $total; |
|
| 96 | + $this->totalActions += $data['count']; |
|
| 97 | + $this->addCallbacksForAction($action); |
|
| 98 | + } |
|
| 99 | + uasort($this->flow, [$this, 'sortByTime']); |
|
| 100 | + return $this->flow; |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * @return int |
|
| 105 | + */ |
|
| 106 | + public function getTotalActions() |
|
| 107 | + { |
|
| 108 | + return $this->totalActions; |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * @return int Microseconds |
|
| 113 | + */ |
|
| 114 | + public function getTotalTime() |
|
| 115 | + { |
|
| 116 | + return $this->totalTime; |
|
| 117 | + // $totalNoise = (count($this->timers) - 1) * $this->noise; |
|
| 118 | + // return $this->stop - $this->start - $totalNoise; |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * @param string $name |
|
| 123 | + * @return void |
|
| 124 | + */ |
|
| 125 | + public function startTimer() |
|
| 126 | + { |
|
| 127 | + if (!isset($this->flow[current_filter()])) { |
|
| 128 | + $this->flow[current_filter()] = [ |
|
| 129 | + 'callbacks' => [], |
|
| 130 | + 'count' => 0, |
|
| 131 | + 'stack' => [], |
|
| 132 | + 'time' => [], |
|
| 133 | + ]; |
|
| 134 | + add_action(current_filter(), [$this, 'stopTimer'], 9000); |
|
| 135 | + } |
|
| 136 | + $count = ++$this->flow[current_filter()]['count']; |
|
| 137 | + array_push($this->flow[current_filter()]['stack'], ['start' => microtime(true)]); |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * @param mixed $possibleFilter |
|
| 142 | + * @return mixed |
|
| 143 | + */ |
|
| 144 | + public function stopTimer($possibleFilter = null) |
|
| 145 | + { |
|
| 146 | + $time = array_pop($this->flow[current_filter()]['stack']); |
|
| 147 | + $time['stop'] = microtime(true); |
|
| 148 | + array_push($this->flow[current_filter()]['time'], $time); |
|
| 149 | + return $possibleFilter; |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * @param array $a |
|
| 154 | + * @param array $b |
|
| 155 | + * @return int |
|
| 156 | + */ |
|
| 157 | + protected function sortByTime($a, $b) |
|
| 158 | + { |
|
| 159 | + if ($a['total'] == $b['total']) { |
|
| 160 | + return 0; |
|
| 161 | + } |
|
| 162 | + return ($a['total'] > $b['total']) ? -1 : 1; |
|
| 163 | + } |
|
| 164 | 164 | } |
@@ -37,18 +37,18 @@ discard block |
||
| 37 | 37 | |
| 38 | 38 | public function __construct() |
| 39 | 39 | { |
| 40 | - $this->flow = []; |
|
| 41 | - $this->start = microtime(true); |
|
| 40 | + $this->flow = [ ]; |
|
| 41 | + $this->start = microtime( true ); |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | /** |
| 45 | 45 | * @return array |
| 46 | 46 | */ |
| 47 | - public function getTotalTimeForHook(array $data) |
|
| 47 | + public function getTotalTimeForHook( array $data ) |
|
| 48 | 48 | { |
| 49 | 49 | $total = 0; |
| 50 | - foreach ($data['time'] as $time) { |
|
| 51 | - $total += ($time['stop'] - $time['start']) * 1000; |
|
| 50 | + foreach( $data[ 'time' ] as $time ) { |
|
| 51 | + $total += ( $time[ 'stop' ] - $time[ 'start' ] ) * 1000; |
|
| 52 | 52 | } |
| 53 | 53 | return $total; |
| 54 | 54 | } |
@@ -56,30 +56,30 @@ discard block |
||
| 56 | 56 | /** |
| 57 | 57 | * @return array |
| 58 | 58 | */ |
| 59 | - public function addCallbacksForAction($action) |
|
| 59 | + public function addCallbacksForAction( $action ) |
|
| 60 | 60 | { |
| 61 | 61 | global $wp_filter; |
| 62 | - if (!array_key_exists($action, $this->flow)) { |
|
| 62 | + if( !array_key_exists( $action, $this->flow ) ) { |
|
| 63 | 63 | return; |
| 64 | 64 | } |
| 65 | - $this->flow[$action]['callbacks_count'] = 0; |
|
| 66 | - foreach ($wp_filter[$action] as $priority => $callbacks) { |
|
| 67 | - if (!array_key_exists($priority, $this->flow[$action]['callbacks'])) { |
|
| 68 | - $this->flow[$action]['callbacks'][$priority] = []; |
|
| 65 | + $this->flow[ $action ][ 'callbacks_count' ] = 0; |
|
| 66 | + foreach( $wp_filter[ $action ] as $priority => $callbacks ) { |
|
| 67 | + if( !array_key_exists( $priority, $this->flow[ $action ][ 'callbacks' ] ) ) { |
|
| 68 | + $this->flow[ $action ][ 'callbacks' ][ $priority ] = [ ]; |
|
| 69 | 69 | } |
| 70 | - foreach ($callbacks as $callback) { |
|
| 71 | - if (is_array($callback['function']) && 2 == count($callback['function'])) { |
|
| 72 | - list($object, $method) = $callback['function']; |
|
| 73 | - if (is_object($object)) { |
|
| 74 | - $object = get_class($object); |
|
| 70 | + foreach( $callbacks as $callback ) { |
|
| 71 | + if( is_array( $callback[ 'function' ] ) && 2 == count( $callback[ 'function' ] ) ) { |
|
| 72 | + list( $object, $method ) = $callback[ 'function' ]; |
|
| 73 | + if( is_object( $object ) ) { |
|
| 74 | + $object = get_class( $object ); |
|
| 75 | 75 | } |
| 76 | - $this->flow[$action]['callbacks'][$priority][] = sprintf('%s::%s', $object, $method); |
|
| 77 | - } elseif (is_object($callback['function'])) { |
|
| 78 | - $this->flow[$action]['callbacks'][$priority][] = get_class($callback['function']); |
|
| 76 | + $this->flow[ $action ][ 'callbacks' ][ $priority ][ ] = sprintf( '%s::%s', $object, $method ); |
|
| 77 | + } elseif( is_object( $callback[ 'function' ] ) ) { |
|
| 78 | + $this->flow[ $action ][ 'callbacks' ][ $priority ][ ] = get_class( $callback[ 'function' ] ); |
|
| 79 | 79 | } else { |
| 80 | - $this->flow[$action]['callbacks'][$priority][] = $callback['function']; |
|
| 80 | + $this->flow[ $action ][ 'callbacks' ][ $priority ][ ] = $callback[ 'function' ]; |
|
| 81 | 81 | } |
| 82 | - ++$this->flow[$action]['callbacks_count']; |
|
| 82 | + ++$this->flow[ $action ][ 'callbacks_count' ]; |
|
| 83 | 83 | } |
| 84 | 84 | } |
| 85 | 85 | } |
@@ -89,14 +89,14 @@ discard block |
||
| 89 | 89 | */ |
| 90 | 90 | public function getMeasure() |
| 91 | 91 | { |
| 92 | - foreach ($this->flow as $action => $data) { |
|
| 93 | - $total = $this->getTotalTimeForHook($data); |
|
| 94 | - $this->flow[$action]['total'] = $total; |
|
| 92 | + foreach( $this->flow as $action => $data ) { |
|
| 93 | + $total = $this->getTotalTimeForHook( $data ); |
|
| 94 | + $this->flow[ $action ][ 'total' ] = $total; |
|
| 95 | 95 | $this->totalTime += $total; |
| 96 | - $this->totalActions += $data['count']; |
|
| 97 | - $this->addCallbacksForAction($action); |
|
| 96 | + $this->totalActions += $data[ 'count' ]; |
|
| 97 | + $this->addCallbacksForAction( $action ); |
|
| 98 | 98 | } |
| 99 | - uasort($this->flow, [$this, 'sortByTime']); |
|
| 99 | + uasort( $this->flow, [ $this, 'sortByTime' ] ); |
|
| 100 | 100 | return $this->flow; |
| 101 | 101 | } |
| 102 | 102 | |
@@ -124,28 +124,28 @@ discard block |
||
| 124 | 124 | */ |
| 125 | 125 | public function startTimer() |
| 126 | 126 | { |
| 127 | - if (!isset($this->flow[current_filter()])) { |
|
| 128 | - $this->flow[current_filter()] = [ |
|
| 129 | - 'callbacks' => [], |
|
| 127 | + if( !isset( $this->flow[ current_filter() ] ) ) { |
|
| 128 | + $this->flow[ current_filter() ] = [ |
|
| 129 | + 'callbacks' => [ ], |
|
| 130 | 130 | 'count' => 0, |
| 131 | - 'stack' => [], |
|
| 132 | - 'time' => [], |
|
| 131 | + 'stack' => [ ], |
|
| 132 | + 'time' => [ ], |
|
| 133 | 133 | ]; |
| 134 | - add_action(current_filter(), [$this, 'stopTimer'], 9000); |
|
| 134 | + add_action( current_filter(), [ $this, 'stopTimer' ], 9000 ); |
|
| 135 | 135 | } |
| 136 | - $count = ++$this->flow[current_filter()]['count']; |
|
| 137 | - array_push($this->flow[current_filter()]['stack'], ['start' => microtime(true)]); |
|
| 136 | + $count = ++$this->flow[ current_filter() ][ 'count' ]; |
|
| 137 | + array_push( $this->flow[ current_filter() ][ 'stack' ], [ 'start' => microtime( true ) ] ); |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | /** |
| 141 | 141 | * @param mixed $possibleFilter |
| 142 | 142 | * @return mixed |
| 143 | 143 | */ |
| 144 | - public function stopTimer($possibleFilter = null) |
|
| 144 | + public function stopTimer( $possibleFilter = null ) |
|
| 145 | 145 | { |
| 146 | - $time = array_pop($this->flow[current_filter()]['stack']); |
|
| 147 | - $time['stop'] = microtime(true); |
|
| 148 | - array_push($this->flow[current_filter()]['time'], $time); |
|
| 146 | + $time = array_pop( $this->flow[ current_filter() ][ 'stack' ] ); |
|
| 147 | + $time[ 'stop' ] = microtime( true ); |
|
| 148 | + array_push( $this->flow[ current_filter() ][ 'time' ], $time ); |
|
| 149 | 149 | return $possibleFilter; |
| 150 | 150 | } |
| 151 | 151 | |
@@ -154,11 +154,11 @@ discard block |
||
| 154 | 154 | * @param array $b |
| 155 | 155 | * @return int |
| 156 | 156 | */ |
| 157 | - protected function sortByTime($a, $b) |
|
| 157 | + protected function sortByTime( $a, $b ) |
|
| 158 | 158 | { |
| 159 | - if ($a['total'] == $b['total']) { |
|
| 159 | + if( $a[ 'total' ] == $b[ 'total' ] ) { |
|
| 160 | 160 | return 0; |
| 161 | 161 | } |
| 162 | - return ($a['total'] > $b['total']) ? -1 : 1; |
|
| 162 | + return ( $a[ 'total' ] > $b[ 'total' ] ) ? -1 : 1; |
|
| 163 | 163 | } |
| 164 | 164 | } |
@@ -74,9 +74,11 @@ |
||
| 74 | 74 | $object = get_class($object); |
| 75 | 75 | } |
| 76 | 76 | $this->flow[$action]['callbacks'][$priority][] = sprintf('%s::%s', $object, $method); |
| 77 | - } elseif (is_object($callback['function'])) { |
|
| 77 | + } |
|
| 78 | + elseif (is_object($callback['function'])) { |
|
| 78 | 79 | $this->flow[$action]['callbacks'][$priority][] = get_class($callback['function']); |
| 79 | - } else { |
|
| 80 | + } |
|
| 81 | + else { |
|
| 80 | 82 | $this->flow[$action]['callbacks'][$priority][] = $callback['function']; |
| 81 | 83 | } |
| 82 | 84 | ++$this->flow[$action]['callbacks_count']; |
@@ -4,289 +4,289 @@ |
||
| 4 | 4 | |
| 5 | 5 | class Controller |
| 6 | 6 | { |
| 7 | - /** |
|
| 8 | - * @var Application |
|
| 9 | - */ |
|
| 10 | - protected $app; |
|
| 7 | + /** |
|
| 8 | + * @var Application |
|
| 9 | + */ |
|
| 10 | + protected $app; |
|
| 11 | 11 | |
| 12 | - public function __construct(Application $app) |
|
| 13 | - { |
|
| 14 | - $this->app = $app; |
|
| 15 | - } |
|
| 12 | + public function __construct(Application $app) |
|
| 13 | + { |
|
| 14 | + $this->app = $app; |
|
| 15 | + } |
|
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * @return void |
|
| 19 | - * @action admin_enqueue_scripts |
|
| 20 | - * @action wp_enqueue_scripts |
|
| 21 | - */ |
|
| 22 | - public function enqueueAssets() |
|
| 23 | - { |
|
| 24 | - wp_enqueue_script(Application::ID, $this->app->url('assets/main.js')); |
|
| 25 | - wp_enqueue_style(Application::ID, $this->app->url('assets/main.css'), array('dashicons')); |
|
| 26 | - wp_enqueue_style(Application::ID.'-syntax', $this->app->url('assets/syntax.css')); |
|
| 27 | - } |
|
| 17 | + /** |
|
| 18 | + * @return void |
|
| 19 | + * @action admin_enqueue_scripts |
|
| 20 | + * @action wp_enqueue_scripts |
|
| 21 | + */ |
|
| 22 | + public function enqueueAssets() |
|
| 23 | + { |
|
| 24 | + wp_enqueue_script(Application::ID, $this->app->url('assets/main.js')); |
|
| 25 | + wp_enqueue_style(Application::ID, $this->app->url('assets/main.css'), array('dashicons')); |
|
| 26 | + wp_enqueue_style(Application::ID.'-syntax', $this->app->url('assets/syntax.css')); |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * @param string $classes |
|
| 31 | - * @return string |
|
| 32 | - * @action admin_body_class |
|
| 33 | - */ |
|
| 34 | - public function filterBodyClasses($classes) |
|
| 35 | - { |
|
| 36 | - return trim($classes.' '.Application::ID); |
|
| 37 | - } |
|
| 29 | + /** |
|
| 30 | + * @param string $classes |
|
| 31 | + * @return string |
|
| 32 | + * @action admin_body_class |
|
| 33 | + */ |
|
| 34 | + public function filterBodyClasses($classes) |
|
| 35 | + { |
|
| 36 | + return trim($classes.' '.Application::ID); |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * @return void |
|
| 41 | - * @filter all |
|
| 42 | - */ |
|
| 43 | - public function initConsole() |
|
| 44 | - { |
|
| 45 | - if (Application::CONSOLE_HOOK != func_get_arg(0)) { |
|
| 46 | - return; |
|
| 47 | - } |
|
| 48 | - $args = array_pad(func_get_args(), 4, ''); |
|
| 49 | - $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 4); |
|
| 50 | - $entry = array_pop($backtrace); |
|
| 51 | - $location = $args[3]; |
|
| 52 | - if (empty(trim($location)) && array_key_exists('file', $entry)) { |
|
| 53 | - $path = explode(ABSPATH, $entry['file']); |
|
| 54 | - $location = sprintf('%s:%s', array_pop($path), $entry['line']); |
|
| 55 | - } |
|
| 56 | - $this->app->console->store($args[1], $args[2], '['.$location.'] '); |
|
| 57 | - } |
|
| 39 | + /** |
|
| 40 | + * @return void |
|
| 41 | + * @filter all |
|
| 42 | + */ |
|
| 43 | + public function initConsole() |
|
| 44 | + { |
|
| 45 | + if (Application::CONSOLE_HOOK != func_get_arg(0)) { |
|
| 46 | + return; |
|
| 47 | + } |
|
| 48 | + $args = array_pad(func_get_args(), 4, ''); |
|
| 49 | + $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 4); |
|
| 50 | + $entry = array_pop($backtrace); |
|
| 51 | + $location = $args[3]; |
|
| 52 | + if (empty(trim($location)) && array_key_exists('file', $entry)) { |
|
| 53 | + $path = explode(ABSPATH, $entry['file']); |
|
| 54 | + $location = sprintf('%s:%s', array_pop($path), $entry['line']); |
|
| 55 | + } |
|
| 56 | + $this->app->console->store($args[1], $args[2], '['.$location.'] '); |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * @return void |
|
| 61 | - * @filter all |
|
| 62 | - */ |
|
| 63 | - public function initProfiler() |
|
| 64 | - { |
|
| 65 | - if (Application::PROFILER_HOOK != func_get_arg(0)) { |
|
| 66 | - return; |
|
| 67 | - } |
|
| 68 | - $this->app->profiler->trace(func_get_arg(1)); |
|
| 69 | - } |
|
| 59 | + /** |
|
| 60 | + * @return void |
|
| 61 | + * @filter all |
|
| 62 | + */ |
|
| 63 | + public function initProfiler() |
|
| 64 | + { |
|
| 65 | + if (Application::PROFILER_HOOK != func_get_arg(0)) { |
|
| 66 | + return; |
|
| 67 | + } |
|
| 68 | + $this->app->profiler->trace(func_get_arg(1)); |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * @return void |
|
| 73 | - * @filter all |
|
| 74 | - */ |
|
| 75 | - public function measureSlowActions() |
|
| 76 | - { |
|
| 77 | - $this->app->actions->startTimer(); |
|
| 78 | - } |
|
| 71 | + /** |
|
| 72 | + * @return void |
|
| 73 | + * @filter all |
|
| 74 | + */ |
|
| 75 | + public function measureSlowActions() |
|
| 76 | + { |
|
| 77 | + $this->app->actions->startTimer(); |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - /** |
|
| 81 | - * @return void |
|
| 82 | - * @action plugins_loaded |
|
| 83 | - */ |
|
| 84 | - public function registerLanguages() |
|
| 85 | - { |
|
| 86 | - load_plugin_textdomain(Application::ID, false, |
|
| 87 | - plugin_basename($this->app->path()).Application::LANG |
|
| 88 | - ); |
|
| 89 | - } |
|
| 80 | + /** |
|
| 81 | + * @return void |
|
| 82 | + * @action plugins_loaded |
|
| 83 | + */ |
|
| 84 | + public function registerLanguages() |
|
| 85 | + { |
|
| 86 | + load_plugin_textdomain(Application::ID, false, |
|
| 87 | + plugin_basename($this->app->path()).Application::LANG |
|
| 88 | + ); |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - /** |
|
| 92 | - * @return void |
|
| 93 | - * @action admin_footer |
|
| 94 | - * @action wp_footer |
|
| 95 | - */ |
|
| 96 | - public function renderBar() |
|
| 97 | - { |
|
| 98 | - apply_filters('debug', 'Profiler Stopped'); |
|
| 99 | - $this->app->render('debug-bar', array( |
|
| 100 | - 'blackbar' => $this->app, |
|
| 101 | - 'actions' => $this->app->actions, |
|
| 102 | - 'actionsLabel' => $this->getSlowActionsLabel(), |
|
| 103 | - 'consoleEntries' => $this->getConsoleEntries(), |
|
| 104 | - 'consoleLabel' => $this->getConsoleLabel(), |
|
| 105 | - 'profiler' => $this->app->profiler, |
|
| 106 | - 'profilerLabel' => $this->getProfilerLabel(), |
|
| 107 | - 'queries' => $this->getQueries(), |
|
| 108 | - 'queriesLabel' => $this->getQueriesLabel(), |
|
| 109 | - 'templates' => $this->getTemplates(), |
|
| 110 | - )); |
|
| 111 | - } |
|
| 91 | + /** |
|
| 92 | + * @return void |
|
| 93 | + * @action admin_footer |
|
| 94 | + * @action wp_footer |
|
| 95 | + */ |
|
| 96 | + public function renderBar() |
|
| 97 | + { |
|
| 98 | + apply_filters('debug', 'Profiler Stopped'); |
|
| 99 | + $this->app->render('debug-bar', array( |
|
| 100 | + 'blackbar' => $this->app, |
|
| 101 | + 'actions' => $this->app->actions, |
|
| 102 | + 'actionsLabel' => $this->getSlowActionsLabel(), |
|
| 103 | + 'consoleEntries' => $this->getConsoleEntries(), |
|
| 104 | + 'consoleLabel' => $this->getConsoleLabel(), |
|
| 105 | + 'profiler' => $this->app->profiler, |
|
| 106 | + 'profilerLabel' => $this->getProfilerLabel(), |
|
| 107 | + 'queries' => $this->getQueries(), |
|
| 108 | + 'queriesLabel' => $this->getQueriesLabel(), |
|
| 109 | + 'templates' => $this->getTemplates(), |
|
| 110 | + )); |
|
| 111 | + } |
|
| 112 | 112 | |
| 113 | - /** |
|
| 114 | - * @param int $time |
|
| 115 | - * @param int $decimals |
|
| 116 | - * @return string |
|
| 117 | - */ |
|
| 118 | - protected function convertToMiliseconds($time, $decimals = 2) |
|
| 119 | - { |
|
| 120 | - return number_format($time * 1000, $decimals); |
|
| 121 | - } |
|
| 113 | + /** |
|
| 114 | + * @param int $time |
|
| 115 | + * @param int $decimals |
|
| 116 | + * @return string |
|
| 117 | + */ |
|
| 118 | + protected function convertToMiliseconds($time, $decimals = 2) |
|
| 119 | + { |
|
| 120 | + return number_format($time * 1000, $decimals); |
|
| 121 | + } |
|
| 122 | 122 | |
| 123 | - /** |
|
| 124 | - * @return array |
|
| 125 | - */ |
|
| 126 | - protected function getConsoleEntries() |
|
| 127 | - { |
|
| 128 | - return array_merge($this->getErrors(), $this->app->console->entries); |
|
| 129 | - } |
|
| 123 | + /** |
|
| 124 | + * @return array |
|
| 125 | + */ |
|
| 126 | + protected function getConsoleEntries() |
|
| 127 | + { |
|
| 128 | + return array_merge($this->getErrors(), $this->app->console->entries); |
|
| 129 | + } |
|
| 130 | 130 | |
| 131 | - /** |
|
| 132 | - * @return string |
|
| 133 | - */ |
|
| 134 | - protected function getConsoleLabel() |
|
| 135 | - { |
|
| 136 | - $class = ''; |
|
| 137 | - $entries = $this->getConsoleEntries(); |
|
| 138 | - $entryCount = count($entries); |
|
| 139 | - $errorCount = 0; |
|
| 140 | - $label = __('Console', 'blackbar'); |
|
| 141 | - foreach ($entries as $entry) { |
|
| 142 | - if (in_array($entry['errno'], [E_NOTICE, E_STRICT, E_DEPRECATED])) { |
|
| 143 | - $class = 'glbb-warning'; |
|
| 144 | - } |
|
| 145 | - if (in_array($entry['errno'], [E_WARNING])) { |
|
| 146 | - ++$errorCount; |
|
| 147 | - } |
|
| 148 | - } |
|
| 149 | - if ($entryCount > 0) { |
|
| 150 | - $label .= sprintf(' (%d)', $entryCount); |
|
| 151 | - } |
|
| 152 | - if ($errorCount > 0) { |
|
| 153 | - $class = 'glbb-error'; |
|
| 154 | - $label .= sprintf(' (%d, %d!)', $entryCount, $errorCount); |
|
| 155 | - } |
|
| 156 | - return '<span class="'.$class.'">'.$label.'</span>'; |
|
| 157 | - } |
|
| 131 | + /** |
|
| 132 | + * @return string |
|
| 133 | + */ |
|
| 134 | + protected function getConsoleLabel() |
|
| 135 | + { |
|
| 136 | + $class = ''; |
|
| 137 | + $entries = $this->getConsoleEntries(); |
|
| 138 | + $entryCount = count($entries); |
|
| 139 | + $errorCount = 0; |
|
| 140 | + $label = __('Console', 'blackbar'); |
|
| 141 | + foreach ($entries as $entry) { |
|
| 142 | + if (in_array($entry['errno'], [E_NOTICE, E_STRICT, E_DEPRECATED])) { |
|
| 143 | + $class = 'glbb-warning'; |
|
| 144 | + } |
|
| 145 | + if (in_array($entry['errno'], [E_WARNING])) { |
|
| 146 | + ++$errorCount; |
|
| 147 | + } |
|
| 148 | + } |
|
| 149 | + if ($entryCount > 0) { |
|
| 150 | + $label .= sprintf(' (%d)', $entryCount); |
|
| 151 | + } |
|
| 152 | + if ($errorCount > 0) { |
|
| 153 | + $class = 'glbb-error'; |
|
| 154 | + $label .= sprintf(' (%d, %d!)', $entryCount, $errorCount); |
|
| 155 | + } |
|
| 156 | + return '<span class="'.$class.'">'.$label.'</span>'; |
|
| 157 | + } |
|
| 158 | 158 | |
| 159 | - /** |
|
| 160 | - * @return array |
|
| 161 | - */ |
|
| 162 | - protected function getErrors() |
|
| 163 | - { |
|
| 164 | - $errors = array(); |
|
| 165 | - foreach ($this->app->errors as $error) { |
|
| 166 | - $class = 'glbb-info'; |
|
| 167 | - if (in_array($error['errno'], [E_NOTICE, E_STRICT, E_DEPRECATED])) { |
|
| 168 | - $class = 'glbb-warning'; |
|
| 169 | - } |
|
| 170 | - if (E_WARNING == $error['errno']) { |
|
| 171 | - $class = 'glbb-error'; |
|
| 172 | - } |
|
| 173 | - if ($error['count'] > 1) { |
|
| 174 | - $error['name'] .= ' ('.$error['count'].')'; |
|
| 175 | - } |
|
| 176 | - $errors[] = array( |
|
| 177 | - 'errno' => $error['errno'], |
|
| 178 | - 'name' => '<span class="'.$class.'">'.$error['name'].'</span>', |
|
| 179 | - 'message' => sprintf(__('%s on line %s in file %s', 'blackbar'), |
|
| 180 | - $error['message'], |
|
| 181 | - $error['line'], |
|
| 182 | - $error['file'] |
|
| 183 | - ), |
|
| 184 | - ); |
|
| 185 | - } |
|
| 186 | - return $errors; |
|
| 187 | - } |
|
| 159 | + /** |
|
| 160 | + * @return array |
|
| 161 | + */ |
|
| 162 | + protected function getErrors() |
|
| 163 | + { |
|
| 164 | + $errors = array(); |
|
| 165 | + foreach ($this->app->errors as $error) { |
|
| 166 | + $class = 'glbb-info'; |
|
| 167 | + if (in_array($error['errno'], [E_NOTICE, E_STRICT, E_DEPRECATED])) { |
|
| 168 | + $class = 'glbb-warning'; |
|
| 169 | + } |
|
| 170 | + if (E_WARNING == $error['errno']) { |
|
| 171 | + $class = 'glbb-error'; |
|
| 172 | + } |
|
| 173 | + if ($error['count'] > 1) { |
|
| 174 | + $error['name'] .= ' ('.$error['count'].')'; |
|
| 175 | + } |
|
| 176 | + $errors[] = array( |
|
| 177 | + 'errno' => $error['errno'], |
|
| 178 | + 'name' => '<span class="'.$class.'">'.$error['name'].'</span>', |
|
| 179 | + 'message' => sprintf(__('%s on line %s in file %s', 'blackbar'), |
|
| 180 | + $error['message'], |
|
| 181 | + $error['line'], |
|
| 182 | + $error['file'] |
|
| 183 | + ), |
|
| 184 | + ); |
|
| 185 | + } |
|
| 186 | + return $errors; |
|
| 187 | + } |
|
| 188 | 188 | |
| 189 | - /** |
|
| 190 | - * @return array |
|
| 191 | - */ |
|
| 192 | - protected function getIncludedFiles() |
|
| 193 | - { |
|
| 194 | - $files = array_values(array_filter(get_included_files(), function ($file) { |
|
| 195 | - $bool = false !== strpos($file, '/themes/') |
|
| 196 | - && false === strpos($file, '/functions.php'); |
|
| 197 | - return (bool) apply_filters('blackbar/templates/file', $bool, $file); |
|
| 198 | - })); |
|
| 199 | - return array_map(function ($key, $value) { |
|
| 200 | - $value = str_replace(trailingslashit(WP_CONTENT_DIR), '', $value); |
|
| 201 | - return sprintf('[%s] => %s', $key, $value); |
|
| 202 | - }, array_keys($files), $files); |
|
| 203 | - } |
|
| 189 | + /** |
|
| 190 | + * @return array |
|
| 191 | + */ |
|
| 192 | + protected function getIncludedFiles() |
|
| 193 | + { |
|
| 194 | + $files = array_values(array_filter(get_included_files(), function ($file) { |
|
| 195 | + $bool = false !== strpos($file, '/themes/') |
|
| 196 | + && false === strpos($file, '/functions.php'); |
|
| 197 | + return (bool) apply_filters('blackbar/templates/file', $bool, $file); |
|
| 198 | + })); |
|
| 199 | + return array_map(function ($key, $value) { |
|
| 200 | + $value = str_replace(trailingslashit(WP_CONTENT_DIR), '', $value); |
|
| 201 | + return sprintf('[%s] => %s', $key, $value); |
|
| 202 | + }, array_keys($files), $files); |
|
| 203 | + } |
|
| 204 | 204 | |
| 205 | - /** |
|
| 206 | - * @return string |
|
| 207 | - */ |
|
| 208 | - protected function getProfilerLabel() |
|
| 209 | - { |
|
| 210 | - $label = __('Profiler', 'blackbar'); |
|
| 211 | - $profilerTime = $this->convertToMiliseconds($this->app->profiler->getTotalTime(), 0); |
|
| 212 | - if ($profilerTime > 0) { |
|
| 213 | - $label .= sprintf(' (%s %s)', $profilerTime, __('ms', 'blackbar')); |
|
| 214 | - } |
|
| 215 | - return $label; |
|
| 216 | - } |
|
| 205 | + /** |
|
| 206 | + * @return string |
|
| 207 | + */ |
|
| 208 | + protected function getProfilerLabel() |
|
| 209 | + { |
|
| 210 | + $label = __('Profiler', 'blackbar'); |
|
| 211 | + $profilerTime = $this->convertToMiliseconds($this->app->profiler->getTotalTime(), 0); |
|
| 212 | + if ($profilerTime > 0) { |
|
| 213 | + $label .= sprintf(' (%s %s)', $profilerTime, __('ms', 'blackbar')); |
|
| 214 | + } |
|
| 215 | + return $label; |
|
| 216 | + } |
|
| 217 | 217 | |
| 218 | - /** |
|
| 219 | - * @return array |
|
| 220 | - */ |
|
| 221 | - protected function getQueries() |
|
| 222 | - { |
|
| 223 | - global $wpdb; |
|
| 224 | - $queries = array(); |
|
| 225 | - $search = array( |
|
| 226 | - 'AND', 'FROM', 'GROUP BY', 'INNER JOIN', 'LEFT JOIN', 'LIMIT', |
|
| 227 | - 'ON DUPLICATE KEY UPDATE', 'ORDER BY', 'OFFSET', ' SET', 'WHERE', |
|
| 228 | - ); |
|
| 229 | - $replace = array_map(function ($value) { |
|
| 230 | - return PHP_EOL.$value; |
|
| 231 | - }, $search); |
|
| 232 | - foreach ($wpdb->queries as $query) { |
|
| 233 | - $miliseconds = number_format(round($query[1] * 1000, 4), 4); |
|
| 234 | - $sql = preg_replace('/\s\s+/', ' ', trim($query[0])); |
|
| 235 | - $sql = str_replace(PHP_EOL, ' ', $sql); |
|
| 236 | - $sql = str_replace($search, $replace, $sql); |
|
| 237 | - $queries[] = array( |
|
| 238 | - 'ms' => $miliseconds, |
|
| 239 | - 'sql' => $sql, |
|
| 240 | - ); |
|
| 241 | - } |
|
| 242 | - return $queries; |
|
| 243 | - } |
|
| 218 | + /** |
|
| 219 | + * @return array |
|
| 220 | + */ |
|
| 221 | + protected function getQueries() |
|
| 222 | + { |
|
| 223 | + global $wpdb; |
|
| 224 | + $queries = array(); |
|
| 225 | + $search = array( |
|
| 226 | + 'AND', 'FROM', 'GROUP BY', 'INNER JOIN', 'LEFT JOIN', 'LIMIT', |
|
| 227 | + 'ON DUPLICATE KEY UPDATE', 'ORDER BY', 'OFFSET', ' SET', 'WHERE', |
|
| 228 | + ); |
|
| 229 | + $replace = array_map(function ($value) { |
|
| 230 | + return PHP_EOL.$value; |
|
| 231 | + }, $search); |
|
| 232 | + foreach ($wpdb->queries as $query) { |
|
| 233 | + $miliseconds = number_format(round($query[1] * 1000, 4), 4); |
|
| 234 | + $sql = preg_replace('/\s\s+/', ' ', trim($query[0])); |
|
| 235 | + $sql = str_replace(PHP_EOL, ' ', $sql); |
|
| 236 | + $sql = str_replace($search, $replace, $sql); |
|
| 237 | + $queries[] = array( |
|
| 238 | + 'ms' => $miliseconds, |
|
| 239 | + 'sql' => $sql, |
|
| 240 | + ); |
|
| 241 | + } |
|
| 242 | + return $queries; |
|
| 243 | + } |
|
| 244 | 244 | |
| 245 | - /** |
|
| 246 | - * @return string |
|
| 247 | - */ |
|
| 248 | - protected function getQueriesLabel() |
|
| 249 | - { |
|
| 250 | - $label = __('SQL', 'blackbar'); |
|
| 251 | - if (!SAVEQUERIES) { |
|
| 252 | - return $label; |
|
| 253 | - } |
|
| 254 | - global $wpdb; |
|
| 255 | - $queryTime = 0; |
|
| 256 | - foreach ($wpdb->queries as $query) { |
|
| 257 | - $queryTime += $query[1]; |
|
| 258 | - } |
|
| 259 | - $queriesCount = '<span class="glbb-queries-count">'.count($wpdb->queries).'</span>'; |
|
| 260 | - $queriesTime = '<span class="glbb-queries-time">'.$this->convertToMiliseconds($queryTime).'</span>'; |
|
| 261 | - return $label.sprintf(' (%s %s | %s %s)', $queriesCount, __('queries', 'blackbar'), $queriesTime, __('ms', 'blackbar')); |
|
| 262 | - } |
|
| 245 | + /** |
|
| 246 | + * @return string |
|
| 247 | + */ |
|
| 248 | + protected function getQueriesLabel() |
|
| 249 | + { |
|
| 250 | + $label = __('SQL', 'blackbar'); |
|
| 251 | + if (!SAVEQUERIES) { |
|
| 252 | + return $label; |
|
| 253 | + } |
|
| 254 | + global $wpdb; |
|
| 255 | + $queryTime = 0; |
|
| 256 | + foreach ($wpdb->queries as $query) { |
|
| 257 | + $queryTime += $query[1]; |
|
| 258 | + } |
|
| 259 | + $queriesCount = '<span class="glbb-queries-count">'.count($wpdb->queries).'</span>'; |
|
| 260 | + $queriesTime = '<span class="glbb-queries-time">'.$this->convertToMiliseconds($queryTime).'</span>'; |
|
| 261 | + return $label.sprintf(' (%s %s | %s %s)', $queriesCount, __('queries', 'blackbar'), $queriesTime, __('ms', 'blackbar')); |
|
| 262 | + } |
|
| 263 | 263 | |
| 264 | - /** |
|
| 265 | - * @return string |
|
| 266 | - */ |
|
| 267 | - protected function getSlowActionsLabel() |
|
| 268 | - { |
|
| 269 | - $label = __('Hooks', 'blackbar'); |
|
| 270 | - $totalTime = $this->convertToMiliseconds($this->app->actions->getTotalTime(), 0); |
|
| 271 | - if ($totalTime > 0) { |
|
| 272 | - $label .= sprintf(' (%s %s)', $totalTime, __('ms', 'blackbar')); |
|
| 273 | - } |
|
| 274 | - return $label; |
|
| 275 | - } |
|
| 264 | + /** |
|
| 265 | + * @return string |
|
| 266 | + */ |
|
| 267 | + protected function getSlowActionsLabel() |
|
| 268 | + { |
|
| 269 | + $label = __('Hooks', 'blackbar'); |
|
| 270 | + $totalTime = $this->convertToMiliseconds($this->app->actions->getTotalTime(), 0); |
|
| 271 | + if ($totalTime > 0) { |
|
| 272 | + $label .= sprintf(' (%s %s)', $totalTime, __('ms', 'blackbar')); |
|
| 273 | + } |
|
| 274 | + return $label; |
|
| 275 | + } |
|
| 276 | 276 | |
| 277 | - /** |
|
| 278 | - * @return void|string |
|
| 279 | - */ |
|
| 280 | - protected function getTemplates() |
|
| 281 | - { |
|
| 282 | - if (is_admin()) { |
|
| 283 | - return; |
|
| 284 | - } |
|
| 285 | - if (class_exists('\GeminiLabs\Castor\Facades\Development')) { |
|
| 286 | - ob_start(); |
|
| 287 | - \GeminiLabs\Castor\Facades\Development::printTemplatePaths(); |
|
| 288 | - return ob_get_clean(); |
|
| 289 | - } |
|
| 290 | - return '<pre>'.implode(PHP_EOL, $this->getIncludedFiles()).'</pre>'; |
|
| 291 | - } |
|
| 277 | + /** |
|
| 278 | + * @return void|string |
|
| 279 | + */ |
|
| 280 | + protected function getTemplates() |
|
| 281 | + { |
|
| 282 | + if (is_admin()) { |
|
| 283 | + return; |
|
| 284 | + } |
|
| 285 | + if (class_exists('\GeminiLabs\Castor\Facades\Development')) { |
|
| 286 | + ob_start(); |
|
| 287 | + \GeminiLabs\Castor\Facades\Development::printTemplatePaths(); |
|
| 288 | + return ob_get_clean(); |
|
| 289 | + } |
|
| 290 | + return '<pre>'.implode(PHP_EOL, $this->getIncludedFiles()).'</pre>'; |
|
| 291 | + } |
|
| 292 | 292 | } |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | */ |
| 10 | 10 | protected $app; |
| 11 | 11 | |
| 12 | - public function __construct(Application $app) |
|
| 12 | + public function __construct( Application $app ) |
|
| 13 | 13 | { |
| 14 | 14 | $this->app = $app; |
| 15 | 15 | } |
@@ -21,9 +21,9 @@ discard block |
||
| 21 | 21 | */ |
| 22 | 22 | public function enqueueAssets() |
| 23 | 23 | { |
| 24 | - wp_enqueue_script(Application::ID, $this->app->url('assets/main.js')); |
|
| 25 | - wp_enqueue_style(Application::ID, $this->app->url('assets/main.css'), array('dashicons')); |
|
| 26 | - wp_enqueue_style(Application::ID.'-syntax', $this->app->url('assets/syntax.css')); |
|
| 24 | + wp_enqueue_script( Application::ID, $this->app->url( 'assets/main.js' ) ); |
|
| 25 | + wp_enqueue_style( Application::ID, $this->app->url( 'assets/main.css' ), array( 'dashicons' ) ); |
|
| 26 | + wp_enqueue_style( Application::ID . '-syntax', $this->app->url( 'assets/syntax.css' ) ); |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | /** |
@@ -31,9 +31,9 @@ discard block |
||
| 31 | 31 | * @return string |
| 32 | 32 | * @action admin_body_class |
| 33 | 33 | */ |
| 34 | - public function filterBodyClasses($classes) |
|
| 34 | + public function filterBodyClasses( $classes ) |
|
| 35 | 35 | { |
| 36 | - return trim($classes.' '.Application::ID); |
|
| 36 | + return trim( $classes . ' ' . Application::ID ); |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | /** |
@@ -42,18 +42,18 @@ discard block |
||
| 42 | 42 | */ |
| 43 | 43 | public function initConsole() |
| 44 | 44 | { |
| 45 | - if (Application::CONSOLE_HOOK != func_get_arg(0)) { |
|
| 45 | + if( Application::CONSOLE_HOOK != func_get_arg( 0 ) ) { |
|
| 46 | 46 | return; |
| 47 | 47 | } |
| 48 | - $args = array_pad(func_get_args(), 4, ''); |
|
| 49 | - $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 4); |
|
| 50 | - $entry = array_pop($backtrace); |
|
| 51 | - $location = $args[3]; |
|
| 52 | - if (empty(trim($location)) && array_key_exists('file', $entry)) { |
|
| 53 | - $path = explode(ABSPATH, $entry['file']); |
|
| 54 | - $location = sprintf('%s:%s', array_pop($path), $entry['line']); |
|
| 48 | + $args = array_pad( func_get_args(), 4, '' ); |
|
| 49 | + $backtrace = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, 4 ); |
|
| 50 | + $entry = array_pop( $backtrace ); |
|
| 51 | + $location = $args[ 3 ]; |
|
| 52 | + if( empty( trim( $location ) ) && array_key_exists( 'file', $entry ) ) { |
|
| 53 | + $path = explode( ABSPATH, $entry[ 'file' ] ); |
|
| 54 | + $location = sprintf( '%s:%s', array_pop( $path ), $entry[ 'line' ] ); |
|
| 55 | 55 | } |
| 56 | - $this->app->console->store($args[1], $args[2], '['.$location.'] '); |
|
| 56 | + $this->app->console->store( $args[ 1 ], $args[ 2 ], '[' . $location . '] ' ); |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | /** |
@@ -62,10 +62,10 @@ discard block |
||
| 62 | 62 | */ |
| 63 | 63 | public function initProfiler() |
| 64 | 64 | { |
| 65 | - if (Application::PROFILER_HOOK != func_get_arg(0)) { |
|
| 65 | + if( Application::PROFILER_HOOK != func_get_arg( 0 ) ) { |
|
| 66 | 66 | return; |
| 67 | 67 | } |
| 68 | - $this->app->profiler->trace(func_get_arg(1)); |
|
| 68 | + $this->app->profiler->trace( func_get_arg( 1 ) ); |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | /** |
@@ -83,8 +83,8 @@ discard block |
||
| 83 | 83 | */ |
| 84 | 84 | public function registerLanguages() |
| 85 | 85 | { |
| 86 | - load_plugin_textdomain(Application::ID, false, |
|
| 87 | - plugin_basename($this->app->path()).Application::LANG |
|
| 86 | + load_plugin_textdomain( Application::ID, false, |
|
| 87 | + plugin_basename( $this->app->path() ) . Application::LANG |
|
| 88 | 88 | ); |
| 89 | 89 | } |
| 90 | 90 | |
@@ -95,8 +95,8 @@ discard block |
||
| 95 | 95 | */ |
| 96 | 96 | public function renderBar() |
| 97 | 97 | { |
| 98 | - apply_filters('debug', 'Profiler Stopped'); |
|
| 99 | - $this->app->render('debug-bar', array( |
|
| 98 | + apply_filters( 'debug', 'Profiler Stopped' ); |
|
| 99 | + $this->app->render( 'debug-bar', array( |
|
| 100 | 100 | 'blackbar' => $this->app, |
| 101 | 101 | 'actions' => $this->app->actions, |
| 102 | 102 | 'actionsLabel' => $this->getSlowActionsLabel(), |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | 'queries' => $this->getQueries(), |
| 108 | 108 | 'queriesLabel' => $this->getQueriesLabel(), |
| 109 | 109 | 'templates' => $this->getTemplates(), |
| 110 | - )); |
|
| 110 | + ) ); |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | /** |
@@ -115,9 +115,9 @@ discard block |
||
| 115 | 115 | * @param int $decimals |
| 116 | 116 | * @return string |
| 117 | 117 | */ |
| 118 | - protected function convertToMiliseconds($time, $decimals = 2) |
|
| 118 | + protected function convertToMiliseconds( $time, $decimals = 2 ) |
|
| 119 | 119 | { |
| 120 | - return number_format($time * 1000, $decimals); |
|
| 120 | + return number_format( $time * 1000, $decimals ); |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | /** |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | */ |
| 126 | 126 | protected function getConsoleEntries() |
| 127 | 127 | { |
| 128 | - return array_merge($this->getErrors(), $this->app->console->entries); |
|
| 128 | + return array_merge( $this->getErrors(), $this->app->console->entries ); |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | /** |
@@ -135,25 +135,25 @@ discard block |
||
| 135 | 135 | { |
| 136 | 136 | $class = ''; |
| 137 | 137 | $entries = $this->getConsoleEntries(); |
| 138 | - $entryCount = count($entries); |
|
| 138 | + $entryCount = count( $entries ); |
|
| 139 | 139 | $errorCount = 0; |
| 140 | - $label = __('Console', 'blackbar'); |
|
| 141 | - foreach ($entries as $entry) { |
|
| 142 | - if (in_array($entry['errno'], [E_NOTICE, E_STRICT, E_DEPRECATED])) { |
|
| 140 | + $label = __( 'Console', 'blackbar' ); |
|
| 141 | + foreach( $entries as $entry ) { |
|
| 142 | + if( in_array( $entry[ 'errno' ], [ E_NOTICE, E_STRICT, E_DEPRECATED ] ) ) { |
|
| 143 | 143 | $class = 'glbb-warning'; |
| 144 | 144 | } |
| 145 | - if (in_array($entry['errno'], [E_WARNING])) { |
|
| 145 | + if( in_array( $entry[ 'errno' ], [ E_WARNING ] ) ) { |
|
| 146 | 146 | ++$errorCount; |
| 147 | 147 | } |
| 148 | 148 | } |
| 149 | - if ($entryCount > 0) { |
|
| 150 | - $label .= sprintf(' (%d)', $entryCount); |
|
| 149 | + if( $entryCount > 0 ) { |
|
| 150 | + $label .= sprintf( ' (%d)', $entryCount ); |
|
| 151 | 151 | } |
| 152 | - if ($errorCount > 0) { |
|
| 152 | + if( $errorCount > 0 ) { |
|
| 153 | 153 | $class = 'glbb-error'; |
| 154 | - $label .= sprintf(' (%d, %d!)', $entryCount, $errorCount); |
|
| 154 | + $label .= sprintf( ' (%d, %d!)', $entryCount, $errorCount ); |
|
| 155 | 155 | } |
| 156 | - return '<span class="'.$class.'">'.$label.'</span>'; |
|
| 156 | + return '<span class="' . $class . '">' . $label . '</span>'; |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | /** |
@@ -162,24 +162,24 @@ discard block |
||
| 162 | 162 | protected function getErrors() |
| 163 | 163 | { |
| 164 | 164 | $errors = array(); |
| 165 | - foreach ($this->app->errors as $error) { |
|
| 165 | + foreach( $this->app->errors as $error ) { |
|
| 166 | 166 | $class = 'glbb-info'; |
| 167 | - if (in_array($error['errno'], [E_NOTICE, E_STRICT, E_DEPRECATED])) { |
|
| 167 | + if( in_array( $error[ 'errno' ], [ E_NOTICE, E_STRICT, E_DEPRECATED ] ) ) { |
|
| 168 | 168 | $class = 'glbb-warning'; |
| 169 | 169 | } |
| 170 | - if (E_WARNING == $error['errno']) { |
|
| 170 | + if( E_WARNING == $error[ 'errno' ] ) { |
|
| 171 | 171 | $class = 'glbb-error'; |
| 172 | 172 | } |
| 173 | - if ($error['count'] > 1) { |
|
| 174 | - $error['name'] .= ' ('.$error['count'].')'; |
|
| 173 | + if( $error[ 'count' ] > 1 ) { |
|
| 174 | + $error[ 'name' ] .= ' (' . $error[ 'count' ] . ')'; |
|
| 175 | 175 | } |
| 176 | - $errors[] = array( |
|
| 177 | - 'errno' => $error['errno'], |
|
| 178 | - 'name' => '<span class="'.$class.'">'.$error['name'].'</span>', |
|
| 179 | - 'message' => sprintf(__('%s on line %s in file %s', 'blackbar'), |
|
| 180 | - $error['message'], |
|
| 181 | - $error['line'], |
|
| 182 | - $error['file'] |
|
| 176 | + $errors[ ] = array( |
|
| 177 | + 'errno' => $error[ 'errno' ], |
|
| 178 | + 'name' => '<span class="' . $class . '">' . $error[ 'name' ] . '</span>', |
|
| 179 | + 'message' => sprintf( __( '%s on line %s in file %s', 'blackbar' ), |
|
| 180 | + $error[ 'message' ], |
|
| 181 | + $error[ 'line' ], |
|
| 182 | + $error[ 'file' ] |
|
| 183 | 183 | ), |
| 184 | 184 | ); |
| 185 | 185 | } |
@@ -191,15 +191,15 @@ discard block |
||
| 191 | 191 | */ |
| 192 | 192 | protected function getIncludedFiles() |
| 193 | 193 | { |
| 194 | - $files = array_values(array_filter(get_included_files(), function ($file) { |
|
| 195 | - $bool = false !== strpos($file, '/themes/') |
|
| 196 | - && false === strpos($file, '/functions.php'); |
|
| 197 | - return (bool) apply_filters('blackbar/templates/file', $bool, $file); |
|
| 198 | - })); |
|
| 199 | - return array_map(function ($key, $value) { |
|
| 200 | - $value = str_replace(trailingslashit(WP_CONTENT_DIR), '', $value); |
|
| 201 | - return sprintf('[%s] => %s', $key, $value); |
|
| 202 | - }, array_keys($files), $files); |
|
| 194 | + $files = array_values( array_filter( get_included_files(), function( $file ) { |
|
| 195 | + $bool = false !== strpos( $file, '/themes/' ) |
|
| 196 | + && false === strpos( $file, '/functions.php' ); |
|
| 197 | + return (bool) apply_filters( 'blackbar/templates/file', $bool, $file ); |
|
| 198 | + }) ); |
|
| 199 | + return array_map( function( $key, $value ) { |
|
| 200 | + $value = str_replace( trailingslashit( WP_CONTENT_DIR ), '', $value ); |
|
| 201 | + return sprintf( '[%s] => %s', $key, $value ); |
|
| 202 | + }, array_keys( $files ), $files ); |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | /** |
@@ -207,10 +207,10 @@ discard block |
||
| 207 | 207 | */ |
| 208 | 208 | protected function getProfilerLabel() |
| 209 | 209 | { |
| 210 | - $label = __('Profiler', 'blackbar'); |
|
| 211 | - $profilerTime = $this->convertToMiliseconds($this->app->profiler->getTotalTime(), 0); |
|
| 212 | - if ($profilerTime > 0) { |
|
| 213 | - $label .= sprintf(' (%s %s)', $profilerTime, __('ms', 'blackbar')); |
|
| 210 | + $label = __( 'Profiler', 'blackbar' ); |
|
| 211 | + $profilerTime = $this->convertToMiliseconds( $this->app->profiler->getTotalTime(), 0 ); |
|
| 212 | + if( $profilerTime > 0 ) { |
|
| 213 | + $label .= sprintf( ' (%s %s)', $profilerTime, __( 'ms', 'blackbar' ) ); |
|
| 214 | 214 | } |
| 215 | 215 | return $label; |
| 216 | 216 | } |
@@ -226,15 +226,15 @@ discard block |
||
| 226 | 226 | 'AND', 'FROM', 'GROUP BY', 'INNER JOIN', 'LEFT JOIN', 'LIMIT', |
| 227 | 227 | 'ON DUPLICATE KEY UPDATE', 'ORDER BY', 'OFFSET', ' SET', 'WHERE', |
| 228 | 228 | ); |
| 229 | - $replace = array_map(function ($value) { |
|
| 230 | - return PHP_EOL.$value; |
|
| 231 | - }, $search); |
|
| 232 | - foreach ($wpdb->queries as $query) { |
|
| 233 | - $miliseconds = number_format(round($query[1] * 1000, 4), 4); |
|
| 234 | - $sql = preg_replace('/\s\s+/', ' ', trim($query[0])); |
|
| 235 | - $sql = str_replace(PHP_EOL, ' ', $sql); |
|
| 236 | - $sql = str_replace($search, $replace, $sql); |
|
| 237 | - $queries[] = array( |
|
| 229 | + $replace = array_map( function( $value ) { |
|
| 230 | + return PHP_EOL . $value; |
|
| 231 | + }, $search ); |
|
| 232 | + foreach( $wpdb->queries as $query ) { |
|
| 233 | + $miliseconds = number_format( round( $query[ 1 ] * 1000, 4 ), 4 ); |
|
| 234 | + $sql = preg_replace( '/\s\s+/', ' ', trim( $query[ 0 ] ) ); |
|
| 235 | + $sql = str_replace( PHP_EOL, ' ', $sql ); |
|
| 236 | + $sql = str_replace( $search, $replace, $sql ); |
|
| 237 | + $queries[ ] = array( |
|
| 238 | 238 | 'ms' => $miliseconds, |
| 239 | 239 | 'sql' => $sql, |
| 240 | 240 | ); |
@@ -247,18 +247,18 @@ discard block |
||
| 247 | 247 | */ |
| 248 | 248 | protected function getQueriesLabel() |
| 249 | 249 | { |
| 250 | - $label = __('SQL', 'blackbar'); |
|
| 251 | - if (!SAVEQUERIES) { |
|
| 250 | + $label = __( 'SQL', 'blackbar' ); |
|
| 251 | + if( !SAVEQUERIES ) { |
|
| 252 | 252 | return $label; |
| 253 | 253 | } |
| 254 | 254 | global $wpdb; |
| 255 | 255 | $queryTime = 0; |
| 256 | - foreach ($wpdb->queries as $query) { |
|
| 257 | - $queryTime += $query[1]; |
|
| 256 | + foreach( $wpdb->queries as $query ) { |
|
| 257 | + $queryTime += $query[ 1 ]; |
|
| 258 | 258 | } |
| 259 | - $queriesCount = '<span class="glbb-queries-count">'.count($wpdb->queries).'</span>'; |
|
| 260 | - $queriesTime = '<span class="glbb-queries-time">'.$this->convertToMiliseconds($queryTime).'</span>'; |
|
| 261 | - return $label.sprintf(' (%s %s | %s %s)', $queriesCount, __('queries', 'blackbar'), $queriesTime, __('ms', 'blackbar')); |
|
| 259 | + $queriesCount = '<span class="glbb-queries-count">' . count( $wpdb->queries ) . '</span>'; |
|
| 260 | + $queriesTime = '<span class="glbb-queries-time">' . $this->convertToMiliseconds( $queryTime ) . '</span>'; |
|
| 261 | + return $label . sprintf( ' (%s %s | %s %s)', $queriesCount, __( 'queries', 'blackbar' ), $queriesTime, __( 'ms', 'blackbar' ) ); |
|
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | /** |
@@ -266,10 +266,10 @@ discard block |
||
| 266 | 266 | */ |
| 267 | 267 | protected function getSlowActionsLabel() |
| 268 | 268 | { |
| 269 | - $label = __('Hooks', 'blackbar'); |
|
| 270 | - $totalTime = $this->convertToMiliseconds($this->app->actions->getTotalTime(), 0); |
|
| 271 | - if ($totalTime > 0) { |
|
| 272 | - $label .= sprintf(' (%s %s)', $totalTime, __('ms', 'blackbar')); |
|
| 269 | + $label = __( 'Hooks', 'blackbar' ); |
|
| 270 | + $totalTime = $this->convertToMiliseconds( $this->app->actions->getTotalTime(), 0 ); |
|
| 271 | + if( $totalTime > 0 ) { |
|
| 272 | + $label .= sprintf( ' (%s %s)', $totalTime, __( 'ms', 'blackbar' ) ); |
|
| 273 | 273 | } |
| 274 | 274 | return $label; |
| 275 | 275 | } |
@@ -279,14 +279,14 @@ discard block |
||
| 279 | 279 | */ |
| 280 | 280 | protected function getTemplates() |
| 281 | 281 | { |
| 282 | - if (is_admin()) { |
|
| 282 | + if( is_admin() ) { |
|
| 283 | 283 | return; |
| 284 | 284 | } |
| 285 | - if (class_exists('\GeminiLabs\Castor\Facades\Development')) { |
|
| 285 | + if( class_exists( '\GeminiLabs\Castor\Facades\Development' ) ) { |
|
| 286 | 286 | ob_start(); |
| 287 | 287 | \GeminiLabs\Castor\Facades\Development::printTemplatePaths(); |
| 288 | 288 | return ob_get_clean(); |
| 289 | 289 | } |
| 290 | - return '<pre>'.implode(PHP_EOL, $this->getIncludedFiles()).'</pre>'; |
|
| 290 | + return '<pre>' . implode( PHP_EOL, $this->getIncludedFiles() ) . '</pre>'; |
|
| 291 | 291 | } |
| 292 | 292 | } |
@@ -191,12 +191,14 @@ discard block |
||
| 191 | 191 | */ |
| 192 | 192 | protected function getIncludedFiles() |
| 193 | 193 | { |
| 194 | - $files = array_values(array_filter(get_included_files(), function ($file) { |
|
| 194 | + $files = array_values(array_filter(get_included_files(), function ($file) |
|
| 195 | + { |
|
| 195 | 196 | $bool = false !== strpos($file, '/themes/') |
| 196 | 197 | && false === strpos($file, '/functions.php'); |
| 197 | 198 | return (bool) apply_filters('blackbar/templates/file', $bool, $file); |
| 198 | 199 | })); |
| 199 | - return array_map(function ($key, $value) { |
|
| 200 | + return array_map(function ($key, $value) |
|
| 201 | + { |
|
| 200 | 202 | $value = str_replace(trailingslashit(WP_CONTENT_DIR), '', $value); |
| 201 | 203 | return sprintf('[%s] => %s', $key, $value); |
| 202 | 204 | }, array_keys($files), $files); |
@@ -226,7 +228,8 @@ discard block |
||
| 226 | 228 | 'AND', 'FROM', 'GROUP BY', 'INNER JOIN', 'LEFT JOIN', 'LIMIT', |
| 227 | 229 | 'ON DUPLICATE KEY UPDATE', 'ORDER BY', 'OFFSET', ' SET', 'WHERE', |
| 228 | 230 | ); |
| 229 | - $replace = array_map(function ($value) { |
|
| 231 | + $replace = array_map(function ($value) |
|
| 232 | + { |
|
| 230 | 233 | return PHP_EOL.$value; |
| 231 | 234 | }, $search); |
| 232 | 235 | foreach ($wpdb->queries as $query) { |
@@ -4,109 +4,109 @@ |
||
| 4 | 4 | |
| 5 | 5 | class Profiler |
| 6 | 6 | { |
| 7 | - /** |
|
| 8 | - * This is the time that WordPress takes to execute the profiler hook. |
|
| 9 | - * @var int |
|
| 10 | - */ |
|
| 11 | - protected $noise = 0; |
|
| 7 | + /** |
|
| 8 | + * This is the time that WordPress takes to execute the profiler hook. |
|
| 9 | + * @var int |
|
| 10 | + */ |
|
| 11 | + protected $noise = 0; |
|
| 12 | 12 | |
| 13 | - /** |
|
| 14 | - * @var int |
|
| 15 | - */ |
|
| 16 | - protected $start = null; |
|
| 13 | + /** |
|
| 14 | + * @var int |
|
| 15 | + */ |
|
| 16 | + protected $start = null; |
|
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * @var int |
|
| 20 | - */ |
|
| 21 | - protected $stop = null; |
|
| 18 | + /** |
|
| 19 | + * @var int |
|
| 20 | + */ |
|
| 21 | + protected $stop = null; |
|
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * @var array |
|
| 25 | - */ |
|
| 26 | - protected $timers = array(); |
|
| 23 | + /** |
|
| 24 | + * @var array |
|
| 25 | + */ |
|
| 26 | + protected $timers = array(); |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * @return array |
|
| 30 | - */ |
|
| 31 | - public function getMeasure() |
|
| 32 | - { |
|
| 33 | - return $this->timers; |
|
| 34 | - } |
|
| 28 | + /** |
|
| 29 | + * @return array |
|
| 30 | + */ |
|
| 31 | + public function getMeasure() |
|
| 32 | + { |
|
| 33 | + return $this->timers; |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * @param array $timer |
|
| 38 | - * @return string |
|
| 39 | - */ |
|
| 40 | - public function getMemoryString($timer) |
|
| 41 | - { |
|
| 42 | - $timer = $this->normalize($timer); |
|
| 43 | - return sprintf('%s kB', round($timer['memory'] / 1000)); |
|
| 44 | - } |
|
| 36 | + /** |
|
| 37 | + * @param array $timer |
|
| 38 | + * @return string |
|
| 39 | + */ |
|
| 40 | + public function getMemoryString($timer) |
|
| 41 | + { |
|
| 42 | + $timer = $this->normalize($timer); |
|
| 43 | + return sprintf('%s kB', round($timer['memory'] / 1000)); |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * @param array $timer |
|
| 48 | - * @return string |
|
| 49 | - */ |
|
| 50 | - public function getNameString($timer) |
|
| 51 | - { |
|
| 52 | - $timer = $this->normalize($timer); |
|
| 53 | - return $timer['name']; |
|
| 54 | - } |
|
| 46 | + /** |
|
| 47 | + * @param array $timer |
|
| 48 | + * @return string |
|
| 49 | + */ |
|
| 50 | + public function getNameString($timer) |
|
| 51 | + { |
|
| 52 | + $timer = $this->normalize($timer); |
|
| 53 | + return $timer['name']; |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * @param array $timer |
|
| 58 | - * @return string |
|
| 59 | - */ |
|
| 60 | - public function getTimeString($timer) |
|
| 61 | - { |
|
| 62 | - $timer = $this->normalize($timer); |
|
| 63 | - $index = array_search($timer['name'], array_column($this->timers, 'name')); |
|
| 64 | - $start = $this->start + ($index * $this->noise); |
|
| 65 | - $time = number_format(round(($timer['time'] - $start) * 1000, 4), 4); |
|
| 66 | - return sprintf('%s ms', $time); |
|
| 67 | - } |
|
| 56 | + /** |
|
| 57 | + * @param array $timer |
|
| 58 | + * @return string |
|
| 59 | + */ |
|
| 60 | + public function getTimeString($timer) |
|
| 61 | + { |
|
| 62 | + $timer = $this->normalize($timer); |
|
| 63 | + $index = array_search($timer['name'], array_column($this->timers, 'name')); |
|
| 64 | + $start = $this->start + ($index * $this->noise); |
|
| 65 | + $time = number_format(round(($timer['time'] - $start) * 1000, 4), 4); |
|
| 66 | + return sprintf('%s ms', $time); |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * @return int Microseconds |
|
| 71 | - */ |
|
| 72 | - public function getTotalTime() |
|
| 73 | - { |
|
| 74 | - $totalNoise = (count($this->timers) - 1) * $this->noise; |
|
| 75 | - return $this->stop - $this->start - $totalNoise; |
|
| 76 | - } |
|
| 69 | + /** |
|
| 70 | + * @return int Microseconds |
|
| 71 | + */ |
|
| 72 | + public function getTotalTime() |
|
| 73 | + { |
|
| 74 | + $totalNoise = (count($this->timers) - 1) * $this->noise; |
|
| 75 | + return $this->stop - $this->start - $totalNoise; |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * @param string $name |
|
| 80 | - * @return void |
|
| 81 | - */ |
|
| 82 | - public function trace($name) |
|
| 83 | - { |
|
| 84 | - $microtime = microtime(true); |
|
| 85 | - if (!$this->start) { |
|
| 86 | - $this->start = $microtime; |
|
| 87 | - } |
|
| 88 | - if ('blackbar/profiler/noise' === $name) { |
|
| 89 | - $this->noise = $microtime - $this->start; |
|
| 90 | - return; |
|
| 91 | - } |
|
| 92 | - $this->timers[] = array( |
|
| 93 | - 'memory' => memory_get_peak_usage(), |
|
| 94 | - 'name' => $name, |
|
| 95 | - 'time' => $microtime, |
|
| 96 | - ); |
|
| 97 | - $this->stop = $microtime; |
|
| 98 | - } |
|
| 78 | + /** |
|
| 79 | + * @param string $name |
|
| 80 | + * @return void |
|
| 81 | + */ |
|
| 82 | + public function trace($name) |
|
| 83 | + { |
|
| 84 | + $microtime = microtime(true); |
|
| 85 | + if (!$this->start) { |
|
| 86 | + $this->start = $microtime; |
|
| 87 | + } |
|
| 88 | + if ('blackbar/profiler/noise' === $name) { |
|
| 89 | + $this->noise = $microtime - $this->start; |
|
| 90 | + return; |
|
| 91 | + } |
|
| 92 | + $this->timers[] = array( |
|
| 93 | + 'memory' => memory_get_peak_usage(), |
|
| 94 | + 'name' => $name, |
|
| 95 | + 'time' => $microtime, |
|
| 96 | + ); |
|
| 97 | + $this->stop = $microtime; |
|
| 98 | + } |
|
| 99 | 99 | |
| 100 | - /** |
|
| 101 | - * @param array $timer |
|
| 102 | - * @return array |
|
| 103 | - */ |
|
| 104 | - protected function normalize($timer) |
|
| 105 | - { |
|
| 106 | - return wp_parse_args((array) $timer, array( |
|
| 107 | - 'memory' => 0, |
|
| 108 | - 'name' => '', |
|
| 109 | - 'time' => 0, |
|
| 110 | - )); |
|
| 111 | - } |
|
| 100 | + /** |
|
| 101 | + * @param array $timer |
|
| 102 | + * @return array |
|
| 103 | + */ |
|
| 104 | + protected function normalize($timer) |
|
| 105 | + { |
|
| 106 | + return wp_parse_args((array) $timer, array( |
|
| 107 | + 'memory' => 0, |
|
| 108 | + 'name' => '', |
|
| 109 | + 'time' => 0, |
|
| 110 | + )); |
|
| 111 | + } |
|
| 112 | 112 | } |
@@ -37,33 +37,33 @@ discard block |
||
| 37 | 37 | * @param array $timer |
| 38 | 38 | * @return string |
| 39 | 39 | */ |
| 40 | - public function getMemoryString($timer) |
|
| 40 | + public function getMemoryString( $timer ) |
|
| 41 | 41 | { |
| 42 | - $timer = $this->normalize($timer); |
|
| 43 | - return sprintf('%s kB', round($timer['memory'] / 1000)); |
|
| 42 | + $timer = $this->normalize( $timer ); |
|
| 43 | + return sprintf( '%s kB', round( $timer[ 'memory' ] / 1000 ) ); |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | /** |
| 47 | 47 | * @param array $timer |
| 48 | 48 | * @return string |
| 49 | 49 | */ |
| 50 | - public function getNameString($timer) |
|
| 50 | + public function getNameString( $timer ) |
|
| 51 | 51 | { |
| 52 | - $timer = $this->normalize($timer); |
|
| 53 | - return $timer['name']; |
|
| 52 | + $timer = $this->normalize( $timer ); |
|
| 53 | + return $timer[ 'name' ]; |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | /** |
| 57 | 57 | * @param array $timer |
| 58 | 58 | * @return string |
| 59 | 59 | */ |
| 60 | - public function getTimeString($timer) |
|
| 60 | + public function getTimeString( $timer ) |
|
| 61 | 61 | { |
| 62 | - $timer = $this->normalize($timer); |
|
| 63 | - $index = array_search($timer['name'], array_column($this->timers, 'name')); |
|
| 64 | - $start = $this->start + ($index * $this->noise); |
|
| 65 | - $time = number_format(round(($timer['time'] - $start) * 1000, 4), 4); |
|
| 66 | - return sprintf('%s ms', $time); |
|
| 62 | + $timer = $this->normalize( $timer ); |
|
| 63 | + $index = array_search( $timer[ 'name' ], array_column( $this->timers, 'name' ) ); |
|
| 64 | + $start = $this->start + ( $index * $this->noise ); |
|
| 65 | + $time = number_format( round( ( $timer[ 'time' ] - $start ) * 1000, 4 ), 4 ); |
|
| 66 | + return sprintf( '%s ms', $time ); |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | */ |
| 72 | 72 | public function getTotalTime() |
| 73 | 73 | { |
| 74 | - $totalNoise = (count($this->timers) - 1) * $this->noise; |
|
| 74 | + $totalNoise = ( count( $this->timers ) - 1 ) * $this->noise; |
|
| 75 | 75 | return $this->stop - $this->start - $totalNoise; |
| 76 | 76 | } |
| 77 | 77 | |
@@ -79,17 +79,17 @@ discard block |
||
| 79 | 79 | * @param string $name |
| 80 | 80 | * @return void |
| 81 | 81 | */ |
| 82 | - public function trace($name) |
|
| 82 | + public function trace( $name ) |
|
| 83 | 83 | { |
| 84 | - $microtime = microtime(true); |
|
| 85 | - if (!$this->start) { |
|
| 84 | + $microtime = microtime( true ); |
|
| 85 | + if( !$this->start ) { |
|
| 86 | 86 | $this->start = $microtime; |
| 87 | 87 | } |
| 88 | - if ('blackbar/profiler/noise' === $name) { |
|
| 88 | + if( 'blackbar/profiler/noise' === $name ) { |
|
| 89 | 89 | $this->noise = $microtime - $this->start; |
| 90 | 90 | return; |
| 91 | 91 | } |
| 92 | - $this->timers[] = array( |
|
| 92 | + $this->timers[ ] = array( |
|
| 93 | 93 | 'memory' => memory_get_peak_usage(), |
| 94 | 94 | 'name' => $name, |
| 95 | 95 | 'time' => $microtime, |
@@ -101,12 +101,12 @@ discard block |
||
| 101 | 101 | * @param array $timer |
| 102 | 102 | * @return array |
| 103 | 103 | */ |
| 104 | - protected function normalize($timer) |
|
| 104 | + protected function normalize( $timer ) |
|
| 105 | 105 | { |
| 106 | - return wp_parse_args((array) $timer, array( |
|
| 106 | + return wp_parse_args( (array) $timer, array( |
|
| 107 | 107 | 'memory' => 0, |
| 108 | 108 | 'name' => '', |
| 109 | 109 | 'time' => 0, |
| 110 | - )); |
|
| 110 | + ) ); |
|
| 111 | 111 | } |
| 112 | 112 | } |
@@ -4,106 +4,106 @@ |
||
| 4 | 4 | |
| 5 | 5 | final class Application |
| 6 | 6 | { |
| 7 | - const CONSOLE_HOOK = 'console'; |
|
| 8 | - const ID = 'blackbar'; |
|
| 9 | - const LANG = '/languages/'; |
|
| 10 | - const PROFILER_HOOK = 'profile'; |
|
| 7 | + const CONSOLE_HOOK = 'console'; |
|
| 8 | + const ID = 'blackbar'; |
|
| 9 | + const LANG = '/languages/'; |
|
| 10 | + const PROFILER_HOOK = 'profile'; |
|
| 11 | 11 | |
| 12 | - public $actions; |
|
| 13 | - public $console; |
|
| 14 | - public $errors = array(); |
|
| 15 | - public $file; |
|
| 16 | - public $profiler; |
|
| 12 | + public $actions; |
|
| 13 | + public $console; |
|
| 14 | + public $errors = array(); |
|
| 15 | + public $file; |
|
| 16 | + public $profiler; |
|
| 17 | 17 | |
| 18 | - public function __construct() |
|
| 19 | - { |
|
| 20 | - $this->actions = new SlowActions(); |
|
| 21 | - $this->console = new Console(); |
|
| 22 | - $this->file = realpath(dirname(__DIR__).'/'.static::ID.'.php'); |
|
| 23 | - $this->profiler = new Profiler(); |
|
| 24 | - } |
|
| 18 | + public function __construct() |
|
| 19 | + { |
|
| 20 | + $this->actions = new SlowActions(); |
|
| 21 | + $this->console = new Console(); |
|
| 22 | + $this->file = realpath(dirname(__DIR__).'/'.static::ID.'.php'); |
|
| 23 | + $this->profiler = new Profiler(); |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * @param int $errno |
|
| 28 | - * @param string $errstr |
|
| 29 | - * @param string $errfile |
|
| 30 | - * @param int $errline |
|
| 31 | - * @return void |
|
| 32 | - */ |
|
| 33 | - public function errorHandler($errno, $errstr, $errfile, $errline) |
|
| 34 | - { |
|
| 35 | - $errname = array_key_exists($errno, Console::ERROR_CODES) |
|
| 36 | - ? Console::ERROR_CODES[$errno] |
|
| 37 | - : 'Unknown'; |
|
| 38 | - $hash = md5($errno.$errstr.$errfile.$errline); |
|
| 39 | - if (array_key_exists($hash, $this->errors)) { |
|
| 40 | - ++$this->errors[$hash]['count']; |
|
| 41 | - } else { |
|
| 42 | - $this->errors[$hash] = array( |
|
| 43 | - 'errno' => $errno, |
|
| 44 | - 'message' => $errstr, |
|
| 45 | - 'file' => $errfile, |
|
| 46 | - 'name' => $errname, |
|
| 47 | - 'line' => $errline, |
|
| 48 | - 'count' => 0, |
|
| 49 | - ); |
|
| 50 | - } |
|
| 51 | - } |
|
| 26 | + /** |
|
| 27 | + * @param int $errno |
|
| 28 | + * @param string $errstr |
|
| 29 | + * @param string $errfile |
|
| 30 | + * @param int $errline |
|
| 31 | + * @return void |
|
| 32 | + */ |
|
| 33 | + public function errorHandler($errno, $errstr, $errfile, $errline) |
|
| 34 | + { |
|
| 35 | + $errname = array_key_exists($errno, Console::ERROR_CODES) |
|
| 36 | + ? Console::ERROR_CODES[$errno] |
|
| 37 | + : 'Unknown'; |
|
| 38 | + $hash = md5($errno.$errstr.$errfile.$errline); |
|
| 39 | + if (array_key_exists($hash, $this->errors)) { |
|
| 40 | + ++$this->errors[$hash]['count']; |
|
| 41 | + } else { |
|
| 42 | + $this->errors[$hash] = array( |
|
| 43 | + 'errno' => $errno, |
|
| 44 | + 'message' => $errstr, |
|
| 45 | + 'file' => $errfile, |
|
| 46 | + 'name' => $errname, |
|
| 47 | + 'line' => $errline, |
|
| 48 | + 'count' => 0, |
|
| 49 | + ); |
|
| 50 | + } |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * @return void |
|
| 55 | - */ |
|
| 56 | - public function init() |
|
| 57 | - { |
|
| 58 | - $controller = new Controller($this); |
|
| 59 | - add_filter('all', array($controller, 'initConsole')); |
|
| 60 | - add_filter('all', array($controller, 'initProfiler')); |
|
| 61 | - add_filter('all', array($controller, 'measureSlowActions')); |
|
| 62 | - add_action('plugins_loaded', array($controller, 'registerLanguages')); |
|
| 63 | - add_action('init', function () use ($controller) { |
|
| 64 | - if (!apply_filters('blackbar/enabled', true)) { |
|
| 65 | - return; |
|
| 66 | - } |
|
| 67 | - add_action('admin_enqueue_scripts', array($controller, 'enqueueAssets')); |
|
| 68 | - add_action('wp_enqueue_scripts', array($controller, 'enqueueAssets')); |
|
| 69 | - add_action('admin_footer', array($controller, 'renderBar')); |
|
| 70 | - add_action('wp_footer', array($controller, 'renderBar')); |
|
| 71 | - add_filter('admin_body_class', array($controller, 'filterBodyClasses')); |
|
| 72 | - }); |
|
| 73 | - apply_filters('debug', 'Profiler Started'); |
|
| 74 | - apply_filters('debug', 'blackbar/profiler/noise'); |
|
| 75 | - set_error_handler(array($this, 'errorHandler'), E_ALL | E_STRICT); |
|
| 76 | - } |
|
| 53 | + /** |
|
| 54 | + * @return void |
|
| 55 | + */ |
|
| 56 | + public function init() |
|
| 57 | + { |
|
| 58 | + $controller = new Controller($this); |
|
| 59 | + add_filter('all', array($controller, 'initConsole')); |
|
| 60 | + add_filter('all', array($controller, 'initProfiler')); |
|
| 61 | + add_filter('all', array($controller, 'measureSlowActions')); |
|
| 62 | + add_action('plugins_loaded', array($controller, 'registerLanguages')); |
|
| 63 | + add_action('init', function () use ($controller) { |
|
| 64 | + if (!apply_filters('blackbar/enabled', true)) { |
|
| 65 | + return; |
|
| 66 | + } |
|
| 67 | + add_action('admin_enqueue_scripts', array($controller, 'enqueueAssets')); |
|
| 68 | + add_action('wp_enqueue_scripts', array($controller, 'enqueueAssets')); |
|
| 69 | + add_action('admin_footer', array($controller, 'renderBar')); |
|
| 70 | + add_action('wp_footer', array($controller, 'renderBar')); |
|
| 71 | + add_filter('admin_body_class', array($controller, 'filterBodyClasses')); |
|
| 72 | + }); |
|
| 73 | + apply_filters('debug', 'Profiler Started'); |
|
| 74 | + apply_filters('debug', 'blackbar/profiler/noise'); |
|
| 75 | + set_error_handler(array($this, 'errorHandler'), E_ALL | E_STRICT); |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * @param string $file |
|
| 80 | - * @return string |
|
| 81 | - */ |
|
| 82 | - public function path($file = '') |
|
| 83 | - { |
|
| 84 | - return plugin_dir_path($this->file).ltrim(trim($file), '/'); |
|
| 85 | - } |
|
| 78 | + /** |
|
| 79 | + * @param string $file |
|
| 80 | + * @return string |
|
| 81 | + */ |
|
| 82 | + public function path($file = '') |
|
| 83 | + { |
|
| 84 | + return plugin_dir_path($this->file).ltrim(trim($file), '/'); |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - /** |
|
| 88 | - * @param string $view |
|
| 89 | - * @return void |
|
| 90 | - */ |
|
| 91 | - public function render($view, array $data = array()) |
|
| 92 | - { |
|
| 93 | - $file = $this->path(sprintf('views/%s.php', str_replace('.php', '', $view))); |
|
| 94 | - if (!file_exists($file)) { |
|
| 95 | - return; |
|
| 96 | - } |
|
| 97 | - extract($data); |
|
| 98 | - include $file; |
|
| 99 | - } |
|
| 87 | + /** |
|
| 88 | + * @param string $view |
|
| 89 | + * @return void |
|
| 90 | + */ |
|
| 91 | + public function render($view, array $data = array()) |
|
| 92 | + { |
|
| 93 | + $file = $this->path(sprintf('views/%s.php', str_replace('.php', '', $view))); |
|
| 94 | + if (!file_exists($file)) { |
|
| 95 | + return; |
|
| 96 | + } |
|
| 97 | + extract($data); |
|
| 98 | + include $file; |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - /** |
|
| 102 | - * @param string $path |
|
| 103 | - * @return string |
|
| 104 | - */ |
|
| 105 | - public function url($path = '') |
|
| 106 | - { |
|
| 107 | - return esc_url(plugin_dir_url($this->file).ltrim(trim($path), '/')); |
|
| 108 | - } |
|
| 101 | + /** |
|
| 102 | + * @param string $path |
|
| 103 | + * @return string |
|
| 104 | + */ |
|
| 105 | + public function url($path = '') |
|
| 106 | + { |
|
| 107 | + return esc_url(plugin_dir_url($this->file).ltrim(trim($path), '/')); |
|
| 108 | + } |
|
| 109 | 109 | } |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | { |
| 20 | 20 | $this->actions = new SlowActions(); |
| 21 | 21 | $this->console = new Console(); |
| 22 | - $this->file = realpath(dirname(__DIR__).'/'.static::ID.'.php'); |
|
| 22 | + $this->file = realpath( dirname( __DIR__ ) . '/' . static::ID . '.php' ); |
|
| 23 | 23 | $this->profiler = new Profiler(); |
| 24 | 24 | } |
| 25 | 25 | |
@@ -30,16 +30,16 @@ discard block |
||
| 30 | 30 | * @param int $errline |
| 31 | 31 | * @return void |
| 32 | 32 | */ |
| 33 | - public function errorHandler($errno, $errstr, $errfile, $errline) |
|
| 33 | + public function errorHandler( $errno, $errstr, $errfile, $errline ) |
|
| 34 | 34 | { |
| 35 | - $errname = array_key_exists($errno, Console::ERROR_CODES) |
|
| 36 | - ? Console::ERROR_CODES[$errno] |
|
| 35 | + $errname = array_key_exists( $errno, Console::ERROR_CODES ) |
|
| 36 | + ? Console::ERROR_CODES[ $errno ] |
|
| 37 | 37 | : 'Unknown'; |
| 38 | - $hash = md5($errno.$errstr.$errfile.$errline); |
|
| 39 | - if (array_key_exists($hash, $this->errors)) { |
|
| 40 | - ++$this->errors[$hash]['count']; |
|
| 38 | + $hash = md5( $errno . $errstr . $errfile . $errline ); |
|
| 39 | + if( array_key_exists( $hash, $this->errors ) ) { |
|
| 40 | + ++$this->errors[ $hash ][ 'count' ]; |
|
| 41 | 41 | } else { |
| 42 | - $this->errors[$hash] = array( |
|
| 42 | + $this->errors[ $hash ] = array( |
|
| 43 | 43 | 'errno' => $errno, |
| 44 | 44 | 'message' => $errstr, |
| 45 | 45 | 'file' => $errfile, |
@@ -55,46 +55,46 @@ discard block |
||
| 55 | 55 | */ |
| 56 | 56 | public function init() |
| 57 | 57 | { |
| 58 | - $controller = new Controller($this); |
|
| 59 | - add_filter('all', array($controller, 'initConsole')); |
|
| 60 | - add_filter('all', array($controller, 'initProfiler')); |
|
| 61 | - add_filter('all', array($controller, 'measureSlowActions')); |
|
| 62 | - add_action('plugins_loaded', array($controller, 'registerLanguages')); |
|
| 63 | - add_action('init', function () use ($controller) { |
|
| 64 | - if (!apply_filters('blackbar/enabled', true)) { |
|
| 58 | + $controller = new Controller( $this ); |
|
| 59 | + add_filter( 'all', array( $controller, 'initConsole' ) ); |
|
| 60 | + add_filter( 'all', array( $controller, 'initProfiler' ) ); |
|
| 61 | + add_filter( 'all', array( $controller, 'measureSlowActions' ) ); |
|
| 62 | + add_action( 'plugins_loaded', array( $controller, 'registerLanguages' ) ); |
|
| 63 | + add_action( 'init', function() use ( $controller ) { |
|
| 64 | + if( !apply_filters( 'blackbar/enabled', true ) ) { |
|
| 65 | 65 | return; |
| 66 | 66 | } |
| 67 | - add_action('admin_enqueue_scripts', array($controller, 'enqueueAssets')); |
|
| 68 | - add_action('wp_enqueue_scripts', array($controller, 'enqueueAssets')); |
|
| 69 | - add_action('admin_footer', array($controller, 'renderBar')); |
|
| 70 | - add_action('wp_footer', array($controller, 'renderBar')); |
|
| 71 | - add_filter('admin_body_class', array($controller, 'filterBodyClasses')); |
|
| 67 | + add_action( 'admin_enqueue_scripts', array( $controller, 'enqueueAssets' ) ); |
|
| 68 | + add_action( 'wp_enqueue_scripts', array( $controller, 'enqueueAssets' ) ); |
|
| 69 | + add_action( 'admin_footer', array( $controller, 'renderBar' ) ); |
|
| 70 | + add_action( 'wp_footer', array( $controller, 'renderBar' ) ); |
|
| 71 | + add_filter( 'admin_body_class', array( $controller, 'filterBodyClasses' ) ); |
|
| 72 | 72 | }); |
| 73 | - apply_filters('debug', 'Profiler Started'); |
|
| 74 | - apply_filters('debug', 'blackbar/profiler/noise'); |
|
| 75 | - set_error_handler(array($this, 'errorHandler'), E_ALL | E_STRICT); |
|
| 73 | + apply_filters( 'debug', 'Profiler Started' ); |
|
| 74 | + apply_filters( 'debug', 'blackbar/profiler/noise' ); |
|
| 75 | + set_error_handler( array( $this, 'errorHandler' ), E_ALL | E_STRICT ); |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | /** |
| 79 | 79 | * @param string $file |
| 80 | 80 | * @return string |
| 81 | 81 | */ |
| 82 | - public function path($file = '') |
|
| 82 | + public function path( $file = '' ) |
|
| 83 | 83 | { |
| 84 | - return plugin_dir_path($this->file).ltrim(trim($file), '/'); |
|
| 84 | + return plugin_dir_path( $this->file ) . ltrim( trim( $file ), '/' ); |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | /** |
| 88 | 88 | * @param string $view |
| 89 | 89 | * @return void |
| 90 | 90 | */ |
| 91 | - public function render($view, array $data = array()) |
|
| 91 | + public function render( $view, array $data = array() ) |
|
| 92 | 92 | { |
| 93 | - $file = $this->path(sprintf('views/%s.php', str_replace('.php', '', $view))); |
|
| 94 | - if (!file_exists($file)) { |
|
| 93 | + $file = $this->path( sprintf( 'views/%s.php', str_replace( '.php', '', $view ) ) ); |
|
| 94 | + if( !file_exists( $file ) ) { |
|
| 95 | 95 | return; |
| 96 | 96 | } |
| 97 | - extract($data); |
|
| 97 | + extract( $data ); |
|
| 98 | 98 | include $file; |
| 99 | 99 | } |
| 100 | 100 | |
@@ -102,8 +102,8 @@ discard block |
||
| 102 | 102 | * @param string $path |
| 103 | 103 | * @return string |
| 104 | 104 | */ |
| 105 | - public function url($path = '') |
|
| 105 | + public function url( $path = '' ) |
|
| 106 | 106 | { |
| 107 | - return esc_url(plugin_dir_url($this->file).ltrim(trim($path), '/')); |
|
| 107 | + return esc_url( plugin_dir_url( $this->file ) . ltrim( trim( $path ), '/' ) ); |
|
| 108 | 108 | } |
| 109 | 109 | } |
@@ -38,7 +38,8 @@ discard block |
||
| 38 | 38 | $hash = md5($errno.$errstr.$errfile.$errline); |
| 39 | 39 | if (array_key_exists($hash, $this->errors)) { |
| 40 | 40 | ++$this->errors[$hash]['count']; |
| 41 | - } else { |
|
| 41 | + } |
|
| 42 | + else { |
|
| 42 | 43 | $this->errors[$hash] = array( |
| 43 | 44 | 'errno' => $errno, |
| 44 | 45 | 'message' => $errstr, |
@@ -60,7 +61,8 @@ discard block |
||
| 60 | 61 | add_filter('all', array($controller, 'initProfiler')); |
| 61 | 62 | add_filter('all', array($controller, 'measureSlowActions')); |
| 62 | 63 | add_action('plugins_loaded', array($controller, 'registerLanguages')); |
| 63 | - add_action('init', function () use ($controller) { |
|
| 64 | + add_action('init', function () use ($controller) |
|
| 65 | + { |
|
| 64 | 66 | if (!apply_filters('blackbar/enabled', true)) { |
| 65 | 67 | return; |
| 66 | 68 | } |
@@ -8,141 +8,141 @@ |
||
| 8 | 8 | */ |
| 9 | 9 | class GL_Plugin_Check_v6 |
| 10 | 10 | { |
| 11 | - const MIN_PHP_VERSION = '7.2'; |
|
| 12 | - const MIN_WORDPRESS_VERSION = '5.8'; |
|
| 11 | + const MIN_PHP_VERSION = '7.2'; |
|
| 12 | + const MIN_WORDPRESS_VERSION = '5.8'; |
|
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * @var array |
|
| 16 | - */ |
|
| 17 | - public $versions; |
|
| 14 | + /** |
|
| 15 | + * @var array |
|
| 16 | + */ |
|
| 17 | + public $versions; |
|
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * @var string |
|
| 21 | - */ |
|
| 22 | - protected $file; |
|
| 19 | + /** |
|
| 20 | + * @var string |
|
| 21 | + */ |
|
| 22 | + protected $file; |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * @param string $file |
|
| 26 | - */ |
|
| 27 | - public function __construct($file) |
|
| 28 | - { |
|
| 29 | - $this->file = realpath($file); |
|
| 30 | - $versionRequirements = get_file_data($this->file, [ |
|
| 31 | - 'php' => 'Requires PHP', |
|
| 32 | - 'wordpress' => 'Requires at least', |
|
| 33 | - ]); |
|
| 34 | - $this->versions = wp_parse_args(array_filter($versionRequirements), [ |
|
| 35 | - 'php' => static::MIN_PHP_VERSION, |
|
| 36 | - 'wordpress' => static::MIN_WORDPRESS_VERSION, |
|
| 37 | - ]); |
|
| 38 | - } |
|
| 24 | + /** |
|
| 25 | + * @param string $file |
|
| 26 | + */ |
|
| 27 | + public function __construct($file) |
|
| 28 | + { |
|
| 29 | + $this->file = realpath($file); |
|
| 30 | + $versionRequirements = get_file_data($this->file, [ |
|
| 31 | + 'php' => 'Requires PHP', |
|
| 32 | + 'wordpress' => 'Requires at least', |
|
| 33 | + ]); |
|
| 34 | + $this->versions = wp_parse_args(array_filter($versionRequirements), [ |
|
| 35 | + 'php' => static::MIN_PHP_VERSION, |
|
| 36 | + 'wordpress' => static::MIN_WORDPRESS_VERSION, |
|
| 37 | + ]); |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * @return bool |
|
| 42 | - */ |
|
| 43 | - public function canProceed() |
|
| 44 | - { |
|
| 45 | - if ($this->isValid()) { |
|
| 46 | - return true; |
|
| 47 | - } |
|
| 48 | - add_action('activated_plugin', [$this, 'deactivate']); |
|
| 49 | - add_action('admin_notices', [$this, 'deactivate']); |
|
| 50 | - return false; |
|
| 51 | - } |
|
| 40 | + /** |
|
| 41 | + * @return bool |
|
| 42 | + */ |
|
| 43 | + public function canProceed() |
|
| 44 | + { |
|
| 45 | + if ($this->isValid()) { |
|
| 46 | + return true; |
|
| 47 | + } |
|
| 48 | + add_action('activated_plugin', [$this, 'deactivate']); |
|
| 49 | + add_action('admin_notices', [$this, 'deactivate']); |
|
| 50 | + return false; |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * @return bool |
|
| 55 | - */ |
|
| 56 | - public function isPhpValid() |
|
| 57 | - { |
|
| 58 | - return version_compare(PHP_VERSION, $this->versions['php'], '>='); |
|
| 59 | - } |
|
| 53 | + /** |
|
| 54 | + * @return bool |
|
| 55 | + */ |
|
| 56 | + public function isPhpValid() |
|
| 57 | + { |
|
| 58 | + return version_compare(PHP_VERSION, $this->versions['php'], '>='); |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * @return bool |
|
| 63 | - */ |
|
| 64 | - public function isValid() |
|
| 65 | - { |
|
| 66 | - return $this->isPhpValid() && $this->isWpValid(); |
|
| 67 | - } |
|
| 61 | + /** |
|
| 62 | + * @return bool |
|
| 63 | + */ |
|
| 64 | + public function isValid() |
|
| 65 | + { |
|
| 66 | + return $this->isPhpValid() && $this->isWpValid(); |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * @return bool |
|
| 71 | - */ |
|
| 72 | - public function isWpValid() |
|
| 73 | - { |
|
| 74 | - global $wp_version; |
|
| 75 | - return version_compare($wp_version, $this->versions['wordpress'], '>='); |
|
| 76 | - } |
|
| 69 | + /** |
|
| 70 | + * @return bool |
|
| 71 | + */ |
|
| 72 | + public function isWpValid() |
|
| 73 | + { |
|
| 74 | + global $wp_version; |
|
| 75 | + return version_compare($wp_version, $this->versions['wordpress'], '>='); |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * @param string $plugin |
|
| 80 | - * @return void |
|
| 81 | - */ |
|
| 82 | - public function deactivate($plugin) |
|
| 83 | - { |
|
| 84 | - if ($this->isValid()) { |
|
| 85 | - return; |
|
| 86 | - } |
|
| 87 | - $pluginSlug = plugin_basename($this->file); |
|
| 88 | - if ($plugin == $pluginSlug) { |
|
| 89 | - $this->redirect(); // exit |
|
| 90 | - } |
|
| 91 | - $pluginData = get_file_data($this->file, ['name' => 'Plugin Name'], 'plugin'); |
|
| 92 | - deactivate_plugins($pluginSlug); |
|
| 93 | - $this->printNotice($pluginData['name']); |
|
| 94 | - } |
|
| 78 | + /** |
|
| 79 | + * @param string $plugin |
|
| 80 | + * @return void |
|
| 81 | + */ |
|
| 82 | + public function deactivate($plugin) |
|
| 83 | + { |
|
| 84 | + if ($this->isValid()) { |
|
| 85 | + return; |
|
| 86 | + } |
|
| 87 | + $pluginSlug = plugin_basename($this->file); |
|
| 88 | + if ($plugin == $pluginSlug) { |
|
| 89 | + $this->redirect(); // exit |
|
| 90 | + } |
|
| 91 | + $pluginData = get_file_data($this->file, ['name' => 'Plugin Name'], 'plugin'); |
|
| 92 | + deactivate_plugins($pluginSlug); |
|
| 93 | + $this->printNotice($pluginData['name']); |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | - /** |
|
| 97 | - * @return array |
|
| 98 | - */ |
|
| 99 | - protected function getMessages() |
|
| 100 | - { |
|
| 101 | - return [ |
|
| 102 | - 'notice' => _x('The %s plugin was deactivated.', 'admin-text', 'blackbar'), |
|
| 103 | - 'php_version' => _x('PHP version', 'admin-text', 'blackbar'), |
|
| 104 | - 'rollback' => _x('You can use the %s plugin to restore %s to the previous version.', 'admin-text', 'blackbar'), |
|
| 105 | - 'update_php' => _x('Please contact your hosting provider or server administrator to upgrade the version of PHP on your server (your server is running PHP version %s), or try to find an alternative plugin.', 'admin-text', 'blackbar'), |
|
| 106 | - 'update_wp' => _x('Update WordPress', 'admin-text', 'blackbar'), |
|
| 107 | - 'wp_version' => _x('WordPress version', 'admin-text', 'blackbar'), |
|
| 108 | - 'wrong_version' => _x('This plugin requires %s or greater in order to work properly.', 'admin-text', 'blackbar'), |
|
| 109 | - ]; |
|
| 110 | - } |
|
| 96 | + /** |
|
| 97 | + * @return array |
|
| 98 | + */ |
|
| 99 | + protected function getMessages() |
|
| 100 | + { |
|
| 101 | + return [ |
|
| 102 | + 'notice' => _x('The %s plugin was deactivated.', 'admin-text', 'blackbar'), |
|
| 103 | + 'php_version' => _x('PHP version', 'admin-text', 'blackbar'), |
|
| 104 | + 'rollback' => _x('You can use the %s plugin to restore %s to the previous version.', 'admin-text', 'blackbar'), |
|
| 105 | + 'update_php' => _x('Please contact your hosting provider or server administrator to upgrade the version of PHP on your server (your server is running PHP version %s), or try to find an alternative plugin.', 'admin-text', 'blackbar'), |
|
| 106 | + 'update_wp' => _x('Update WordPress', 'admin-text', 'blackbar'), |
|
| 107 | + 'wp_version' => _x('WordPress version', 'admin-text', 'blackbar'), |
|
| 108 | + 'wrong_version' => _x('This plugin requires %s or greater in order to work properly.', 'admin-text', 'blackbar'), |
|
| 109 | + ]; |
|
| 110 | + } |
|
| 111 | 111 | |
| 112 | - /** |
|
| 113 | - * @param string $pluginName |
|
| 114 | - * @return void |
|
| 115 | - */ |
|
| 116 | - protected function printNotice($pluginName) |
|
| 117 | - { |
|
| 118 | - $noticeTemplate = '<div id="message" class="notice notice-error error is-dismissible"><p><strong>%s</strong></p><p>%s</p><p>%s</p></div>'; |
|
| 119 | - $messages = $this->getMessages(); |
|
| 120 | - $rollbackMessage = sprintf('<strong>'.$messages['rollback'].'</strong>', '<a href="https://wordpress.org/plugins/wp-rollback/" target="_blank">WP Rollback</a>', $pluginName); |
|
| 121 | - if (!$this->isPhpValid()) { |
|
| 122 | - printf($noticeTemplate, |
|
| 123 | - sprintf($messages['notice'], $pluginName), |
|
| 124 | - sprintf($messages['wrong_version'], $messages['php_version'].' '.$this->versions['php']), |
|
| 125 | - sprintf($messages['update_php'], PHP_VERSION).'</p><p>'.$rollbackMessage |
|
| 126 | - ); |
|
| 127 | - } elseif (!$this->isWpValid()) { |
|
| 128 | - printf($noticeTemplate, |
|
| 129 | - sprintf($messages['notice'], $pluginName), |
|
| 130 | - sprintf($messages['wrong_version'], $messages['wp_version'].' '.$this->versions['wordpress']), |
|
| 131 | - $rollbackMessage.'</p><p>'.sprintf('<a href="%s">%s</a>', admin_url('update-core.php'), $messages['update_wp']) |
|
| 132 | - ); |
|
| 133 | - } |
|
| 134 | - } |
|
| 112 | + /** |
|
| 113 | + * @param string $pluginName |
|
| 114 | + * @return void |
|
| 115 | + */ |
|
| 116 | + protected function printNotice($pluginName) |
|
| 117 | + { |
|
| 118 | + $noticeTemplate = '<div id="message" class="notice notice-error error is-dismissible"><p><strong>%s</strong></p><p>%s</p><p>%s</p></div>'; |
|
| 119 | + $messages = $this->getMessages(); |
|
| 120 | + $rollbackMessage = sprintf('<strong>'.$messages['rollback'].'</strong>', '<a href="https://wordpress.org/plugins/wp-rollback/" target="_blank">WP Rollback</a>', $pluginName); |
|
| 121 | + if (!$this->isPhpValid()) { |
|
| 122 | + printf($noticeTemplate, |
|
| 123 | + sprintf($messages['notice'], $pluginName), |
|
| 124 | + sprintf($messages['wrong_version'], $messages['php_version'].' '.$this->versions['php']), |
|
| 125 | + sprintf($messages['update_php'], PHP_VERSION).'</p><p>'.$rollbackMessage |
|
| 126 | + ); |
|
| 127 | + } elseif (!$this->isWpValid()) { |
|
| 128 | + printf($noticeTemplate, |
|
| 129 | + sprintf($messages['notice'], $pluginName), |
|
| 130 | + sprintf($messages['wrong_version'], $messages['wp_version'].' '.$this->versions['wordpress']), |
|
| 131 | + $rollbackMessage.'</p><p>'.sprintf('<a href="%s">%s</a>', admin_url('update-core.php'), $messages['update_wp']) |
|
| 132 | + ); |
|
| 133 | + } |
|
| 134 | + } |
|
| 135 | 135 | |
| 136 | - /** |
|
| 137 | - * @return void |
|
| 138 | - */ |
|
| 139 | - protected function redirect() |
|
| 140 | - { |
|
| 141 | - wp_safe_redirect(self_admin_url(sprintf('plugins.php?plugin_status=%s&paged=%s&s=%s', |
|
| 142 | - filter_input(INPUT_GET, 'plugin_status'), |
|
| 143 | - filter_input(INPUT_GET, 'paged'), |
|
| 144 | - filter_input(INPUT_GET, 's') |
|
| 145 | - ))); |
|
| 146 | - exit; |
|
| 147 | - } |
|
| 136 | + /** |
|
| 137 | + * @return void |
|
| 138 | + */ |
|
| 139 | + protected function redirect() |
|
| 140 | + { |
|
| 141 | + wp_safe_redirect(self_admin_url(sprintf('plugins.php?plugin_status=%s&paged=%s&s=%s', |
|
| 142 | + filter_input(INPUT_GET, 'plugin_status'), |
|
| 143 | + filter_input(INPUT_GET, 'paged'), |
|
| 144 | + filter_input(INPUT_GET, 's') |
|
| 145 | + ))); |
|
| 146 | + exit; |
|
| 147 | + } |
|
| 148 | 148 | } |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -defined('ABSPATH') || exit; |
|
| 3 | +defined( 'ABSPATH' ) || exit; |
|
| 4 | 4 | |
| 5 | 5 | /** |
| 6 | 6 | * Check for minimum system requirements on plugin activation. |
@@ -24,17 +24,17 @@ discard block |
||
| 24 | 24 | /** |
| 25 | 25 | * @param string $file |
| 26 | 26 | */ |
| 27 | - public function __construct($file) |
|
| 27 | + public function __construct( $file ) |
|
| 28 | 28 | { |
| 29 | - $this->file = realpath($file); |
|
| 30 | - $versionRequirements = get_file_data($this->file, [ |
|
| 29 | + $this->file = realpath( $file ); |
|
| 30 | + $versionRequirements = get_file_data( $this->file, [ |
|
| 31 | 31 | 'php' => 'Requires PHP', |
| 32 | 32 | 'wordpress' => 'Requires at least', |
| 33 | - ]); |
|
| 34 | - $this->versions = wp_parse_args(array_filter($versionRequirements), [ |
|
| 33 | + ] ); |
|
| 34 | + $this->versions = wp_parse_args( array_filter( $versionRequirements ), [ |
|
| 35 | 35 | 'php' => static::MIN_PHP_VERSION, |
| 36 | 36 | 'wordpress' => static::MIN_WORDPRESS_VERSION, |
| 37 | - ]); |
|
| 37 | + ] ); |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | /** |
@@ -42,11 +42,11 @@ discard block |
||
| 42 | 42 | */ |
| 43 | 43 | public function canProceed() |
| 44 | 44 | { |
| 45 | - if ($this->isValid()) { |
|
| 45 | + if( $this->isValid() ) { |
|
| 46 | 46 | return true; |
| 47 | 47 | } |
| 48 | - add_action('activated_plugin', [$this, 'deactivate']); |
|
| 49 | - add_action('admin_notices', [$this, 'deactivate']); |
|
| 48 | + add_action( 'activated_plugin', [ $this, 'deactivate' ] ); |
|
| 49 | + add_action( 'admin_notices', [ $this, 'deactivate' ] ); |
|
| 50 | 50 | return false; |
| 51 | 51 | } |
| 52 | 52 | |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | */ |
| 56 | 56 | public function isPhpValid() |
| 57 | 57 | { |
| 58 | - return version_compare(PHP_VERSION, $this->versions['php'], '>='); |
|
| 58 | + return version_compare( PHP_VERSION, $this->versions[ 'php' ], '>=' ); |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | /** |
@@ -72,25 +72,25 @@ discard block |
||
| 72 | 72 | public function isWpValid() |
| 73 | 73 | { |
| 74 | 74 | global $wp_version; |
| 75 | - return version_compare($wp_version, $this->versions['wordpress'], '>='); |
|
| 75 | + return version_compare( $wp_version, $this->versions[ 'wordpress' ], '>=' ); |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | /** |
| 79 | 79 | * @param string $plugin |
| 80 | 80 | * @return void |
| 81 | 81 | */ |
| 82 | - public function deactivate($plugin) |
|
| 82 | + public function deactivate( $plugin ) |
|
| 83 | 83 | { |
| 84 | - if ($this->isValid()) { |
|
| 84 | + if( $this->isValid() ) { |
|
| 85 | 85 | return; |
| 86 | 86 | } |
| 87 | - $pluginSlug = plugin_basename($this->file); |
|
| 88 | - if ($plugin == $pluginSlug) { |
|
| 87 | + $pluginSlug = plugin_basename( $this->file ); |
|
| 88 | + if( $plugin == $pluginSlug ) { |
|
| 89 | 89 | $this->redirect(); // exit |
| 90 | 90 | } |
| 91 | - $pluginData = get_file_data($this->file, ['name' => 'Plugin Name'], 'plugin'); |
|
| 92 | - deactivate_plugins($pluginSlug); |
|
| 93 | - $this->printNotice($pluginData['name']); |
|
| 91 | + $pluginData = get_file_data( $this->file, [ 'name' => 'Plugin Name' ], 'plugin' ); |
|
| 92 | + deactivate_plugins( $pluginSlug ); |
|
| 93 | + $this->printNotice( $pluginData[ 'name' ] ); |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | /** |
@@ -99,13 +99,13 @@ discard block |
||
| 99 | 99 | protected function getMessages() |
| 100 | 100 | { |
| 101 | 101 | return [ |
| 102 | - 'notice' => _x('The %s plugin was deactivated.', 'admin-text', 'blackbar'), |
|
| 103 | - 'php_version' => _x('PHP version', 'admin-text', 'blackbar'), |
|
| 104 | - 'rollback' => _x('You can use the %s plugin to restore %s to the previous version.', 'admin-text', 'blackbar'), |
|
| 105 | - 'update_php' => _x('Please contact your hosting provider or server administrator to upgrade the version of PHP on your server (your server is running PHP version %s), or try to find an alternative plugin.', 'admin-text', 'blackbar'), |
|
| 106 | - 'update_wp' => _x('Update WordPress', 'admin-text', 'blackbar'), |
|
| 107 | - 'wp_version' => _x('WordPress version', 'admin-text', 'blackbar'), |
|
| 108 | - 'wrong_version' => _x('This plugin requires %s or greater in order to work properly.', 'admin-text', 'blackbar'), |
|
| 102 | + 'notice' => _x( 'The %s plugin was deactivated.', 'admin-text', 'blackbar' ), |
|
| 103 | + 'php_version' => _x( 'PHP version', 'admin-text', 'blackbar' ), |
|
| 104 | + 'rollback' => _x( 'You can use the %s plugin to restore %s to the previous version.', 'admin-text', 'blackbar' ), |
|
| 105 | + 'update_php' => _x( 'Please contact your hosting provider or server administrator to upgrade the version of PHP on your server (your server is running PHP version %s), or try to find an alternative plugin.', 'admin-text', 'blackbar' ), |
|
| 106 | + 'update_wp' => _x( 'Update WordPress', 'admin-text', 'blackbar' ), |
|
| 107 | + 'wp_version' => _x( 'WordPress version', 'admin-text', 'blackbar' ), |
|
| 108 | + 'wrong_version' => _x( 'This plugin requires %s or greater in order to work properly.', 'admin-text', 'blackbar' ), |
|
| 109 | 109 | ]; |
| 110 | 110 | } |
| 111 | 111 | |
@@ -113,22 +113,22 @@ discard block |
||
| 113 | 113 | * @param string $pluginName |
| 114 | 114 | * @return void |
| 115 | 115 | */ |
| 116 | - protected function printNotice($pluginName) |
|
| 116 | + protected function printNotice( $pluginName ) |
|
| 117 | 117 | { |
| 118 | 118 | $noticeTemplate = '<div id="message" class="notice notice-error error is-dismissible"><p><strong>%s</strong></p><p>%s</p><p>%s</p></div>'; |
| 119 | 119 | $messages = $this->getMessages(); |
| 120 | - $rollbackMessage = sprintf('<strong>'.$messages['rollback'].'</strong>', '<a href="https://wordpress.org/plugins/wp-rollback/" target="_blank">WP Rollback</a>', $pluginName); |
|
| 121 | - if (!$this->isPhpValid()) { |
|
| 122 | - printf($noticeTemplate, |
|
| 123 | - sprintf($messages['notice'], $pluginName), |
|
| 124 | - sprintf($messages['wrong_version'], $messages['php_version'].' '.$this->versions['php']), |
|
| 125 | - sprintf($messages['update_php'], PHP_VERSION).'</p><p>'.$rollbackMessage |
|
| 120 | + $rollbackMessage = sprintf( '<strong>' . $messages[ 'rollback' ] . '</strong>', '<a href="https://wordpress.org/plugins/wp-rollback/" target="_blank">WP Rollback</a>', $pluginName ); |
|
| 121 | + if( !$this->isPhpValid() ) { |
|
| 122 | + printf( $noticeTemplate, |
|
| 123 | + sprintf( $messages[ 'notice' ], $pluginName ), |
|
| 124 | + sprintf( $messages[ 'wrong_version' ], $messages[ 'php_version' ] . ' ' . $this->versions[ 'php' ] ), |
|
| 125 | + sprintf( $messages[ 'update_php' ], PHP_VERSION ) . '</p><p>' . $rollbackMessage |
|
| 126 | 126 | ); |
| 127 | - } elseif (!$this->isWpValid()) { |
|
| 128 | - printf($noticeTemplate, |
|
| 129 | - sprintf($messages['notice'], $pluginName), |
|
| 130 | - sprintf($messages['wrong_version'], $messages['wp_version'].' '.$this->versions['wordpress']), |
|
| 131 | - $rollbackMessage.'</p><p>'.sprintf('<a href="%s">%s</a>', admin_url('update-core.php'), $messages['update_wp']) |
|
| 127 | + } elseif( !$this->isWpValid() ) { |
|
| 128 | + printf( $noticeTemplate, |
|
| 129 | + sprintf( $messages[ 'notice' ], $pluginName ), |
|
| 130 | + sprintf( $messages[ 'wrong_version' ], $messages[ 'wp_version' ] . ' ' . $this->versions[ 'wordpress' ] ), |
|
| 131 | + $rollbackMessage . '</p><p>' . sprintf( '<a href="%s">%s</a>', admin_url( 'update-core.php' ), $messages[ 'update_wp' ] ) |
|
| 132 | 132 | ); |
| 133 | 133 | } |
| 134 | 134 | } |
@@ -138,11 +138,11 @@ discard block |
||
| 138 | 138 | */ |
| 139 | 139 | protected function redirect() |
| 140 | 140 | { |
| 141 | - wp_safe_redirect(self_admin_url(sprintf('plugins.php?plugin_status=%s&paged=%s&s=%s', |
|
| 142 | - filter_input(INPUT_GET, 'plugin_status'), |
|
| 143 | - filter_input(INPUT_GET, 'paged'), |
|
| 144 | - filter_input(INPUT_GET, 's') |
|
| 145 | - ))); |
|
| 141 | + wp_safe_redirect( self_admin_url( sprintf( 'plugins.php?plugin_status=%s&paged=%s&s=%s', |
|
| 142 | + filter_input( INPUT_GET, 'plugin_status' ), |
|
| 143 | + filter_input( INPUT_GET, 'paged' ), |
|
| 144 | + filter_input( INPUT_GET, 's' ) |
|
| 145 | + ) ) ); |
|
| 146 | 146 | exit; |
| 147 | 147 | } |
| 148 | 148 | } |
@@ -124,7 +124,8 @@ |
||
| 124 | 124 | sprintf($messages['wrong_version'], $messages['php_version'].' '.$this->versions['php']), |
| 125 | 125 | sprintf($messages['update_php'], PHP_VERSION).'</p><p>'.$rollbackMessage |
| 126 | 126 | ); |
| 127 | - } elseif (!$this->isWpValid()) { |
|
| 127 | + } |
|
| 128 | + elseif (!$this->isWpValid()) { |
|
| 128 | 129 | printf($noticeTemplate, |
| 129 | 130 | sprintf($messages['notice'], $pluginName), |
| 130 | 131 | sprintf($messages['wrong_version'], $messages['wp_version'].' '.$this->versions['wordpress']), |