1 | <?php |
||
11 | class WP_Logging { |
||
12 | |||
13 | |||
14 | /** |
||
15 | * Class constructor. |
||
16 | * |
||
17 | * @since 1.0 |
||
18 | * |
||
19 | * @access public |
||
20 | * @return void |
||
|
|||
21 | */ |
||
22 | function __construct() { |
||
34 | |||
35 | /** |
||
36 | * Allows you to tie in a cron job and prune old logs. |
||
37 | * |
||
38 | * @since 1.1 |
||
39 | * @access public |
||
40 | * |
||
41 | * @uses $this->get_logs_to_prune() Returns array of posts via get_posts of logs to prune |
||
42 | * @uses $this->prune_old_logs() Deletes the logs that we don't want anymore |
||
43 | */ |
||
44 | public function prune_logs(){ |
||
59 | |||
60 | /** |
||
61 | * Deletes the old logs that we don't want |
||
62 | * |
||
63 | * @since 1.1 |
||
64 | * @access private |
||
65 | * |
||
66 | * @param array/obj $logs required The array of logs we want to prune |
||
67 | * |
||
68 | * @uses wp_delete_post() Deletes the post from WordPress |
||
69 | * |
||
70 | * @filter wp_logging_force_delete_log Allows user to override the force delete setting which bypasses the trash |
||
71 | */ |
||
72 | private function prune_old_logs( $logs ){ |
||
81 | |||
82 | /** |
||
83 | * Returns an array of posts that are prune candidates. |
||
84 | * |
||
85 | * @since 1.1 |
||
86 | * @access private |
||
87 | * |
||
88 | * @return array $old_logs The array of posts that were returned from get_posts |
||
89 | * |
||
90 | * @uses apply_filters() Allows users to change given args |
||
91 | * @uses get_posts() Returns an array of posts from given args |
||
92 | * |
||
93 | * @filter wp_logging_prune_when Users can change how long ago we are looking for logs to prune |
||
94 | * @filter wp_logging_prune_query_args Gives users access to change any query args for pruning |
||
95 | */ |
||
96 | private function get_logs_to_prune(){ |
||
116 | |||
117 | /** |
||
118 | * Log types |
||
119 | * |
||
120 | * Sets up the default log types and allows for new ones to be created |
||
121 | * |
||
122 | * @access private |
||
123 | * @since 1.0 |
||
124 | * |
||
125 | * @return array |
||
126 | */ |
||
127 | |||
128 | private static function log_types() { |
||
135 | |||
136 | |||
137 | /** |
||
138 | * Registers the wp_log Post Type |
||
139 | * |
||
140 | * @access public |
||
141 | * @since 1.0 |
||
142 | * |
||
143 | * @uses register_post_type() |
||
144 | * |
||
145 | * @return void |
||
146 | */ |
||
147 | |||
148 | public function register_post_type() { |
||
164 | |||
165 | |||
166 | /** |
||
167 | * Registers the Type Taxonomy |
||
168 | * |
||
169 | * The Type taxonomy is used to determine the type of log entry |
||
170 | * |
||
171 | * @access public |
||
172 | * @since 1.0 |
||
173 | * |
||
174 | * @uses register_taxonomy() |
||
175 | * @uses term_exists() |
||
176 | * @uses wp_insert_term() |
||
177 | * |
||
178 | * @return void |
||
179 | */ |
||
180 | |||
181 | public function register_taxonomy() { |
||
193 | |||
194 | |||
195 | /** |
||
196 | * Check if a log type is valid |
||
197 | * |
||
198 | * Checks to see if the specified type is in the registered list of types |
||
199 | * |
||
200 | * @access private |
||
201 | * @since 1.0 |
||
202 | * |
||
203 | * |
||
204 | * @return array |
||
205 | */ |
||
206 | |||
207 | private static function valid_type( $type ) { |
||
210 | |||
211 | |||
212 | /** |
||
213 | * Create new log entry |
||
214 | * |
||
215 | * This is just a simple and fast way to log something. Use self::insert_log() |
||
216 | * if you need to store custom meta data |
||
217 | * |
||
218 | * @access private |
||
219 | * @since 1.0 |
||
220 | * |
||
221 | * @uses self::insert_log() |
||
222 | * |
||
223 | * @return int The ID of the new log entry |
||
224 | */ |
||
225 | |||
226 | public static function add( $title = '', $message = '', $parent = 0, $type = null ) { |
||
238 | |||
239 | |||
240 | /** |
||
241 | * Stores a log entry |
||
242 | * |
||
243 | * @access private |
||
244 | * @since 1.0 |
||
245 | * |
||
246 | * @uses wp_parse_args() |
||
247 | * @uses wp_insert_post() |
||
248 | * @uses update_post_meta() |
||
249 | * @uses wp_set_object_terms() |
||
250 | * @uses sanitize_key() |
||
251 | * |
||
252 | * @return int The ID of the newly created log item |
||
253 | */ |
||
254 | |||
255 | public static function insert_log( $log_data = array(), $log_meta = array() ) { |
||
290 | |||
291 | |||
292 | /** |
||
293 | * Update and existing log item |
||
294 | * |
||
295 | * @access private |
||
296 | * @since 1.0 |
||
297 | * |
||
298 | * @uses wp_parse_args() |
||
299 | * @uses wp_update_post() |
||
300 | * @uses update_post_meta() |
||
301 | * |
||
302 | * @return bool True if successful, false otherwise |
||
303 | */ |
||
304 | public static function update_log( $log_data = array(), $log_meta = array() ) { |
||
329 | |||
330 | |||
331 | /** |
||
332 | * Easily retrieves log items for a particular object ID |
||
333 | * |
||
334 | * @access private |
||
335 | * @since 1.0 |
||
336 | * |
||
337 | * @uses self::get_connected_logs() |
||
338 | * |
||
339 | * @return array |
||
340 | */ |
||
341 | |||
342 | public static function get_logs( $object_id = 0, $type = null, $paged = null ) { |
||
346 | |||
347 | |||
348 | /** |
||
349 | * Retrieve all connected logs |
||
350 | * |
||
351 | * Used for retrieving logs related to particular items, such as a specific purchase. |
||
352 | * |
||
353 | * @access private |
||
354 | * @since 1.0 |
||
355 | * |
||
356 | * @uses wp_parse_args() |
||
357 | * @uses get_posts() |
||
358 | * @uses get_query_var() |
||
359 | * @uses self::valid_type() |
||
360 | * |
||
361 | * @return array / false |
||
362 | */ |
||
363 | |||
364 | public static function get_connected_logs( $args = array() ) { |
||
398 | |||
399 | |||
400 | /** |
||
401 | * Retrieves number of log entries connected to particular object ID |
||
402 | * |
||
403 | * @access private |
||
404 | * @since 1.0 |
||
405 | * |
||
406 | * @uses WP_Query() |
||
407 | * @uses self::valid_type() |
||
408 | * |
||
409 | * @return int |
||
410 | */ |
||
411 | |||
412 | public static function get_log_count( $object_id = 0, $type = null, $meta_query = null ) { |
||
442 | |||
443 | } |
||
444 | $GLOBALS['wp_logs'] = new WP_Logging(); |
||
445 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.