PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.1.7.3
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.1.7.3
4.4.8 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 All 139 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.1.7.3, at inc/admin/class-lp-admin-menu.php

194 lines 4.2 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 * Admin bar menu.
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 ( ! is_admin() || ! is_user_logged_in() ) {
57 return;
58 }
59
60 // Add link view archive courses.
61 $wp_admin_bar->add_node(
62 array(
63 'parent' => 'site-name',
64 'id' => 'courses-page',
65 'title' => esc_html__( 'View Courses', 'learnpress' ),
66 'href' => learn_press_get_page_link( 'courses' ),
67 )
68 );
69
70 // Ad link view profile.
71 $wp_admin_bar->add_node(
72 array(
73 'id' => 'course_profile',
74 'parent' => 'user-actions',
75 'title' => esc_html__( 'View Profile', 'learnpress' ),
76 'href' => learn_press_get_page_link( 'profile' ),
77 )
78 );
79 }
80
81 /**
82 * Get main menu capability.
83 *
84 * @return string
85 */
86 public function get_capability() {
87 return $this->capability;
88 }
89
90 /**
91 * Register for menu for admin
92 */
93 public function admin_menu() {
94 // Not for translate menu_title, because it make compare $current_screen with "learnpress_page_.*" wrong
95 add_menu_page(
96 __( 'Learning Management System', 'learnpress' ),
97 'LearnPress',
98 $this->get_capability(),
99 'learn_press',
100 '',
101 'dashicons-welcome-learn-more',
102 '3.14'
103 );
104
105 // Default submenu items
106 $menu_items = array();
107 $menu_items['statistic'] = include_once 'sub-menus/class-lp-submenu-statistics.php';
108 $menu_items['addons'] = include_once 'sub-menus/class-lp-submenu-addons.php';
109 $menu_items['settings'] = include_once 'sub-menus/class-lp-submenu-settings.php';
110 $menu_items['tools'] = include_once 'sub-menus/class-lp-submenu-tools.php';
111 $menu_items['categories'] = include_once 'sub-menus/class-lp-submenu-categories.php';
112 $menu_items['tags'] = include_once 'sub-menus/class-lp-submenu-tags.php';
113
114 $menu_items = apply_filters( 'learn-press/admin/menu-items', $menu_items );
115
116 // Sort menu items by it's priority
117 uasort( $menu_items, 'learn_press_sort_list_by_priority_callback' );
118
119 add_action(
120 'parent_file',
121 function( $parent_file ) {
122 global $current_screen;
123
124 $taxonomy = $current_screen->taxonomy;
125 if ( $taxonomy == 'course_tag' ) {
126 $parent_file = 'learn_press';
127 } elseif ( $taxonomy == 'course_category' ) {
128 $parent_file = 'learn_press';
129 }
130
131 return $parent_file;
132 }
133 );
134
135 if ( $menu_items ) {
136 foreach ( $menu_items as $k => $item ) {
137 if ( is_string( $item ) && class_exists( $item ) ) {
138 $item = new $item();
139 }
140
141 if ( ! $item instanceof LP_Abstract_Submenu ) {
142 continue;
143 }
144
145 if ( in_array( $k, [ 'tags', 'categories' ] ) ) {
146 $callback = false;
147 } else {
148 $callback = $item->get_callback();
149 }
150
151 add_submenu_page(
152 'learn_press',
153 $item->get_page_title(),
154 $item->get_menu_title(),
155 $item->get_capability(),
156 $item->get_id(),
157 $callback
158 );
159 }
160 $this->menu_items = $menu_items;
161 }
162
163 $addons = LP_Admin::instance()->get_addons();
164 }
165
166 /**
167 * Callback function using for "usort".
168 *
169 * @param LP_Abstract_Submenu $a
170 * @param LP_Abstract_Submenu $b
171 *
172 * @return mixed
173 */
174 public function sort_menu_items( $a, $b ) {
175 return $a->get_priority() > $b->get_priority();
176 }
177
178 public function get_menu_items() {
179 return $this->menu_items;
180 }
181
182 public static function instance() {
183 static $instance = false;
184
185 if ( ! $instance ) {
186 $instance = new self();
187 }
188
189 return $instance;
190 }
191 }
192
193 return LP_Admin_Menu::instance();
194