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