PluginProbe
Filter Gallery / 1.1.4
Filter Gallery v1.1.4
1.1.4 1.1.3 1.1.2 trunk 0.0.1 0.0.2 0.0.3 0.0.4 0.0.5 0.0.6 0.0.7 0.0.8 0.0.9 0.1.0 0.1.1 0.1.2 0.1.3 0.1.4 0.1.5 0.1.6 0.1.7 0.1.8 0.1.9 0.2.0 0.2.1 All 27 releases
filter-gallery / filter-gallery.php

filter-gallery.php in Filter Gallery 1.1.4, at filter-gallery.php

1,409 lines 61.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 /**
6 * Plugin Name: Filter Gallery
7 * Plugin URI: https://wpfrank.com/
8 * Description: Filter Gallery is a lightweight and powerful WordPress plugin to create beautiful filterable galleries.
9 * Version: 1.1.4
10 * Requires at least: 6.0
11 * Requires PHP: 7.4
12 * Author: FARAZFRANK
13 * Author URI: https://profiles.wordpress.org/farazfrank/
14 * License: GPL v2 or later
15 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
16 * Text Domain: filter-gallery
17 * Domain Path: /languages
18 */
19
20 if (!defined('UFG_VERSION')) {
21 define('UFG_VERSION', '1.1.4');
22 }
23
24 require_once plugin_dir_path(__FILE__) . 'includes/class-ufg-migration.php';
25 UFG_Migration::init();
26
27 if (!function_exists('ufg_normalize_filters_recursive')) {
28 function ufg_normalize_filters_recursive(&$filters) {
29 if (!is_array($filters)) return;
30 foreach ($filters as &$item) {
31 $is_obj = is_object($item);
32 $item_arr = $is_obj ? (array)$item : $item;
33 if (is_array($item_arr)) {
34 $legacy_title = isset($item_arr['title']) ? $item_arr['title'] : '';
35 $legacy_text = isset($item_arr['text']) ? $item_arr['text'] : '';
36 $has_filterkey = isset($item_arr['filterkey']);
37
38 if (!$has_filterkey) {
39 if (!empty($legacy_title)) {
40 $item_arr['filterkey'] = strtolower(str_replace(' ', '-', $legacy_title));
41 } else if (!empty($legacy_text)) {
42 $characters = 'abcdefghijklmnopqrstuvwxyz0123456789';
43 $rand_str = '';
44 for ($i = 0; $i < 5; $i++) {
45 $rand_str .= $characters[wp_rand(0, 35)];
46 }
47 $item_arr['filterkey'] = strtolower(str_replace(' ', '-', $legacy_text)) . '-' . $rand_str;
48 } else {
49 $characters = 'abcdefghijklmnopqrstuvwxyz0123456789';
50 $rand_str = '';
51 for ($i = 0; $i < 5; $i++) {
52 $rand_str .= $characters[wp_rand(0, 35)];
53 }
54 $item_arr['filterkey'] = 'filter-' . $rand_str;
55 }
56 $display_text = !empty($legacy_text) ? $legacy_text : (!empty($legacy_title) ? $legacy_title : 'Filter');
57 $item_arr['title'] = $display_text;
58 $item_arr['text'] = $display_text;
59 }
60 if (!isset($item_arr['children'])) {
61 $item_arr['children'] = array();
62 } else if (is_array($item_arr['children'])) {
63 ufg_normalize_filters_recursive($item_arr['children']);
64 }
65 if (!isset($item_arr['color'])) {
66 $item_arr['color'] = '#38B2F6';
67 }
68
69 $item = $is_obj ? (object)$item_arr : $item_arr;
70 }
71 }
72 }
73 }
74
75 if (!function_exists('ufg_remove_blank_filters_recursive')) {
76 function ufg_remove_blank_filters_recursive(&$filters) {
77 if (!is_array($filters)) return;
78 $new_filters = array();
79 foreach ($filters as $item) {
80 $is_obj = is_object($item);
81 $item_arr = $is_obj ? (array)$item : $item;
82 if (is_array($item_arr)) {
83 $title = isset($item_arr['title']) ? trim($item_arr['title']) : '';
84 $text = isset($item_arr['text']) ? trim($item_arr['text']) : '';
85 $icon = isset($item_arr['icon']) ? trim($item_arr['icon']) : '';
86
87 $has_title = ($title !== '') || ($text !== '');
88 $has_icon = ($icon !== '');
89
90 if (!$has_title && !$has_icon) {
91 continue;
92 }
93
94 if (isset($item_arr['children']) && is_array($item_arr['children'])) {
95 ufg_remove_blank_filters_recursive($item_arr['children']);
96 }
97 $new_filters[] = $is_obj ? (object)$item_arr : $item_arr;
98 }
99 }
100 $filters = $new_filters;
101 }
102 }
103
104 // custom image size
105 add_image_size('ufg_200_200', 200, 200, true);
106 add_image_size('ufg_300_300', 300, 300, true);
107 add_image_size('ufg_400_400', 400, 400, true);
108
109 // FG activation
110 function ufg_activation()
111 {
112 // update current plugin version via migration class rather than activation hook to ensure migrations run
113 /*
114 if (is_admin()) {
115 if (!function_exists('get_plugin_data')) {
116 require_once(ABSPATH . 'wp-admin/includes/plugin.php');
117 }
118 $ufg_plugin_data = get_plugin_data(__FILE__);
119 if (isset($ufg_plugin_data['Version'])) {
120 $ufg_plugin_version = $ufg_plugin_data['Version'];
121 update_option('ufg_current_version', $ufg_plugin_version);
122 }
123 }
124 */
125 }
126 register_activation_hook(__FILE__, 'ufg_activation');
127
128 // FG deactivation
129 function ufg_deactivation()
130 {
131 // update last active plugin version
132 $ufg_last_version = get_option('ufg_current_version');
133 if ($ufg_last_version !== "") {
134 update_option('ufg_last_version', $ufg_last_version);
135 }
136 }
137 register_deactivation_hook(__FILE__, 'ufg_deactivation');
138
139 // FG uninstall
140 function ufg_uninstall()
141 {
142 }
143 register_uninstall_hook(__FILE__, 'ufg_uninstall');
144
145 // load translation
146 function ufg_load_translation()
147 {
148 load_plugin_textdomain('filter-gallery', false, dirname(plugin_basename(__FILE__)) . '/languages');
149 }
150 add_action('init', 'ufg_load_translation');
151
152 // FG menu
153 function ufg_menu_page()
154 {
155 // add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $position );
156 add_menu_page(
157 __('Filter Gallery', 'filter-gallery'),
158 __('Filter Gallery', 'filter-gallery'),
159 'manage_options',
160 'filter-gallery',
161 'ufg_main',
162 'dashicons-format-gallery',
163 65
164 );
165
166 //add_submenu_page( string $parent_slug, string $page_title, string $menu_title, string $capability, string $menu_slug, callable $function = '', int $position )
167 add_submenu_page('filter-gallery', __('Manage Gallery', 'filter-gallery'), __('Manage Gallery', 'filter-gallery'), 'manage_options', 'ufg-manage-gallery', 'ufg_manage_gallery');
168 add_submenu_page('filter-gallery', __('Import / Export', 'filter-gallery'), __('Import / Export', 'filter-gallery'), 'manage_options', 'ufg-import-export', 'ufg_import_export_page');
169 add_submenu_page('filter-gallery', __('Docs', 'filter-gallery'), __('Docs', 'filter-gallery'), 'manage_options', 'ufg-docs', 'ufg_docs_page');
170 add_submenu_page('filter-gallery', __('Free vs Pro', 'filter-gallery'), __('Free vs Pro', 'filter-gallery'), 'manage_options', 'ufg-free-vs-pro', 'ufg_free_vs_pro_page');
171 }
172 add_action('admin_menu', 'ufg_menu_page');
173
174 // FG main page body
175 function ufg_main()
176 {
177 ufg_enqueue_react_app();
178 require 'admin/galleries.php';
179 }
180
181 // FG Docs page body
182 function ufg_docs_page()
183 {
184 ufg_enqueue_react_app();
185 require 'admin/docs.php';
186 }
187
188 // Free vs Pro page body
189 function ufg_free_vs_pro_page()
190 {
191 wp_enqueue_style(
192 'ufg-google-font-outfit',
193 'https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700;800;900&display=swap',
194 array(),
195 null
196 );
197 wp_enqueue_style(
198 'ufg-fontawesome-admin',
199 plugins_url('admin/assets/fontawesome-free-6.5.2-web/css/all.min.css', __FILE__),
200 array(),
201 '6.5.2'
202 );
203 wp_enqueue_style(
204 'ufg-pricing-css',
205 plugins_url('admin/assets/css/ufg-pricing.css', __FILE__),
206 array(),
207 UFG_VERSION
208 );
209 require 'admin/free-vs-pro.php';
210 }
211
212 // FG sub menu filters page body
213 function ufg_manage_gallery()
214 {
215 ufg_enqueue_react_app();
216 require 'admin/manage-gallery.php';
217 }
218
219 function ufg_enqueue_react_app()
220 {
221 $asset_file = include(plugin_dir_path(__FILE__) . 'build/index.asset.php');
222 wp_register_script(
223 'ufg-react-app',
224 plugins_url('build/index.js', __FILE__),
225 array('jquery', 'wp-element', 'wp-components', 'wp-api-fetch', 'wp-media-utils'),
226 '5.3.1',
227 true
228 );
229 wp_set_script_translations(
230 'ufg-react-app',
231 'filter-gallery',
232 plugin_dir_path(__FILE__) . 'languages'
233 );
234 wp_enqueue_style(
235 'ufg-react-app-style',
236 plugins_url('build/index.css', __FILE__),
237 array('wp-components'),
238 $asset_file['version']
239 );
240
241 // Enqueue FontAwesome for the Icon Picker to render correctly in the admin React UI
242 wp_enqueue_style(
243 'ufg-fontawesome-admin',
244 plugins_url('admin/assets/fontawesome-free-6.5.2-web/css/all.min.css', __FILE__),
245 array(),
246 '6.5.2'
247 );
248
249 // Enqueue custom admin fixes for the React UI
250 wp_enqueue_style(
251 'ufg-admin-fixes',
252 plugins_url('admin/assets/css/ufg-admin-fixes.css', __FILE__),
253 array('ufg-react-app-style'),
254 time()
255 );
256
257
258 // Fetch galleries for the dashboard
259 global $wpdb;
260 $ufg_gallery_key = "ufg_filters_";
261
262 $cache_key = 'ufg_all_galleries';
263 $ufg_all_galleries = wp_cache_get($cache_key, 'ufg_galleries');
264
265 if (false === $ufg_all_galleries) {
266 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
267 $ufg_all_galleries = $wpdb->get_results(
268 $wpdb->prepare("SELECT option_name FROM `{$wpdb->prefix}options` WHERE `option_name` LIKE %s ORDER BY option_id ASC", '%' . $wpdb->esc_like($ufg_gallery_key) . '%')
269 );
270 wp_cache_set($cache_key, $ufg_all_galleries, 'ufg_galleries', 3600);
271 }
272
273 $galleries = array();
274 if (count($ufg_all_galleries)) {
275 foreach ($ufg_all_galleries as $gallery) {
276 $ufg_gallery_key_name = $gallery->option_name;
277 $ufg_underscore_pos = strrpos($ufg_gallery_key_name, '_');
278 $ufg_gallery_id = substr($ufg_gallery_key_name, ($ufg_underscore_pos + 1));
279 $details = get_option("ufg_details_" . $ufg_gallery_id);
280 $g_filters = get_option("ufg_filters_" . $ufg_gallery_id);
281 ufg_normalize_filters_recursive($g_filters);
282 $galleries[] = array(
283 'id' => $ufg_gallery_id,
284 'name' => isset($details['gallery_name']) ? $details['gallery_name'] : '',
285 'gallery' => get_option("ufg_gallery_" . $ufg_gallery_id),
286 'filters' => $g_filters,
287 );
288 }
289 }
290
291 // Fetch single gallery data if editing
292 $currentGalleryData = null;
293 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
294 if (isset($_GET['page']) && $_GET['page'] === 'ufg-manage-gallery' && isset($_GET['id'])) {
295 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
296 $id = sanitize_text_field(wp_unslash($_GET['id']));
297 $filters = get_option("ufg_filters_" . $id);
298 ufg_normalize_filters_recursive($filters);
299 $gallery = get_option("ufg_gallery_" . $id);
300 $settings = get_option("ufg_settings_" . $id);
301 $details = get_option("ufg_details_" . $id);
302
303 $parsedImages = array();
304 if (is_array($gallery) && isset($gallery['ufg-attachment-id']) && is_array($gallery['ufg-attachment-id'])) {
305 foreach ($gallery['ufg-attachment-id'] as $k => $v) {
306 $att_id = $v;
307 $parsedImages[] = array(
308 'id' => (int) $att_id,
309 'url' => wp_get_attachment_image_url($att_id, 'medium'),
310 'link_url' => isset($gallery['ufg-url'][$att_id]) ? $gallery['ufg-url'][$att_id] : (isset($gallery['ufg-url'][$k]) ? $gallery['ufg-url'][$k] : ''),
311 'title' => isset($gallery['ufg-title'][$att_id]) ? $gallery['ufg-title'][$att_id] : '',
312 'alt' => isset($gallery['ufg-alt'][$att_id]) ? $gallery['ufg-alt'][$att_id] : '',
313 'description' => isset($gallery['ufg-description'][$att_id]) ? $gallery['ufg-description'][$att_id] : '',
314 'filters' => isset($gallery['ufg-image-filters'][$att_id]) ? $gallery['ufg-image-filters'][$att_id] : (isset($gallery['ufg-image-filters'][$k]) ? $gallery['ufg-image-filters'][$k] : array())
315 );
316 }
317 }
318
319 $default_5_filters = array(
320 (object) array('title' => 'One', 'text' => 'One', 'filterkey' => 'one', 'icon' => 'fas fa-camera', 'color' => '#38B2F6', 'children' => array()),
321 (object) array('title' => 'Two', 'text' => 'Two', 'filterkey' => 'two', 'icon' => 'fas fa-image', 'color' => '#38B2F6', 'children' => array()),
322 (object) array('title' => 'Three', 'text' => 'Three', 'filterkey' => 'three', 'icon' => 'fas fa-star', 'color' => '#38B2F6', 'children' => array()),
323 (object) array('title' => 'Four', 'text' => 'Four', 'filterkey' => 'four', 'icon' => 'fas fa-heart', 'color' => '#38B2F6', 'children' => array()),
324 (object) array('title' => 'Five', 'text' => 'Five', 'filterkey' => 'five', 'icon' => 'fas fa-shield-alt', 'color' => '#38B2F6', 'children' => array()),
325 );
326 if (empty($filters) || !is_array($filters)) {
327 $filters = $default_5_filters;
328 }
329
330 $currentGalleryData = array(
331 'id' => $id,
332 'name' => isset($details['gallery_name']) ? $details['gallery_name'] : '',
333 'filters' => $filters,
334 'images' => $parsedImages,
335 'settings' => is_array($settings) ? array_merge(array(
336 'show_filters' => 1,
337 'show_filters_icon' => 1,
338 'enable_deep_linking' => 0,
339 'show_filters_count' => 1,
340 'show_search_box' => 0,
341 'search_box_placeholder' => 'Type here to search images',
342 'show_all_button' => 1,
343 'all_button_text' => 'All',
344 'all_button_icon' => 'fas fa-filter',
345 'all_button_color' => '#ffffff',
346 'all_button_bg_color' => '#0A85ED',
347 'parent_button_color' => '#4F46E5',
348 'parent_button_bg_color' => '#EEF2FF',
349 'parent_button_hover_color' => '#000000',
350 'parent_active_button_color' => '#FFFFFF',
351 'parent_active_button_bg_color' => '#4F46E5',
352 'parent_filters_heading' => '',
353 'l1_filters_heading' => '',
354 'l1_button_color' => '#4F46E5',
355 'l1_button_bg_color' => '#EEF2FF',
356 'child_filter_effect' => 'show_hide',
357 'active_button_color' => '#FFFFFF',
358 'active_button_bg_color' => '#4F46E5',
359 'l2_button_color' => '#4F46E5',
360 'l2_button_bg_color' => '#EEF2FF',
361 'l3_button_color' => '#4F46E5',
362 'l3_button_bg_color' => '#EEF2FF',
363 'l4_button_color' => '#4F46E5',
364 'l4_button_bg_color' => '#EEF2FF',
365 'columns_desktop' => 4,
366 'columns_tab' => 3,
367 'columns_mobile_landscape' => 3,
368 'columns_mobile_portrait' => 2,
369 'thumbnail_image' => 1,
370 'thumbnail_image_size' => 'full',
371 'thumbnail_border' => 1,
372 'thumbnail_border_thickness' => 1,
373 'thumbnail_border_color' => '#ffffff',
374 'thumbnail_bg_color' => '#222a33',
375 'image_title' => 1,
376 'image_title_font_size' => 18,
377 'image_title_color' => '#FFFFFF',
378 'image_description' => 1,
379 'image_description_font_size' => 14,
380 'image_description_color' => '#FFFFFF',
381 'image_description_text_limit' => 60,
382 'image_hover_effect' => 'border_overlay',
383 'read_more_link_sh' => 0,
384 'read_more_link' => 1,
385 'read_more_button_text' => 'Read More Link',
386 'read_more_button_icon' => 'fas fa-link',
387 'read_more_button_color' => '#ffffff',
388 'read_more_button_bg_color' => '#0080ff',
389 'read_more_button_target' => '_self',
390 'image_sorting' => 5,
391 'image_search' => 1,
392 'lightbox' => 1,
393 'lightbox_title' => 1,
394 'lightbox_description' => 0,
395 'lightbox_numbering' => 0,
396 'custom_css' => '',
397 'load_more' => 'off',
398 'load_limit' => 10,
399 'load_color' => '#0080ff',
400 'load_txt_color' => '#FFFFFF',
401 'load_btn_txt' => 'Load More',
402 'filter_style' => 'buttons',
403 'combine_filter_search' => '0',
404 'filter_padding' => '8px 16px',
405 'filter_margin' => '5px',
406 'filter_padding_type' => 'small',
407 'filter_padding_v' => '8',
408 'filter_padding_h' => '16',
409 'filter_margin_val' => '5',
410 'l1_button_hover_color' => '#059669',
411 'l1_active_button_color' => '#FFFFFF',
412 'l1_active_button_bg_color' => '#059669',
413 'l2_button_hover_color' => '#4F46E5',
414 'l2_active_button_color' => '#FFFFFF',
415 'l2_active_button_bg_color' => '#4F46E5',
416 'l3_button_hover_color' => '#D97706',
417 'l3_active_button_color' => '#FFFFFF',
418 'l3_active_button_bg_color' => '#D97706',
419 'l4_button_hover_color' => '#E11D48',
420 'l4_active_button_color' => '#FFFFFF',
421 'l4_active_button_bg_color' => '#E11D48'
422 ), $settings) : array(),
423 );
424 }
425
426 wp_enqueue_media();
427
428 wp_localize_script('ufg-react-app', 'ufgAdminData', array(
429 'ajaxUrl' => admin_url('admin-ajax.php'),
430 'galleries' => $galleries,
431 'currentGalleryData' => $currentGalleryData,
432 'nextId' => ufg_get_next_id(),
433 'defaultSettings' => array(
434 'show_filters' => 1,
435 'show_filters_icon' => 1,
436 'enable_deep_linking' => 0,
437 'show_filters_count' => 1,
438 'show_search_box' => 0,
439 'search_box_placeholder' => 'Type here to search images',
440 'show_all_button' => 1,
441 'all_button_text' => 'All',
442 'all_button_icon' => 'fas fa-filter',
443
444 'all_button_color' => '#ffffff',
445 'all_button_bg_color' => '#0A85ED',
446 'parent_button_color' => '#4F46E5',
447 'parent_button_bg_color' => '#EEF2FF',
448 'parent_button_hover_color' => '#000000',
449 'parent_active_button_color' => '#FFFFFF',
450 'parent_active_button_bg_color' => '#4F46E5',
451 'parent_filters_heading' => '',
452 'l1_filters_heading' => '',
453 'l1_button_color' => '#4F46E5',
454 'l1_button_bg_color' => '#EEF2FF',
455 'child_filter_effect' => 'show_hide',
456 'active_button_color' => '#FFFFFF',
457 'active_button_bg_color' => '#4F46E5',
458 'l2_button_color' => '#4F46E5',
459 'l2_button_bg_color' => '#EEF2FF',
460 'l3_button_color' => '#4F46E5',
461 'l3_button_bg_color' => '#EEF2FF',
462 'l4_button_color' => '#4F46E5',
463 'l4_button_bg_color' => '#EEF2FF',
464 'columns_desktop' => 4,
465 'columns_tab' => 3,
466 'columns_mobile_landscape' => 3,
467 'columns_mobile_portrait' => 2,
468 'thumbnail_image' => 1,
469 'thumbnail_image_size' => 'full',
470 'thumbnail_border' => 1,
471 'thumbnail_border_thickness' => 1,
472 'thumbnail_border_color' => '#ffffff',
473 'thumbnail_bg_color' => '#222a33',
474 'image_title' => 1,
475 'image_title_font_size' => 18,
476 'image_title_color' => '#FFFFFF',
477 'image_description' => 1,
478 'image_description_font_size' => 14,
479 'image_description_color' => '#FFFFFF',
480 'image_description_text_limit' => 60,
481 'image_hover_effect' => 'border_overlay',
482 'read_more_link_sh' => 0,
483 'read_more_link' => 1,
484 'read_more_button_text' => 'Read More Link',
485 'read_more_button_icon' => 'fas fa-link',
486 'read_more_button_color' => '#ffffff',
487 'read_more_button_bg_color' => '#0080ff',
488 'read_more_button_target' => '_self',
489 'image_sorting' => 5,
490 'image_search' => 1,
491 'lightbox' => 1,
492 'lightbox_title' => 1,
493 'lightbox_description' => 0,
494 'lightbox_numbering' => 0,
495 'custom_css' => '',
496 'load_more' => 'off',
497 'load_limit' => 10,
498 'load_color' => '#0080ff',
499 'load_txt_color' => '#FFFFFF',
500 'load_btn_txt' => 'Load More',
501 'filter_style' => 'buttons',
502 'combine_filter_search' => '0',
503 'filter_padding' => '8px 16px',
504 'filter_margin' => '5px',
505 'filter_padding_type' => 'small',
506 'filter_padding_v' => '8',
507 'filter_padding_h' => '16',
508 'filter_margin_val' => '5',
509 'parent_button_hover_color' => '#000000',
510 'parent_active_button_color' => '#FFFFFF',
511 'parent_active_button_bg_color' => '#4F46E5',
512 'l1_button_hover_color' => '#059669',
513 'l1_active_button_color' => '#FFFFFF',
514 'l1_active_button_bg_color' => '#059669',
515 'l2_button_hover_color' => '#4F46E5',
516 'l2_active_button_color' => '#FFFFFF',
517 'l2_active_button_bg_color' => '#4F46E5',
518 'l3_button_hover_color' => '#D97706',
519 'l3_active_button_color' => '#FFFFFF',
520 'l3_active_button_bg_color' => '#D97706',
521 'l4_button_hover_color' => '#E11D48',
522 'l4_active_button_color' => '#FFFFFF',
523 'l4_active_button_bg_color' => '#E11D48'
524 ),
525 'nonces' => array(
526 'clone' => wp_create_nonce('ufg-clone-gallery'),
527 'remove' => wp_create_nonce('ufg-remove-gallery'),
528 'addFilters' => wp_create_nonce('add-filters'),
529 'saveGallery' => wp_create_nonce('save-gallery'),
530 'saveSetting' => wp_create_nonce('save-setting'),
531 'addImage' => wp_create_nonce('add-image')
532 ),
533 'version' => UFG_VERSION
534 ));
535 wp_enqueue_script('ufg-react-app');
536 wp_enqueue_script('ufg-admin-custom-js', plugins_url('admin/assets/js/ufg-admin-custom.js', __FILE__), array('jquery', 'ufg-react-app'), UFG_VERSION, true);
537 }
538
539 //get / create next gallery id
540 function ufg_get_next_id()
541 {
542 global $wpdb;
543 $ufg_options_table_name = "{$wpdb->prefix}options";
544 $ufg_gallery_key = "ufg_gallery_";
545 // reference : https://wordpress.stackexchange.com/questions/8825/how-do-you-properly-prepare-a-like-sql-statement
546 $cache_key = 'ufg_next_gallery_id';
547 $ufg_gallery_count_res = wp_cache_get($cache_key, 'ufg_galleries');
548
549 if (false === $ufg_gallery_count_res) {
550 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
551 $ufg_gallery_count_res = $wpdb->get_row(
552 $wpdb->prepare("SELECT option_name FROM `{$wpdb->prefix}options` WHERE `option_name` LIKE %s ORDER BY option_id DESC LIMIT 1", '%' . $wpdb->esc_like($ufg_gallery_key) . '%'),
553 ARRAY_N
554 );
555 wp_cache_set($cache_key, $ufg_gallery_count_res, 'ufg_galleries', 3600);
556 }
557
558 if ($wpdb->num_rows) {
559 $ufg_gallery_last_key = $ufg_gallery_count_res[0];
560 $ufg_underscore_pos = strrpos($ufg_gallery_last_key, '_');
561 $ufg_last_slider_id = (int) substr($ufg_gallery_last_key, ($ufg_underscore_pos + 1));
562 return ($ufg_last_slider_id + 1);
563 } else {
564 return 1;
565 }
566 }
567
568 // 1. save filters ajax
569 function ufg_gallery_filters_callback()
570 {
571 if (isset($_POST['nonce']) && !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])), 'add-filters')) {
572 die;
573 } else {
574 // save filters
575
576 $ufg_gallery_id = isset($_POST['id']) ? sanitize_text_field(wp_unslash($_POST['id'])) : '';
577 $ufg_gallery_name = isset($_POST['gallery_name']) ? sanitize_text_field(wp_unslash($_POST['gallery_name'])) : '';
578
579 // gerate random unique key string start
580 if (!function_exists('UFGgenerateRandomString')) {
581 function UFGgenerateRandomString($length = 7)
582 {
583 $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
584 $charactersLength = strlen($characters);
585 $randomString = '';
586 for ($i = 0; $i < $length; $i++) {
587 $randomString .= $characters[wp_rand(0, $charactersLength - 1)];
588 }
589 return $randomString;
590 }
591 }
592
593 // add filterkey index into newly added filers start
594 if (!function_exists('UFGaddMissingFilterKeys')) {
595 function UFGaddMissingFilterKeys(&$array)
596 {
597 foreach ($array as &$item) {
598 // Check for missing filterkey in parent
599 if (!isset($item->filterkey)) {
600 $item->filterkey = strtolower(str_replace(' ', '-', $item->title)) . '-' . UFGgenerateRandomString();
601 }
602
603 // Check for children
604 if (isset($item->children) && is_array($item->children)) {
605 foreach ($item->children as &$child) {
606 if (!isset($child->filterkey)) {
607 $child->filterkey = strtolower(str_replace(' ', '-', $child->title)) . '-' . UFGgenerateRandomString();
608 }
609 }
610 }
611 }
612 }
613 }
614
615 $filters = array();
616 if (isset($_POST['filters'])) {
617 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- sanitized in loop below
618 $filters = json_decode(stripslashes(wp_unslash($_POST['filters'])), false);
619 }
620
621 if (is_array($filters)) {
622 // Sanitize filter data
623 foreach ($filters as &$item) {
624 $item->text = sanitize_text_field($item->text);
625 if (isset($item->children) && is_array($item->children)) {
626 foreach ($item->children as &$child) {
627 $child->text = sanitize_text_field($child->text);
628 }
629 }
630 }
631 UFGaddMissingFilterKeys($filters);
632 }
633
634 update_option("ufg_filters_" . $ufg_gallery_id, $filters);
635
636 $ufg_details = array('ufg_gallery_id' => $ufg_gallery_id, 'gallery_name' => $ufg_gallery_name);
637 update_option("ufg_details_" . $ufg_gallery_id, $ufg_details);
638 }
639 wp_send_json_success();
640 }
641 add_action('wp_ajax_ufg_gallery_filters', 'ufg_gallery_filters_callback');
642
643 // 2. add images to the gallery
644 function ufg_li_generate_ajax_callback()
645 {
646 if (!isset($_POST['nonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])), 'add-image')) {
647 wp_die('Nonce verification failed');
648 }
649
650 if (isset($_POST['attachment_id']) && isset($_POST['ufg_gallery_id'])) {
651 //defaults
652 $ufg_title = $ufg_alt = $ufg_description = $ufg_url = "";
653 //load values
654 $ufg_attachment_id = isset($_POST['attachment_id']) ? sanitize_text_field(wp_unslash($_POST['attachment_id'])) : 0;
655 $ufg_title = get_the_title($ufg_attachment_id);
656 $ufg_alt = get_post_meta($ufg_attachment_id, '_wp_attachment_image_alt', TRUE);
657 //wp_get_attachment_image_src ( int $ufg_attachment_id, string|array $size = 'thumbnail', bool $icon = false )
658 //thumb, thumbnail, medium, large, post-thumbnail
659 $medium = wp_get_attachment_image_src($ufg_attachment_id, 'medium', true); // attachment medium URL
660 $attachment = get_post($ufg_attachment_id);
661 $ufg_description = $attachment->post_content; // attachment description
662 //get saved filters
663 $ufg_gallery_id = isset($_POST['ufg_gallery_id']) ? sanitize_text_field(wp_unslash($_POST['ufg_gallery_id'])) : 0;
664 $filters = get_option("ufg_filters_" . $ufg_gallery_id);
665 ?>
666 <script>
667 jQuery(document).ready(function () {
668 jQuery(function (jQuery) {
669 jQuery('.ufg-image-filters').multiselect({
670 buttonWidth: '100%',
671 enableFiltering: true,
672 nonSelectedText: "<?php echo esc_js(__('Select Filters', 'filter-gallery')); ?>"
673 });
674 });
675 });
676 </script>
677 <li class="ufg-admin-image-item ufg-image-<?php echo intval($ufg_attachment_id); ?>"
678 data-position="<?php echo intval($ufg_attachment_id); ?>">
679 <div class="ufg-admin-form-group">
680 <input type="hidden" class="ufg-admin-form-control ufg-attachment-id"
681 name="ufg-attachment-id[<?php echo intval($ufg_attachment_id); ?>]"
682 value="<?php echo intval($ufg_attachment_id); ?>">
683 <img loading="lazy" src="<?php echo esc_url($medium[0]); ?>" class="ufg-admin-img" alt="" width="150px"
684 height="150px">
685 </div>
686 <div class="ufg-admin-form-group">
687 <input type="text" class="ufg-admin-form-control ufg-title"
688 name="ufg-title[<?php echo intval($ufg_attachment_id); ?>]" value="<?php echo esc_attr($ufg_title); ?>"
689 placeholder="<?php esc_attr_e('Image Title', 'filter-gallery'); ?>">
690 </div>
691 <div class="ufg-admin-form-group">
692 <input type="text" class="ufg-admin-form-control ufg-alt"
693 name="ufg-alt[<?php echo intval($ufg_attachment_id); ?>]" value="<?php echo esc_attr($ufg_alt); ?>"
694 placeholder="<?php esc_attr_e('Image Alternative Text', 'filter-gallery'); ?>">
695 </div>
696 <div class="ufg-admin-form-group">
697 <textarea class="ufg-admin-form-control ufg-description"
698 name="ufg-description[<?php echo intval($ufg_attachment_id); ?>]"
699 placeholder="<?php esc_attr_e('Image Description', 'filter-gallery'); ?>"><?php echo esc_textarea($ufg_description); ?></textarea>
700 </div>
701 <div class="ufg-admin-form-group">
702 <input type="url" disabled readonly class="ufg-admin-form-control ufg-url"
703 name="ufg-url[<?php echo intval($ufg_attachment_id); ?>]" value=""
704 placeholder="<?php esc_attr_e('Link URL (Pro Only)', 'filter-gallery'); ?>">
705 </div>
706 <div class="ufg-admin-form-group">
707 <?php
708 $ufg_gallery_id_num = (int) $ufg_gallery_id;
709 $ufg_gallery_data = get_option("ufg_gallery_" . $ufg_gallery_id_num);
710 $selected_filters = (isset($ufg_gallery_data['ufg-image-filters'][$ufg_attachment_id])) ? $ufg_gallery_data['ufg-image-filters'][$ufg_attachment_id] : array();
711 echo wp_kses_post(ufg_get_filter_list($ufg_attachment_id, $filters, $selected_filters));
712 ?>
713 </div>
714 <div class="ufg-admin-form-group ufg-admin-text-center">
715 <button type="button" id="ufg-remove-image"
716 onclick="return removeImage('<?php echo intval($ufg_attachment_id); ?>');"
717 class="ufg-admin-btn ufg-admin-btn-remove"><?php esc_html_e('Remove', 'filter-gallery'); ?></button>
718 </div>
719 </li>
720 <?php
721 wp_die(); // this is required to terminate immediately and return a proper response
722 }
723 }
724 add_action('wp_ajax_ufg_image_id', 'ufg_li_generate_ajax_callback');
725
726 // generate filter select for image
727 function ufg_get_filter_list($ufg_attachment_id, $filters, $selected_filters)
728 {
729
730 if (is_array($filters) && $filters_count = count($filters)) {
731
732 /* echo "<pre>";
733 echo "Filters";
734 echo "<hr>";
735 print_r(($filters));
736 echo "</pre>";
737 echo "<hr>"; */
738
739 /* echo "<pre>";
740 echo "Selected Filters";
741 echo "<hr>";
742 print_r(($selected_filters));
743 echo "</pre>";
744 echo "<hr>"; */
745
746 /* foreach ($selected_filters as $key => $value) {
747 echo '<input type="text" class="ufg-filter-image" name="ufg-filter-image['.$value.'][]" id="ufg-filter-image[]" style="width: 98%;" value="'.$ufg_attachment_id.'" >';
748 } */
749 // zero = Parent Filters | level_one = Child Filters
750 echo '<select name="ufg-image-filters[' . intval($ufg_attachment_id) . '][]" class="ufg-image-filters" data-max="" multiple="multiple">';
751 for ($i = 0; $i < $filters_count; $i++) {
752 $text_zero = $filters[$i]->text;
753 $value_zero = str_replace(" ", "-", strtolower($filters[$i]->filterkey));
754 if (is_array($selected_filters)) {
755 if (in_array($value_zero, $selected_filters) === TRUE)
756 $selected = "selected=selected";
757 else
758 $selected = "";
759 } else {
760 $selected_filters = array();
761 }
762 echo "<option value='" . esc_attr($value_zero) . "' " . esc_attr($selected) . ">" . esc_html($text_zero) . "</option>";
763
764 //check level one children
765 $child_count_level_one = 0;
766 $child_count_level_two = 0;
767 if (is_array($filters[$i]->children)) {
768 $child_count_level_one = count($filters[$i]->children);
769 }
770 if ($child_count_level_one) {
771 $level_one_array = $filters[$i]->children;
772 for ($j = 0; $j < $child_count_level_one; $j++) {
773 $value_level_one = str_replace(" ", "-", strtolower($level_one_array[$j]->filterkey));
774 if (in_array($value_level_one, $selected_filters) === TRUE)
775 $selected_one = "selected=selected";
776 else
777 $selected_one = "";
778 echo "<option value='" . esc_attr($value_level_one) . "' " . esc_attr($selected_one) . ">&#10148; " . esc_html($level_one_array[$j]->text) . "</option>";
779
780 /*
781 //check level 2 children
782 $child_count_level_two = count($level_one_array[$j]->children);
783 if($child_count_level_two) {
784 $level_two_array = $level_one_array[$j]->children;
785 for($k = 0; $k < $child_count_level_two; $k++){
786 $value_level_two = str_replace(" ","-", strtolower($level_two_array[$k]->text));
787 if(in_array($value_level_two, $selected_filters) === TRUE) $selected_two = "selected=selected"; else $selected_two = "";
788 echo "<option value='$value_level_two' $selected_two>&#10148; &#10148; ".$level_two_array[$k]->text."</option>";
789
790
791 //check level 3 children
792 $child_count_level_three = count($level_two_array[$k]->children);
793 if($child_count_level_three) {
794 $level_three_array = $level_two_array[$k]->children;
795 for($l = 0; $l < $child_count_level_three; $l++){
796 $value_level_three = str_replace(" ","-", strtolower($level_three_array[$l]->text));
797 if(in_array($value_level_three, $selected_filters) === TRUE) $selected_three = "selected=selected"; else $selected_three = "";
798 echo "<option value='$value_level_three' $selected_three>&#10148; &#10148; &#10148; ".$level_three_array[$l]->text."</option>";
799
800
801 //check level 4 children
802 $child_count_level_four = count($level_three_array[$l]->children);
803 if($child_count_level_four) {
804 $level_four_array = $level_three_array[$l]->children;
805 for($m = 0; $m < $child_count_level_four; $m++){
806 $value_level_four = str_replace(" ","-", strtolower($level_four_array[$m]->text));
807 if(in_array($value_level_four, $selected_filters) === TRUE) $selected_four = "selected=selected"; else $selected_four = "";
808 echo "<option value='$value_level_four' $selected_four>&#10148; &#10148; &#10148; &#10148; ".$level_four_array[$m]->text."</option>";
809
810
811 //check level 5 children
812 $child_count_level_five = count($level_four_array[$m]->children);
813 if($child_count_level_five) {
814 $level_five_array = $level_four_array[$m]->children;
815 for($n = 0; $n < $child_count_level_five; $n++){
816 $value_level_five = str_replace(" ","-", strtolower($level_five_array[$n]->text));
817 if(in_array($value_level_five, $selected_filters) === TRUE) $selected_five = "selected=selected"; else $selected_five = "";
818 echo "<option value='$value_level_five' $selected_five>&#10148; &#10148; &#10148; &#10148; &#10148; ".$level_five_array[$n]->text."</option>";
819 }
820 }
821 //check level 5 children end
822
823 }
824 }
825 //check level 4 children end
826
827 }
828 }
829 //check level 3 children end
830
831 }
832 }
833 //check level 2 children end
834 */
835 }
836 }
837 }
838 echo '</select>';
839 }
840 }
841
842 // 3. save gallery images
843 function ufg_save_gallery_callback()
844 {
845 if (isset($_POST['nonce']) && !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])), 'save-gallery')) {
846 wp_send_json_error('Nonce verification failed');
847 } else {
848 $ufg_gallery_id = isset($_POST['id']) ? sanitize_text_field(wp_unslash($_POST['id'])) : '';
849
850 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- data is sanitized after parse_str below
851 $image_id_raw = isset($_POST['image_id']) ? wp_unslash($_POST['image_id']) : '';
852 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- data is sanitized after parse_str below
853 $image_title_raw = isset($_POST['image_title']) ? wp_unslash($_POST['image_title']) : '';
854 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- data is sanitized after parse_str below
855 $image_alt_raw = isset($_POST['image_alt']) ? wp_unslash($_POST['image_alt']) : '';
856 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- data is sanitized after parse_str below
857 $image_description_raw = isset($_POST['image_description']) ? wp_unslash($_POST['image_description']) : '';
858 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- data is sanitized after parse_str below
859 $image_url_raw = isset($_POST['image_url']) ? wp_unslash($_POST['image_url']) : '';
860 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- data is sanitized after parse_str below
861 $image_filters_raw = isset($_POST['image_filters']) ? wp_unslash($_POST['image_filters']) : '';
862
863 $ufg_image_id = $ufg_image_title = $ufg_image_alt = $ufg_image_description = $ufg_image_url = $ufg_image_filters = array();
864
865 parse_str($image_id_raw, $ufg_image_id);
866 parse_str($image_title_raw, $ufg_image_title);
867 parse_str($image_alt_raw, $ufg_image_alt);
868 parse_str($image_description_raw, $ufg_image_description);
869 parse_str($image_url_raw, $ufg_image_url);
870 parse_str($image_filters_raw, $ufg_image_filters);
871
872 // update attachment meta - title, alt, description
873 if (isset($ufg_image_id['ufg-attachment-id']) && is_array($ufg_image_id['ufg-attachment-id'])) {
874 foreach ($ufg_image_id['ufg-attachment-id'] as $ufg_id) {
875 $ufg_title = isset($ufg_image_title['ufg-title'][$ufg_id]) ? sanitize_text_field($ufg_image_title['ufg-title'][$ufg_id]) : '';
876 $ufg_description = isset($ufg_image_description['ufg-description'][$ufg_id]) ? sanitize_textarea_field($ufg_image_description['ufg-description'][$ufg_id]) : '';
877 $ufg_alt = isset($ufg_image_alt['ufg-alt'][$ufg_id]) ? sanitize_text_field($ufg_image_alt['ufg-alt'][$ufg_id]) : '';
878
879 $ufg_image_update = array(
880 'ID' => $ufg_id,
881 'post_title' => $ufg_title,
882 'post_content' => $ufg_description,
883 );
884 wp_update_post($ufg_image_update);
885 update_post_meta($ufg_id, '_wp_attachment_image_alt', $ufg_alt);
886 }
887 }
888
889 $ufg_gallery = array(
890 'ufg-attachment-id' => isset($ufg_image_id['ufg-attachment-id']) ? $ufg_image_id['ufg-attachment-id'] : array(),
891 'ufg-title' => isset($ufg_image_title['ufg-title']) ? $ufg_image_title['ufg-title'] : array(),
892 'ufg-alt' => isset($ufg_image_alt['ufg-alt']) ? $ufg_image_alt['ufg-alt'] : array(),
893 'ufg-description' => isset($ufg_image_description['ufg-description']) ? $ufg_image_description['ufg-description'] : array(),
894 'ufg-url' => isset($ufg_image_url['ufg-url']) ? $ufg_image_url['ufg-url'] : array(),
895 'ufg-image-filters' => isset($ufg_image_filters['ufg-image-filters']) ? $ufg_image_filters['ufg-image-filters'] : array(),
896 );
897
898 update_option("ufg_gallery_" . $ufg_gallery_id, $ufg_gallery);
899 wp_send_json_success();
900 }
901 }
902 add_action('wp_ajax_ufg_save_gallery', 'ufg_save_gallery_callback');
903
904 // 4. load gallery images
905 function ufg_load_gallery_callback($ufg_gallery_id)
906 {
907 if (isset($_POST['nonce']) && !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])), 'load-gallery')) {
908 die;
909 } else {
910 //get / create next gallery id
911 if (isset($_POST['id'])) {
912 $ufg_gallery_id = sanitize_text_field(wp_unslash($_POST['id']));
913
914 // load filters and gallery options
915 $ufg_filters = get_option("ufg_filters_" . $ufg_gallery_id);
916 $ufg_gallery = get_option("ufg_gallery_" . $ufg_gallery_id);
917 //defaults
918 $ufg_title = $ufg_alt = $ufg_description = $ufg_url = "";
919 foreach ($ufg_gallery['ufg-attachment-id'] as $key => $value) {
920 $ufg_attachment_id = $value;
921 //load values
922 $ufg_title = get_the_title($ufg_attachment_id);
923 $ufg_alt = get_post_meta($ufg_attachment_id, '_wp_attachment_image_alt', TRUE);
924 //wp_get_attachment_image_src ( int $ufg_attachment_id, string|array $size = 'thumbnail', bool $icon = false )
925 //thumb, thumbnail, medium, large, post-thumbnail
926 $medium = wp_get_attachment_image_src($ufg_attachment_id, 'medium', true); // attachment medium URL
927 $attachment = get_post($ufg_attachment_id);
928 $ufg_description = $attachment->post_content; // attachment description
929 //get saved filters
930 $filters = get_option("ufg_filters_" . $ufg_gallery_id);
931 ?>
932 <li class="ufg-admin-image-item ufg-image-<?php echo intval($ufg_attachment_id); ?>"
933 data-position="<?php echo intval($ufg_attachment_id); ?>">
934 <div class="ufg-admin-form-group">
935 <input type="hidden" class="ufg-admin-form-control ufg-attachment-id" id="ufg-attachment-id"
936 name="ufg-attachment-id[<?php echo intval($ufg_attachment_id); ?>]"
937 value="<?php echo intval($ufg_attachment_id); ?>">
938 <img src="<?php echo esc_url($medium[0]); ?>" class="ufg-admin-img" alt="" width="150px" height="150px">
939 <span class="ufg-admin-badge">Image ID: <?php echo intval($ufg_attachment_id); ?></span>
940 </div>
941 <div class="ufg-admin-form-group">
942 <input type="text" class="ufg-admin-form-control ufg-title"
943 name="ufg-title[<?php echo intval($ufg_attachment_id); ?>]" value="<?php echo esc_attr($ufg_title); ?>"
944 placeholder="<?php esc_attr_e('Image Title', 'filter-gallery'); ?>">
945 </div>
946 <div class="ufg-admin-form-group">
947 <input type="text" class="ufg-admin-form-control ufg-alt"
948 name="ufg-alt[<?php echo intval($ufg_attachment_id); ?>]" value="<?php echo esc_attr($ufg_alt); ?>"
949 placeholder="<?php esc_attr_e('Image Alternative Text', 'filter-gallery'); ?>">
950 </div>
951 <div class="ufg-admin-form-group">
952 <textarea class="ufg-admin-form-control ufg-description"
953 name="ufg-description[<?php echo intval($ufg_attachment_id); ?>]"
954 placeholder="<?php esc_attr_e('Image Description', 'filter-gallery'); ?>"><?php echo esc_textarea($ufg_description); ?></textarea>
955 </div>
956 <div class="ufg-admin-form-group">
957 <input type="url" disabled readonly class="ufg-admin-form-control ufg-url"
958 name="ufg-url[<?php echo intval($ufg_attachment_id); ?>]"
959 value=""
960 placeholder="<?php esc_attr_e('Link URL (Pro Only)', 'filter-gallery'); ?>">
961 </div>
962 <div class="ufg-admin-form-group">
963 <?php $selected_filters = isset($ufg_gallery['ufg-image-filters'][$value]) ? $ufg_gallery['ufg-image-filters'][$value] : array();
964
965 echo wp_kses_post(ufg_get_filter_list($ufg_attachment_id, $filters, $selected_filters));
966 ?>
967 </div>
968 <div class="ufg-admin-form-group ufg-admin-text-center">
969 <button type="button" id="ufg-remove-image"
970 onclick="return removeImage('<?php echo intval($ufg_attachment_id); ?>');"
971 class="ufg-admin-btn ufg-admin-btn-remove"><?php esc_html_e('Remove', 'filter-gallery'); ?></button>
972 </div>
973 </li>
974 <?php
975 }
976 ?>
977 <script>
978 jQuery(document).ready(function () {
979 jQuery(function (jQuery) {
980 jQuery('.ufg-image-filters').multiselect({
981 buttonWidth: '100%',
982 enableFiltering: true,
983 nonSelectedText: "<?php echo esc_js(__('Select Filters', 'filter-gallery')); ?>",
984 });
985 });
986 });
987 </script>
988 <?php
989 die;
990 }
991 }
992 }
993 add_action('wp_ajax_ufg_load_gallery', 'ufg_load_gallery_callback');
994
995 // 5. save gallery settings
996 function ufg_save_setting_callback()
997 {
998 if (isset($_POST['nonce']) && !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])), 'save-setting')) {
999 die;
1000 } else {
1001 $ufg_gallery_id = isset($_POST['ufg_gallery_id']) ? sanitize_text_field(wp_unslash($_POST['ufg_gallery_id'])) : 0;
1002 $settings = array(
1003 //gallery details
1004 'ufg_gallery_id' => $ufg_gallery_id,
1005
1006 //filters settings
1007 'default_filter' => isset($_POST['default_filter']) ? sanitize_text_field(wp_unslash($_POST['default_filter'])) : '',
1008 'filter_style' => (isset($_POST['filter_style']) && sanitize_text_field(wp_unslash($_POST['filter_style'])) === 'dropdown') ? 'dropdown' : 'buttons',
1009 'combine_filter_search' => '0',
1010 'filter_padding' => isset($_POST['filter_padding']) ? sanitize_text_field(wp_unslash($_POST['filter_padding'])) : '',
1011 'filter_margin' => isset($_POST['filter_margin']) ? sanitize_text_field(wp_unslash($_POST['filter_margin'])) : '',
1012 'filter_padding_type' => isset($_POST['filter_padding_type']) ? sanitize_text_field(wp_unslash($_POST['filter_padding_type'])) : '',
1013 'filter_padding_v' => isset($_POST['filter_padding_v']) ? sanitize_text_field(wp_unslash($_POST['filter_padding_v'])) : '',
1014 'filter_padding_h' => isset($_POST['filter_padding_h']) ? sanitize_text_field(wp_unslash($_POST['filter_padding_h'])) : '',
1015 'filter_margin_val' => isset($_POST['filter_margin_val']) ? sanitize_text_field(wp_unslash($_POST['filter_margin_val'])) : '',
1016 'parent_button_hover_color' => isset($_POST['parent_button_hover_color']) ? sanitize_text_field(wp_unslash($_POST['parent_button_hover_color'])) : '',
1017 'parent_active_button_color' => isset($_POST['parent_active_button_color']) ? sanitize_text_field(wp_unslash($_POST['parent_active_button_color'])) : '',
1018 'parent_active_button_bg_color' => isset($_POST['parent_active_button_bg_color']) ? sanitize_text_field(wp_unslash($_POST['parent_active_button_bg_color'])) : '',
1019 'show_filters' => isset($_POST['show_filters']) ? sanitize_text_field(wp_unslash($_POST['show_filters'])) : '',
1020 'show_search_box' => isset($_POST['show_search_box']) ? sanitize_text_field(wp_unslash($_POST['show_search_box'])) : '',
1021 'search_box_placeholder' => isset($_POST['search_box_placeholder']) ? sanitize_text_field(wp_unslash($_POST['search_box_placeholder'])) : '',
1022 'show_filters_icon' => isset($_POST['show_filters_icon']) ? sanitize_text_field(wp_unslash($_POST['show_filters_icon'])) : '',
1023 'enable_deep_linking' => '0',
1024 //'show_filters_count' => isset($_POST['show_filters_count']) ? sanitize_text_field(wp_unslash($_POST['show_filters_count'])) : '',
1025 'show_all_button' => isset($_POST['show_all_button']) ? sanitize_text_field(wp_unslash($_POST['show_all_button'])) : '',
1026 'all_button_text' => isset($_POST['all_button_text']) ? sanitize_text_field(wp_unslash($_POST['all_button_text'])) : '',
1027 'all_button_icon' => isset($_POST['all_button_icon']) ? sanitize_text_field(wp_unslash($_POST['all_button_icon'])) : '',
1028
1029 'all_button_color' => isset($_POST['all_button_color']) ? sanitize_text_field(wp_unslash($_POST['all_button_color'])) : '',
1030 'all_button_bg_color' => isset($_POST['all_button_bg_color']) ? sanitize_text_field(wp_unslash($_POST['all_button_bg_color'])) : '',
1031 'parent_filters_heading' => isset($_POST['parent_filters_heading']) ? sanitize_text_field(wp_unslash($_POST['parent_filters_heading'])) : '',
1032 'parent_button_color' => isset($_POST['parent_button_color']) ? sanitize_text_field(wp_unslash($_POST['parent_button_color'])) : '',
1033 'parent_button_bg_color' => isset($_POST['parent_button_bg_color']) ? sanitize_text_field(wp_unslash($_POST['parent_button_bg_color'])) : '',
1034 'l1_filters_heading' => isset($_POST['l1_filters_heading']) ? sanitize_text_field(wp_unslash($_POST['l1_filters_heading'])) : '',
1035 'l1_button_color' => isset($_POST['l1_button_color']) ? sanitize_text_field(wp_unslash($_POST['l1_button_color'])) : '',
1036 'l1_button_bg_color' => isset($_POST['l1_button_bg_color']) ? sanitize_text_field(wp_unslash($_POST['l1_button_bg_color'])) : '',
1037 'l2_button_color' => isset($_POST['l2_button_color']) ? sanitize_text_field(wp_unslash($_POST['l2_button_color'])) : '',
1038 'l2_button_bg_color' => isset($_POST['l2_button_bg_color']) ? sanitize_text_field(wp_unslash($_POST['l2_button_bg_color'])) : '',
1039 'l3_button_color' => isset($_POST['l3_button_color']) ? sanitize_text_field(wp_unslash($_POST['l3_button_color'])) : '',
1040 'l3_button_bg_color' => isset($_POST['l3_button_bg_color']) ? sanitize_text_field(wp_unslash($_POST['l3_button_bg_color'])) : '',
1041 'l4_button_color' => isset($_POST['l4_button_color']) ? sanitize_text_field(wp_unslash($_POST['l4_button_color'])) : '',
1042 'l4_button_bg_color' => isset($_POST['l4_button_bg_color']) ? sanitize_text_field(wp_unslash($_POST['l4_button_bg_color'])) : '',
1043 'child_filter_effect' => isset($_POST['child_filter_effect']) ? sanitize_text_field(wp_unslash($_POST['child_filter_effect'])) : '',
1044 'active_button_color' => isset($_POST['active_button_color']) ? sanitize_text_field(wp_unslash($_POST['active_button_color'])) : '',
1045 'active_button_bg_color' => isset($_POST['active_button_bg_color']) ? sanitize_text_field(wp_unslash($_POST['active_button_bg_color'])) : '',
1046
1047 //gallery settings
1048 'columns_desktop' => (isset($_POST['columns_desktop']) && in_array($_POST['columns_desktop'], array('3', '4', '6'), true)) ? sanitize_text_field(wp_unslash($_POST['columns_desktop'])) : '4',
1049 'columns_tab' => (isset($_POST['columns_tab']) && in_array($_POST['columns_tab'], array('1', '2', '3'), true)) ? sanitize_text_field(wp_unslash($_POST['columns_tab'])) : '3',
1050 'columns_mobile_landscape' => (isset($_POST['columns_mobile_landscape']) && in_array($_POST['columns_mobile_landscape'], array('1', '2', '3'), true)) ? sanitize_text_field(wp_unslash($_POST['columns_mobile_landscape'])) : '3',
1051 'columns_mobile_portrait' => (isset($_POST['columns_mobile_portrait']) && in_array($_POST['columns_mobile_portrait'], array('1', '2'), true)) ? sanitize_text_field(wp_unslash($_POST['columns_mobile_portrait'])) : '2',
1052 'thumbnail_image' => isset($_POST['thumbnail_image']) ? sanitize_text_field(wp_unslash($_POST['thumbnail_image'])) : '',
1053 'thumbnail_image_size' => isset($_POST['thumbnail_image_size']) ? sanitize_text_field(wp_unslash($_POST['thumbnail_image_size'])) : '',
1054 'thumbnail_border' => isset($_POST['thumbnail_border']) ? sanitize_text_field(wp_unslash($_POST['thumbnail_border'])) : '',
1055 'thumbnail_border_thickness' => isset($_POST['thumbnail_border_thickness']) ? sanitize_text_field(wp_unslash($_POST['thumbnail_border_thickness'])) : '',
1056 'thumbnail_border_color' => isset($_POST['thumbnail_border_color']) ? sanitize_text_field(wp_unslash($_POST['thumbnail_border_color'])) : '',
1057 'thumbnail_bg_color' => isset($_POST['thumbnail_bg_color']) ? sanitize_text_field(wp_unslash($_POST['thumbnail_bg_color'])) : '',
1058 'image_title' => isset($_POST['image_title']) ? sanitize_text_field(wp_unslash($_POST['image_title'])) : '',
1059 'image_title_font_size' => isset($_POST['image_title_font_size']) ? sanitize_text_field(wp_unslash($_POST['image_title_font_size'])) : '',
1060 'image_title_color' => isset($_POST['image_title_color']) ? sanitize_text_field(wp_unslash($_POST['image_title_color'])) : '',
1061 'image_description' => isset($_POST['image_description']) ? sanitize_text_field(wp_unslash($_POST['image_description'])) : '',
1062 'image_description_font_size' => isset($_POST['image_description_font_size']) ? sanitize_text_field(wp_unslash($_POST['image_description_font_size'])) : '',
1063 'image_description_color' => isset($_POST['image_description_color']) ? sanitize_text_field(wp_unslash($_POST['image_description_color'])) : '',
1064 'image_description_text_limit' => isset($_POST['image_description_text_limit']) ? sanitize_text_field(wp_unslash($_POST['image_description_text_limit'])) : '',
1065 'image_hover_effect' => isset($_POST['image_hover_effect']) ? sanitize_text_field(wp_unslash($_POST['image_hover_effect'])) : '',
1066 'read_more_link_sh' => '0',
1067 'read_more_link' => '1',
1068 'read_more_button_text' => 'Read More Link',
1069 'read_more_button_icon' => 'fas fa-link',
1070 'read_more_button_color' => '#ffffff',
1071 'read_more_button_bg_color' => '#0080ff',
1072 'read_more_button_target' => '_self',
1073 'image_sorting' => (isset($_POST['image_sorting']) && in_array($_POST['image_sorting'], array('5', '1', '2'), true)) ? sanitize_text_field(wp_unslash($_POST['image_sorting'])) : '5',
1074 'custom_css' => '',
1075
1076 //lightbox settings
1077 'lightbox' => isset($_POST['lightbox']) ? sanitize_text_field(wp_unslash($_POST['lightbox'])) : '',
1078 'lightbox_title' => isset($_POST['lightbox_title']) ? sanitize_text_field(wp_unslash($_POST['lightbox_title'])) : '',
1079 'lightbox_description' => '0',
1080 'lightbox_numbering' => '0',
1081
1082 // Load More
1083 'load_more' => 'off',
1084 'load_limit' => isset($_POST['load_limit']) ? sanitize_text_field(wp_unslash($_POST['load_limit'])) : '',
1085 'load_color' => isset($_POST['load_color']) ? sanitize_text_field(wp_unslash($_POST['load_color'])) : '',
1086 'load_txt_color' => isset($_POST['load_txt_color']) ? sanitize_text_field(wp_unslash($_POST['load_txt_color'])) : '',
1087 'load_btn_txt' => isset($_POST['load_btn_txt']) ? sanitize_text_field(wp_unslash($_POST['load_btn_txt'])) : '',
1088 );
1089
1090 update_option("ufg_settings_" . $ufg_gallery_id, $settings);
1091 die;
1092 }
1093 }
1094 add_action('wp_ajax_ufg_save_setting', 'ufg_save_setting_callback');
1095
1096 // 6. remove gallery/galleries start
1097 function ufg_remove_gallery_callback()
1098 {
1099 if (isset($_POST['nonce']) && !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])), 'ufg-remove-gallery')) {
1100 echo "Nonce not verified.";
1101 die;
1102 } else {
1103 // verified action
1104 if (isset($_POST['ufg_gallery_id']) && isset($_POST['do_action'])) {
1105
1106 $raw_id = is_array($_POST['ufg_gallery_id']) ? array_map('sanitize_text_field', wp_unslash($_POST['ufg_gallery_id'])) : sanitize_text_field(wp_unslash($_POST['ufg_gallery_id']));
1107 $ufg_gallery_id = $raw_id;
1108 $ufg_do_action = sanitize_text_field(wp_unslash($_POST['do_action']));
1109
1110 //single gallery delete
1111 if ($ufg_do_action == 'single') {
1112 delete_option("ufg_filters_" . $ufg_gallery_id);
1113 delete_option("ufg_gallery_" . $ufg_gallery_id);
1114 delete_option("ufg_settings_" . $ufg_gallery_id);
1115 delete_option("ufg_details_" . $ufg_gallery_id);
1116 }
1117
1118 //multiple gallery delete
1119 if ($ufg_do_action == 'multiple' && is_array($ufg_gallery_id)) {
1120 foreach ($ufg_gallery_id as $ufg_single_id) {
1121 delete_option("ufg_filters_" . $ufg_single_id);
1122 delete_option("ufg_gallery_" . $ufg_single_id);
1123 delete_option("ufg_settings_" . $ufg_single_id);
1124 delete_option("ufg_details_" . $ufg_single_id);
1125 }
1126 }
1127 }
1128 wp_die();
1129 }
1130 }
1131 add_action('wp_ajax_ufg_remove_gallery', 'ufg_remove_gallery_callback');
1132 // 6. remove gallery/galleries end
1133
1134 // 7. clone gallery start
1135 function ufg_clone_gallery_callback()
1136 {
1137 if (isset($_POST['nonce']) && !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])), 'ufg-clone-gallery')) {
1138 echo "Nonce not verified action.";
1139 die;
1140 } else {
1141 // verified action
1142 if (isset($_POST['ufg_gallery_id']) && isset($_POST['ufg_gallery_counter'])) {
1143 $ufg_gallery_id = sanitize_text_field(wp_unslash($_POST['ufg_gallery_id']));
1144 $ufg_gallery_counter = sanitize_text_field(wp_unslash($_POST['ufg_gallery_counter']));
1145
1146 //get cloning gallery data
1147 $ufg_cloning_filters = get_option("ufg_filters_" . $ufg_gallery_id);
1148 $ufg_cloning_gallery = get_option("ufg_gallery_" . $ufg_gallery_id);
1149 $ufg_cloning_setting = get_option("ufg_settings_" . $ufg_gallery_id);
1150 $ufg_cloning_details = get_option("ufg_details_" . $ufg_gallery_id);
1151
1152 //print_r($ufg_cloning_gallery);
1153
1154 //generate new gallery id for clone
1155 $new_ufg_gallery_id = ufg_get_next_id();
1156 $new_ufg_gallery_name = $ufg_cloning_details['gallery_name'] . ' - Clone';
1157
1158 // update clone id into gallery data
1159 foreach ($ufg_cloning_gallery as $key => $value) {
1160 $ufg_cloning_setting['ufg_gallery_id'] = $new_ufg_gallery_id;
1161 }
1162 // update gallery details
1163 $ufg_cloning_details = array('ufg_gallery_id' => $ufg_gallery_id, 'gallery_name' => $new_ufg_gallery_name);
1164
1165 //print_r($ufg_cloning_gallery);
1166 if ($new_ufg_gallery_id > $ufg_gallery_id) {
1167 add_option('ufg_filters_' . $new_ufg_gallery_id, $ufg_cloning_filters);
1168 add_option('ufg_gallery_' . $new_ufg_gallery_id, $ufg_cloning_gallery);
1169 add_option('ufg_settings_' . $new_ufg_gallery_id, $ufg_cloning_setting);
1170 update_option('ufg_details_' . $new_ufg_gallery_id, $ufg_cloning_details);
1171 $ufg_do_action = "'single'";
1172
1173 echo '
1174 <tr id=' . intval($new_ufg_gallery_id) . '>
1175 <th scope="row">' . intval($ufg_gallery_counter) . '</th>
1176 <td>' . esc_html($new_ufg_gallery_name) . '</td>
1177 <td>
1178 <input type="text" id="ufg-shortcode-' . intval($new_ufg_gallery_id) . '" class="btn btn-info btn-sm" value="[ufg id=' . intval($new_ufg_gallery_id) . ']">
1179 <button type="button" id="ufg-shortcode-' . intval($new_ufg_gallery_id) . '" class="btn btn-info btn-sm" title="Click To Copy Gallery Shortcode" onclick="return UFGCopyShortcode(' . intval($new_ufg_gallery_id) . ')">Copy</button>
1180 <button class="btn btn-sm btn-success d-none ufg-copied-' . intval($new_ufg_gallery_id) . '">Copied</button>
1181 </td>
1182 <td>
1183 <button type="button" id="ufg-clone" class="btn btn-warning btn-sm" title="Clone Gallery" value="' . intval($new_ufg_gallery_id) . '" onclick="return UFGCloneGallery(' . intval($new_ufg_gallery_id) . ', ' . intval($ufg_gallery_counter) . ');"><i class="fas fa-copy"></i></button>
1184 <a href="?page=ufg-manage-gallery&id=' . intval($new_ufg_gallery_id) . '" class="btn btn-primary btn-sm" href="#"><i class="fas fa-edit"></i></a>
1185 <button id="ufg-delete-gallery" class="btn btn-danger btn-sm" title="Delete Gallery" value="' . intval($new_ufg_gallery_id) . '" onclick="return UFGRemoveGallery(\'' . intval($new_ufg_gallery_id) . '\', \'' . esc_js($ufg_do_action) . '\');"><i class="fas fa-trash-alt"></i></button>
1186 </td>
1187 <td class="text-center">
1188 <input type="checkbox" id="ufg-gallery-id" name="ufg-gallery-id" value="' . intval($new_ufg_gallery_id) . '" title="Select Gallery">
1189 </td>
1190 </tr>
1191 ';
1192 }
1193 }
1194 wp_die();
1195 }
1196 }
1197 add_action('wp_ajax_ufg_clone_gallery', 'ufg_clone_gallery_callback');
1198 // 7. clone gallery end
1199
1200 // 8. Import / Export page
1201 function ufg_import_export_page()
1202 {
1203 require plugin_dir_path(__FILE__) . 'admin/import-export.php';
1204 }
1205
1206 // 8a. Export galleries AJAX
1207 function ufg_export_galleries_callback()
1208 {
1209 if (!isset($_POST['nonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])), 'ufg-import-export')) {
1210 wp_send_json_error('Nonce verification failed.');
1211 }
1212
1213 if (!current_user_can('manage_options')) {
1214 wp_send_json_error('Permission denied.');
1215 }
1216
1217 $gallery_ids = isset($_POST['gallery_ids']) ? array_map('absint', $_POST['gallery_ids']) : array();
1218 if (empty($gallery_ids)) {
1219 wp_send_json_error('No galleries selected.');
1220 }
1221
1222 $export_data = array(
1223 'plugin' => 'filter-gallery-pro',
1224 'version' => '6.0.5',
1225 'export_date' => gmdate('Y-m-d'),
1226 'source_url' => home_url(),
1227 'galleries' => array(),
1228 );
1229
1230 foreach ($gallery_ids as $gid) {
1231 $details = get_option("ufg_details_" . $gid);
1232 $filters = get_option("ufg_filters_" . $gid);
1233 $gallery = get_option("ufg_gallery_" . $gid);
1234 $settings = get_option("ufg_settings_" . $gid);
1235
1236 if (!$gallery && !$filters) {
1237 continue; // skip if gallery doesn't exist
1238 }
1239
1240 // Build image URL map: attachment_id => full URL
1241 $image_urls = array();
1242 if (is_array($gallery) && isset($gallery['ufg-attachment-id']) && is_array($gallery['ufg-attachment-id'])) {
1243 foreach ($gallery['ufg-attachment-id'] as $att_id) {
1244 $url = wp_get_attachment_url($att_id);
1245 if ($url) {
1246 $image_urls[$att_id] = $url;
1247 }
1248 }
1249 }
1250
1251 $export_data['galleries'][] = array(
1252 'original_id' => $gid,
1253 'details' => $details ? $details : array(),
1254 'filters' => $filters ? $filters : array(),
1255 'gallery' => $gallery ? $gallery : array(),
1256 'settings' => $settings ? $settings : array(),
1257 'image_urls' => $image_urls,
1258 );
1259 }
1260
1261 wp_send_json_success($export_data);
1262 }
1263 add_action('wp_ajax_ufg_export_galleries', 'ufg_export_galleries_callback');
1264
1265 // 8b. Import single gallery AJAX
1266 function ufg_import_gallery_callback()
1267 {
1268 if (!isset($_POST['nonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])), 'ufg-import-export')) {
1269 wp_send_json_error('Nonce verification failed.');
1270 }
1271
1272 if (!current_user_can('manage_options')) {
1273 wp_send_json_error('Permission denied.');
1274 }
1275
1276 if (!isset($_POST['gallery_data'])) {
1277 wp_send_json_error('No gallery data provided.');
1278 }
1279
1280 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1281 $raw = wp_unslash($_POST['gallery_data']);
1282 $data = json_decode($raw, true);
1283 if (!$data || !is_array($data)) {
1284 wp_send_json_error('Invalid gallery data format.');
1285 }
1286
1287 $skip_images = isset($_POST['skip_images']) && $_POST['skip_images'] === '1';
1288
1289 // Get a new gallery ID
1290 $new_id = ufg_get_next_id();
1291
1292 $details = isset($data['details']) ? $data['details'] : array();
1293 $filters = isset($data['filters']) ? $data['filters'] : array();
1294 $gallery = isset($data['gallery']) ? $data['gallery'] : array();
1295 $settings = isset($data['settings']) ? $data['settings'] : array();
1296 $image_urls = isset($data['image_urls']) ? $data['image_urls'] : array();
1297
1298 $images_imported = 0;
1299 $images_failed = 0;
1300
1301 // Remap attachment IDs if we have images to import
1302 if (!$skip_images && !empty($image_urls) && is_array($gallery) && isset($gallery['ufg-attachment-id'])) {
1303 // Need media sideload function
1304 require_once ABSPATH . 'wp-admin/includes/media.php';
1305 require_once ABSPATH . 'wp-admin/includes/file.php';
1306 require_once ABSPATH . 'wp-admin/includes/image.php';
1307
1308 $id_map = array(); // old_id => new_id
1309
1310 foreach ($image_urls as $old_id => $url) {
1311 // Download and sideload the image
1312 $new_att_id = media_sideload_image($url, 0, null, 'id');
1313 if (!is_wp_error($new_att_id)) {
1314 $id_map[$old_id] = $new_att_id;
1315 $images_imported++;
1316 } else {
1317 $images_failed++;
1318 }
1319 }
1320
1321 // Remap attachment IDs in gallery data
1322 if (!empty($id_map)) {
1323 // Remap ufg-attachment-id array
1324 $new_att_ids = array();
1325 foreach ($gallery['ufg-attachment-id'] as $old_id) {
1326 if (isset($id_map[$old_id])) {
1327 $new_att_ids[] = $id_map[$old_id];
1328 }
1329 }
1330 $gallery['ufg-attachment-id'] = $new_att_ids;
1331
1332 // Remap keyed arrays: ufg-url, ufg-title, ufg-alt, ufg-description, ufg-image-filters
1333 $keyed_fields = array('ufg-url', 'ufg-title', 'ufg-alt', 'ufg-description', 'ufg-image-filters');
1334 foreach ($keyed_fields as $field) {
1335 if (isset($gallery[$field]) && is_array($gallery[$field])) {
1336 $new_data = array();
1337 foreach ($gallery[$field] as $old_key => $val) {
1338 $new_key = isset($id_map[$old_key]) ? $id_map[$old_key] : $old_key;
1339 $new_data[$new_key] = $val;
1340 }
1341 $gallery[$field] = $new_data;
1342 }
1343 }
1344 }
1345 } elseif ($skip_images) {
1346 // Clear image data when skipping
1347 $gallery['ufg-attachment-id'] = array();
1348 $gallery['ufg-url'] = array();
1349 $gallery['ufg-title'] = array();
1350 $gallery['ufg-alt'] = array();
1351 $gallery['ufg-description'] = array();
1352 $gallery['ufg-image-filters'] = array();
1353 }
1354
1355 // Update gallery name for imported gallery
1356 $gallery_name = isset($details['gallery_name']) ? $details['gallery_name'] : 'Imported Gallery';
1357 $details = array(
1358 'ufg_gallery_id' => $new_id,
1359 'gallery_name' => $gallery_name . ' (Imported)',
1360 );
1361
1362 // Save all 4 option entries
1363 add_option('ufg_filters_' . $new_id, $filters);
1364 add_option('ufg_gallery_' . $new_id, $gallery);
1365 add_option('ufg_settings_' . $new_id, $settings);
1366 update_option('ufg_details_' . $new_id, $details);
1367
1368 // Clear cache so new gallery shows up
1369 wp_cache_delete('ufg_all_galleries', 'ufg_galleries');
1370 wp_cache_delete('ufg_next_gallery_id', 'ufg_galleries');
1371
1372 wp_send_json_success(array(
1373 'new_id' => $new_id,
1374 'gallery_name' => $details['gallery_name'],
1375 'images_imported' => $images_imported,
1376 'images_failed' => $images_failed,
1377 ));
1378 }
1379 add_action('wp_ajax_ufg_import_gallery', 'ufg_import_gallery_callback');
1380
1381 // Register and enqueue sf scripts
1382 function ufg_register_scripts()
1383 {
1384 // Register and enqueue jQuery
1385 wp_register_script('jquery', false, array(), '3.6.0', true);
1386 wp_enqueue_script('jquery');
1387
1388 // Register and enqueue styles with versions
1389 wp_register_style('ufg-frontend-css', plugin_dir_url(__FILE__) . 'admin/assets/css/ufg-frontend.css', array(), UFG_VERSION);
1390
1391 wp_register_style('ufg-fontawesome-css', plugin_dir_url(__FILE__) . 'admin/assets/fontawesome-free-6.5.2-web/css/all.min.css', array(), '6.5.2');
1392
1393 wp_register_style('ufg-lightbox-css', plugin_dir_url(__FILE__) . 'admin/assets/lightbox/lokesh/css/ufg-lightbox-min.css', array(), '4.5.2');
1394
1395 // Register and enqueue scripts with versions and dependencies
1396 wp_register_script('ufg-lightbox-js', plugin_dir_url(__FILE__) . 'admin/assets/lightbox/lokesh/js/ufg.lightbox.min.js', array('jquery'), '2.11.2', true);
1397
1398 wp_register_script('ufg-isotope-js', plugin_dir_url(__FILE__) . 'admin/assets/js/isotope.pkgd.min.js', array('jquery'), '3.0.6', true);
1399
1400 // Register a custom script to attach inline script
1401 wp_register_script('ufg-custom-js', plugin_dir_url(__FILE__) . 'admin/assets/js/ufg-custom.js', array('jquery', 'ufg-isotope-js'), '1.0.0', true);
1402 }
1403 add_action('wp_enqueue_scripts', 'ufg_register_scripts');
1404
1405 include('shortcode.php');
1406
1407 // Gallery Text Widget Support
1408 add_filter('widget_text', 'do_shortcode');
1409