@@ -60,7 +60,7 @@ public function __construct( $file ) {
60
60
*/
61
61
public function __get ( $ key ) {
62
62
if ( 'name ' === $ key ) {
63
- _doing_it_wrong ( __CLASS__ . '->name ' , 'The "name" property is deprecated. Use get_name() instead. ' , '$$next-version$$ ' );
63
+ _doing_it_wrong ( __CLASS__ . '->name ' , 'The "name" property is deprecated. Use get_name() instead. ' , '4.24.5 ' );
64
64
65
65
return $ this ->get_name ();
66
66
}
@@ -567,17 +567,21 @@ public function count_statuses( $args = array() ) {
567
567
568
568
$ cache_key = 'sensei-statuses- ' . md5 ( wp_json_encode ( $ args ) );
569
569
570
- $ query = "SELECT comment_approved, COUNT( * ) AS total FROM {$ wpdb ->comments } WHERE comment_type = %s " ;
570
+ $ query = $ wpdb -> prepare ( "SELECT comment_approved, COUNT( * ) AS total FROM {$ wpdb ->comments } WHERE comment_type = %s " , $ type ) ;
571
571
572
572
// Restrict to specific posts.
573
573
if ( isset ( $ args ['post__in ' ] ) && ! empty ( $ args ['post__in ' ] ) && is_array ( $ args ['post__in ' ] ) ) {
574
- $ query .= ' AND comment_post_ID IN ( ' . implode ( ', ' , array_map ( 'absint ' , $ args ['post__in ' ] ) ) . ') ' ;
574
+ $ post__in_placeholder = implode ( ', ' , array_fill ( 0 , count ( $ args ['post__in ' ] ), '%d ' ) );
575
+ // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare -- Placeholders created dynamically.
576
+ $ query .= $ wpdb ->prepare ( " AND comment_post_ID IN ( $ post__in_placeholder ) " , $ args ['post__in ' ] );
575
577
} elseif ( ! empty ( $ args ['post_id ' ] ) ) {
576
578
$ query .= $ wpdb ->prepare ( ' AND comment_post_ID = %d ' , $ args ['post_id ' ] );
577
579
}
578
580
// Restrict to specific users.
579
581
if ( isset ( $ args ['user_id ' ] ) && is_array ( $ args ['user_id ' ] ) ) {
580
- $ query .= ' AND user_id IN ( ' . implode ( ', ' , array_map ( 'absint ' , $ args ['user_id ' ] ) ) . ') ' ;
582
+ $ user_id_placeholder = implode ( ', ' , array_fill ( 0 , count ( $ args ['user_id ' ] ), '%d ' ) );
583
+ // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare -- Placeholders created dynamically.
584
+ $ query .= $ wpdb ->prepare ( " AND user_id IN ( $ user_id_placeholder ) " , $ args ['user_id ' ] );
581
585
} elseif ( ! empty ( $ args ['user_id ' ] ) ) {
582
586
$ query .= $ wpdb ->prepare ( ' AND user_id = %d ' , $ args ['user_id ' ] );
583
587
}
@@ -589,8 +593,8 @@ public function count_statuses( $args = array() ) {
589
593
590
594
$ counts = wp_cache_get ( $ cache_key , 'counts ' );
591
595
if ( false === $ counts ) {
592
- $ sql = $ wpdb -> prepare ( $ query , $ type );
593
- $ results = (array ) $ wpdb ->get_results ( $ sql , ARRAY_A );
596
+ // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- SQL prepared in advance.
597
+ $ results = (array ) $ wpdb ->get_results ( $ query , ARRAY_A );
594
598
$ counts = array_fill_keys ( $ this ->get_stati ( $ type ), 0 );
595
599
596
600
foreach ( $ results as $ row ) {
@@ -1273,16 +1277,13 @@ public static function grade_gap_fill_question( $question_id, $user_answer ) {
1273
1277
* @return int $number_of_graded_lessons
1274
1278
*/
1275
1279
public static function get_graded_lessons_count () {
1276
-
1277
1280
global $ wpdb ;
1278
1281
1279
- $ comment_query_piece = [];
1280
- $ comment_query_piece ['select ' ] = 'SELECT COUNT(*) AS total ' ;
1281
- $ comment_query_piece ['from ' ] = " FROM {$ wpdb ->comments } INNER JOIN {$ wpdb ->commentmeta } ON ( {$ wpdb ->comments }.comment_ID = {$ wpdb ->commentmeta }.comment_id ) " ;
1282
- $ comment_query_piece ['where ' ] = " WHERE {$ wpdb ->comments }.comment_type IN ('sensei_lesson_status') AND ( {$ wpdb ->commentmeta }.meta_key = 'grade') " ;
1283
-
1284
- $ comment_query = $ comment_query_piece ['select ' ] . $ comment_query_piece ['from ' ] . $ comment_query_piece ['where ' ];
1285
- $ number_of_graded_lessons = intval ( $ wpdb ->get_var ( $ comment_query , 0 , 0 ) );
1282
+ $ number_of_graded_lessons = (int ) $ wpdb ->get_var (
1283
+ "SELECT COUNT(*) AS total
1284
+ FROM {$ wpdb ->comments } INNER JOIN {$ wpdb ->commentmeta } ON ( {$ wpdb ->comments }.comment_ID = {$ wpdb ->commentmeta }.comment_id )
1285
+ WHERE {$ wpdb ->comments }.comment_type IN ('sensei_lesson_status') AND ( {$ wpdb ->commentmeta }.meta_key = 'grade') "
1286
+ );
1286
1287
1287
1288
return $ number_of_graded_lessons ;
1288
1289
}
@@ -1291,22 +1292,18 @@ public static function get_graded_lessons_count() {
1291
1292
* Add together all the graded lesson grades
1292
1293
*
1293
1294
* @since 1.9.0
1294
- * @return double $sum_of_all_grades
1295
+ * @return int $sum_of_all_grades
1295
1296
*/
1296
1297
public static function get_graded_lessons_sum () {
1297
-
1298
1298
global $ wpdb ;
1299
1299
1300
- $ comment_query_piece = [];
1301
- $ comment_query_piece ['select ' ] = "SELECT SUM( {$ wpdb ->commentmeta }.meta_value) AS meta_sum " ;
1302
- $ comment_query_piece ['from ' ] = " FROM {$ wpdb ->comments } INNER JOIN {$ wpdb ->commentmeta } ON ( {$ wpdb ->comments }.comment_ID = {$ wpdb ->commentmeta }.comment_id ) " ;
1303
- $ comment_query_piece ['where ' ] = " WHERE {$ wpdb ->comments }.comment_type IN ('sensei_lesson_status') AND ( {$ wpdb ->commentmeta }.meta_key = 'grade') " ;
1304
-
1305
- $ comment_query = $ comment_query_piece ['select ' ] . $ comment_query_piece ['from ' ] . $ comment_query_piece ['where ' ];
1306
- $ sum_of_all_grades = intval ( $ wpdb ->get_var ( $ comment_query , 0 , 0 ) );
1300
+ $ sum_of_all_grades = (int ) $ wpdb ->get_var (
1301
+ "SELECT SUM( {$ wpdb ->commentmeta }.meta_value) AS meta_sum
1302
+ FROM {$ wpdb ->comments } INNER JOIN {$ wpdb ->commentmeta } ON ( {$ wpdb ->comments }.comment_ID = {$ wpdb ->commentmeta }.comment_id )
1303
+ WHERE {$ wpdb ->comments }.comment_type IN ('sensei_lesson_status') AND ( {$ wpdb ->commentmeta }.meta_key = 'grade') "
1304
+ );
1307
1305
1308
1306
return $ sum_of_all_grades ;
1309
-
1310
1307
}
1311
1308
1312
1309
/**
@@ -1339,19 +1336,19 @@ public function get_graded_lessons_average_grade() {
1339
1336
*
1340
1337
* @since 1.9.0
1341
1338
* @param $user_id
1342
- * @return double
1339
+ * @return int
1343
1340
*/
1344
1341
public static function get_user_graded_lessons_sum ( $ user_id ) {
1345
1342
global $ wpdb ;
1346
1343
1347
- $ clean_user_id = esc_sql ( $ user_id );
1348
- $ comment_query_piece = [];
1349
- $ comment_query_piece [ ' select ' ] = "SELECT SUM( {$ wpdb ->commentmeta }.meta_value) AS meta_sum " ;
1350
- $ comment_query_piece [ ' from ' ] = " FROM {$ wpdb ->comments } INNER JOIN {$ wpdb ->commentmeta } ON ( {$ wpdb ->comments }.comment_ID = {$ wpdb ->commentmeta }.comment_id ) " ;
1351
- $ comment_query_piece [ ' where ' ] = " WHERE {$ wpdb ->comments }.comment_type IN ('sensei_lesson_status') AND ( {$ wpdb ->commentmeta }.meta_key = 'grade') AND {$ wpdb ->comments }.user_id = { $ clean_user_id } " ;
1352
-
1353
- $ comment_query = $ comment_query_piece [ ' select ' ] . $ comment_query_piece [ ' from ' ] . $ comment_query_piece [ ' where ' ];
1354
- $ sum_of_all_grades = intval ( $ wpdb -> get_var ( $ comment_query , 0 , 0 ) );
1344
+ $ sum_of_all_grades = ( int ) $ wpdb -> get_var (
1345
+ $ wpdb -> prepare (
1346
+ "SELECT SUM( {$ wpdb ->commentmeta }.meta_value) AS meta_sum
1347
+ FROM {$ wpdb ->comments } INNER JOIN {$ wpdb ->commentmeta } ON ( {$ wpdb ->comments }.comment_ID = {$ wpdb ->commentmeta }.comment_id )
1348
+ WHERE {$ wpdb ->comments }.comment_type IN ('sensei_lesson_status') AND ( {$ wpdb ->commentmeta }.meta_key = 'grade') AND {$ wpdb ->comments }.user_id = %d " ,
1349
+ $ user_id
1350
+ )
1351
+ );
1355
1352
1356
1353
return $ sum_of_all_grades ;
1357
1354
}
@@ -1362,23 +1359,21 @@ public static function get_user_graded_lessons_sum( $user_id ) {
1362
1359
* @since 1.9.0
1363
1360
*
1364
1361
* @param int lesson_id
1365
- * @return double
1362
+ * @return int
1366
1363
*/
1367
1364
public static function get_lessons_users_grades_sum ( $ lesson_id ) {
1368
-
1369
1365
global $ wpdb ;
1370
1366
1371
- $ clean_lesson_id = esc_sql ( $ lesson_id );
1372
- $ comment_query_piece = [];
1373
- $ comment_query_piece [ ' select ' ] = "SELECT SUM( {$ wpdb ->commentmeta }.meta_value) AS meta_sum " ;
1374
- $ comment_query_piece [ ' from ' ] = " FROM {$ wpdb ->comments } INNER JOIN {$ wpdb ->commentmeta } ON ( {$ wpdb ->comments }.comment_ID = {$ wpdb ->commentmeta }.comment_id ) " ;
1375
- $ comment_query_piece [ ' where ' ] = " WHERE {$ wpdb ->comments }.comment_type IN ('sensei_lesson_status') AND ( {$ wpdb ->commentmeta }.meta_key = 'grade') AND {$ wpdb ->comments }.comment_post_ID = { $ clean_lesson_id } " ;
1376
-
1377
- $ comment_query = $ comment_query_piece [ ' select ' ] . $ comment_query_piece [ ' from ' ] . $ comment_query_piece [ ' where ' ];
1378
- $ sum_of_all_grades = intval ( $ wpdb -> get_var ( $ comment_query , 0 , 0 ) );
1367
+ $ sum_of_all_grades = ( int ) $ wpdb -> get_var (
1368
+ $ wpdb -> prepare (
1369
+ "SELECT SUM( {$ wpdb ->commentmeta }.meta_value) AS meta_sum
1370
+ FROM {$ wpdb ->comments } INNER JOIN {$ wpdb ->commentmeta } ON ( {$ wpdb ->comments }.comment_ID = {$ wpdb ->commentmeta }.comment_id )
1371
+ WHERE {$ wpdb ->comments }.comment_type IN ('sensei_lesson_status') AND ( {$ wpdb ->commentmeta }.meta_key = 'grade') AND {$ wpdb ->comments }.comment_post_ID = %d " ,
1372
+ $ lesson_id
1373
+ )
1374
+ );
1379
1375
1380
1376
return $ sum_of_all_grades ;
1381
-
1382
1377
}
1383
1378
1384
1379
/**
@@ -1387,29 +1382,31 @@ public static function get_lessons_users_grades_sum( $lesson_id ) {
1387
1382
* @since 1.9.0
1388
1383
*
1389
1384
* @param int $course_id
1390
- * @return double
1385
+ * @return int
1391
1386
*/
1392
1387
public static function get_course_users_grades_sum ( $ course_id ) {
1393
1388
global $ wpdb ;
1394
1389
1395
1390
$ lesson_ids = Sensei ()->course ->course_lessons ( $ course_id , 'any ' , 'ids ' );
1396
-
1397
1391
if ( ! $ lesson_ids ) {
1398
1392
return 0 ;
1399
1393
}
1400
1394
1401
- $ comment_query_piece = [];
1402
- $ clean_lesson_ids = implode ( ', ' , esc_sql ( $ lesson_ids ) );
1403
- $ comment_query_piece ['select ' ] = "SELECT SUM( {$ wpdb ->commentmeta }.meta_value) AS meta_sum " ;
1404
- $ comment_query_piece ['from ' ] = " FROM {$ wpdb ->comments } INNER JOIN {$ wpdb ->commentmeta } ON ( {$ wpdb ->comments }.comment_ID = {$ wpdb ->commentmeta }.comment_id ) " ;
1405
- $ comment_query_piece ['where ' ] = " WHERE {$ wpdb ->comments }.comment_type IN ('sensei_lesson_status') AND {$ wpdb ->comments }.comment_approved IN ('graded', 'passed', 'failed') AND ( {$ wpdb ->commentmeta }.meta_key = 'grade')
1406
- AND {$ wpdb ->comments }.comment_post_ID IN ( {$ clean_lesson_ids }) " ;
1395
+ $ lesson_ids_placeholder = implode ( ', ' , array_fill ( 0 , count ( $ lesson_ids ), '%d ' ) );
1407
1396
1408
- $ comment_query = $ comment_query_piece ['select ' ] . $ comment_query_piece ['from ' ] . $ comment_query_piece ['where ' ];
1409
- $ sum_of_all_grades = intval ( $ wpdb ->get_var ( $ comment_query , 0 , 0 ) );
1397
+ // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare -- Placeholders created dynamically.
1398
+ $ sum_of_all_grades = (int ) $ wpdb ->get_var (
1399
+ $ wpdb ->prepare (
1400
+ "SELECT SUM( {$ wpdb ->commentmeta }.meta_value) AS meta_sum
1401
+ FROM {$ wpdb ->comments } INNER JOIN {$ wpdb ->commentmeta } ON ( {$ wpdb ->comments }.comment_ID = {$ wpdb ->commentmeta }.comment_id )
1402
+ WHERE {$ wpdb ->comments }.comment_type IN ('sensei_lesson_status') AND {$ wpdb ->comments }.comment_approved IN ('graded', 'passed', 'failed') AND ( {$ wpdb ->commentmeta }.meta_key = 'grade')
1403
+ AND {$ wpdb ->comments }.comment_post_ID IN ( {$ lesson_ids_placeholder }) " ,
1404
+ $ lesson_ids
1405
+ )
1406
+ );
1407
+ // phpcs:enable WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
1410
1408
1411
1409
return $ sum_of_all_grades ;
1412
-
1413
1410
}
1414
1411
1415
1412
/**
0 commit comments