|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace LIN3S\WPSymfonyForm\Admin; |
|
4
|
|
|
|
|
5
|
|
|
use LIN3S\WPSymfonyForm\Admin\Storage\YamlStorage; |
|
6
|
|
|
use LIN3S\WPSymfonyForm\Admin\Views\LogsTable; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Main admin class. |
|
10
|
|
|
* |
|
11
|
|
|
* @author Beñat Espiña <[email protected]> |
|
12
|
|
|
*/ |
|
13
|
|
|
final class Admin |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* The instance of the current class. |
|
17
|
|
|
* |
|
18
|
|
|
* @var self |
|
19
|
|
|
*/ |
|
20
|
|
|
private static $instance; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* The logs table. |
|
24
|
|
|
* |
|
25
|
|
|
* @var LogsTable |
|
26
|
|
|
*/ |
|
27
|
|
|
public $logTable; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Singleton constructor. |
|
31
|
|
|
* |
|
32
|
|
|
* @return self |
|
33
|
|
|
*/ |
|
34
|
|
|
public static function instance() |
|
35
|
|
|
{ |
|
36
|
|
|
if (!isset(self::$instance)) { |
|
37
|
|
|
self::$instance = new self(); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
return self::$instance; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Constructor. |
|
45
|
|
|
*/ |
|
46
|
|
|
private function __construct() |
|
47
|
|
|
{ |
|
48
|
|
|
add_filter('set-screen-option', function ($status, $option, $value) { |
|
|
|
|
|
|
49
|
|
|
return $value; |
|
50
|
|
|
}, 10, 3); |
|
|
|
|
|
|
51
|
|
|
|
|
52
|
|
|
add_action('admin_menu', [$this, 'menu']); |
|
|
|
|
|
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Loads the menu inside WordPress admin sidebar. |
|
57
|
|
|
*/ |
|
58
|
|
|
public function menu() |
|
59
|
|
|
{ |
|
60
|
|
|
$menu = add_menu_page( |
|
61
|
|
|
'Symfony Forms', |
|
62
|
|
|
'Symfony Forms', |
|
63
|
|
|
'manage_options', |
|
64
|
|
|
'symfony-form', |
|
65
|
|
|
[$this, 'emailLogArchivePage'] |
|
66
|
|
|
); |
|
67
|
|
|
|
|
68
|
|
|
add_action("load-$menu", [$this, 'screenOptions']); |
|
|
|
|
|
|
69
|
|
|
|
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Adds screen options. |
|
74
|
|
|
*/ |
|
75
|
|
|
public function screenOptions() |
|
76
|
|
|
{ |
|
77
|
|
|
add_screen_option('per_page', [ |
|
78
|
|
|
'label' => 'Logs', |
|
79
|
|
|
'default' => 10, |
|
80
|
|
|
'option' => 'logs_per_page', |
|
81
|
|
|
]); |
|
82
|
|
|
|
|
83
|
|
|
$this->logTable = new LogsTable( |
|
84
|
|
|
new YamlStorage() |
|
85
|
|
|
); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Renders email log archive page. |
|
90
|
|
|
*/ |
|
91
|
|
|
public function emailLogArchivePage() |
|
92
|
|
|
{ |
|
93
|
|
|
?> |
|
94
|
|
|
<div class="wrap"> |
|
95
|
|
|
<h2><?php _e('Sent emails logs', \WPSymfonyForm::TRANSLATION_DOMAIN); ?></h2> |
|
96
|
|
|
<div id="poststuff"> |
|
97
|
|
|
<div id="post-body" class="metabox-holder"> |
|
98
|
|
|
<div id="post-body-content"> |
|
99
|
|
|
<div class="meta-box-sortables ui-sortable"> |
|
100
|
|
|
<form method="post"> |
|
101
|
|
|
<?php |
|
102
|
|
|
$this->logTable->prepare_items(); |
|
103
|
|
|
$this->logTable->display(); ?> |
|
104
|
|
|
</form> |
|
105
|
|
|
</div> |
|
106
|
|
|
</div> |
|
107
|
|
|
</div> |
|
108
|
|
|
<br class="clear"> |
|
109
|
|
|
</div> |
|
110
|
|
|
</div> |
|
111
|
|
|
<?php |
|
112
|
|
|
} |
|
113
|
|
|
} |
|
114
|
|
|
|