<commit_before><?php
namespace elasticsearch;

class Category{
	var $searched = false;
	var $total = 0;
	var $scores = array();
	var $page = 1;

	function __construct(){
		add_action('pre_get_posts', array(&$this, 'do_search'));
		add_action('the_posts', array(&$this, 'process_search'));
	}

	function do_search($wp_query){
		$this->searched = false;

		$cats = array();

		$enabled = Config::option('enable_categories');

		if(isset($wp_query->query_vars['category_name']) && !empty($wp_query->query_vars['category_name'])){
			$cat = get_category_by_slug($wp_query->query_vars['category_name']);

			if(!in_array($cat->term_id, $enabled)){
				return;
			}

			$cats[] = $cat;
		}

		if(isset($wp_query->query_vars['cat'])){
			$catids = explode(',', $wp_query->query_vars['cat']);

			foreach($catids as $id){
				if(!in_array($id, $enabled)){
					return;
				}

				$cats[] = get_category($id);
			}
		}
		
		if(!$wp_query->is_main_query() || !(is_tax() || !empty($cats)) || is_admin() || !$enabled){
			return;
		}
<commit_msg>Updated to check enabled flag before trying to use it as an array when it could be null or false.<commit_after><?php
namespace elasticsearch;

class Category{
	var $searched = false;
	var $total = 0;
	var $scores = array();
	var $page = 1;

	function __construct(){
		add_action('pre_get_posts', array(&$this, 'do_search'));
		add_action('the_posts', array(&$this, 'process_search'));
	}

	function do_search($wp_query){
		$this->searched = false;

		$cats = array();

		$enabled = Config::option('enable_categories');
		
		if(!$wp_query->is_main_query() || is_admin() || !is_tax() || !$enabled) {
			return;
		}

		if(isset($wp_query->query_vars['category_name']) && !empty($wp_query->query_vars['category_name'])){
			$cat = get_category_by_slug($wp_query->query_vars['category_name']);

			if(!in_array($cat->term_id, $enabled)){
				return;
			}

			$cats[] = $cat;
		}

		if(isset($wp_query->query_vars['cat'])){
			$catids = explode(',', $wp_query->query_vars['cat']);

			foreach($catids as $id){
				if(!in_array($id, $enabled)){
					return;
				}

				$cats[] = get_category($id);
			}
		}
		
		if (empty($cats)) {
			return;
		}

{'fraction_non_alphanumeric': 0.19917203311867526, 'fraction_numerical': 0.0018399264029438822, 'mean_word_length': 4.534351145038168, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7353271', 'n_tokens_mistral': 910, 'n_tokens_neox': 781, 'n_words': 141}