So I have been using the theme Vilan from ThemeForest. Along with the theme come a couple of plugins, of which one is Revolution Slider. I'm also using Bedrock by Roots. I'm getting the following error:
Notice: wpdb::prepare was called incorrectly. The query argument of wpdb::prepare() must have a placeholder. Please see Debugging in WordPress for more information. (This message was added in version 3.9.) in /Applications/MAMP/htdocs/localppl/web/wp/wp-includes/functions.php on line 3547.
It wouldn't bother me except that the WordPress Gallery gets stuck on loading whenever displaying on grid mode. I found out the error is coming from Revolution slider, because I turned it off and on and the problem would appear and disappear whenever I did so. I tried to track back the problem and I found it would work fine once I removed the code below. Now, I'm sure the problem is with the database call, but I don't know how to fix it (I'll use a child theme to replace the filter).
It works fine once I remove the prepare call, but I read that it is used to prevent SQL injections. Even if, I still want to learn how to fix this while using it, if possible.
if (is_plugin_active('revslider/revslider.php')) {
global $wpdb;
$rs_table_name = $wpdb->prefix . "revslider_sliders";
$rs = $wpdb->get_results( $wpdb->prepare("SELECT id, title, alias FROM $rs_table_name ORDER BY id ASC LIMIT 999", '') );
$revsliders = array();
if ($rs) {
foreach ( $rs as $slider ) {
$revsliders[$slider->alias] = $slider->alias;
}
} else {
$revsliders["No sliders found"] = 0;
}
// Page header slideshow metabox
$meta_boxes[] = array(
// Meta box id, UNIQUE per meta box. Optional since 4.1.5
'id' => 'general_page_header_slideshow_meta',
// Meta box title - Will appear at the drag and drop handle bar. Required.
'title' => __( 'Page Header Slideshow', 'okthemes' ),
// Post types, accept custom post types as well - DEFAULT is array('post'). Optional.
'pages' => array( 'page' ),
// Where the meta box appear: normal (default), advanced, side. Optional.
'context' => 'normal',
// Order of meta box: high (default), low. Optional.
'priority' => 'high',
// Auto save: true, false (default). Optional.
'autosave' => true,
// List of meta fields
'fields' => array(
array(
'name' => 'Page header slider',
'id' => "{$prefix}page_header_slider",
'desc' => 'Enable/Disable page header slider.',
'std' => 0,
'type' => 'checkbox',
),
// SELECT BOX
array(
'name' => __( 'Select the page header slider', 'okthemes' ),
'id' => "{$prefix}page_header_slider_select",
'type' => 'select',
// Array of 'value' => 'Label' pairs for select box
'options' => $revsliders,
// Select multiple values, optional. Default is false.
'multiple' => false,
'std' => '',
'placeholder' => __( 'Select a slider', 'okthemes' ),
),
),
);
} //end check for rev slider
prepare
. a query isn't injectable if it doesn't take any input, there are no arguments to prepare.