|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Amarkal\Settings; |
|
4
|
|
|
|
|
5
|
|
|
class SubPage |
|
6
|
|
|
{ |
|
|
|
|
|
|
7
|
|
|
private $config; |
|
8
|
|
|
|
|
9
|
|
|
private $form; |
|
10
|
|
|
|
|
11
|
|
|
public function __construct( array $args = array() ) |
|
12
|
|
|
{ |
|
13
|
|
|
$this->config = array_merge($this->default_args(), $args); |
|
14
|
|
|
$this->form = new \Amarkal\UI\Form($this->config['fields']); |
|
15
|
|
|
|
|
16
|
|
|
\add_action('admin_menu', array($this,'add_submenu_page')); |
|
17
|
|
|
\add_action('admin_enqueue_scripts', array($this,'enqueue_scripts')); |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
View Code Duplication |
public function add_submenu_page() |
|
|
|
|
|
|
21
|
|
|
{ |
|
22
|
|
|
\add_submenu_page( |
|
23
|
|
|
$this->config['parent_slug'], |
|
24
|
|
|
$this->config['title'], |
|
25
|
|
|
$this->config['menu_title'], |
|
26
|
|
|
$this->config['capability'], |
|
27
|
|
|
$this->config['slug'], |
|
28
|
|
|
array($this, 'render') |
|
29
|
|
|
); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function enqueue_scripts() |
|
33
|
|
|
{ |
|
34
|
|
|
// Only enqueue styles & scripts if this is a settings page |
|
35
|
|
|
if($this->config['slug'] === filter_input(INPUT_GET, 'page')) |
|
36
|
|
|
{ |
|
37
|
|
|
\wp_enqueue_style('amarkal-settings'); |
|
38
|
|
|
\wp_enqueue_script('amarkal-settings'); |
|
39
|
|
|
} |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function render() |
|
43
|
|
|
{ |
|
44
|
|
|
$this->form->update(); |
|
45
|
|
|
include __DIR__.'/SubPage.phtml'; |
|
46
|
|
|
\add_filter('admin_footer_text', array($this, 'footer_credits')); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Renders Amarkal's credits on the page's footer. |
|
51
|
|
|
*/ |
|
52
|
|
|
public function footer_credits() |
|
53
|
|
|
{ |
|
54
|
|
|
echo '<span id="footer-thankyou">Created with <a href="https://github.com/askupasoftware/amarkal-settings">amarkal-settings</a>, a module within the <a href="https://github.com/askupasoftware/amarkal">Amarkal Framework</a></span>'; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
private function default_args() |
|
58
|
|
|
{ |
|
59
|
|
|
return array( |
|
60
|
|
|
'parent_slug' => '', |
|
61
|
|
|
'slug' => '', |
|
62
|
|
|
'title' => '', |
|
63
|
|
|
'subtitle' => '', |
|
64
|
|
|
'menu_title' => '', |
|
65
|
|
|
'capability' => 'manage_options' |
|
66
|
|
|
); |
|
67
|
|
|
} |
|
68
|
|
|
} |