| 1 |
<?php |
| 2 |
|
| 3 |
add_action('admin_menu', 'wpc_create_menu'); |
| 4 |
function wpc_create_menu() { |
| 5 |
//create new top-level menu |
| 6 |
add_menu_page('WP Courses', 'WP Courses', 'administrator', 'wpc_settings', 'wpc_settings_page', esc_url(WPC_PLUGIN_URL . 'images/wpc-icon-sm-white.png')); |
| 7 |
} |
| 8 |
|
| 9 |
function wpc_settings_page(){ ?> |
| 10 |
<?php include 'admin-nav-menu.php'; ?> |
| 11 |
<div class="wpc-main-admin-wrapper wrap"> |
| 12 |
<?php include 'dashboard.php'; ?> |
| 13 |
</div> |
| 14 |
<?php } |
| 15 |
|
| 16 |
function wpc_register_submenu(){ |
| 17 |
// Free and premium menu 1 |
| 18 |
add_submenu_page( 'wpc_settings', esc_html__('Dashboard', 'wp-courses'), esc_html__('Dashboard', 'wp-courses') . ' <span class="wpc-admin-separator"></span>', 'manage_options', 'wpc_settings', 'wpc_settings_page' ); |
| 19 |
add_submenu_page( 'wpc_settings', esc_html__('Setup and Help', 'wp-courses'), esc_html__('Setup and Help', 'wp-courses') . ' <i class="fa fa-info-circle" aria-hidden="true"></i>', 'manage_options', 'wpc_help', 'wpc_help_page' ); |
| 20 |
add_submenu_page( 'wpc_settings', esc_html__('All Courses', 'wp-courses'), esc_html__('All Courses', 'wp-courses') . ' <span class="wpc-admin-separator"></span>', 'manage_options', 'edit.php?post_type=course' ); |
| 21 |
add_submenu_page( 'wpc_settings', esc_html__('All Lessons', 'wp-courses'), esc_html__('All Lessons', 'wp-courses'), 'manage_options', 'edit.php?post_type=lesson' ); |
| 22 |
if(WPCP_VERSION > 3.07 || WPCP_VERSION === false) { |
| 23 |
add_submenu_page( 'wpc_settings', esc_html__('All Quizzes', 'wp-courses'), esc_html__('All Quizzes', 'wp-courses'), 'manage_options', 'edit.php?post_type=wpc-quiz' ); |
| 24 |
} |
| 25 |
|
| 26 |
// Hidden pages |
| 27 |
add_submenu_page( 'wpc_settings', esc_html__('Course Order', 'wp-courses'), esc_html__('Course Order', 'wp-courses') . ' <span class="wpc-admin-hide"></span>', 'manage_options', 'order_courses', 'wpc_order_courses_page' ); |
| 28 |
add_submenu_page( 'wpc_settings', esc_html__('Lesson Order', 'wp-courses'), esc_html__('Lesson Order', 'wp-courses') . ' <span class="wpc-admin-hide"></span>', 'manage_options', 'order_lessons', 'wpc_order_lessons_page' ); |
| 29 |
add_submenu_page( 'wpc_settings', esc_html__('Shortcode Note', 'wp-courses'), esc_html__('Shortcode Note', 'wp-courses') . ' <span class="wpc-admin-hide"></span>', 'manage_options', 'wpc_shortcode_note', 'wpc_shortcode_note_page' ); |
| 30 |
|
| 31 |
// Free and premium menu 2 |
| 32 |
add_submenu_page( 'wpc_settings', esc_html__('All Teachers', 'wp-courses'), esc_html__('All Teachers', 'wp-courses'), 'manage_options', 'edit.php?post_type=teacher' ); |
| 33 |
add_submenu_page( 'wpc_settings', esc_html__('All Students', 'wp-courses'), esc_html__('All Students', 'wp-courses'), 'manage_options', 'manage_students', 'wpc_manage_students_page' ); |
| 34 |
add_submenu_page( 'wpc_settings', esc_html__('All Settings', 'wp-courses'), esc_html__('Settings', 'wp-courses') . ' <span class="wpc-admin-separator"></span>', 'manage_options', 'wpc_options', 'wpc_options_page' ); |
| 35 |
|
| 36 |
// Free only menu |
| 37 |
if( is_plugin_active( 'wp-courses-premium/wp-courses-premium.php' ) == false ) { |
| 38 |
add_submenu_page( 'wpc_settings', esc_html__('All Emails', 'wp-courses'), esc_html__('All Emails', 'wp-courses') . ' <span class="wpc-admin-separator"></span>', 'manage_options', 'wpc_premium_emails', 'wpc_premium_emails'); |
| 39 |
add_submenu_page( 'wpc_settings', esc_html__('All Badges', 'wp-courses'), esc_html__('All Badges', 'wp-courses'), 'manage_options', 'wpc_premium_badges', 'wpc_premium_badges'); |
| 40 |
add_submenu_page( 'wpc_settings', esc_html__('All Certificates', 'wp-courses'), esc_html__('All Certificates', 'wp-courses'), 'manage_options', 'wpc_premium_certificates', 'wpc_premium_certificates'); |
| 41 |
} |
| 42 |
|
| 43 |
do_action( 'wpc_after_register_submenu' ); |
| 44 |
} |
| 45 |
|
| 46 |
add_action('admin_menu', 'wpc_register_submenu'); |
| 47 |
|
| 48 |
function wpc_premium_emails() { ?> |
| 49 |
<?php include 'admin-nav-menu.php'; ?> |
| 50 |
<?php include 'templates/premium-emails.php'; ?> |
| 51 |
<?php } |
| 52 |
|
| 53 |
function wpc_premium_badges() { ?> |
| 54 |
<?php include 'admin-nav-menu.php'; ?> |
| 55 |
<?php include 'templates/premium-badges.php'; ?> |
| 56 |
<?php } |
| 57 |
|
| 58 |
function wpc_premium_certificates() { ?> |
| 59 |
<?php include 'admin-nav-menu.php'; ?> |
| 60 |
<?php include 'templates/premium-certificates.php'; ?> |
| 61 |
<?php } |
| 62 |
|
| 63 |
function get_user_and_fallback() { |
| 64 |
try { |
| 65 |
$userName = wp_get_current_user()->data->display_name; |
| 66 |
} catch(\Error $e) { |
| 67 |
$userName = 'there'; |
| 68 |
} |
| 69 |
|
| 70 |
return $userName; |
| 71 |
} |
| 72 |
|
| 73 |
function wpc_help_page(){ ?> |
| 74 |
<?php |
| 75 |
$userName = get_user_and_fallback(); |
| 76 |
?> |
| 77 |
|
| 78 |
<?php include 'admin-nav-menu.php'; ?> |
| 79 |
<?php include 'templates/help.php'; ?> |
| 80 |
<?php } |
| 81 |
|
| 82 |
function wpc_manage_students_page(){ |
| 83 |
include 'admin-nav-menu.php'; |
| 84 |
|
| 85 |
if(isset($_GET['student_id'])){ |
| 86 |
include 'templates/single-student.php'; |
| 87 |
} else { |
| 88 |
include 'wpc-admin-student-table.php'; |
| 89 |
} |
| 90 |
} |
| 91 |
|
| 92 |
// Order lesson page |
| 93 |
function wpc_order_lessons_page(){ |
| 94 |
include 'admin-nav-menu.php'; |
| 95 |
include 'templates/order-lessons.php'; |
| 96 |
} |
| 97 |
|
| 98 |
// Shortcode note page |
| 99 |
function wpc_shortcode_note_page(){ |
| 100 |
include 'admin-nav-menu.php'; |
| 101 |
include 'templates/shortcode_note.php'; |
| 102 |
} |
| 103 |
|
| 104 |
add_action( 'admin_footer', 'wpc_change_lesson_restriction_javascript' ); |
| 105 |
|
| 106 |
function wpc_order_courses_page(){ ?> |
| 107 |
<?php include 'admin-nav-menu.php'; ?> |
| 108 |
<?php include 'templates/order-courses.php'; ?> |
| 109 |
<?php } |
| 110 |
|
| 111 |
// Keep submenu displayed / opened |
| 112 |
function manipulate_submenu( $parent_file ) { |
| 113 |
|
| 114 |
global $plugin_page, $parent_file, $submenu_file; |
| 115 |
$screen = get_current_screen(); |
| 116 |
|
| 117 |
// 1) Keep menu opened |
| 118 |
// Course categories, course difficulties |
| 119 |
if (($screen->base === 'edit-tags' || $screen->base === 'term') && $screen->post_type === 'course' && ($screen->taxonomy === 'course-category' || $screen->taxonomy === 'course-difficulty')) { |
| 120 |
$plugin_page = 'wpc_help'; |
| 121 |
} |
| 122 |
|
| 123 |
// New quiz, new email, new badge, new certificate |
| 124 |
if ($screen->action === 'add' && $screen->base === 'post' && ($screen->post_type === 'wpc-quiz' || $screen->post_type === 'wpc-email' || $screen->post_type === 'wpc-badge' || $screen->post_type === 'wpc-certificate')) { |
| 125 |
$plugin_page = 'wpc_help'; |
| 126 |
} |
| 127 |
|
| 128 |
// 2) Hide highligting |
| 129 |
// Edit quiz, edit email, edit badge, edit certificate |
| 130 |
if ($screen->action === '' && $screen->base === 'post' && ($screen->post_type === 'wpc-quiz' || $screen->post_type === 'wpc-email' || $screen->post_type === 'wpc-badge' || $screen->post_type === 'wpc-certificate')) { |
| 131 |
$plugin_page = 'wpc_help'; |
| 132 |
$submenu_file = 'post-new.php?post_type=wpc-badge'; |
| 133 |
} |
| 134 |
|
| 135 |
return $parent_file; |
| 136 |
} |
| 137 |
|
| 138 |
add_filter( 'parent_file', 'manipulate_submenu' ); |