Plugin modification to make it work
-
The first fresh installation of this plugin didn’t work for me. I created a specific category to be hidden anywhere and assigned this category to one post (just for testing), but nothing happened: the post was anywhere, like it was before using the plugin.
As my WordPress version is 4.0 I thought it could be some compatibility problem, and I digged into the code.
I have finally got a working implementation with two small changes (I have not checked if they are both required or it is just the first one… anyway, now it works). The main problem was with getting the category_hide option: the code was using explode as if categories would be a comma-separated list of categories, but they where actually an array. I just got rid of explode.
The function I changed is wp_hide_category, which is located in the wp_hide_category.php plugin file. The following code shows my modified version of the function (changes are indicated with comments):
function wp_hide_category($query) { if(!is_admin() /* && $query->is_main_query() */ ) { $wp_hide_category_hide_place = get_option('wp_hide_category_hide_place'); // Modified from original: $category_hide = explode(',', get_option('wp_hide_category_id')); $category_hide = get_option('wp_hide_category_id'); if(!empty( $wp_hide_category_hide_place)) { foreach($wp_hide_category_hide_place as $template_name){ $call_name = 'is_' . $template_name; if($query->$call_name()){ if(!empty($category_hide)) { foreach($category_hide as $cat_id) { // Modified from original: $query->set('cat', '-' . $cat_id); $query->set('category__not_in', $cat_id); } } } } } } }
Hope this helps.
- The topic ‘Plugin modification to make it work’ is closed to new replies.