@@ -7130,8 +7130,6 @@ public function array_only( $array = array(), $keys = null ) {
71307130 * @return bool|int
71317131 */
71327132 public function is_instructor_of_this_course ( $ instructor_id = 0 , $ course_id = 0 , $ is_approved = true ) {
7133- global $ wpdb ;
7134-
71357133 $ instructor_id = $ this ->get_user_id ( $ instructor_id );
71367134 $ course_id = $ this ->get_post_id ( $ course_id );
71377135
@@ -7143,40 +7141,36 @@ public function is_instructor_of_this_course( $instructor_id = 0, $course_id = 0
71437141 $ instructor = TutorCache::get ( $ cache_key );
71447142
71457143 if ( false === $ instructor ) {
7144+ $ meta_query_args = array (
7145+ array (
7146+ 'key ' => '_tutor_instructor_course_id ' ,
7147+ 'value ' => $ course_id ,
7148+ 'compare ' => '= ' ,
7149+ 'type ' => 'NUMERIC ' ,
7150+ ),
7151+ );
71467152
71477153 if ( $ is_approved ) {
7148- $ is_approved_instructor = (int ) $ wpdb ->get_var (
7149- $ wpdb ->prepare (
7150- "SELECT COUNT(umeta_id)
7151- FROM {$ wpdb ->usermeta }
7152- WHERE user_id = %d
7153- AND meta_key = %s
7154- AND meta_value = %s " ,
7155- $ instructor_id ,
7156- '_tutor_instructor_status ' ,
7157- 'approved ' ,
7158- )
7154+ $ meta_query_args [] = array (
7155+ 'key ' => '_tutor_instructor_status ' ,
7156+ 'value ' => 'approved ' ,
7157+ 'compare ' => '= ' ,
71597158 );
7160-
7161- if ( ! $ is_approved_instructor ) {
7162- return false ;
7163- }
71647159 }
71657160
7166- //phpcs:disable
7167- $ instructor = $ wpdb ->get_col (
7168- $ wpdb ->prepare (
7169- "SELECT umeta_id
7170- FROM {$ wpdb ->usermeta }
7171- WHERE user_id = %d
7172- AND meta_key = '_tutor_instructor_course_id'
7173- AND meta_value = %d
7174- " ,
7175- $ instructor_id ,
7176- $ course_id
7177- )
7161+ $ meta_query_args ['relation ' ] = 'AND ' ;
7162+ $ meta_query = new \WP_Meta_Query ( $ meta_query_args );
7163+ $ instructor_query = new \WP_User_Query (
7164+ array (
7165+ 'include ' => array ( $ instructor_id ),
7166+ 'number ' => 1 ,
7167+ 'fields ' => 'ID ' ,
7168+ 'count_total ' => false ,
7169+ 'meta_query ' => $ meta_query ->queries ,
7170+ )
71787171 );
7179- //phpcs:enable
7172+
7173+ $ instructor = $ instructor_query ->get_results ();
71807174
71817175 TutorCache::set ( $ cache_key , $ instructor );
71827176 }
0 commit comments