Commit ca24bafd authored by Noemie Kerroux's avatar Noemie Kerroux

Fix forbidden templates

parent 0418d0af
......@@ -121,6 +121,8 @@ class WPGlobalSearch {
(" . $post_metas_likes . ")
AND
pm.meta_key NOT LIKE '_wp_page_template'
AND
pm.post_id NOT IN " . self::get_formatted_sql_element_ids($default_args['forbidden_templates']) . "
)
)";
......@@ -162,6 +164,29 @@ class WPGlobalSearch {
$results .= ")";
return $results;
}
public static function get_formatted_sql_element_ids($array = []){
$results = "(";
foreach ($array as $key => $apt) {
$post_id = self::wp_search_get_template_id($apt);
if(!empty($post_id)) {
$results .= "'" . $post_id . "'";
if($apt !== end($array)){
$results .= ',';
}
}
}
$results .= ")";
return $results;
}
public static function wp_search_get_template_id($template_string)
{
// $template_string - Ex : template-products.php
global $wpdb;
$template_id = $wpdb->get_var("SELECT pm.post_id FROM {$wpdb->base_prefix}postmeta pm, {$wpdb->base_prefix}posts p WHERE pm.meta_key = '_wp_page_template' AND pm.meta_value = '" . $template_string . "' AND p.post_status = 'publish' AND p.ID = pm.post_id");
return $template_id;
}
}
?>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment