PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.3
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.3
4.4.7 4.4.6 4.4.5 4.4.4 4.4.3 4.4.2 4.4.1 4.4.0 4.3.9.1 4.3.9 4.3.8 4.3.7 4.1.6.9 4.1.6.9.1 4.1.6.9.2 4.1.6.9.3 4.1.6.9.4 4.1.7 4.1.7.1 4.1.7.2 4.1.7.3 4.1.7.3.1 4.1.7.3.2 4.2.0 4.2.1 All 138 releases
learnpress / inc / admin / class-lp-admin-menu.php

class-lp-admin-menu.php in LearnPress – WordPress LMS Plugin for Create and Sell Online Courses 4.4.3, at inc/admin/class-lp-admin-menu.php

204 lines 4.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Setup menus in WP admin.
4 *
5 * @author ThimPress
6 * @package LearnPress
7 * @version 1.0
8 */
9
10 defined( 'ABSPATH' ) || exit;
11
12 /**
13 * Class LP_Admin_Menu
14 */
15 class LP_Admin_Menu {
16
17 /**
18 * Array of submenu items.
19 *
20 * @var array
21 */
22 protected $menu_items = array();
23
24 /**
25 * Main menu capability.
26 *
27 * @var string
28 */
29 protected $capability = '';
30
31 /**
32 * LP_Admin_Menu Construct
33 */
34 public function __construct() {
35 add_action( 'admin_menu', array( $this, 'admin_menu' ) );
36
37 if ( apply_filters( 'learn_press_show_admin_bar_courses_page', true ) ) {
38 add_action( 'admin_bar_menu', array( $this, 'admin_bar_menus' ), 50 );
39 }
40
41 /**
42 * @since 3.0.0
43 */
44 $this->capability = 'edit_' . LP_COURSE_CPT . 's';
45 include_once 'sub-menus/abstract-submenu.php';
46 }
47
48 /**
49 * Added url Pages of LP.
50 *
51 * @param WP_Admin_Bar $wp_admin_bar
52 *
53 * @return void
54 */
55 public function admin_bar_menus( $wp_admin_bar ) {
56 if ( ! current_user_can( 'administrator' ) ) {
57 return;
58 }
59
60 $url_pages = [
61 'lp-courses' => [
62 'title' => esc_html__( 'View Page Courses', 'learnpress' ),
63 'href' => learn_press_get_page_link( 'courses' ),
64 'parent' => 'site-name',
65 ],
66 'lp-profile' => [
67 'title' => esc_html__( 'View Page Profile', 'learnpress' ),
68 'href' => learn_press_get_page_link( 'profile' ),
69 'parent' => 'site-name',
70 ],
71 'lp-instructors' => [
72 'title' => esc_html__( 'View Page Instructors', 'learnpress' ),
73 'href' => learn_press_get_page_link( 'instructors' ),
74 'parent' => 'site-name',
75 ],
76 ];
77
78 foreach ( $url_pages as $id => $url_page ) {
79 $wp_admin_bar->add_node(
80 array(
81 'id' => $id,
82 'parent' => $url_page['parent'] ?? 'appearance',
83 'title' => sprintf( '<span class="ab-label">%s</span>', $url_page['title'] ),
84 'href' => $url_page['href'],
85 )
86 );
87 }
88 }
89
90 /**
91 * Get main menu capability.
92 *
93 * @return string
94 */
95 public function get_capability() {
96 return $this->capability;
97 }
98
99 /**
100 * Register for menu for admin
101 */
102 public function admin_menu() {
103 // Not for translate menu_title, because it make compare $current_screen with "learnpress_page_.*" wrong
104 add_menu_page(
105 __( 'Learning Management System', 'learnpress' ),
106 'LearnPress',
107 $this->get_capability(),
108 'learn_press',
109 '',
110 LP_PLUGIN_URL . '/assets/images/logo-menu.png',
111 '3.14'
112 );
113
114 // Default submenu items
115 $menu_items = array();
116 $menu_items['statistic'] = include_once 'sub-menus/class-lp-submenu-statistics.php';
117 $menu_items['student-enrolled'] = include_once 'sub-menus/class-lp-submenu-students-enrolled.php';
118 $menu_items['addons'] = include_once 'sub-menus/class-lp-submenu-addons.php';
119 $menu_items['themes'] = include_once 'sub-menus/class-lp-submenu-themes.php';
120 $menu_items['settings'] = include_once 'sub-menus/class-lp-submenu-settings.php';
121 $menu_items['tools'] = include_once 'sub-menus/class-lp-submenu-tools.php';
122 $menu_items['categories'] = include_once 'sub-menus/class-lp-submenu-categories.php';
123 $menu_items['tags'] = include_once 'sub-menus/class-lp-submenu-tags.php';
124
125 $menu_items = apply_filters( 'learn-press/admin/menu-items', $menu_items );
126
127 // Sort menu items by its priority
128 uasort( $menu_items, 'learn_press_sort_list_by_priority_callback' );
129
130 add_action(
131 'parent_file',
132 function ( $parent_file ) {
133 global $current_screen;
134
135 $taxonomy = $current_screen->taxonomy;
136 if ( $taxonomy == 'course_tag' ) {
137 $parent_file = 'learn_press';
138 } elseif ( $taxonomy == 'course_category' ) {
139 $parent_file = 'learn_press';
140 }
141
142 return $parent_file;
143 }
144 );
145
146 if ( $menu_items ) {
147 foreach ( $menu_items as $k => $item ) {
148 if ( is_string( $item ) && class_exists( $item ) ) {
149 $item = new $item();
150 }
151
152 if ( ! $item instanceof LP_Abstract_Submenu ) {
153 continue;
154 }
155
156 if ( in_array( $k, [ 'tags', 'categories' ] ) ) {
157 $callback = false;
158 } else {
159 $callback = $item->get_callback();
160 }
161
162 add_submenu_page(
163 'learn_press',
164 $item->get_page_title(),
165 $item->get_menu_title(),
166 $item->get_capability(),
167 $item->get_id(),
168 $callback
169 );
170 }
171 $this->menu_items = $menu_items;
172 }
173
174 //$addons = LP_Admin::instance()->get_addons();
175 }
176
177 /**
178 * Callback function using for "usort".
179 *
180 * @param LP_Abstract_Submenu $a
181 * @param LP_Abstract_Submenu $b
182 *
183 * @return mixed
184 */
185 public function sort_menu_items( $a, $b ) {
186 return $a->get_priority() > $b->get_priority();
187 }
188
189 public function get_menu_items() {
190 return $this->menu_items;
191 }
192
193 public static function instance() {
194 static $instance;
195 if ( is_null( $instance ) ) {
196 $instance = new self();
197 }
198
199 return $instance;
200 }
201 }
202
203 return LP_Admin_Menu::instance();
204