PluginProbe
Blog Filter – Post Grid Filter by Category or Tag / 1.8.2
Blog Filter – Post Grid Filter by Category or Tag v1.8.2
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.2, at blog-filter.php

398 lines 12.5 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.2
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.2');
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 }
214
215 public function load_textdomain()
216 {
217 load_plugin_textdomain('blog-filter', false, dirname(plugin_basename(__FILE__)) . '/languages');
218 }
219
220 public function blog_filter_menu()
221 {
222 $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'));
223 }
224
225 public function awl_blog_filter_page()
226 {
227 require_once('blog-filter-settings.php');
228 }
229
230 public function enqueue_admin_scripts($hook_suffix)
231 {
232 if (isset($_GET['page']) && $_GET['page'] === 'blog-filter-settings-page') {
233 wp_enqueue_style('awl-blog-filter-settings-css', BF_PLUGIN_URL . 'css/blog-filter-settings.css', array(), BF_PLUGIN_VER);
234 wp_enqueue_style('wp-color-picker');
235
236 wp_enqueue_script('jquery');
237 wp_enqueue_script('wp-color-picker');
238 wp_enqueue_script('awl-blog-filter-isotope-js', BF_PLUGIN_URL . 'js/isotope.pkgd.js', array('jquery'), BF_PLUGIN_VER, false);
239
240 wp_enqueue_style('blog-filter-tailwind', BF_PLUGIN_URL . 'css/styles.min.css', [], '1.0');
241
242 // Localize nonce for admin ajax operations
243 wp_localize_script('awl-blog-filter-isotope-js', 'bfg_admin_ajax', array(
244 'nonce' => wp_create_nonce('bfg_admin_nonce')
245 ));
246 }
247 }
248
249 public function disable_lazy_load_for_plugin_images($value, $image, $context)
250 {
251 if (strpos($image, 'portfolio_thumbnail') !== false) {
252 return false;
253 }
254 return $value;
255 }
256
257 public function bf_plugins_page_settings_link($links)
258 {
259 $bf_settings_link = '<a href="edit.php?page=blog-filter-settings-page">' . esc_html__('Settings', 'blog-filter') . '</a>';
260 array_unshift($links, $bf_settings_link);
261 return $links;
262 }
263
264 public function bfg_get_shortcode_defaults()
265 {
266 return array(
267 // General & Post Type Settings
268 'post_type' => 'post',
269 'blog_direction' => 'ltr',
270 'blog_fixed_grid' => 'no',
271 'blog_template' => 'template1',
272
273 // Columns
274 'blog_col_large_desktops' => 'col-lg-4',
275 'blog_col_desktops' => 'col-md-4',
276 'blog_col_tablets' => 'col-sm-6',
277 'blog_col_phones' => 'col-xs-12',
278
279 // Image Settings
280 'blog_image' => 'no',
281 'blog_image_hover_effect' => 'none',
282 'blog_image_quality' => 'large',
283
284 // Title Settings
285 'blog_title' => 'no',
286 'blog_title_font_size' => 25,
287 'blog_title_color' => '#000',
288 'blog_title_below_image' => 'no',
289
290 // Description Settings
291 'blog_desc' => 'no',
292 'blog_desc_characters' => '100',
293 'blog_desc_font_size' => 12,
294 'blog_desc_color' => '#606060',
295 'blog_desc_box_color' => '#EDEEF0',
296 'three_dots' => 'no',
297
298 // Links and Display
299 'link_on_date' => 'no',
300
301 // Read More
302 'blog_read_more' => 'no',
303 'blog_read_more_text' => __('Read More', 'blog-filter'),
304
305 // Metadata Display
306 'blog_date' => 'no',
307 'blog_date_below_image' => 'no',
308 'blog_author' => 'no',
309 'blog_author_below_image' => 'no',
310 'blog_categories' => 'no',
311 'blog_tags' => 'no',
312
313 // Pagination & Load
314 'blog_pagination' => 'no',
315 'blog_load_more' => 'no',
316 'blog_pagination_loadmore_color' => '#58BBEE',
317 'blog_per_page_and_init_load' => '12',
318 'load_more_text' => __('Load More', 'blog-filter'),
319 'no_more_text' => __('No More Posts', 'blog-filter'),
320
321 // Filters
322 'blog_filters' => 'no',
323 'filter_post_count' => 'no',
324 'blog_filter_all' => 'no',
325 'blog_all_text' => __('All', 'blog-filter'),
326 'blog_first_filter_selected' => 'no',
327
328 // Search
329 'blog_search' => 'no',
330 'blog_search_text' => __('Search', 'blog-filter'),
331
332 // Styling & Colors
333 'blog_buttons_color' => '#58BBEE',
334
335 // Taxonomy Filtering
336 'blog_filtering' => 'blog_category',
337
338 'selected_terms' => '',
339
340 // Custom CSS
341 'custom_css' => '',
342 );
343 }
344 }
345
346 // register bf scripts
347 function bf_register_scripts()
348 {
349
350 //js
351 wp_register_script('awl-bf-filterizr-js', plugin_dir_url(__FILE__) . 'js/jquery.filterizr.js', array('jquery'), BF_PLUGIN_VER, false);
352
353 // css
354 wp_register_style('awl-bf-filter-output-css', plugin_dir_url(__FILE__) . 'css/blog-filter-output.css', array(), BF_PLUGIN_VER);
355 wp_register_style('awl-bf-hover-css', plugin_dir_url(__FILE__) . 'css/hover.css', array(), BF_PLUGIN_VER);
356
357 }
358 add_action('wp_enqueue_scripts', 'bf_register_scripts');
359
360 // Backward compatibility wrapper for old function name
361 if (! function_exists('awplife_bf_register_scripts')) {
362 function awplife_bf_register_scripts()
363 {
364 bf_register_scripts();
365 }
366 }
367
368 $bf_post_filter_object = new Awl_Blog_Filter();
369 // Backward compatibility
370 $pf_post_filter_object = $bf_post_filter_object;
371
372 if (! function_exists('bfg_get_shortcode_defaults')) {
373 function bfg_get_shortcode_defaults()
374 {
375 global $bf_post_filter_object;
376 return $bf_post_filter_object->bfg_get_shortcode_defaults();
377 }
378 }
379
380 if (! function_exists('plugins_page_settings_link')) {
381 function plugins_page_settings_link($links)
382 {
383 global $bf_post_filter_object;
384 return $bf_post_filter_object->bf_plugins_page_settings_link($links);
385 }
386 }
387
388 if (! function_exists('bf_plugins_page_settings_link')) {
389 function bf_plugins_page_settings_link($links)
390 {
391 global $bf_post_filter_object;
392 return $bf_post_filter_object->bf_plugins_page_settings_link($links);
393 }
394 }
395
396 //Shortcode page
397 require_once('blog-filter-shortcode.php');
398 } ?>