Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save bappi-d-great/7e6806f04707aa2d4f79 to your computer and use it in GitHub Desktop.
Save bappi-d-great/7e6806f04707aa2d4f79 to your computer and use it in GitHub Desktop.
Shortcode to show instructor lists in WPMU coursepress pro
<?php
/*
* use [get_all_instructors]
* Change wp-content/plugins/ to correct plugins folder if you use a separate folder for plugins at line 9
*/
add_shortcode( 'get_all_instructors', 'get_all_instructors_cb' );
function get_all_instructors_cb() {
include ABSPATH . 'wp-content/plugins/coursepress/includes/classes/class.instructorsearch.php';
if ( isset( $_GET['page_num'] ) ) {
$page_num = ( int ) $_GET['page_num'];
} else {
$page_num = 1;
}
if ( isset( $_GET['s'] ) ) {
$usersearch = $_GET['s'];
} else {
$usersearch = '';
}
$wp_user_search = new Instructor_Search( $usersearch, $page_num );
$html = '<table class="instructor_list" width="100%">';
$html .= '<tr>';
$html .= '<th>Username</th>';
$html .= '<th>First Name</th>';
$html .= '<th>Surname</th>';
$html .= '<th>Registered</th>';
$html .= '<th>Courses</th>';
$html .= '</tr>';
foreach ( $wp_user_search->results as $user ) {
$user_object = new Instructor( $user->data->ID );
$html .= '<tr>';
$html .= '<td>'.$user_object->user_login.'</td>';
$html .= '<td>'.$user_object->first_name.'</td>';
$html .= '<td>'.$user_object->last_name.'</td>';
$html .= '<td>'.$user_object->user_registered.'</td>';
$html .= '<td>'.$user_object->courses_number.'</td>';
$html .= '</tr>';
}
$html .= '</table>';
$html .= '<style>.instructor_list td, .instructor_list th{width: 20% !important; text-align:center}</style>';
return $html;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment