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

SubPage::footer_credits()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Amarkal\Settings;
4
5
class SubPage
6
{   
0 ignored issues
show
Coding Style introduced by
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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
}