Completed
Push — master ( 35416d...50e245 )
by CodexShaper
03:37
created

WPB_Admin_Menu::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 2
rs 10
c 0
b 0
f 0
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 = null;
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
		$callback = $this->callback ?? array( $this, 'render_content' );
140
		$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

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

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

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

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

169
		/** @scrutinizer ignore-call */ 
170
  wp_enqueue_script( $this->plugin_name . '-admin' );
Loading history...
170
	}
171
172
	/**
173
	 * Render app content.
174
	 *
175
	 * @return void
176
	 */
177
	public function render_content() {
178
		echo '<div class="wrap"><div id="wpb-admin" base-url="' . esc_attr( get_site_url() ) . '" csrf-token="' . esc_attr( wpb_csrf_token() ) . '"></div></div>';
0 ignored issues
show
Bug introduced by
The function get_site_url 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

178
		echo '<div class="wrap"><div id="wpb-admin" base-url="' . esc_attr( /** @scrutinizer ignore-call */ get_site_url() ) . '" csrf-token="' . esc_attr( wpb_csrf_token() ) . '"></div></div>';
Loading history...
Bug introduced by
The function esc_attr 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

178
		echo '<div class="wrap"><div id="wpb-admin" base-url="' . /** @scrutinizer ignore-call */ esc_attr( get_site_url() ) . '" csrf-token="' . esc_attr( wpb_csrf_token() ) . '"></div></div>';
Loading history...
179
	}
180
}
181