PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.1.7.2
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.1.7.2
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 / lp-admin-actions.php

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

311 lines 8.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Defines the functions which called by hooks
4 */
5
6 // add_action( 'in_admin_footer', 'learn_press_footer_advertisement', - 10 );
7 add_action( 'admin_footer', 'learn_press_footer_advertisement', - 10 );
8
9 /***************************************/
10
11 /**
12 * Filter post types the user can access in admin
13 *
14 * @param $query
15 * @editor tungnx
16 * @modify 4.1.4 - comment - not use make redundancy
17 */
18 /*function _learn_press_set_user_items( $query ) {
19 global $post_type, $pagenow, $wpdb;
20
21 if ( ! function_exists( 'wp_get_current_user' ) ) {
22 include( ABSPATH . 'wp-includes/pluggable.php' );
23 }
24
25 if ( ! did_action( 'plugin_loaded' ) || current_user_can( 'manage_options' ) || ! current_user_can( LP_TEACHER_ROLE ) || ! is_admin() || ( $pagenow != 'edit.php' ) ) {
26 return $query;
27 }
28
29 if ( ! in_array(
30 $post_type,
31 apply_filters(
32 'learn-press/filter-user-access-types',
33 array(
34 LP_COURSE_CPT,
35 LP_LESSON_CPT,
36 LP_QUIZ_CPT,
37 LP_QUESTION_CPT,
38 )
39 )
40 ) ) {
41 return;
42 }
43
44 $items = $wpdb->get_col(
45 $wpdb->prepare(
46 "SELECT ID FROM $wpdb->posts
47 WHERE post_type = %s
48 AND post_author = %d",
49 $post_type,
50 get_current_user_id()
51 )
52 );
53
54 if ( count( $items ) == 0 ) {
55 $query->set( 'post_type', 'no-item-access' );
56 } else {
57 $query->set( 'post__in', $items );
58 }
59 add_filter( 'views_edit-' . $post_type . '', '_learn_press_restrict_view_items', 10 );
60 }
61
62 add_action( 'pre_get_posts', '_learn_press_set_user_items', 10 );*/
63
64 /**
65 * Restrict user views
66 *
67 * @param $views
68 *
69 * @return mixed
70 * @editor tungnx
71 * @modify 4.1.4 - comment - not see use anywhere
72 */
73 /*function _learn_press_restrict_view_items( $views ) {
74 $post_type = get_query_var( 'post_type' );
75 $new_views = array(
76 'all' => __( 'All', 'learnpress' ),
77 'publish' => __( 'Published', 'learnpress' ),
78 'private' => __( 'Private', 'learnpress' ),
79 'pending' => __( 'Pending Review', 'learnpress' ),
80 'future' => __( 'Scheduled', 'learnpress' ),
81 'draft' => __( 'Draft', 'learnpress' ),
82 'trash' => __( 'Trash', 'learnpress' ),
83 );
84
85 $url = 'edit.php';
86
87 foreach ( $new_views as $view => $name ) {
88 $query = array(
89 'post_type' => $post_type,
90 );
91 if ( $view == 'all' ) {
92 $query['all_posts'] = 1;
93 $class = ( get_query_var( 'all_posts' ) == 1 || ( get_query_var( 'post_status' ) == '' && get_query_var( 'author' ) == '' ) ) ? ' class="current"' : '';
94 } else {
95 $query['post_status'] = $view;
96 $class = ( get_query_var( 'post_status' ) == $view ) ? ' class="current"' : '';
97 }
98 $result = new WP_Query( $query );
99
100 if ( $result->found_posts > 0 ) {
101 $views[ $view ] = sprintf(
102 '<a href="%s"' . $class . '>' . $name . ' <span class="count">(%d)</span></a>',
103 esc_url_raw( add_query_arg( $query, $url ) ),
104 $result->found_posts
105 );
106 } else {
107 unset( $views[ $view ] );
108 }
109 }
110
111 unset( $views['mine'] );
112
113 return $views;
114 }*/
115
116 /**
117 * Update permalink structure for course
118 */
119 // function learn_press_update_permalink_structure() {
120 // global $pagenow;
121
122 // if ( $pagenow != 'options-permalink.php' ) {
123 // return;
124 // }
125
126 // if ( strtolower( $_SERVER['REQUEST_METHOD'] ) != 'post' ) {
127 // return;
128 // }
129
130 // $rewrite_prefix = '';
131 // $permalink_structure = ! empty( $_REQUEST['permalink_structure'] ) ? $_REQUEST['permalink_structure'] : '';
132
133 // if ( $permalink_structure ) {
134 // $rewrite_prefix = array();
135 // $segs = explode( '/', $permalink_structure );
136
137 // if ( sizeof( $segs ) ) {
138 // foreach ( $segs as $seg ) {
139 // if ( strpos( $seg, '%' ) !== false || $seg == 'archives' ) {
140 // break;
141 // }
142 // $rewrite_prefix[] = $seg;
143 // }
144 // }
145
146 // $rewrite_prefix = array_filter( $rewrite_prefix );
147
148 // if ( sizeof( $rewrite_prefix ) ) {
149 // $rewrite_prefix = join( '/', $rewrite_prefix ) . '/';
150 // } else {
151 // $rewrite_prefix = '';
152 // }
153 // }
154
155 // update_option( 'learn_press_permalink_structure', $rewrite_prefix );
156 // }
157 // add_action( 'init', 'learn_press_update_permalink_structure' );
158
159 /**
160 * Active Courses menu under LearnPress
161 * when user is editing course and course
162 * category.
163 */
164 function learn_press_active_course_menu() {
165 $post_type = LP_Request::get( 'post_type' );
166
167 if ( ! $post_type ) {
168 return;
169 }
170 ?>
171
172 <script>
173 jQuery( function( $ ) {
174 var $lpMainMenu = $( '#toplevel_page_learn_press' ),
175 href = 'edit.php?post_type=<?php echo esc_js( $_GET['post_type'] ); ?>',
176 $current = $( 'a[href="' + href + '"]', $lpMainMenu );
177
178 if ( $current.length ) {
179 $current.addClass( 'current' );
180 $current.parent( 'li' ).addClass( 'current' );
181 }
182
183 <?php if ( $post_type === LP_COURSE_CPT && LP_Request::get( 'taxonomy' ) === 'course_category' ) { ?>
184 $( 'body' ).removeClass( 'sticky-menu' );
185 $lpMainMenu.addClass( 'wp-has-current-submenu wp-menu-open' ).removeClass( 'wp-not-current-submenu' );
186 $lpMainMenu.children( 'a' ).addClass( 'wp-has-current-submenu wp-menu-open' ).removeClass( 'wp-not-current-submenu' );
187 <?php
188 }
189 ?>
190 });
191 </script>
192
193 <?php
194 }
195 add_action( 'admin_footer', 'learn_press_active_course_menu' );
196
197 /*
198 * Display tabs related to course in admin when user
199 * viewing/editing course/category/tags.
200 */
201 function learn_press_admin_course_tabs() {
202 if ( ! is_admin() ) {
203 return;
204 }
205
206 $wp_screen = get_current_screen();
207
208 if ( ! $wp_screen || 'edit-lp_course' !== $wp_screen->id ) {
209 return;
210 }
211
212 $admin_tabs = apply_filters(
213 'learn_press_admin_tabs_info',
214 array(
215 10 => array(
216 'link' => 'edit.php?post_type=lp_course',
217 'name' => esc_html__( 'Courses', 'learnpress' ),
218 'id' => 'edit-lp_course',
219 ),
220 20 => array(
221 'link' => 'edit-tags.php?taxonomy=course_category&post_type=lp_course',
222 'name' => esc_html__( 'Categories', 'learnpress' ),
223 'id' => 'edit-course_category',
224 ),
225 30 => array(
226 'link' => 'edit-tags.php?taxonomy=course_tag&post_type=lp_course',
227 'name' => esc_html__( 'Tags', 'learnpress' ),
228 'id' => 'edit-course_tag',
229 ),
230
231 )
232 );
233
234 ksort( $admin_tabs );
235 $tabs = array();
236
237 foreach ( $admin_tabs as $key => $value ) {
238 array_push( $tabs, $key );
239 }
240
241 $pages = apply_filters(
242 'learn_press_admin_tabs_on_pages',
243 array( 'edit-lp_course', 'edit-course_category', 'edit-course_tag', 'lp_course' )
244 );
245
246 $admin_tabs_on_page = array();
247
248 foreach ( $pages as $page ) {
249 $admin_tabs_on_page[ $page ] = $tabs;
250 }
251
252 $current_page_id = get_current_screen()->id;
253 $current_user = wp_get_current_user();
254
255 if ( ! in_array( 'administrator', $current_user->roles ) ) {
256 return;
257 }
258
259 if ( ! empty( $admin_tabs_on_page[ $current_page_id ] ) && count( $admin_tabs_on_page[ $current_page_id ] ) ) {
260
261 echo '<h2 class="nav-tab-wrapper lp-nav-tab-wrapper">';
262
263 foreach ( $admin_tabs_on_page[ $current_page_id ] as $admin_tab_id ) {
264 $class = ( $admin_tabs[ $admin_tab_id ]['id'] == $current_page_id ) ? 'nav-tab nav-tab-active' : 'nav-tab';
265 // echo '<a href="' . admin_url( $admin_tabs[ $admin_tab_id ]['link'] ) . '" class="' . $class . ' nav-tab-' . $admin_tabs[ $admin_tab_id ]['id'] . '">' . $admin_tabs[ $admin_tab_id ]['name'] . '</a>';
266 echo wp_kses(
267 sprintf(
268 '<a href="%s" class="%s">%s</a>',
269 admin_url( $admin_tabs[ $admin_tab_id ]['link'] ),
270 $class . ' nav-tab-' . $admin_tabs[ $admin_tab_id ]['id'],
271 $admin_tabs[ $admin_tab_id ]['name']
272 ),
273 true
274 );
275 }
276
277 echo '</h2>';
278 }
279 }
280 add_action( 'all_admin_notices', 'learn_press_admin_course_tabs' );
281
282 /**
283 * Create some warning messages:
284 * + LP Profile page is not setup
285 * + LP Checkout page is not setup
286 */
287 if ( ! function_exists( 'lp_remove_admin_warning' ) ) {
288 function lp_remove_admin_warning() {
289 if ( isset( $_POST['action'] ) && $_POST['action'] === 'lp_remove_admin_warning' && isset( $_POST['name'] ) ) {
290 if ( empty( $transient_profile ) ) {
291 set_transient( $_POST['name'], true, 60 * 60 * 12 );
292 }
293
294 echo 'success';
295 wp_die();
296
297 }
298
299 echo 'error';
300 wp_die();
301 }
302 }
303 add_action( 'wp_ajax_lp_remove_admin_warning', 'lp_remove_admin_warning' );
304
305 // 3.3.0
306 function learn_press_fill_in_blanks_admin_editor( $question ) {
307 learn_press_admin_view( 'question/fill-in-blanks', array( 'question' => $question ) );
308 }
309 add_action( 'learn-press/question-admin-editor', 'learn_press_fill_in_blanks_admin_editor' );
310
311