Documentation

WP_Logging
in package

Class for logging events and errors

Tags
copyright

Copyright (c) 2012, Pippin Williamson

license

http://opensource.org/licenses/gpl-2.0.php GNU Public License

Table of Contents

__construct()  : void
Class constructor.
add()  : int
Create new log entry
get_connected_logs()  : array<string|int, mixed>
Retrieve all connected logs
get_log_count()  : int
Retrieves number of log entries connected to particular object ID
get_logs()  : array<string|int, mixed>
Easily retrieves log items for a particular object ID
insert_log()  : int
Stores a log entry
prune_logs()  : mixed
Allows you to tie in a cron job and prune old logs.
register_post_type()  : void
Registers the wp_log Post Type
register_taxonomy()  : void
Registers the Type Taxonomy
update_log()  : bool
Update and existing log item
get_logs_to_prune()  : array<string|int, mixed>
Returns an array of posts that are prune candidates.
log_types()  : array<string|int, mixed>
Log types
prune_old_logs()  : mixed
Deletes the old logs that we don't want
valid_type()  : array<string|int, mixed>
Check if a log type is valid

Methods

__construct()

Class constructor.

public __construct() : void
Tags
since
1.0
access

public

Return values
void

add()

Create new log entry

public static add([mixed $title = '' ][, mixed $message = '' ], mixed $parent[, mixed $type = null ]) : int

This is just a simple and fast way to log something. Use self::insert_log() if you need to store custom meta data

Parameters
$title : mixed = ''
$message : mixed = ''
$parent : mixed
$type : mixed = null
Tags
access

private

since
1.0
uses
self::insert_log()
Return values
int

The ID of the new log entry

get_connected_logs()

Retrieve all connected logs

public static get_connected_logs([mixed $args = array() ]) : array<string|int, mixed>

Used for retrieving logs related to particular items, such as a specific purchase.

Parameters
$args : mixed = array()
Tags
access

private

since
1.0
uses
wp_parse_args()
uses
get_posts()
uses
get_query_var()
uses
self::valid_type()
Return values
array<string|int, mixed>

/ false

get_log_count()

Retrieves number of log entries connected to particular object ID

public static get_log_count(mixed $object_id[, mixed $type = null ][, mixed $meta_query = null ]) : int
Parameters
$object_id : mixed
$type : mixed = null
$meta_query : mixed = null
Tags
access

private

since
1.0
uses
WP_Query()
uses
self::valid_type()
Return values
int

get_logs()

Easily retrieves log items for a particular object ID

public static get_logs(mixed $object_id[, mixed $type = null ][, mixed $paged = null ]) : array<string|int, mixed>
Parameters
$object_id : mixed
$type : mixed = null
$paged : mixed = null
Tags
access

private

since
1.0
uses
self::get_connected_logs()
Return values
array<string|int, mixed>

insert_log()

Stores a log entry

public static insert_log([mixed $log_data = array() ][, mixed $log_meta = array() ]) : int
Parameters
$log_data : mixed = array()
$log_meta : mixed = array()
Tags
access

private

since
1.0
uses
wp_parse_args()
uses
wp_insert_post()
uses
update_post_meta()
uses
wp_set_object_terms()
uses
sanitize_key()
Return values
int

The ID of the newly created log item

prune_logs()

Allows you to tie in a cron job and prune old logs.

public prune_logs() : mixed
Tags
since
1.1
access

public

uses

$this->get_logs_to_prune() Returns array of posts via get_posts of logs to prune

uses

$this->prune_old_logs() Deletes the logs that we don't want anymore

Return values
mixed

register_post_type()

Registers the wp_log Post Type

public register_post_type() : void
Tags
access

public

since
1.0
uses
register_post_type()
Return values
void

register_taxonomy()

Registers the Type Taxonomy

public register_taxonomy() : void

The Type taxonomy is used to determine the type of log entry

Tags
access

public

since
1.0
uses
register_taxonomy()
uses
term_exists()
uses
wp_insert_term()
Return values
void

update_log()

Update and existing log item

public static update_log([mixed $log_data = array() ][, mixed $log_meta = array() ]) : bool
Parameters
$log_data : mixed = array()
$log_meta : mixed = array()
Tags
access

private

since
1.0
uses
wp_parse_args()
uses
wp_update_post()
uses
update_post_meta()
Return values
bool

True if successful, false otherwise

get_logs_to_prune()

Returns an array of posts that are prune candidates.

private get_logs_to_prune() : array<string|int, mixed>
Tags
since
1.1
access

private

uses
apply_filters()

Allows users to change given args

uses
get_posts()

Returns an array of posts from given args

filter

wp_logging_prune_when Users can change how long ago we are looking for logs to prune

filter

wp_logging_prune_query_args Gives users access to change any query args for pruning

Return values
array<string|int, mixed>

$old_logs The array of posts that were returned from get_posts

log_types()

Log types

private static log_types() : array<string|int, mixed>

Sets up the default log types and allows for new ones to be created

Tags
access

private

since
1.0
Return values
array<string|int, mixed>

prune_old_logs()

Deletes the old logs that we don't want

private prune_old_logs(mixed $logs) : mixed
Parameters
$logs : mixed
Tags
since
1.1
access

private

uses
wp_delete_post()

Deletes the post from WordPress

filter

wp_logging_force_delete_log Allows user to override the force delete setting which bypasses the trash

Return values
mixed

valid_type()

Check if a log type is valid

private static valid_type(mixed $type) : array<string|int, mixed>

Checks to see if the specified type is in the registered list of types

Parameters
$type : mixed
Tags
access

private

since
1.0
Return values
array<string|int, mixed>

Search results