PluginProbe
Filter Gallery / 1.1.3
Filter Gallery v1.1.3
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.3, at filter-gallery.php

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