-
Notifications
You must be signed in to change notification settings - Fork 7
/
Example.php
56 lines (51 loc) · 1.4 KB
/
Example.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
/**
* This class is an example for custom logger class.
*/
namespace Hello;
use \LogBook\Logger;
class Example extends Logger
{
/**
* @var string $label The label that is used on list table.
*/
protected $label = 'Post';
/**
* @var array $hooks An array of WordPress's action/filter hooks.
*/
protected $hooks = array( 'publish_post' );
/**
* @var string $log_level The log level. See `src/Level/`
*/
protected $log_level = \LogBook::DEFAULT_LEVEL;
/**
* @var int $priority Number of priority that will be passed to `add_filter()`.
*/
protected $priority = 10;
/**
* @var int $accepted_args Number of args that will be passed to `add_filter()`.
*/
protected $accepted_args = 1;
/**
* Set the properties to the `Talog\Log` object for the log.
*
* @param mixed $additional_args An array of the args that was passed from WordPress hook.
*/
public function log( $additional_args )
{
/**
* `$additional_args` contains args as array that passed from WordPress's hook.
* Following example is `$post_id` that came from `publish_post` hook.
*/
list( $post_id ) = $additional_args;
/**
* title will be listed in table on the admin.
*/
$this->set_title( "Nice! #{$post_id} was published!" );
/**
* You can add additional contents if you need.
*/
$this->add_content( 'Title 1', 'HTML content 1' );
$this->add_content( 'Title 2', 'HTML content 2' );
}
}