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

WPB_Admin_SubMenu::enqueue_scripts()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 4
rs 10
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   protected
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   protected
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   protected
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   protected
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   protected
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   protected
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   protected
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   protected
93
	 * @var      string    $plugin_name    The string used to uniquely identify this plugin.
94
	 */
95
	public $plugin_name;
96
97
	/**
98
	 * Create a new menu page.
99
	 *
100
	 * @since    1.0.0
101
	 * @access   public
102
	 */
103
	public function save() {
104
		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

104
		/** @scrutinizer ignore-call */ 
105
  add_action( 'admin_menu', array( $this, 'create_submenu' ) );
Loading history...
105
	}
106
107
	/**
108
	 * Create a new submenu page.
109
	 *
110
	 * @since    1.0.0
111
	 * @param    array $options Pass proprties as an array.
112
	 * @access   public
113
	 */
114
	public function make( $options = array() ) {
115
		foreach ( $options as $property => $value ) {
116
			if ( property_exists( $this, $property ) ) {
117
				$this->{$property} = $value;
118
			}
119
		}
120
		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

120
		/** @scrutinizer ignore-call */ 
121
  add_action( 'admin_menu', array( $this, 'create_submenu' ) );
Loading history...
121
	}
122
123
	/**
124
	 * Register new submenu page.
125
	 *
126
	 * @return void
127
	 */
128
	public function create_submenu() {
129
		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

129
		if ( /** @scrutinizer ignore-call */ current_user_can( $this->capability ) ) {
Loading history...
130
			$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

130
			$hook = /** @scrutinizer ignore-call */ add_submenu_page(
Loading history...
131
				$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...
132
				$this->page_title,
133
				$this->menu_title,
134
				$this->capability,
135
				$this->slug,
136
				$this->callback,
137
				$this->icon
138
			);
139
		}
140
141
		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

141
		/** @scrutinizer ignore-call */ 
142
  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...
142
	}
143
144
	/**
145
	 * Initialize hooks for the admin page.
146
	 *
147
	 * @return void
148
	 */
149
	public function init_hooks() {
150
		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

150
		/** @scrutinizer ignore-call */ 
151
  add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
Loading history...
151
	}
152
153
	/**
154
	 * Load scripts and styles for the submenu page.
155
	 *
156
	 * @return void
157
	 */
158
	public function enqueue_scripts() {
159
		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

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

161
		/** @scrutinizer ignore-call */ 
162
  wp_enqueue_script( $this->plugin_name . '-admin' );
Loading history...
162
	}
163
}
164