PluginProbe ʕ •ᴥ•ʔ
Photo Gallery by FooGallery : Responsive Image Gallery, Masonry Gallery & Carousel / 3.1.13
Photo Gallery by FooGallery : Responsive Image Gallery, Masonry Gallery & Carousel v3.1.13
trunk 1.10.3 2.0.24 2.1.34 2.2.44 2.3.3 2.4.32 3.0.6 3.1.11 3.1.12 3.1.13 3.1.20 3.1.25 3.1.26 3.1.26.1 3.1.26.2
foogallery / includes / class-previews.php
foogallery / includes Last commit date
admin 5 months ago compatibility 5 months ago extensions 5 months ago foopluginbase 5 months ago public 5 months ago thumbs 5 months ago asset-manifest.php 5 months ago class-attachment-filters.php 5 months ago class-foogallery-animated-gif-support.php 5 months ago class-foogallery-attachment-custom-class.php 5 months ago class-foogallery-attachment-type.php 5 months ago class-foogallery-attachment.php 5 months ago class-foogallery-cache.php 5 months ago class-foogallery-common-fields.php 5 months ago class-foogallery-crop-position.php 5 months ago class-foogallery-datasource-media_library.php 5 months ago class-foogallery-debug.php 5 months ago class-foogallery-extensions-compatibility.php 5 months ago class-foogallery-force-https.php 5 months ago class-foogallery-lazyload.php 5 months ago class-foogallery-license-constant-handler.php 5 months ago class-foogallery-lightbox.php 5 months ago class-foogallery-paging.php 5 months ago class-foogallery-password-protect.php 5 months ago class-foogallery-sitemaps.php 5 months ago class-foogallery-widget.php 5 months ago class-foogallery.php 5 months ago class-gallery-advanced-settings.php 5 months ago class-il8n.php 5 months ago class-override-thumbnail.php 5 months ago class-posttypes.php 5 months ago class-previews.php 5 months ago class-retina.php 5 months ago class-thumbnail-dimensions.php 5 months ago class-thumbnails.php 5 months ago class-version-check.php 5 months ago constants.php 5 months ago functions.php 5 months ago includes.php 5 months ago index.php 5 months ago render-functions.php 5 months ago
class-previews.php
97 lines
1 <?php
2
3 /**
4 * Class to handle preview scenarios, where rest/ajax calls are made from a gallery that is in preview mode.
5 */
6 if (! class_exists('FooGallery_Previews')) {
7
8 class FooGallery_Previews
9 {
10
11 /**
12 * FooGallery_Previews constructor.
13 */
14 function __construct()
15 {
16 //override gallery settings specifically for previews.
17
18 if ($this->should_init()) {
19 $this->safe_init();
20 }
21
22 add_action('rest_api_init', function () {
23 if ($this->should_init()) {
24 $this->safe_init();
25 }
26 });
27 }
28
29 /**
30 * Check if the preview functionality should be initialized.
31 */
32 private function should_init()
33 {
34 //first, check if we are in the admin
35 if (is_admin()) {
36 return true;
37 }
38
39 //then, check if we are a rest request in admin
40 if (foogallery_is_rest_request_from_admin()) {
41 return true;
42 }
43
44 return false;
45 }
46
47 /**
48 * Safely init the preview functionality.
49 */
50 private function safe_init()
51 {
52 if (has_filter('foogallery_instance_get_setting')) {
53 return;
54 }
55
56 add_filter('foogallery_instance_get_setting', array($this, 'override_instance_get_setting_for_previews'), 10, 4);
57 add_action('foogallery_preview_before_render', array($this, 'store_preview_data'), 10, 2);
58 }
59
60 /**
61 * Temporarily store the preview data, so it can be picked up by AJAX / Rest requests.
62 */
63 public function store_preview_data($foogallery_id, $args)
64 {
65 //store transient for 5 minutes
66 set_transient('foogallery_preview_data_' . $foogallery_id, $args, 60 * 5);
67 }
68
69 /**
70 * Override the gallery settings for previews.
71 */
72 public function override_instance_get_setting_for_previews($value, $key, $default, $gallery)
73 {
74 if (!isset($gallery) || !is_a($gallery, 'FooGallery')) {
75 return $value;
76 }
77
78 $gallery_id = intval($gallery->ID);
79 if ($gallery_id === 0) {
80 return $value;
81 }
82
83 $temp_preview_data = get_transient('foogallery_preview_data_' . $gallery_id);
84
85 if (!is_array($temp_preview_data) || empty($temp_preview_data)) {
86 return $value;
87 }
88
89 if (isset($temp_preview_data[$key])) {
90 return $temp_preview_data[$key];
91 }
92
93 return $value;
94 }
95 }
96 }
97