LLMS_Admin_Menus
LLMS_Admin_Menus class
Contents
Source Source
File: includes/admin/class.llms.admin.menus.php
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 | class LLMS_Admin_Menus { /** * Constructor * * @since 1.0.0 * @since 3.19.0 Add action scheduler posts table. * * @return void */ public function __construct() { add_action( 'admin_init' , array ( $this , 'status_page_actions' ) ); add_action( 'admin_init' , array ( $this , 'builder_page_actions' ) ); add_action( 'load-admin_page_llms-course-builder' , array ( $this , 'builder_title' ) ); add_filter( 'custom_menu_order' , array ( $this , 'submenu_order' ) ); add_action( 'admin_menu' , array ( $this , 'display_admin_menu' ) ); add_action( 'admin_menu' , array ( $this , 'display_admin_menu_late' ), 7777 ); // Shame shame shame. add_action( 'admin_menu' , array ( $this , 'instructor_menu_hack' ) ); add_filter( 'action_scheduler_post_type_args' , array ( $this , 'action_scheduler_menu' ) ); } /** * If WP_DEBUG is not enabled, expose the schedule-action post type management via direct link * * EG: site.com/wp-admin/edit.php?post_type=scheduled-action * * @since 3.19.0 * * @param array $args Default custom post type arguments. * @return array */ public function action_scheduler_menu( $args ) { // If WP_DEBUG is enabled the menu item will already be displayed under "tools.php". if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { return $args ; } // Otherwise we'll add a hidden menu accessible via direct link only. return array_merge ( $args , array ( 'show_ui' => true, 'show_in_menu' => '' , 'show_in_admin_bar' => false, ) ); } /** * Remove the default menu page from the submenu. * * @since 1.0.0 * @since 3.2.0 Unknown. * @since 5.0.0 Adds custom sorting for LifterLMS submenu items. * @since 7.1.0 Added `llms-dashboard` to the order array in first position. * * @param bool $flag Flag from core filter (always false). * @return bool */ public function submenu_order( $flag ) { global $submenu ; if ( isset( $submenu [ 'lifterlms' ] ) ) { // Our desired order. $order = array ( 'llms-dashboard' , 'llms-settings' , 'llms-reporting' , 'edit.php?post_type=llms_form' ); // Temporary array to hold our submenu items. $new_submenu = array (); // Any items not defined in the $order array will be added at the end of the new array. $num_items = count ( $submenu [ 'lifterlms' ] ); foreach ( $submenu [ 'lifterlms' ] as $item ) { // Locate the desired order. $key = array_search ( $item [2], $order , true ); // Not found, increment the number of items to add it to the end of the array in its original order. if ( false === $key ) { $key = ++ $num_items ; } // Add the item to the new submenu. $new_submenu [ $key ] = $item ; } // Sort. ksort( $new_submenu ); // Remove the keys so the new array doesn't skip any numbers. $submenu [ 'lifterlms' ] = array_values ( $new_submenu ); } return $flag ; } /** * Handle init actions on the course builder page * * Used for post-locking redirects when taking over from another user * on the course builder page. * * @since 3.13.0 * @since 3.16.7 Unknown. * * @return void */ public function builder_page_actions() { if ( ! isset( $_GET [ 'page' ] ) || 'llms-course-builder' !== $_GET [ 'page' ] ) { return ; } if ( ! empty ( $_GET [ 'get-post-lock' ] ) && ! empty ( $_GET [ 'course_id' ] ) ) { $post_id = absint( $_GET [ 'course_id' ] ); check_admin_referer( 'lock-post_' . $post_id ); wp_set_post_lock( $post_id ); wp_safe_redirect( add_query_arg( array ( 'page' => 'llms-course-builder' , 'course_id' => $post_id , ), admin_url( 'admin.php' ) ) ); exit (); } add_action( 'admin_bar_menu' , array ( 'LLMS_Admin_Builder' , 'admin_bar_menu' ), 100, 1 ); } /** * Set the global $title variable for the builder * * Prevents the <title> in the admin head being partially empty on builder screen. * * @since 3.14.9 * * @return void */ public function builder_title() { global $title ; $title = __( 'Course Builder' , 'lifterlms' ); } /** * Admin Menu. * * @since 1.0.0 * @since 3.13.0 Unknown. * @since 5.3.1 Use encoded SVG LifterLMS icon so that WordPress can "paint" it. * submenu page in place of NULL. * @since 7.1.0 Added the 'Dashboard' submenu page. * @since 7.4.1 Added the 'Resources' submenu page. * * @return void */ public function display_admin_menu() { global $menu ; $menu [51] = array ( '' , 'read' , 'llms-separator' , '' , 'wp-menu-separator' ); $icon_url = 'data:image/svg+xml;base64,' . base64_encode ( file_get_contents ( LLMS_PLUGIN_DIR . 'assets/images/lifterlms-icon-grey.svg' ) ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents, WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode add_menu_page( 'lifterlms' , 'LifterLMS' , 'read' , 'lifterlms' , '__return_empty_string' , $icon_url , 51 ); add_submenu_page( 'lifterlms' , __( 'LifterLMS Dashboard' , 'lifterlms' ), __( 'Dashboard' , 'lifterlms' ), 'manage_lifterlms' , 'llms-dashboard' , array ( $this , 'dashboard_page_init' ) ); add_submenu_page( 'lifterlms' , __( 'LifterLMS Settings' , 'lifterlms' ), __( 'Settings' , 'lifterlms' ), 'manage_lifterlms' , 'llms-settings' , array ( $this , 'settings_page_init' ) ); add_submenu_page( 'lifterlms' , __( 'LifterLMS Reporting' , 'lifterlms' ), __( 'Reporting' , 'lifterlms' ), 'view_lifterlms_reports' , 'llms-reporting' , array ( $this , 'reporting_page_init' ) ); add_submenu_page( 'lifterlms' , __( 'LifterLMS Import' , 'lifterlms' ), __( 'Import' , 'lifterlms' ), 'manage_lifterlms' , 'llms-import' , array ( $this , 'import_page_init' ) ); add_submenu_page( 'lifterlms' , __( 'LifterLMS Status' , 'lifterlms' ), __( 'Status' , 'lifterlms' ), 'manage_lifterlms' , 'llms-status' , array ( $this , 'status_page_init' ) ); add_submenu_page( 'lifterlms' , __( 'LifterLMS Resources' , 'lifterlms' ), __( 'Resources' , 'lifterlms' ), 'manage_lifterlms' , 'llms-resources' , array ( $this , 'resources_page_init' ) ); // Passing '' to register the page without actually adding a menu item. add_submenu_page( '' , __( 'LifterLMS Course Builder' , 'lifterlms' ), __( 'Course Builder' , 'lifterlms' ), 'edit_courses' , 'llms-course-builder' , array ( $this , 'builder_init' ) ); } /** * Add items to the admin menu with a later priority * * @since 3.5.0 * @since 3.22.0 Unknown. * * @return void */ public function display_admin_menu_late() { /** * Disable the display and output of LifterLMS Add-ons screen. * * @since Unknown * * @param boolean $display Whether or not to display the screen. Defaults to `false` which shows the screen. */ if ( apply_filters( 'lifterlms_disable_addons_screen' , false ) ) { return ; } add_submenu_page( 'lifterlms' , __( 'LifterLMS Add-ons, Courses, and Resources' , 'lifterlms' ), __( 'Add-ons & more' , 'lifterlms' ), 'manage_lifterlms' , 'llms-add-ons' , array ( $this , 'add_ons_page_init' ) ); } /** * Output the add-ons screen. * * @since 3.5.0 * @since 3.22.0 Unknown. * @since 6.0.0 Removed loading the LLMS_Admin_AddOns class file that is now handled by the autoloader. * * @return void */ public function add_ons_page_init() { $view = new LLMS_Admin_AddOns(); $view ->handle_actions(); $view ->output(); } /** * Output the HTML for the Course Builder * * @since 3.13.0 * @since 3.16.0 Unknown. * @since 6.0.0 Removed loading the LLMS_Admin_Builder class file that is now handled by the autoloader. * * @return void */ public function builder_init() { LLMS_Admin_Builder::output(); } /** * Outputs the LifterLMS Importer Screen HTML * * @since 3.3.0 * * @return void */ public function import_page_init() { LLMS_Admin_Import::output(); } /** * Removes edit.php from the admin menu for instructors/asst instructors * * Note: The post screen is still technically accessible. * * Posts will need to be submitted for review as the instructors only actually have * the capability of a contributor with regards to posts * but this hack will allow instructors to publish new lessons, quizzes, & questions. * * @since 3.13.0 * @since 7.0.1 Added filterable early return allowing 3rd parties to modify * the user roles affected by this hack. * * * @return void */ public function instructor_menu_hack() { /** * Filters the WP_User roles should receive the instructor admin menu hack. * * If you wish to provide explicit access to the `post` post type, to the * instrutor or instructor's assistant role, the role will need to be * removed from this array so they can access to the post type edit.php * screen. * * @see LLMS_Admin_Menus::instructor_menu_hack * * @since 7.0.1 * * @param string[] $roles The list of WP_User roles which need the hack. */ $roles = apply_filters( 'llms_instructor_menu_hack_roles' , array ( 'instructor' , 'instructors_assistant' ) ); $user = wp_get_current_user(); if ( array_intersect ( $roles , $user ->roles ) ) { remove_menu_page( 'edit.php' ); } } /** * Output the HTML for admin dashboard screen. * * @since 7.1.0 * * @return void */ public function dashboard_page_init() { LLMS_Admin_Dashboard::register_meta_boxes(); LLMS_Admin_Dashboard::output(); } /** * Output the HTML for admin settings screens * * @since Unknown * @since 6.0.0 Removed loading the LLMS_Admin_Settings class file that is now handled by the autoloader. * * @return void */ public function settings_page_init() { LLMS_Admin_Settings::output(); } /** * Output the HTML for the reporting screens * * @since 3.2.0 * @since 3.13.0 Unknown. * @since 3.35.0 Sanitize input data. * @since 4.7.0 Removed inclusion of `LLMS_Admin_Reporting` which is now loaded automatically. * * @return void */ public function reporting_page_init() { if ( isset( $_GET [ 'student_id' ] ) && ! llms_current_user_can( 'view_lifterlms_reports' , llms_filter_input( INPUT_GET, 'student_id' , FILTER_SANITIZE_NUMBER_INT ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended wp_die( __( 'You do not have permission to access this content.' , 'lifterlms' ) ); } $reporting = new LLMS_Admin_Reporting(); $reporting ->output(); } /** * Include files used on the Status page. * * @since 3.37.19 * @since 4.12.0 Added `llms_load_admin_tools` action. * @since 6.0.0 Removed loading of class files that don't instantiate their class in favor of autoloading. * * @return void */ protected function status_page_includes() { // Tools. foreach ( glob ( LLMS_PLUGIN_DIR . 'includes/admin/tools/class-llms-admin-tool-*.php' ) as $tool_path ) { require_once $tool_path ; } /** * Action which can be used by 3rd parties to load custom admin page tools. * * @since 4.12.0 */ do_action( 'llms_load_admin_tools' ); } /** * Handle form submission actions on the status pages * * @since 3.11.2 * @since 3.37.19 Load tools-related files. * * @ return void |
Expand full source code Collapse full source code View on GitHub
Methods Methods
- __construct — Constructor
- action_scheduler_menu — If WP_DEBUG is not enabled, expose the schedule-action post type management via direct link
- add_ons_page_init — Output the add-ons screen.
- builder_init — Output the HTML for the Course Builder
- builder_page_actions — Handle init actions on the course builder page
- builder_title — Set the global $title variable for the builder
- display_admin_menu — Admin Menu
- display_admin_menu_late — Add items to the admin menu with a later priority
- import_page_init — Outputs the LifterLMS Importer Screen HTML
- instructor_menu_hack — Removes edit.php from the admin menu for instructors/asst instructors
- reporting_page_init — Output the HTML for the reporting screens
- settings_page_init — Output the HTML for admin settings screens
- status_page_actions — Handle form submission actions on the status pages
- status_page_includes — Include files used on the Status page.
- status_page_init — Output the HTML for the Status Pages
- submenu_order — Remove the default menu page from the submenu
Changelog Changelog
Version | Description |
---|---|
5.0.0 | Add custom LifterLMS submenu item sorting. |
3.37.19 | Load tools on the status page. |
3.35.0 | Sanitize input data. |
3.19.0 | Added action scheduler posts table. |
1.0.0 | Introduced. |