| @@ -196,11 +196,39 @@ | ||
| 196 | 196 | */ |
| 197 | 197 | add_action( 'trashed_post', __CLASS__ . '::redirect_to_course_list_page' ); |
| 198 | 198 | |
| 199 | 199 | add_filter( 'tutor_enroll_required_login_class', array( $this, 'add_enroll_required_login_class' ) ); |
| 200 | + /** | |
| 201 | + * Remove wp trash button if instructor settings is disabled | |
| 202 | + * | |
| 203 | + * @since 2.7.3 | |
| 204 | + */ | |
| 205 | + add_action( 'admin_init', array( $this, 'disable_course_trash_instructor' ) ); | |
| 200 | 206 | } |
| 201 | 207 | |
| 202 | 208 | /** |
| 209 | + * Remove move to trash button on WordPress editor for instructor. | |
| 210 | + * | |
| 211 | + * @since 2.7.3 | |
| 212 | + * | |
| 213 | + * @return void | |
| 214 | + */ | |
| 215 | + public function disable_course_trash_instructor() { | |
| 216 | + if ( current_user_can( 'edit_tutor_course' ) && ! current_user_can( 'administrator' ) ) { | |
| 217 | + $can_trash_post = tutor_utils()->get_option( 'instructor_can_delete_course' ); | |
| 218 | + $role = get_role( tutor()->instructor_role ); | |
| 219 | + | |
| 220 | + if ( ! $can_trash_post ) { | |
| 221 | + $role->remove_cap( 'delete_tutor_courses' ); | |
| 222 | + $role->remove_cap( 'delete_tutor_course' ); | |
| 223 | + } else { | |
| 224 | + $role->add_cap( 'delete_tutor_courses' ); | |
| 225 | + $role->add_cap( 'delete_tutor_course' ); | |
| 226 | + } | |
| 227 | + } | |
| 228 | + } | |
| 229 | + | |
| 230 | + /** | |
| 203 | 231 | * Add enroll require login class |
| 204 | 232 | * |
| 205 | 233 | * @since 2.6.0 |
| 206 | 234 | * |
| @@ -943,9 +971,28 @@ | ||
| 943 | 971 | if ( false === CourseModel::is_main_instructor( $course_id ) ) { |
| 944 | 972 | wp_send_json_error( array( 'message' => __( 'Only main instructor can delete this course', 'tutor' ) ) ); |
| 945 | 973 | } |
| 946 | 974 | |
| 947 | - CourseModel::delete_course( $course_id ); | |
| 975 | + // Check if user is only an instructor. | |
| 976 | + if ( ! current_user_can( 'administrator' ) ) { | |
| 977 | + // Check if instructor can trash course. | |
| 978 | + $can_trash_post = tutor_utils()->get_option( 'instructor_can_delete_course' ); | |
| 979 | + | |
| 980 | + if ( ! $can_trash_post ) { | |
| 981 | + wp_send_json_error( tutor_utils()->error_message() ); | |
| 982 | + } | |
| 983 | + } | |
| 984 | + | |
| 985 | + $trash_course = wp_update_post( | |
| 986 | + array( | |
| 987 | + 'ID' => $course_id, | |
| 988 | + 'post_status' => 'trash', | |
| 989 | + ) | |
| 990 | + ); | |
| 991 | + | |
| 992 | + if ( $trash_course ) { | |
| 993 | + wp_send_json_success( __( 'Course has been trashed successfully ', 'tutor' ) ); | |
| 994 | + } | |
| 948 | 995 | wp_send_json_success(); |
| 949 | 996 | } |
| 950 | 997 | |
| 951 | 998 | /** |