Completed
Push — master ( c1bd80...7840cd )
by CodexShaper
11:04 queued 12s
created

WPB_Admin_Menu::make()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 4
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 7
rs 10
1
<?php
2
/**
3
 * The admin-specific functionality of the plugin.
4
 *
5
 * @link       https://github.com/maab16
6
 * @since      1.0.0
7
 *
8
 * @package    WPB
9
 * @subpackage WPB/admin
10
 */
11
12
/**
13
 * The admin-specific functionality of the plugin.
14
 *
15
 * Defines the plugin name, version, and two examples hooks for how to
16
 * enqueue the admin-specific stylesheet and JavaScript.
17
 *
18
 * @package    WPB
19
 * @subpackage WPB/admin
20
 * @author     Md Abu Ahsan basir <[email protected]>
21
 */
22
class WPB_Admin_Menu {
23
24
	/**
25
	 * The menu page title.
26
	 *
27
	 * @since    1.0.0
28
	 * @access   protected
29
	 * @var      string    $page_title    The string used to set menu page title.
30
	 */
31
	public $page_title;
32
33
	/**
34
	 * The menu title.
35
	 *
36
	 * @since    1.0.0
37
	 * @access   protected
38
	 * @var      string    $menu_title    The string used to set menu title.
39
	 */
40
	public $menu_title;
41
42
	/**
43
	 * The menu capability.
44
	 *
45
	 * @since    1.0.0
46
	 * @access   protected
47
	 * @var      string    $capability    The string used to set menu capability.
48
	 */
49
	public $capability;
50
51
	/**
52
	 * The menu slug.
53
	 *
54
	 * @since    1.0.0
55
	 * @access   protected
56
	 * @var      string    $slug    The string used to set menu slug.
57
	 */
58
	public $slug;
59
60
	/**
61
	 * The callback to render content.
62
	 *
63
	 * @since    1.0.0
64
	 * @access   protected
65
	 * @var      callback    $callback    The callback used to render content.
66
	 */
67
	public $callback;
68
69
	/**
70
	 * The menu icon.
71
	 *
72
	 * @since    1.0.0
73
	 * @access   protected
74
	 * @var      string    $icon    The string used to set menu icon.
75
	 */
76
	public $icon;
77
78
	/**
79
	 * The menu position.
80
	 *
81
	 * @since    1.0.0
82
	 * @access   protected
83
	 * @var      int    $position    The string used to set menu position.
84
	 */
85
	public $position;
86
87
	/**
88
	 * The menu plugin name.
89
	 *
90
	 * @since    1.0.0
91
	 * @access   protected
92
	 * @var      string    $plugin_name    The string used to uniquely identify this plugin.
93
	 */
94
	public $plugin_name;
95
96
	/**
97
	 * Create a new menu page.
98
	 *
99
	 * @since    1.0.0
100
	 * @access   public
101
	 */
102
	public function save() {
103
		add_action( 'admin_menu', array( $this, 'create_menu' ) );
0 ignored issues
show
Bug introduced by
The function add_action was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

103
		/** @scrutinizer ignore-call */ 
104
  add_action( 'admin_menu', array( $this, 'create_menu' ) );
Loading history...
104
	}
105
106
	/**
107
	 * Create a new menu page.
108
	 *
109
	 * @since    1.0.0
110
	 * @param    array $options Pass proprties as an array.
111
	 * @access   public
112
	 */
113
	public function make( $options = array() ) {
114
		foreach ( $options as $property => $value ) {
115
			if ( property_exists( get_called_class(), $property ) ) {
116
				$this->{$property} = $value;
117
			}
118
		}
119
		add_action( 'admin_menu', array( $this, 'create_menu' ) );
0 ignored issues
show
Bug introduced by
The function add_action was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

119
		/** @scrutinizer ignore-call */ 
120
  add_action( 'admin_menu', array( $this, 'create_menu' ) );
Loading history...
120
	}
121
122
	/**
123
	 * Register new menu page.
124
	 *
125
	 * @return void
126
	 */
127
	public function create_menu() {
128
		$hook = add_menu_page(
0 ignored issues
show
Bug introduced by
The function add_menu_page was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

128
		$hook = /** @scrutinizer ignore-call */ add_menu_page(
Loading history...
129
			$this->page_title,
130
			$this->menu_title,
131
			$this->capability,
132
			$this->slug,
133
			$this->callback,
134
			$this->icon
135
		);
136
137
		add_action( 'load-' . $hook, array( $this, 'init_hooks' ) );
0 ignored issues
show
Bug introduced by
The function add_action was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

137
		/** @scrutinizer ignore-call */ 
138
  add_action( 'load-' . $hook, array( $this, 'init_hooks' ) );
Loading history...
138
	}
139
140
	/**
141
	 * Initialize hooks for the admin page.
142
	 *
143
	 * @return void
144
	 */
145
	public function init_hooks() {
146
		add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
0 ignored issues
show
Bug introduced by
The function add_action was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

146
		/** @scrutinizer ignore-call */ 
147
  add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
Loading history...
147
	}
148
149
	/**
150
	 * Load scripts and styles for the current menu page.
151
	 *
152
	 * @return void
153
	 */
154
	public function enqueue_scripts() {
155
		wp_enqueue_style( $this->plugin_name . '-vendors' );
0 ignored issues
show
Bug introduced by
The function wp_enqueue_style was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

155
		/** @scrutinizer ignore-call */ 
156
  wp_enqueue_style( $this->plugin_name . '-vendors' );
Loading history...
156
		wp_enqueue_style( $this->plugin_name . '-admin' );
157
		wp_enqueue_script( $this->plugin_name . '-admin' );
0 ignored issues
show
Bug introduced by
The function wp_enqueue_script was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

157
		/** @scrutinizer ignore-call */ 
158
  wp_enqueue_script( $this->plugin_name . '-admin' );
Loading history...
158
	}
159
}
160