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

WPB_Admin_Menu   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 147
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 27
dl 0
loc 147
rs 10
c 1
b 0
f 0
wmc 8

6 Methods

Rating   Name   Duplication   Size   Complexity  
A save() 0 2 1
A make() 0 7 3
A enqueue_scripts() 0 4 1
A create_menu() 0 11 1
A __construct() 0 2 1
A init_hooks() 0 2 1
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   public
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   public
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   public
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   public
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   public
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   public
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   public
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   private
92
	 * @var      string    $plugin_name    The string used to uniquely identify this plugin.
93
	 */
94
	private $plugin_name;
95
96
	/**
97
	 * Boot Menu.
98
	 *
99
	 * @param  string $plugin_name The string used to uniquely identify this plugin.
100
	 * @since    1.0.0
101
	 * @access   public
102
	 */
103
	public function __construct( $plugin_name ) {
104
		$this->plugin_name = $plugin_name;
105
	}
106
107
	/**
108
	 * Create a new menu page.
109
	 *
110
	 * @since    1.0.0
111
	 * @access   public
112
	 */
113
	public function save() {
114
		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

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

130
		/** @scrutinizer ignore-call */ 
131
  add_action( 'admin_menu', array( $this, 'create_menu' ) );
Loading history...
131
	}
132
133
	/**
134
	 * Register new menu page.
135
	 *
136
	 * @return void
137
	 */
138
	public function create_menu() {
139
		$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

139
		$hook = /** @scrutinizer ignore-call */ add_menu_page(
Loading history...
140
			$this->page_title,
141
			$this->menu_title,
142
			$this->capability,
143
			$this->slug,
144
			$this->callback,
145
			$this->icon
146
		);
147
148
		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

148
		/** @scrutinizer ignore-call */ 
149
  add_action( 'load-' . $hook, array( $this, 'init_hooks' ) );
Loading history...
149
	}
150
151
	/**
152
	 * Initialize hooks for the admin page.
153
	 *
154
	 * @return void
155
	 */
156
	public function init_hooks() {
157
		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

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

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

168
		/** @scrutinizer ignore-call */ 
169
  wp_enqueue_script( $this->plugin_name . '-admin' );
Loading history...
169
	}
170
}
171