Menu::plugin_page()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace CodexShaper\WP\Admin\Menus;
4
5
/**
6
 * Menu Generator.
7
 */
8
class Menu
9
{
10
    public $page_title;
11
12
    public $menu_title;
13
14
    public $capability;
15
16
    public $slug;
17
18
    public $callback;
19
20
    public $icon;
21
22
    public $position;
23
24
    public $plugin_name;
25
26
    public function save()
27
    {
28
        add_action('admin_menu', [$this, 'create_menu']);
29
    }
30
31 View Code Duplication
    public static function make($options = [])
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...
32
    {
33
        foreach ($options as $property => $value) {
34
            if (property_exists($this, $property)) {
35
                $this->{$property} = $value;
0 ignored issues
show
Bug introduced by
The variable $this does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
36
            }
37
        }
38
        add_action('admin_menu', [$this, 'create_menu']);
39
    }
40
41
    /**
42
     * Register our menu page.
43
     *
44
     * @return void
45
     */
46
    public function create_menu()
47
    {
48
        global $submenu;
49
50
        $hook = add_menu_page(
51
            $this->page_title,
52
            $this->menu_title,
53
            $this->capability,
54
            $this->slug,
55
            $this->callback,
56
            $this->icon
57
        );
58
59
        // if ( current_user_can( $this->capability ) ) {
60
        //     $submenu[ $this->slug ][] = array( __( 'Clients', 'textdomain' ), $this->capability, 'admin.php?page=' . $this->slug . '#/clients' );
61
        //     $submenu[ $this->slug ][] = array( __( 'Settings', 'textdomain' ), $this->capability, 'admin.php?page=' . $this->slug . '#/settings' );
62
        // }
63
64
        add_action('load-'.$hook, [$this, 'init_hooks']);
65
    }
66
67
    /**
68
     * Initialize our hooks for the admin page.
69
     *
70
     * @return void
71
     */
72
    public function init_hooks()
73
    {
74
        add_action('admin_enqueue_scripts', [$this, 'enqueue_scripts']);
75
    }
76
77
    /**
78
     * Load scripts and styles for the app.
79
     *
80
     * @return void
81
     */
82
    public function enqueue_scripts()
83
    {
84
        wp_enqueue_style($this->plugin_name . '-vendors');
85
        wp_enqueue_style($this->plugin_name . '-admin');
86
        wp_enqueue_script($this->plugin_name . '-admin');
87
    }
88
89
    /**
90
     * Render our admin page.
91
     *
92
     * @return void
93
     */
94
    public function plugin_page()
95
    {
96
        echo '<div class="wrap"><div id="'. $this->plugin_name .'-admin" csrf-token="'.csrf_token().'"></div></div>';
97
    }
98
}
99