|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace lsx; |
|
4
|
|
|
|
|
5
|
|
|
if ( ! class_exists( '\lsx\LSX_Logger' ) ) { |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* LSX_Logger Main Class |
|
9
|
|
|
* |
|
10
|
|
|
* @package LSX_Logger |
|
11
|
|
|
* @author LightSpeed |
|
12
|
|
|
* @license GPL-3.0+ |
|
13
|
|
|
* @link |
|
14
|
|
|
* @copyright 2017 LightSpeedDevelopment |
|
15
|
|
|
*/ |
|
16
|
|
|
class LSX_Logger { |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Holds instance of the class |
|
20
|
|
|
* |
|
21
|
|
|
* @since 1.1.0 |
|
22
|
|
|
* @var \lsx\Geo_Content |
|
23
|
|
|
*/ |
|
24
|
|
|
private static $instance; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Holds the Logs of what happened |
|
28
|
|
|
*/ |
|
29
|
|
|
private $logs = array(); |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Constructor. |
|
33
|
|
|
*/ |
|
34
|
|
|
public function __construct() { |
|
35
|
|
|
add_action( 'wp_before_admin_bar_render', array( $this, 'wp_admin_bar_menu' ) ); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Return an instance of this class. |
|
40
|
|
|
* |
|
41
|
|
|
* @return LSX_Logger A single instance |
|
42
|
|
|
*/ |
|
43
|
|
|
public static function init() { |
|
44
|
|
|
|
|
45
|
|
|
// If the single instance hasn't been set, set it now. |
|
46
|
|
|
if ( ! isset( self::$instance ) ) { |
|
47
|
|
|
self::$instance = new self(); |
|
|
|
|
|
|
48
|
|
|
} |
|
49
|
|
|
return self::$instance; |
|
|
|
|
|
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Adds a field to the log |
|
54
|
|
|
* |
|
55
|
|
|
* @param $plugin string |
|
56
|
|
|
* @param $key string |
|
57
|
|
|
* @param $message string |
|
58
|
|
|
* @return void |
|
59
|
|
|
*/ |
|
60
|
|
|
public function log( $plugin = '', $key = '', $message = '' ) { |
|
61
|
|
|
$this->logs[ $plugin ][ $key ] = $message; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Gets a field from the API lookup object |
|
66
|
|
|
* |
|
67
|
|
|
* @param $plugin string | boolean |
|
68
|
|
|
* @return string |
|
69
|
|
|
*/ |
|
70
|
|
|
public function output_log( $plugin = false ) { |
|
71
|
|
|
$return = ''; |
|
72
|
|
|
if ( ! empty( $this->logs ) ) { |
|
73
|
|
|
foreach ( $this->logs as $plugin_key => $log ) { |
|
74
|
|
|
|
|
75
|
|
|
$return = '<div style="padding: 15px;">'; |
|
76
|
|
|
if ( false !== $plugin && $plugin_key !== $plugin ) { |
|
77
|
|
|
continue; |
|
78
|
|
|
} else if ( false === $plugin ) { |
|
79
|
|
|
$return .= '<h4>' . $plugin_key . '</h4>'; |
|
80
|
|
|
} |
|
81
|
|
|
$return .= '<ul>'; |
|
82
|
|
|
$return .= $this->loop_through_logs( $log ); |
|
83
|
|
|
$return .= '</ul>'; |
|
84
|
|
|
$return .= '</div>'; |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
return $return; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* Gets a field from the API lookup object |
|
92
|
|
|
* |
|
93
|
|
|
* @param $log_array array |
|
94
|
|
|
* @return string |
|
95
|
|
|
*/ |
|
96
|
|
|
public function loop_through_logs( $log_array = array() ) { |
|
97
|
|
|
$return = ''; |
|
98
|
|
|
foreach ( $log_array as $key => $message ) { |
|
99
|
|
|
$return .= '<li>' . $message . ' <small>(' . $key . ')</small></li>'; |
|
100
|
|
|
} |
|
101
|
|
|
return $return; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* Registers an admin bar menu so you can see the output of the log messages |
|
106
|
|
|
* |
|
107
|
|
|
* @return void |
|
108
|
|
|
*/ |
|
109
|
|
|
function wp_admin_bar_menu() { |
|
|
|
|
|
|
110
|
|
|
global $wp_admin_bar; |
|
111
|
|
|
$wp_admin_bar->add_menu( array( |
|
112
|
|
|
'parent' => false, |
|
113
|
|
|
'id' => 'lsx_logger', |
|
114
|
|
|
'title' => __( 'LSX Log' ), // link title |
|
115
|
|
|
'href' => '', |
|
116
|
|
|
)); |
|
117
|
|
|
$wp_admin_bar->add_menu( array( |
|
118
|
|
|
'parent' => 'lsx_logger', |
|
119
|
|
|
'id' => 'lsx_logger_output', |
|
120
|
|
|
'title' => '', // link title |
|
121
|
|
|
'href' => '', |
|
122
|
|
|
'meta' => array( |
|
123
|
|
|
'html' => $this->output_log(), |
|
124
|
|
|
'class' => '', |
|
125
|
|
|
), |
|
126
|
|
|
)); |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
} |
|
130
|
|
|
} |
|
131
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..