Completed
Push — master ( 7840cd...ebd957 )
by CodexShaper
11:45
created

WPB_Admin_SubMenu   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 150
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 29
dl 0
loc 150
rs 10
c 1
b 0
f 0
wmc 9

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A enqueue_scripts() 0 4 1
A save() 0 2 1
A make() 0 7 3
A init_hooks() 0 2 1
A create_submenu() 0 14 2
1
<?php
2
3
/**
4
 * The admin-specific functionality of the plugin.
5
 *
6
 * @link       https://github.com/maab16
7
 * @since      1.0.0
8
 *
9
 * @package    WPB
10
 * @subpackage WPB/admin
11
 */
12
13
/**
14
 * The admin-specific functionality of the plugin.
15
 *
16
 * Defines the plugin name, version, and two examples hooks for how to
17
 * enqueue the admin-specific stylesheet and JavaScript.
18
 *
19
 * @package    WPB
20
 * @subpackage WPB/admin
21
 * @author     Md Abu Ahsan basir <[email protected]>
22
 */
23
class WPB_Admin_SubMenu {
24
25
	/**
26
	 * The menu page title.
27
	 *
28
	 * @since    1.0.0
29
	 * @access   public
30
	 * @var      string    $page_title    The string used to set menu page title.
31
	 */
32
	public $page_title;
33
34
	/**
35
	 * The menu title.
36
	 *
37
	 * @since    1.0.0
38
	 * @access   public
39
	 * @var      string    $menu_title    The string used to set menu title.
40
	 */
41
	public $menu_title;
42
43
	/**
44
	 * The menu capability.
45
	 *
46
	 * @since    1.0.0
47
	 * @access   public
48
	 * @var      string    $capability    The string used to set menu capability.
49
	 */
50
	public $capability;
51
52
	/**
53
	 * The menu slug.
54
	 *
55
	 * @since    1.0.0
56
	 * @access   public
57
	 * @var      string    $slug    The string used to set menu slug.
58
	 */
59
	public $slug;
60
61
	/**
62
	 * The callback to render content.
63
	 *
64
	 * @since    1.0.0
65
	 * @access   public
66
	 * @var      callback    $callback    The callback used to render content.
67
	 */
68
	public $callback;
69
70
	/**
71
	 * The menu icon.
72
	 *
73
	 * @since    1.0.0
74
	 * @access   public
75
	 * @var      string    $icon    The string used to set menu icon.
76
	 */
77
	public $icon;
78
79
	/**
80
	 * The menu position.
81
	 *
82
	 * @since    1.0.0
83
	 * @access   public
84
	 * @var      int    $position    The string used to set menu position.
85
	 */
86
	public $position;
87
88
	/**
89
	 * The menu plugin name.
90
	 *
91
	 * @since    1.0.0
92
	 * @access   private
93
	 * @var      string    $plugin_name    The string used to uniquely identify this plugin.
94
	 */
95
	private $plugin_name;
96
97
	/**
98
	 * Boot Menu.
99
	 *
100
	 * @param  string $plugin_name The string used to uniquely identify this plugin.
101
	 * @since    1.0.0
102
	 * @access   public
103
	 */
104
	public function __construct( $plugin_name ) {
105
		$this->plugin_name = $plugin_name;
106
	}
107
108
	/**
109
	 * Create a new menu page.
110
	 *
111
	 * @since    1.0.0
112
	 * @access   public
113
	 */
114
	public function save() {
115
		add_action( 'admin_menu', array( $this, 'create_submenu' ) );
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

115
		/** @scrutinizer ignore-call */ 
116
  add_action( 'admin_menu', array( $this, 'create_submenu' ) );
Loading history...
116
	}
117
118
	/**
119
	 * Create a new submenu page.
120
	 *
121
	 * @since    1.0.0
122
	 * @param    array $options Pass proprties as an array.
123
	 * @access   public
124
	 */
125
	public function make( $options = array() ) {
126
		foreach ( $options as $property => $value ) {
127
			if ( property_exists( $this, $property ) ) {
128
				$this->{$property} = $value;
129
			}
130
		}
131
		add_action( 'admin_menu', array( $this, 'create_submenu' ) );
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

131
		/** @scrutinizer ignore-call */ 
132
  add_action( 'admin_menu', array( $this, 'create_submenu' ) );
Loading history...
132
	}
133
134
	/**
135
	 * Register new submenu page.
136
	 *
137
	 * @return void
138
	 */
139
	public function create_submenu() {
140
		if ( current_user_can( $this->capability ) ) {
0 ignored issues
show
Bug introduced by
The function current_user_can 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

140
		if ( /** @scrutinizer ignore-call */ current_user_can( $this->capability ) ) {
Loading history...
141
			$hook = add_submenu_page(
0 ignored issues
show
Bug introduced by
The function add_submenu_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

141
			$hook = /** @scrutinizer ignore-call */ add_submenu_page(
Loading history...
142
				$this->parent_slug,
0 ignored issues
show
Bug Best Practice introduced by
The property parent_slug does not exist on WPB_Admin_SubMenu. Did you maybe forget to declare it?
Loading history...
143
				$this->page_title,
144
				$this->menu_title,
145
				$this->capability,
146
				$this->slug,
147
				$this->callback,
148
				$this->icon
149
			);
150
		}
151
152
		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

152
		/** @scrutinizer ignore-call */ 
153
  add_action( 'load-' . $hook, array( $this, 'init_hooks' ) );
Loading history...
Comprehensibility Best Practice introduced by
The variable $hook does not seem to be defined for all execution paths leading up to this point.
Loading history...
153
	}
154
155
	/**
156
	 * Initialize hooks for the admin page.
157
	 *
158
	 * @return void
159
	 */
160
	public function init_hooks() {
161
		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

161
		/** @scrutinizer ignore-call */ 
162
  add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
Loading history...
162
	}
163
164
	/**
165
	 * Load scripts and styles for the submenu page.
166
	 *
167
	 * @return void
168
	 */
169
	public function enqueue_scripts() {
170
		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

170
		/** @scrutinizer ignore-call */ 
171
  wp_enqueue_style( $this->plugin_name . '-vendors' );
Loading history...
171
		wp_enqueue_style( $this->plugin_name . '-admin' );
172
		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

172
		/** @scrutinizer ignore-call */ 
173
  wp_enqueue_script( $this->plugin_name . '-admin' );
Loading history...
173
	}
174
}
175