79717416

Date: 2025-07-28 13:48:01
Score: 0.5
Natty:
Report link

You're mostly doing it right, but the Plugin Check Plugin (PCP) warning occurs because you're building the SQL string before passing it into $wpdb->prepare() — and this confuses static analyzers like Plugin Check.

Here’s the problem line:

$sql = "SELECT COUNT(*) FROM {$table1} WHERE section_course_id = %d";

$query = $db->wpdb->prepare( $sql, $post_id );

Even though $table1 is safe (likely a constant or controlled variable), tools like PCP expect everything except placeholders to be inside $wpdb->prepare() to enforce best practices.

Fix Properly

Use sprintf() to inject the table name (since placeholders cannot be used for table names), then pass the resulting query string into $wpdb->prepare() with only values substituted through placeholders.

Fixed Code:

$db = STEPUP_Database::getInstance();

$table1 = $db->tb_lp_sections;

$sql = sprintf("SELECT COUNT(*) FROM %s WHERE section_course_id = %%d", $table1);

$query = $db->wpdb->prepare($sql, $post_id);

$result = $db->wpdb->get_var($query);

Note the double percent sign (%%d) inside sprintf() which escapes %d so that it remains available for $wpdb->prepare() to process.

Why This Works

Summary

References

Reasons:
  • Long answer (-1):
  • No code block (0.5):
  • Low reputation (1):
Posted by: Aasif Khan