PluginProbe
Booking Calendar / 10.10.2
Booking Calendar v10.10.2
11.8.2 11.8.1 11.8 11.7 11.6.1 11.6 11.5 11.4.3 11.4.2 11.4.1 11.4 11.3 11.2.1 11.2 11.1 11.0 10.15.7 10.15.6 10.1.3 10.10 10.10.1 10.10.2 10.11 10.11.2 10.11.3 All 202 releases
booking / core / any / class-admin-menu.php

class-admin-menu.php in Booking Calendar 10.10.2, at core/any/class-admin-menu.php

268 lines 15.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php /**
2 * @version 1.1
3 * @package Any
4 * @category Menu in Admin Panel
5 * @author wpdevelop
6 *
7 * @web-site https://wpbookingcalendar.com/
8 * @email info@wpbookingcalendar.com
9 *
10 * @modified 2015-11-02
11 */
12
13 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
14
15 class WPBC_Admin_Menus {
16
17 /* Static Variables */
18 static $capability = array( 'administrator' => 'activate_plugins',
19 'editor' => 'publish_pages',
20 'author' => 'publish_posts',
21 'contributor' => 'edit_posts',
22 'subscriber' => 'read'
23 );
24 protected $menu_tag;
25 protected $menu_title;
26 protected $menu_title_second; // For root menu chnage second title in submenu - little hack
27 protected $page_header; // Header - H2, in page content
28 protected $browser_header; // Browser Header Title
29 protected $in_menu;
30 protected $user_role; // Acceess Role for current menu item
31 protected $mune_icon_url; // Icon - if used 'none', then you can define it in the CSS backgound: .toplevel_page_wpbc .wp-menu-image { background-image: url("../img/icon-16x16.png"); background-position: 7px 7px; } But its mean that you are need to load this CSS in every admin page.
32
33 public $root_position; /* Positions for Core Menu Items
34 2 Dashboard
35 4 Separator
36 5 Posts
37 10 Media
38 15 Links
39 20 Pages
40 25 Comments
41 59 Separator
42 60 Appearance
43 65 Plugins
44 70 Users
45 75 Tools
46 80 Settings
47 99 Separator
48 */
49
50 function __construct( $slug, $param = array() ) {
51
52 $this->in_menu = false;
53 $this->menu_tag = $slug; // For exmaple: 'wpbc-settings' - its 'page' parameter in URL
54
55 if ( isset( $param['menu_title'] ) ) $this->menu_title = $param['menu_title'];
56 if ( isset( $param['menu_title_second'] ) ) $this->menu_title_second = $param['menu_title_second'];
57 if ( isset( $param['page_header'] ) ) $this->page_header = $param['page_header'];
58 if ( isset( $param['browser_header'] ) ) $this->browser_header = $param['browser_header'];
59 if ( isset( $param['in_menu'] ) ) $this->in_menu = $param['in_menu'];
60 if ( isset( $param['position'] ) ) $this->root_position = $param['position'];
61 else $this->root_position = null;
62
63 if ( isset( $param['mune_icon_url'] ) ) $this->mune_icon_url = $param['mune_icon_url'];
64 else $this->mune_icon_url = 'none';
65
66 if ( isset( $param['user_role'] ) ) $this->user_role = $param['user_role'];
67 else $this->user_role = 'subscriber';
68
69 add_action( 'admin_menu', array($this, 'new_admin_page'), 10 );
70
71 add_action( 'admin_menu', array($this, 'change_second_root_menu_title'), 11 ); // Change Title of Submenu title for root menu item
72 }
73
74
75 public function load_js() {
76 do_action( 'wpbc_load_js_on_admin_page' );
77 }
78
79
80 public function load_css() {
81 do_action( 'wpbc_load_css_on_admin_page' );
82 }
83
84
85 /**
86 * Define Plugin Menu Page
87 *
88 */
89 public function new_admin_page(){
90
91 if ( $this->in_menu == 'root' ) { // Main Menu
92
93 $page = $this->create_plugin_menu(
94 $this->browser_header // Browser Page Header Title
95 , $this->menu_title // Menu Title
96 , ( ( isset( self::$capability[ $this->user_role ] ) ) ? self::$capability[ $this->user_role ] : self::$capability[ 'subscriber' ] ) // Capabilities
97 , $this->menu_tag // Slug // I was used early -> plugin_basename(WPBC_FILE).'wpbc'
98 , $this->mune_icon_url // Icon // - if used 'none', then you can define it in the CSS backgound: .toplevel_page_wpbc .wp-menu-image { background-image: url("../img/icon-16x16.png"); background-position: 7px 7px; } But its mean that you are need to load this CSS in every admin page.
99 , array( $this, 'content' ) // Function for output content of page
100 );
101
102 } else { // Sub Menu
103
104 $page = $this->create_plugin_submenu(
105 $this->in_menu // The slug name for parent menu (or file name of standard WordPress admin page)
106 , $this->browser_header // Page Title
107 , $this->menu_title // Menu Title
108 , ( ( isset( self::$capability[ $this->user_role ] ) ) ? self::$capability[ $this->user_role ] : self::$capability[ 'subscriber' ] ) // Capabilities
109 , $this->menu_tag // Slug
110 , array( $this, 'content' ) // Function for output content of page
111 );
112 }
113
114 //do_action('wpbc_define_settings_pages', $this->menu_tag ); // Define sub classes, like: page-settings-general.php $this->menu_tag - 'wpbc-settings' - its 'page' parameter in URL
115
116 do_action('wpbc_menu_created', $this->menu_tag ); // Define sub classes, like: page-settings-general.php $this->menu_tag - 'wpbc-settings' - its 'page' parameter in URL
117 do_action('wpbc_define_nav_tabs', $this->menu_tag ); // Define Nav tabs.
118 }
119
120
121 /**
122 * Content of the Menu Page
123 *
124 Define page S t r u c t u r e, nav T A B s , set N O N C E: wpbc_ajax_admin_nonce field
125
126 in ..\any\class\class-admin-page-structure.php
127
128 then show page C O N T E N T in files, like page-structure.php
129
130 $this->menu_tag - 'wpbc-settings' - its 'page' parameter in URL
131 */
132 public function content() {
133
134 do_action('wpbc_page_structure_show', $this->menu_tag );
135 }
136
137
138
139 /**
140 * Hack for changing Root 2nd Submenu Title
141 *
142 * @global type $submenu
143 */
144 public function change_second_root_menu_title() {
145
146 // Change Title of the Main menu inside of submenu
147 global $submenu;
148
149 if ( ( $this->in_menu == 'root' )
150 && ( isset( $submenu[ $this->menu_tag ] ) )
151 && ( isset( $this->menu_title_second ) )
152 ) {
153 $submenu[ $this->menu_tag ][0][0] = $this->menu_title_second;
154 }
155 }
156
157
158 /**
159 * Add Menu
160 *
161 * @param type $menu_page_title
162 * @param type $menu_title
163 * @param type $capability
164 * @param type $menu_slug
165 * @param type $mune_icon_url
166 * @param type $page_content
167 * @param type $page_css
168 * @param type $page_js
169 * @return type
170 */
171 protected function create_plugin_menu($menu_page_title, $menu_title, $capability, $menu_slug, $mune_icon_url, $page_content ) {
172 /**
173 * add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $position );
174 * @return string The resulting page's hook_suffix
175 */
176
177
178 // FixIn: 9.0.1.7.
179
180 // The url to the icon to be used for this menu. Using 'none' would leave div.wp-menu-image empty so an icon can be added as background with CSS.
181
182 if ( '<svg' == substr( $mune_icon_url, 0, 4 ) ) {
183 /*
184 $mune_icon_url_svg = '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="" viewBox="-2 -1 20 20">
185 <path d="M3.5 0a.5.5 0 0 1 .5.5V1h8V.5a.5.5 0 0 1 1 0V1h1a2 2 0 0 1 2 2v11a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2V3a2 2 0 0 1 2-2h1V.5a.5.5 0 0 1 .5-.5zM2 2a1 1 0 0 0-1 1v1h14V3a1 1 0 0 0-1-1H2zm13 3H1v9a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V5z"/>
186 <path d="M9 7.5a.5.5 0 0 1 .5-.5H15v2H9.5a.5.5 0 0 1-.5-.5v-1zm-2 3v1a.5.5 0 0 1-.5.5H1v-2h5.5a.5.5 0 0 1 .5.5z"/>
187 </svg>';
188 */
189 $mune_icon_url = sprintf( 'data:image/svg+xml;base64,%s', base64_encode( $mune_icon_url ) );
190
191 } elseif ( $mune_icon_url == 'none' ) {
192 $mune_icon_url = 'none';
193 } elseif ( empty( $mune_icon_url ) ) {
194 $mune_icon_url = '';
195 } else {
196 $mune_icon_url = plugins_url( $mune_icon_url, WPBC_FILE );
197 }
198
199 $page = add_menu_page( $menu_page_title, // The text to be displayed in the title tags of the page when the menu is selected
200 $menu_title, // The text to be used for the menu
201 $capability, // The capability required for this menu to be displayed to the user.
202 $menu_slug, // The slug name to refer to this menu by (should be unique for this menu)
203 $page_content, // The function to be called to output the content for this page.
204 $mune_icon_url//(($mune_icon_url=='none')?'none':((empty($mune_icon_url))?'':plugins_url($mune_icon_url, WPBC_FILE)) ) // The url to the icon to be used for this menu. Using 'none' would leave div.wp-menu-image empty so an icon can be added as background with CSS.
205 , $this->root_position /* @param int $position The position in the menu order this one should appear
206 * Positions for Core Menu Items
207 2 Dashboard
208 4 Separator
209 5 Posts
210 10 Media
211 15 Links
212 20 Pages
213 25 Comments
214 59 Separator
215 60 Appearance
216 65 Plugins
217 70 Users
218 75 Tools
219 80 Settings
220 99 Separator
221 */
222 );
223
224 add_action( 'admin_print_styles-' . $page, array( $this, 'load_css' ) );
225
226 add_action( 'admin_print_scripts-' . $page, array( $this, 'load_js' ) );
227
228 return $page;
229 }
230
231
232 /**
233 * Add Sub Menu
234 *
235 * @param type $parent_menu_slug - The slug name for the parent menu (or the file name of a standard WordPress admin page)
236 * @param type $menu_page_title
237 * @param type $menu_title
238 * @param type $capability
239 * @param type $menu_slug
240 * @param type $page_content
241 * @param type $page_css
242 * @param type $page_js
243 * @return type
244 */
245 protected function create_plugin_submenu( $parent_menu_slug, $menu_page_title, $menu_title, $capability, $menu_slug, $page_content ) {
246
247 /**
248 * function add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $function = '' );
249 * @return string|bool The resulting page's hook_suffix, or false if the user does not have the capability required.
250 */
251
252 $page = add_submenu_page(
253 $parent_menu_slug, // The slug name for the parent menu (or the file name of a standard WordPress admin page)
254 $menu_page_title, // The text to be displayed in the title tags of the page when the menu is selected
255 $menu_title, // The text to be used for the menu
256 $capability, // The capability required for this menu to be displayed to the user.
257 $menu_slug, // The slug name to refer to this menu by (should be unique for this menu)
258 $page_content // The function to be called to output the content for this page.
259 );
260
261 add_action( 'admin_print_styles-' . $page, array( $this, 'load_css' ) );
262
263 add_action( 'admin_print_scripts-' . $page, array( $this, 'load_js' ) );
264
265 return $page;
266 }
267 }
268