Completed
Push — master ( 1d5718...95de79 )
by Askupa
01:58
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
        }
39
    }
40
    
41
    public function render()
42
    {
43
        $this->form->update();
44
        include __DIR__.'/SubPage.phtml';
45
    }
46
    
47 View Code Duplication
    private function default_args()
48
    {
49
        return array(
50
            'parent_slug' => '',
51
            'slug'        => '',
52
            'title'       => '',
53
            'menu_title'  => '',
54
            'capability'  => 'manage_options'
55
        );
56
    }
57
}