@@ -7145,11 +7145,9 @@ public function array_only( $array = array(), $keys = null ) {
71457145 * @param int $course_id course id.
71467146 * @param bool $is_approved is approved.
71477147 *
7148- * @return bool|int
7148+ * @return bool
71497149 */
71507150 public function is_instructor_of_this_course ( $ instructor_id = 0 , $ course_id = 0 , $ is_approved = true ) {
7151- global $ wpdb ;
7152-
71537151 $ instructor_id = $ this ->get_user_id ( $ instructor_id );
71547152 $ course_id = $ this ->get_post_id ( $ course_id );
71557153
@@ -7161,46 +7159,42 @@ public function is_instructor_of_this_course( $instructor_id = 0, $course_id = 0
71617159 $ instructor = TutorCache::get ( $ cache_key );
71627160
71637161 if ( false === $ instructor ) {
7162+ $ meta_query_args = array (
7163+ array (
7164+ 'key ' => '_tutor_instructor_course_id ' ,
7165+ 'value ' => $ course_id ,
7166+ 'compare ' => '= ' ,
7167+ 'type ' => 'NUMERIC ' ,
7168+ ),
7169+ );
71647170
71657171 if ( $ is_approved ) {
7166- $ is_approved_instructor = (int ) $ wpdb ->get_var (
7167- $ wpdb ->prepare (
7168- "SELECT COUNT(umeta_id)
7169- FROM {$ wpdb ->usermeta }
7170- WHERE user_id = %d
7171- AND meta_key = %s
7172- AND meta_value = %s " ,
7173- $ instructor_id ,
7174- '_tutor_instructor_status ' ,
7175- 'approved ' ,
7176- )
7172+ $ meta_query_args [] = array (
7173+ 'key ' => '_tutor_instructor_status ' ,
7174+ 'value ' => 'approved ' ,
7175+ 'compare ' => '= ' ,
71777176 );
7178-
7179- if ( ! $ is_approved_instructor ) {
7180- return false ;
7181- }
71827177 }
71837178
7184- //phpcs:disable
7185- $ instructor = $ wpdb ->get_col (
7186- $ wpdb ->prepare (
7187- "SELECT umeta_id
7188- FROM {$ wpdb ->usermeta }
7189- WHERE user_id = %d
7190- AND meta_key = '_tutor_instructor_course_id'
7191- AND meta_value = %d
7192- " ,
7193- $ instructor_id ,
7194- $ course_id
7195- )
7179+ $ meta_query_args ['relation ' ] = 'AND ' ;
7180+ $ meta_query = new \WP_Meta_Query ( $ meta_query_args );
7181+ $ instructor_query = new \WP_User_Query (
7182+ array (
7183+ 'include ' => array ( $ instructor_id ),
7184+ 'number ' => 1 ,
7185+ 'fields ' => 'ID ' ,
7186+ 'count_total ' => false ,
7187+ 'meta_query ' => $ meta_query ->queries ,
7188+ )
71967189 );
7197- //phpcs:enable
7190+
7191+ $ instructor = $ instructor_query ->get_results ();
71987192
71997193 TutorCache::set ( $ cache_key , $ instructor );
72007194 }
72017195
7202- if ( is_array ( $ instructor ) && count ( $ instructor ) ) {
7203- return $ instructor ;
7196+ if ( $ this -> count ( $ instructor ) ) {
7197+ return true ;
72047198 }
72057199
72067200 return false ;
0 commit comments