elementor / wp2static

WordPress static site generator for security, performance and cost benefits
https://wp2static.com
The Unlicense
1.43k stars 272 forks source link

Notice on Addons page with v7.2 #896

Open Olwyne opened 1 year ago

Olwyne commented 1 year ago

Describe the bug

On WP2Static 7.2, the following notice appears above the Addons page :

Notice: Function wpdb::prepare was called incorrectly. The query argument of wpdb::prepare() must have a placeholder. Please see [Debugging in WordPress](https://wordpress.org/support/article/debugging-in-wordpress/) for more information. (This message was added in version 3.9.0.) in /var/www/html/wp-includes/functions.php on line 5835

This is due to Addons.php (line 53) file building a query string without a %s placeholder in the case where $type === 'all'

public static function getAll( string $type = 'all' ) : array {
        global $wpdb;

        $table_name = $wpdb->prefix . 'wp2static_addons';

        $query_string = "SELECT * FROM $table_name";
        $query_params = [];
        if ( $type !== 'all' ) {
            $query_string .= ' WHERE type = %s';
            $query_params[] = $type;
        }
        $query_string .= ' ORDER BY type DESC';

        return $wpdb->get_results(
            $wpdb->prepare( $query_string, $query_params )
        );
    }

To Reproduce Steps to reproduce the behavior:

  1. Go to Addons page (with debug mode on)
  2. See notice

Expected behavior No notice should appear on the Addons page

Screenshots

Capture d’écran 2023-02-23 à 16 47 19

Environment (please complete the following information):