Codexshaper /
wpb-framework
| 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 | |||||||
| 9 | /** |
||||||
| 10 | * The admin-specific functionality of the plugin. |
||||||
| 11 | * |
||||||
| 12 | * Defines the plugin name, version, and two examples hooks for how to |
||||||
| 13 | * enqueue the admin-specific stylesheet and JavaScript. |
||||||
| 14 | * |
||||||
| 15 | * @author Md Abu Ahsan basir <[email protected]> |
||||||
| 16 | */ |
||||||
| 17 | class WPB_Admin_Menu |
||||||
| 18 | { |
||||||
| 19 | /** |
||||||
| 20 | * The menu page title. |
||||||
| 21 | * |
||||||
| 22 | * @since 1.0.0 |
||||||
| 23 | * |
||||||
| 24 | * @var string The string used to set menu page title. |
||||||
| 25 | */ |
||||||
| 26 | public $page_title; |
||||||
| 27 | |||||||
| 28 | /** |
||||||
| 29 | * The menu title. |
||||||
| 30 | * |
||||||
| 31 | * @since 1.0.0 |
||||||
| 32 | * |
||||||
| 33 | * @var string The string used to set menu title. |
||||||
| 34 | */ |
||||||
| 35 | public $menu_title; |
||||||
| 36 | |||||||
| 37 | /** |
||||||
| 38 | * The menu capability. |
||||||
| 39 | * |
||||||
| 40 | * @since 1.0.0 |
||||||
| 41 | * |
||||||
| 42 | * @var string The string used to set menu capability. |
||||||
| 43 | */ |
||||||
| 44 | public $capability; |
||||||
| 45 | |||||||
| 46 | /** |
||||||
| 47 | * The menu slug. |
||||||
| 48 | * |
||||||
| 49 | * @since 1.0.0 |
||||||
| 50 | * |
||||||
| 51 | * @var string The string used to set menu slug. |
||||||
| 52 | */ |
||||||
| 53 | public $slug; |
||||||
| 54 | |||||||
| 55 | /** |
||||||
| 56 | * The callback to render content. |
||||||
| 57 | * |
||||||
| 58 | * @since 1.0.0 |
||||||
| 59 | * |
||||||
| 60 | * @var callback The callback used to render content. |
||||||
| 61 | */ |
||||||
| 62 | public $callback = null; |
||||||
| 63 | |||||||
| 64 | /** |
||||||
| 65 | * The menu icon. |
||||||
| 66 | * |
||||||
| 67 | * @since 1.0.0 |
||||||
| 68 | * |
||||||
| 69 | * @var string The string used to set menu icon. |
||||||
| 70 | */ |
||||||
| 71 | public $icon; |
||||||
| 72 | |||||||
| 73 | /** |
||||||
| 74 | * The menu position. |
||||||
| 75 | * |
||||||
| 76 | * @since 1.0.0 |
||||||
| 77 | * |
||||||
| 78 | * @var int The string used to set menu position. |
||||||
| 79 | */ |
||||||
| 80 | public $position; |
||||||
| 81 | |||||||
| 82 | /** |
||||||
| 83 | * The menu plugin name. |
||||||
| 84 | * |
||||||
| 85 | * @since 1.0.0 |
||||||
| 86 | * |
||||||
| 87 | * @var string The string used to uniquely identify this plugin. |
||||||
| 88 | */ |
||||||
| 89 | private $plugin_name; |
||||||
| 90 | |||||||
| 91 | /** |
||||||
| 92 | * Boot Menu. |
||||||
| 93 | * |
||||||
| 94 | * @param string $plugin_name The string used to uniquely identify this plugin. |
||||||
| 95 | * |
||||||
| 96 | * @since 1.0.0 |
||||||
| 97 | */ |
||||||
| 98 | public function __construct($plugin_name) |
||||||
| 99 | { |
||||||
| 100 | $this->plugin_name = $plugin_name; |
||||||
| 101 | } |
||||||
| 102 | |||||||
| 103 | /** |
||||||
| 104 | * Create a new menu page. |
||||||
| 105 | * |
||||||
| 106 | * @since 1.0.0 |
||||||
| 107 | */ |
||||||
| 108 | public function save() |
||||||
| 109 | { |
||||||
| 110 | add_action('admin_menu', [$this, 'create_menu']); |
||||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||||
| 111 | } |
||||||
| 112 | |||||||
| 113 | /** |
||||||
| 114 | * Create a new menu page. |
||||||
| 115 | * |
||||||
| 116 | * @since 1.0.0 |
||||||
| 117 | * |
||||||
| 118 | * @param array $options Pass proprties as an array. |
||||||
| 119 | */ |
||||||
| 120 | public function make($options = []) |
||||||
| 121 | { |
||||||
| 122 | foreach ($options as $property => $value) { |
||||||
| 123 | if (property_exists(get_called_class(), $property)) { |
||||||
| 124 | $this->{$property} = $value; |
||||||
| 125 | } |
||||||
| 126 | } |
||||||
| 127 | add_action('admin_menu', [$this, 'create_menu']); |
||||||
|
0 ignored issues
–
show
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
Loading history...
|
|||||||
| 128 | } |
||||||
| 129 | |||||||
| 130 | /** |
||||||
| 131 | * Register new menu page. |
||||||
| 132 | * |
||||||
| 133 | * @return void |
||||||
| 134 | */ |
||||||
| 135 | public function create_menu() |
||||||
| 136 | { |
||||||
| 137 | $callback = $this->callback ?? [$this, 'render_content']; |
||||||
| 138 | $hook = add_menu_page( |
||||||
|
0 ignored issues
–
show
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
Loading history...
|
|||||||
| 139 | $this->page_title, |
||||||
| 140 | $this->menu_title, |
||||||
| 141 | $this->capability, |
||||||
| 142 | $this->slug, |
||||||
| 143 | $callback, |
||||||
| 144 | $this->icon |
||||||
| 145 | ); |
||||||
| 146 | |||||||
| 147 | add_action('load-'.$hook, [$this, 'init_hooks']); |
||||||
|
0 ignored issues
–
show
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
Loading history...
|
|||||||
| 148 | } |
||||||
| 149 | |||||||
| 150 | /** |
||||||
| 151 | * Initialize hooks for the admin page. |
||||||
| 152 | * |
||||||
| 153 | * @return void |
||||||
| 154 | */ |
||||||
| 155 | public function init_hooks() |
||||||
| 156 | { |
||||||
| 157 | add_action('admin_enqueue_scripts', [$this, 'enqueue_scripts']); |
||||||
|
0 ignored issues
–
show
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
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 | { |
||||||
| 167 | wp_enqueue_style($this->plugin_name.'-vendors'); |
||||||
|
0 ignored issues
–
show
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
Loading history...
|
|||||||
| 168 | wp_enqueue_style($this->plugin_name.'-admin'); |
||||||
| 169 | wp_enqueue_script($this->plugin_name.'-admin'); |
||||||
|
0 ignored issues
–
show
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
Loading history...
|
|||||||
| 170 | } |
||||||
| 171 | |||||||
| 172 | /** |
||||||
| 173 | * Render app content. |
||||||
| 174 | * |
||||||
| 175 | * @return void |
||||||
| 176 | */ |
||||||
| 177 | public function render_content() |
||||||
| 178 | { |
||||||
| 179 | 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
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
Loading history...
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
Loading history...
|
|||||||
| 180 | } |
||||||
| 181 | } |
||||||
| 182 |