Admin
Source
File: classes/Admin.php
13 14 15 16 17 18 19 20 21 22 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 | class Admin { public function __construct() { add_action( 'admin_menu' , [ $this , 'register_admin_menu' ] ); add_action( 'admin_init' , [ $this , 'filter_courses_for_instructors' ] ); add_filter( 'plugin_action_links_' . DOZENT_BASENAME, [ $this , 'insert_plugin_settings_link' ], 10, 2 ); } public function insert_plugin_settings_link( $links , $file ) { if ( $file === DOZENT_BASENAME ) { $links [] = '<a href="' . admin_url( 'options-general.php?page=dozent' ) . '">' . __( 'Settings' , 'dozent' ) . '</a>' ; } return $links ; } public function register_admin_menu() { //todo: manage_options will be instructor_permission add_menu_page( __( 'Dozent LMS' , 'dozent' ), __( 'Dozent LMS' , 'dozent' ), 'manage_options' , 'dozent' , null, 'dashicons-welcome-learn-more' , 4 ); add_submenu_page( 'dozent' , __( 'Categories' , 'dozent' ), __( 'Categories' , 'dozent' ), 'manage_options' , 'edit-tags.php?taxonomy=course_category&post_type=dozent_course' , null ); add_submenu_page( 'dozent' , __( 'Instructors' , 'dozent' ), __( 'Instructors' , 'dozent' ), 'manage_options' , 'dozent_instructors' , [ $this , 'instructors' ] ); add_submenu_page( 'dozent' , __( 'Withdrawals' , 'dozent' ), __( 'Withdrawals' , 'dozent' ), 'manage_options' , 'dozent_withdrawals' , array ( $this , 'withdrawals' ) ); $optionClass = new Options(); add_submenu_page( 'dozent' , __( 'Settings' , 'dozent' ), __( 'Settings' , 'dozent' ), 'manage_options' , 'dozent-options' , [ & $optionClass , 'option_panel' ] ); } public function instructors() { $sub_page = dozent_input_text( 'sub_page' ); if ( $sub_page ) { include DOZENT_ABSPATH . "views/users/{$sub_page}.php" ; } else { include DOZENT_ABSPATH . "views/users/instructors.php" ; } } /** * Show all withdrawals from the instructors * * @since DozentLMS 1.0.0 */ public function withdrawals() { include DOZENT_ABSPATH . 'views/admin/withdrawals.php' ; } /** * Filter posts for the current instructor if insructor role is not administrator * * @since DozentLMS 1.0.0 */ public function filter_courses_for_instructors() { if ( ! current_user_can( 'administrator' ) && is_dozent_instructor() ) { remove_menu_page( 'edit-comments.php' ); //Comments add_filter( 'posts_clauses_request' , [ $this , 'posts_clauses_request' ] ); } } public function posts_clauses_request( $clauses ) { global $wpdb ; $user_id = get_current_user_id(); $courses_ids = $wpdb ->get_col( "SELECT course_id from {$wpdb->dozent_instructor_courses} WHERE instructor_id = {$user_id} " ); $custom_author_query = "AND {$wpdb->posts}.post_author = {$user_id}" ; if ( dozent_count( $courses_ids ) ) { $in_query_pre = implode( ',' , $courses_ids ); $custom_author_query = " AND ( {$wpdb->posts}.post_author = {$user_id} OR {$wpdb->posts}.ID IN({$in_query_pre}) ) " ; } $clauses [ 'where' ] .= $custom_author_query ; return $clauses ; } } |
Methods
- __construct
- filter_courses_for_instructors — Filter posts for the current instructor if insructor role is not administrator
- insert_plugin_settings_link
- instructors
- posts_clauses_request
- register_admin_menu
- withdrawals — Show all withdrawals from the instructors