Completed
Push — master ( 31de30...727b9d )
by Askupa
03:14
created

SubPage.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Amarkal\Settings;
4
5
class SubPage
6
{   
0 ignored issues
show
The opening class brace should be on a newline by itself.
Loading history...
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
    }
47
    
48
    private function default_args()
49
    {
50
        return array(
51
            'parent_slug' => '',
52
            'slug'        => '',
53
            'title'       => '',
54
            'subtitle'    => '',
55
            'menu_title'  => '',
56
            'capability'  => 'manage_options'
57
        );
58
    }
59
}