Skip to content

Commit

Permalink
Merge pull request #939 from woothemes/release-1-8-4
Browse files Browse the repository at this point in the history
Relase 1.8.4
  • Loading branch information
dwainm committed Jun 10, 2015
2 parents 799e369 + 9b591fa commit 74f237a
Show file tree
Hide file tree
Showing 14 changed files with 140 additions and 47 deletions.
2 changes: 1 addition & 1 deletion assets/js/learners-general.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ jQuery(document).ready( function($) {
url: ajaxurl,
dataType: 'json',
afterTypeDelay: 100,
minTermLength: 1,
minTermLength: 3,
data: ajaxData
}, function (data) {

Expand Down
2 changes: 1 addition & 1 deletion assets/js/learners-general.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
*** Sensei Changelog ***

2015.06.11 - version 1.8.4
* Fix - Query post type changes for non Sensei queries. Added better checking to ensure this
query filter only applies to teachers.
* Fix - Performance issues on the all courses page with a large user base.
* Fix - Performance: user ajax search timed out due to large user base. Enforce minimum string search length.
* Fix - Update all instances of 'numberofposts' with 'posts_per_page'. Also adding and upper
limit as '-1' (unlimited) is not good.

2015.06.05 - version 1.8.3
* Fix - Fixed an issue where only 10 questions could be seen in quizzes
* Tweak - Correctly pluralise the string 'Currently completed x lesson(s) of y in total'
Expand Down
62 changes: 55 additions & 7 deletions classes/class-sensei-teacher.php
Original file line number Diff line number Diff line change
Expand Up @@ -759,14 +759,49 @@ public function limit_grading_totals( $args ){
* @return WP_Query $query
*/
public function add_courses_to_author_archive( $query ) {

if ( is_admin() || ! $query->is_author() ){
return $query;
}

$post_types= array( 'post','course' );
$query->set( 'post_type', $post_types );
// this should only apply to users with the teacher role
$current_page_user = get_user_by('login', $query->get('author_name') );
if( ! $current_page_user || ! in_array('teacher', $current_page_user->roles ) ) {

return $query;

}

// Change post types depending on what is set already
$current_post_types = $query->get( 'post_type' );
if( empty( $current_post_types ) ){

// if empty it means post by default, so add post so that it also includes that for now
$new_post_types = array( 'post', 'course' );

} elseif( is_array( $current_post_types ) ) {

// merge the post types instead of overwriting it
$new_post_types = array_merge( $current_post_types, array( 'course' ) );

}else{

// in this instance it is probably just one post type in string format
$new_post_types = array( $current_post_types , 'course');

}

// change the query before returning it
$query->set('post_type', $new_post_types );

/**
* Change the query on the teacher author archive template
*
* @since 1.8.4
* @param WP_Query $query
*/
return apply_filters( 'sensei_teacher_archive_query', $query );

return $query;
}

/**
Expand Down Expand Up @@ -1180,16 +1215,29 @@ public function course_teacher_filter_options() {
return;
}

$all_users = get_users();
// get all roles
$roles = get_editable_roles();

// get roles with the course edit capability
// and then get the users with those roles
$users_who_can_edit_courses = array();
foreach( $roles as $role_item ){

$role = get_role( strtolower( $role_item['name'] ) );

foreach( $all_users as $user ){
if( is_a( $role, 'WP_Role' ) && $role->has_cap('edit_courses') ){

$user_query_args = array( 'role' => $role->name, 'fields' => array( 'ID', 'display_name' ) );
$role_users_who_can_edit_courses = get_users( $user_query_args );

// add user from the current $user_role to all users
$users_who_can_edit_courses = array_merge( $users_who_can_edit_courses, $role_users_who_can_edit_courses );

if($user->has_cap('edit_courses')){
$users_who_can_edit_courses[] = $user;
}

}

// Create the select element with the given users who can edit course
$selected = isset( $_GET['course_teacher'] ) ? $_GET['course_teacher'] : '';
$course_options = '';
foreach( $users_who_can_edit_courses as $user ) {
Expand Down
16 changes: 8 additions & 8 deletions classes/class-woothemes-sensei-course.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public function course_woocommerce_product_meta_box_content () {
$select_course_woocommerce_product = get_post_meta( $post->ID, '_course_woocommerce_product', true );

$post_args = array( 'post_type' => array( 'product', 'product_variation' ),
'numberposts' => -1,
'posts_per_page' => -1,
'orderby' => 'title',
'order' => 'DESC',
'exclude' => $post->ID,
Expand Down Expand Up @@ -231,7 +231,7 @@ public function course_prerequisite_meta_box_content () {
$select_course_prerequisite = get_post_meta( $post->ID, '_course_prerequisite', true );

$post_args = array( 'post_type' => 'course',
'numberposts' => -1,
'posts_per_page' => -1,
'orderby' => 'title',
'order' => 'DESC',
'exclude' => $post->ID,
Expand Down Expand Up @@ -837,7 +837,7 @@ public function course_lessons( $course_id = 0, $post_status = 'publish', $field
$lessons = array();

$post_args = array( 'post_type' => 'lesson',
'posts_per_page' => 500,
'posts_per_page' => -1,
'orderby' => 'date',
'order' => 'ASC',
'meta_query' => array(
Expand Down Expand Up @@ -976,7 +976,7 @@ public function course_author_lesson_count( $author_id = 0, $course_id = 0 ) {
$count = 0;

$lesson_args = array( 'post_type' => 'lesson',
'numberposts' => -1,
'posts_per_page' => -1,
'author' => $author_id,
'meta_key' => '_lesson_course',
'meta_value' => $course_id,
Expand All @@ -1002,7 +1002,7 @@ public function course_lesson_count( $course_id = 0 ) {
$count = 0;

$lesson_args = array( 'post_type' => 'lesson',
'numberposts' => -1,
'posts_per_page' => -1,
'meta_key' => '_lesson_course',
'meta_value' => $course_id,
'post_status' => 'publish',
Expand All @@ -1027,7 +1027,7 @@ public function course_lesson_preview_count( $course_id = 0 ) {
$count = 0;

$lesson_args = array( 'post_type' => 'lesson',
'numberposts' => -1,
'posts_per_page' => -1,
'post_status' => 'publish',
'suppress_filters' => 0,
'meta_query' => array(
Expand Down Expand Up @@ -1061,7 +1061,7 @@ public function get_product_courses( $product_id = 0 ) {
// Check for WooCommerce
if ( WooThemes_Sensei_Utils::sensei_is_woocommerce_activated() && 0 < $product_id ) {
$post_args = array( 'post_type' => 'course',
'numberposts' => -1,
'posts_per_page' => -1,
'meta_key' => '_course_woocommerce_product',
'meta_value' => $product_id,
'post_status' => 'publish',
Expand Down Expand Up @@ -1477,7 +1477,7 @@ public static function get_all_courses(){

$args = array(
'post_type' => 'course',
'posts_per_page' => 5000,
'posts_per_page' => -1,
'orderby' => 'title',
'order' => 'ASC',
'post_status' => 'any',
Expand Down
4 changes: 2 additions & 2 deletions classes/class-woothemes-sensei-grading.php
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ public function courses_drop_down_html( $selected_course_id = 0 ) {
$html = '';

$course_args = array( 'post_type' => 'course',
'numberposts' => -1,
'posts_per_page' => -1,
'orderby' => 'title',
'order' => 'ASC',
'post_status' => 'any',
Expand Down Expand Up @@ -528,7 +528,7 @@ public function lessons_drop_down_html( $course_id = 0, $selected_lesson_id = 0
if ( 0 < intval( $course_id ) ) {

$lesson_args = array( 'post_type' => 'lesson',
'numberposts' => -1,
'posts_per_page' => -1,
'orderby' => 'title',
'order' => 'ASC',
'meta_key' => '_lesson_course',
Expand Down
12 changes: 6 additions & 6 deletions classes/class-woothemes-sensei-lesson.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ public function lesson_prerequisite_meta_box_content () {
$select_lesson_prerequisite = get_post_meta( $post->ID, '_lesson_prerequisite', true );
// Get the Lesson Posts
$post_args = array( 'post_type' => 'lesson',
'numberposts' => -1,
'posts_per_page' => -1,
'orderby' => 'title',
'order' => 'ASC',
'exclude' => $post->ID,
Expand Down Expand Up @@ -507,7 +507,7 @@ public function lesson_course_meta_box_content () {
} // End If Statement
// Get the Lesson Posts
$post_args = array( 'post_type' => 'course',
'numberposts' => -1,
'posts_per_page' => -1,
'orderby' => 'title',
'order' => 'ASC',
'post_status' => 'any',
Expand Down Expand Up @@ -563,7 +563,7 @@ public function lesson_course_meta_box_content () {
$select_course_woocommerce_product = get_post_meta( $post_item->ID, '_course_woocommerce_product', true );

$product_args = array( 'post_type' => array( 'product', 'product_variation' ),
'numberposts' => -1,
'posts_per_page' => -1,
'orderby' => 'title',
'order' => 'DESC',
'post_status' => array( 'publish', 'private', 'draft' ),
Expand Down Expand Up @@ -2583,7 +2583,7 @@ public function lesson_quizzes( $lesson_id = 0, $post_status = 'any', $fields =
$posts_array = array();

$post_args = array( 'post_type' => 'quiz',
'numberposts' => 1,
'posts_per_page' => 1,
'orderby' => 'title',
'order' => 'DESC',
'post_parent' => $lesson_id,
Expand Down Expand Up @@ -2712,7 +2712,7 @@ public function lesson_quiz_questions( $quiz_id = 0, $post_status = 'any', $orde

$qargs = array(
'post_type' => 'question',
'numberposts' => $question_number,
'posts_per_page' => $question_number,
'orderby' => $orderby,
'tax_query' => array(
array(
Expand Down Expand Up @@ -2823,7 +2823,7 @@ public function set_default_question_order( $quiz_id = 0 ) {

$args = array(
'post_type' => 'question',
'numberposts' => -1,
'posts_per_page' => -1,
'orderby' => 'ID',
'order' => 'ASC',
'meta_query' => array(
Expand Down
20 changes: 10 additions & 10 deletions classes/class-woothemes-sensei-updates.php
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ public function assign_role_caps() {
*/
public function set_default_quiz_grade_type() {
$args = array( 'post_type' => 'quiz',
'numberposts' => -1,
'posts_per_page' => -1,
'post_status' => 'publish',
'suppress_filters' => 0
);
Expand All @@ -515,7 +515,7 @@ public function set_default_quiz_grade_type() {
*/
public function set_default_question_type() {
$args = array( 'post_type' => 'question',
'numberposts' => -1,
'posts_per_page' => -1,
'post_status' => 'publish',
'suppress_filters' => 0
);
Expand Down Expand Up @@ -559,7 +559,7 @@ public function update_question_answer_data( $n = 50, $offset = 0 ) {


$args = array( 'post_type' => 'quiz',
'numberposts' => $n,
'posts_per_page' => $n,
'offset' => $offset,
'post_status' => 'publish',
'suppress_filters' => 0
Expand Down Expand Up @@ -642,7 +642,7 @@ public function update_question_answer_data( $n = 50, $offset = 0 ) {
*/
public function update_question_grade_points() {
$args = array( 'post_type' => 'question',
'numberposts' => -1,
'posts_per_page' => -1,
'post_status' => 'publish',
'suppress_filters' => 0
);
Expand All @@ -662,7 +662,7 @@ public function update_question_grade_points() {
*/
public function convert_essay_paste_questions() {
$args = array( 'post_type' => 'question',
'numberposts' => -1,
'posts_per_page' => -1,
'post_status' => 'publish',
'tax_query' => array(
array(
Expand Down Expand Up @@ -708,7 +708,7 @@ public function set_random_question_order( $n = 50, $offset = 0 ) {

$args = array( 'post_type' => 'quiz',
'post_status' => 'any',
'numberposts' => $n,
'posts_per_page' => $n,
'offset' => $offset,
'suppress_filters' => 0
);
Expand Down Expand Up @@ -736,7 +736,7 @@ public function set_default_show_question_count( $n = 50, $offset = 0 ) {

$args = array( 'post_type' => 'quiz',
'post_status' => 'any',
'numberposts' => $n,
'posts_per_page' => $n,
'offset' => $offset,
'meta_key' => '_show_questions',
'suppress_filters' => 0
Expand Down Expand Up @@ -984,7 +984,7 @@ public function update_quiz_lesson_relationship( $n = 50, $offset = 0 ) {

$args = array(
'post_type' => 'quiz',
'numberposts' => $n,
'posts_per_page' => $n,
'offset' => $offset,
'post_status' => 'any'
);
Expand Down Expand Up @@ -1040,7 +1040,7 @@ function status_changes_fix_lessons( $n = 50, $offset = 0 ) {
$args = array(
'post_type' => 'lesson',
'post_status' => 'any',
'numberposts' => $n,
'posts_per_page' => $n,
'offset' => $offset,
'fields' => 'ids'
);
Expand Down Expand Up @@ -1119,7 +1119,7 @@ function status_changes_convert_lessons( $n = 50, $offset = 0 ) {
$args = array(
'post_type' => 'lesson',
'post_status' => 'any',
'numberposts' => -1,
'posts_per_page' => -1,
'meta_query' => array(
array(
'key' => '_quiz_has_questions',
Expand Down
4 changes: 2 additions & 2 deletions classes/class-woothemes-sensei-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ public static function sensei_customer_bought_product ( $customer_email, $user_i
return false;

$orders = get_posts( array(
'numberposts' => -1,
'posts_per_page' => -1,
'meta_key' => '_customer_user',
'meta_value' => intval( $user_id ),
'post_type' => 'shop_order',
Expand Down Expand Up @@ -1086,7 +1086,7 @@ public static function lesson_quiz_questions( $quiz_id = 0 ) {
$questions_array = array();
if ( 0 < $quiz_id ) {
$question_args = array( 'post_type' => 'question',
'numberposts' => -1,
'posts_per_page' => -1,
'orderby' => 'ID',
'order' => 'ASC',
'meta_query' => array(
Expand Down
Loading

0 comments on commit 74f237a

Please sign in to comment.