PluginProbe
Blog Filter – Post Grid Filter by Category or Tag / 1.8.6
Blog Filter – Post Grid Filter by Category or Tag v1.8.6
1.8.7 1.8.6 1.8.4 1.8.5 1.8.3 1.8.2 1.8.1 1.0.9 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 All 85 releases
blog-filter / blog-filter.php

blog-filter.php in Blog Filter – Post Grid Filter by Category or Tag 1.8.6, at blog-filter.php

399 lines 12.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if (!defined('ABSPATH'))
3 exit; // Exit if accessed directly
4 /**
5 Plugin Name: Blog Filter
6 Description: Blog Filter For WordPress Blog With Multiple Filters
7 Version: 1.8.6
8 Author: A WP Life
9 Author URI: http://awplife.com/
10 Text Domain: blog-filter
11 Domain Path: /languages
12 License: GPLv2 or later
13 License URI: http://www.gnu.org/licenses/gpl-2.0.html
14 **/
15
16 if (!class_exists('Awl_Blog_Filter')) {
17
18 class Awl_Blog_Filter
19 {
20
21 public function __construct()
22 {
23 $this->_constants();
24 $this->_hooks();
25 }
26
27 protected function _constants()
28 {
29 //Plugin Version
30 define('BF_PLUGIN_VER', '1.8.6');
31
32 //Plugin Text Domain
33 define('BF_TEXT_DOMAIN', 'blog-filter');
34
35 //Plugin Name
36 define('BF_PLUGIN_NAME', 'Blog Filter');
37
38 //Plugin Slug
39 define('BF_PLUGIN_SLUG', 'awl_blog_filter');
40
41 //Plugin Directory Path
42 define('BF_PLUGIN_DIR', plugin_dir_path(__FILE__));
43
44 //Plugin Directory URL
45 define('BF_PLUGIN_URL', plugin_dir_url(__FILE__));
46 } // end of constructor function
47
48 protected function _hooks()
49 {
50
51 //Load text domain
52 add_action('plugins_loaded', array($this, 'load_textdomain'));
53
54 //add menu item, change menu for multisite
55 add_action('admin_menu', array($this, 'blog_filter_menu'), 101);
56
57 //Added settings link on plugins page
58 $bf_plugin_name = plugin_basename(__FILE__);
59 add_filter("plugin_action_links_$bf_plugin_name", array($this, 'bf_plugins_page_settings_link'));
60
61 add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_scripts'));
62
63 add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts_in_header'));
64
65 add_action('wp_ajax_load_more', array($this, 'load_more_posts'));
66
67 add_action('wp_ajax_nopriv_load_more', array($this, 'load_more_posts'));
68
69 add_filter('wp_img_tag_add_loading_attr', array($this, 'disable_lazy_load_for_plugin_images'), 10, 3);
70
71 add_action('wp_ajax_get_taxonomies_for_post_type', array($this, 'bfg_get_taxonomies_callback'));
72
73 add_action('wp_ajax_get_terms_for_taxonomy', array($this, 'bfg_get_terms_for_taxonomy_callback'));
74 }// end of hook function
75
76 /**
77 * Returns an array of all default shortcode attributes.
78 * Centralized for easy maintenance.
79 */
80
81
82 public function bfg_get_taxonomies_callback()
83 {
84 // First, check for security.
85 if (!check_ajax_referer('bfg_admin_nonce', 'security', false)) {
86 wp_send_json_error('Invalid security token.', 403);
87 return;
88 }
89
90 if (!current_user_can('manage_options')) {
91 wp_send_json_error('Permission denied.', 403);
92 return;
93 }
94
95 if (!isset($_POST['post_type']) || empty($_POST['post_type'])) {
96 wp_send_json_error('No post type specified.', 400);
97 return;
98 }
99
100 $post_type = sanitize_text_field(wp_unslash($_POST['post_type']));
101
102 // Get all public taxonomies associated with the post type.
103 $taxonomies = get_object_taxonomies($post_type, 'objects');
104
105 $options_html = '<option value="none">' . __('None', 'blog-filter') . '</option>';
106
107 if (!empty($taxonomies)) {
108 foreach ($taxonomies as $taxonomy) {
109 // We only want public taxonomies that can be shown in a UI.
110 if ($taxonomy->public && $taxonomy->show_ui) {
111 $options_html .= '<option value="' . esc_attr($taxonomy->name) . '">' . esc_html($taxonomy->label) . ' (' . esc_html($taxonomy->name) . ')</option>';
112 }
113 }
114 }
115
116 // Check if we actually found any usable taxonomies
117 if ($options_html === '<option value="none">' . __('None', 'blog-filter') . '</option>') {
118 wp_send_json_success('<option value="none">' . __('No taxonomies found for this post type', 'blog-filter') . '</option>');
119 } else {
120 wp_send_json_success($options_html);
121 }
122 }
123
124 public function bfg_get_terms_for_taxonomy_callback()
125 {
126 // Security check
127 check_ajax_referer('bfg_admin_nonce', 'security');
128 if (!current_user_can('manage_options')) {
129 wp_send_json_error('Permission denied.', 403);
130 return;
131 }
132
133 // --- Prepare data ---
134 if (!isset($_POST['taxonomy']) || empty($_POST['taxonomy'])) {
135 wp_send_json_error('No taxonomy specified.', 400);
136 return;
137 }
138 $taxonomy_name = sanitize_text_field(wp_unslash($_POST['taxonomy']));
139 $taxonomy_obj = get_taxonomy($taxonomy_name);
140 if (!$taxonomy_obj) {
141 wp_send_json_error('Invalid taxonomy.', 400);
142 return;
143 }
144 $terms = get_terms(['taxonomy' => $taxonomy_name, 'hide_empty' => false]);
145 $dropdown_html = '<option value="all">' . __('All', 'blog-filter') . '</option>';
146 $table_html = '';
147
148 // --- Build HTML for all three elements if terms exist ---
149 if (!is_wp_error($terms) && !empty($terms)) {
150 // Build Dropdown HTML
151 foreach ($terms as $term) {
152 $dropdown_html .= '<option value="' . esc_attr($term->term_id) . '">' . esc_html($term->name) . '</option>';
153 }
154
155 // Build Inclusion Table HTML
156 ob_start();
157 ?>
158 <div class="bfg-overflow-auto" style="max-height: 415px;">
159 <table class="bfg-w-full bfg-border-collapse bfg-border bfg-border-gray-300">
160 <thead>
161 <tr class="bfg-bg-gray-200">
162 <th class="bfg-p-2 bfg-border bfg-border-gray-300"><?php esc_html_e('ID', 'blog-filter'); ?></th>
163 <th class="bfg-p-2 bfg-border bfg-border-gray-300">
164 <?php echo esc_html($taxonomy_obj->labels->singular_name); ?>
165 </th>
166 <th class="bfg-p-2 bfg-border bfg-border-gray-300"><?php esc_html_e('Post Count', 'blog-filter'); ?></th>
167 <th class="bfg-p-2 bfg-border bfg-border-gray-300 bfg-text-center"></th>
168 </tr>
169 </thead>
170 <tbody>
171 <?php foreach ($terms as $term): ?>
172 <tr>
173 <td class="bfg-p-2 bfg-border bfg-border-gray-300"><?php echo esc_html($term->term_id); ?></td>
174 <td class="bfg-p-2 bfg-border bfg-border-gray-300"><?php echo esc_html($term->name); ?></td>
175 <td class="bfg-p-2 bfg-border bfg-border-gray-300"><?php echo esc_html($term->count); ?></td>
176 <td class="bfg-p-2 bfg-border bfg-border-gray-300 bfg-text-center">
177 <input type="checkbox" class="bfg-term-checkbox" name="selected_terms[]"
178 value="<?php echo esc_attr($term->term_id); ?>">
179 </td>
180 </tr>
181 <?php endforeach; ?>
182 </tbody>
183 </table>
184 <p><b><?php esc_html_e('Note: Blog Filter Standard supports up to 4 taxonomy as filters', 'blog-filter'); ?></b></p>
185 </div>
186 <?php
187 $table_html = ob_get_clean();
188 } else {
189 $table_html = '<p>' . __('No terms found for this taxonomy.', 'blog-filter') . '</p>';
190 }
191
192 // Send all three HTML strings back in a single JSON object
193 wp_send_json_success([
194 'dropdown' => $dropdown_html,
195 'table' => $table_html,
196 ]);
197 }
198
199 public function load_more_posts()
200 {
201
202 if (!isset($_POST['nonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])), 'load_more_nonce')) {
203 wp_die('Invalid security token.', 403);
204 }
205
206 require(BF_PLUGIN_DIR . 'templates/blog-filter-ajax-get.php');
207 wp_die();
208 }
209
210 public function enqueue_scripts_in_header()
211 {
212 wp_enqueue_script('jquery');
213 wp_enqueue_script('imagesloaded');
214 }
215
216 public function load_textdomain()
217 {
218 load_plugin_textdomain('blog-filter', false, dirname(plugin_basename(__FILE__)) . '/languages');
219 }
220
221 public function blog_filter_menu()
222 {
223 $filter_settings_menu = add_submenu_page('edit.php', __('Blog Filters Settings', 'blog-filter'), __('Blog Filters Settings', 'blog-filter'), 'administrator', 'blog-filter-settings-page', array($this, 'awl_blog_filter_page'));
224 }
225
226 public function awl_blog_filter_page()
227 {
228 require_once('blog-filter-settings.php');
229 }
230
231 public function enqueue_admin_scripts($hook_suffix)
232 {
233 if (isset($_GET['page']) && $_GET['page'] === 'blog-filter-settings-page') {
234 wp_enqueue_style('awl-blog-filter-settings-css', BF_PLUGIN_URL . 'css/blog-filter-settings.css', array(), BF_PLUGIN_VER);
235 wp_enqueue_style('wp-color-picker');
236
237 wp_enqueue_script('jquery');
238 wp_enqueue_script('wp-color-picker');
239 wp_enqueue_script('awl-blog-filter-isotope-js', BF_PLUGIN_URL . 'js/isotope.pkgd.js', array('jquery'), BF_PLUGIN_VER, false);
240
241 wp_enqueue_style('blog-filter-tailwind', BF_PLUGIN_URL . 'css/styles.min.css', [], '1.0');
242
243 // Localize nonce for admin ajax operations
244 wp_localize_script('awl-blog-filter-isotope-js', 'bfg_admin_ajax', array(
245 'nonce' => wp_create_nonce('bfg_admin_nonce')
246 ));
247 }
248 }
249
250 public function disable_lazy_load_for_plugin_images($value, $image, $context)
251 {
252 if (strpos($image, 'portfolio_thumbnail') !== false) {
253 return false;
254 }
255 return $value;
256 }
257
258 public function bf_plugins_page_settings_link($links)
259 {
260 $bf_settings_link = '<a href="edit.php?page=blog-filter-settings-page">' . esc_html__('Settings', 'blog-filter') . '</a>';
261 array_unshift($links, $bf_settings_link);
262 return $links;
263 }
264
265 public function bfg_get_shortcode_defaults()
266 {
267 return array(
268 // General & Post Type Settings
269 'post_type' => 'post',
270 'blog_direction' => 'ltr',
271 'blog_fixed_grid' => 'no',
272 'blog_template' => 'template1',
273
274 // Columns
275 'blog_col_large_desktops' => 'col-lg-4',
276 'blog_col_desktops' => 'col-md-4',
277 'blog_col_tablets' => 'col-sm-6',
278 'blog_col_phones' => 'col-xs-12',
279
280 // Image Settings
281 'blog_image' => 'yes',
282 'blog_image_hover_effect' => 'none',
283 'blog_image_quality' => 'large',
284
285 // Title Settings
286 'blog_title' => 'yes',
287 'blog_title_font_size' => 25,
288 'blog_title_color' => '#000',
289 'blog_title_below_image' => 'no',
290
291 // Description Settings
292 'blog_desc' => 'yes',
293 'blog_desc_characters' => '100',
294 'blog_desc_font_size' => 12,
295 'blog_desc_color' => '#606060',
296 'blog_desc_box_color' => '#EDEEF0',
297 'three_dots' => 'yes',
298
299 // Links and Display
300 'link_on_date' => 'no',
301
302 // Read More
303 'blog_read_more' => 'yes',
304 'blog_read_more_text' => __('Read More', 'blog-filter'),
305
306 // Metadata Display
307 'blog_date' => 'yes',
308 'blog_date_below_image' => 'no',
309 'blog_author' => 'yes',
310 'blog_author_below_image' => 'no',
311 'blog_categories' => 'yes',
312 'blog_tags' => 'no',
313
314 // Pagination & Load
315 'blog_pagination' => 'no',
316 'blog_load_more' => 'no',
317 'blog_pagination_loadmore_color' => '#58BBEE',
318 'blog_per_page_and_init_load' => '12',
319 'load_more_text' => __('Load More', 'blog-filter'),
320 'no_more_text' => __('No More Posts', 'blog-filter'),
321
322 // Filters
323 'blog_filters' => 'yes',
324 'filter_post_count' => 'no',
325 'blog_filter_all' => 'yes',
326 'blog_all_text' => __('All', 'blog-filter'),
327 'blog_first_filter_selected' => 'no',
328
329 // Search
330 'blog_search' => 'no',
331 'blog_search_text' => __('Search', 'blog-filter'),
332
333 // Styling & Colors
334 'blog_buttons_color' => '#58BBEE',
335
336 // Taxonomy Filtering
337 'blog_filtering' => 'category',
338
339 'selected_terms' => '',
340
341 // Custom CSS
342 'custom_css' => '',
343 );
344 }
345 }
346
347 // register bf scripts
348 function bf_register_scripts()
349 {
350
351 //js
352 wp_register_script('awl-bf-filterizr-js', plugin_dir_url(__FILE__) . 'js/jquery.filterizr.js', array('jquery', 'imagesloaded'), BF_PLUGIN_VER, true);
353
354 // css
355 wp_register_style('awl-bf-filter-output-css', plugin_dir_url(__FILE__) . 'css/blog-filter-output.css', array(), BF_PLUGIN_VER);
356 wp_register_style('awl-bf-hover-css', plugin_dir_url(__FILE__) . 'css/hover.css', array(), BF_PLUGIN_VER);
357
358 }
359 add_action('wp_enqueue_scripts', 'bf_register_scripts');
360
361 // Backward compatibility wrapper for old function name
362 if (! function_exists('awplife_bf_register_scripts')) {
363 function awplife_bf_register_scripts()
364 {
365 bf_register_scripts();
366 }
367 }
368
369 $bf_post_filter_object = new Awl_Blog_Filter();
370 // Backward compatibility
371 $pf_post_filter_object = $bf_post_filter_object;
372
373 if (! function_exists('bfg_get_shortcode_defaults')) {
374 function bfg_get_shortcode_defaults()
375 {
376 global $bf_post_filter_object;
377 return $bf_post_filter_object->bfg_get_shortcode_defaults();
378 }
379 }
380
381 if (! function_exists('plugins_page_settings_link')) {
382 function plugins_page_settings_link($links)
383 {
384 global $bf_post_filter_object;
385 return $bf_post_filter_object->bf_plugins_page_settings_link($links);
386 }
387 }
388
389 if (! function_exists('bf_plugins_page_settings_link')) {
390 function bf_plugins_page_settings_link($links)
391 {
392 global $bf_post_filter_object;
393 return $bf_post_filter_object->bf_plugins_page_settings_link($links);
394 }
395 }
396
397 //Shortcode page
398 require_once('blog-filter-shortcode.php');
399 } ?>