| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * Class used to cache gallery HTML output to save requests to the database | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * Date: 20/03/2017 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | if ( ! class_exists( 'FooGallery_Cache' ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | 	class FooGallery_Cache { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | 		function __construct() { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | 			if ( is_admin() ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | 				//intercept the gallery save and save the html output to post meta | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | 				add_action( 'foogallery_after_save_gallery', array( $this, 'cache_gallery_html_output_after_save' ), 10, 2 ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | 				//add some settings to allow the clearing and disabling of the cache | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | 				add_filter( 'foogallery_admin_settings_override', array( $this, 'add_cache_settings' ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | 				//render the clear HTML cache button | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | 				add_action( 'foogallery_admin_settings_custom_type_render_setting', array( $this, 'render_settings' ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | 				// Ajax call for clearing HTML cache | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | 				add_action( 'wp_ajax_foogallery_clear_html_cache', array( $this, 'ajax_clear_all_caches' ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | 				add_action( 'foogallery_admin_new_version_detected', array( $this, 'clear_cache_on_update' ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | 				//clear the gallery caches when settings are updated or reset | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | 				add_action( 'foogallery_settings_updated', array( $this, 'clear_all_gallery_caches' ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | 				add_action( 'foogallery_settings_reset', array( $this, 'clear_all_gallery_caches' ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | 			add_filter( 'foogallery_load_gallery_template', array( $this, 'fetch_gallery_html_from_cache' ), 10, 3 ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  | 			add_filter( 'foogallery_html_cache_disabled', array( $this, 'disable_html_cache' ), 10, 3 ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | 		/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | 		 * Override if the gallery html cache is disabled | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  | 		 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  | 		 * @param $disabled bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  | 		 * @param $gallery FooGallery | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  | 		 * @return bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | 		 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  | 		function disable_html_cache( $disabled, $gallery ) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  | 			//check if the gallery sorting is random | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  | 			if ( 'rand' === $gallery->sorting ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  | 				$disabled = true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  | 			return $disabled; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  | 		/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  | 		 * Save the HTML output of the gallery after the gallery has been saved | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  | 		 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  | 		 * @param $post_id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  | 		 * @param $form_post | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  | 		 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  | 		function cache_gallery_html_output_after_save( $post_id, $form_post ) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  | 			$this->cache_gallery_html_output( $post_id ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  | 		/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  | 		 * Save the HTML output of the gallery to post meta so that it can be used in future requests | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  | 		 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  | 		 * @param $foogallery_id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  | 		 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  | 		function cache_gallery_html_output( $foogallery_id ) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  | 			$caching_enabled = $this->is_caching_enabled(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  | 			//check if caching is disabled and quit early | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  | 			if ( !$caching_enabled ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  | 				return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  | 			//we need a way to force the gallery to render it's output every time it is saved | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  | 			global $foogallery_force_gallery_cache; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  | 			$foogallery_force_gallery_cache = true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  | 			//capture the html output | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  | 			ob_start(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  | 			foogallery_render_gallery( $foogallery_id ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  | 			$gallery_html = ob_get_contents(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  | 			ob_end_clean(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  | 			if ( $caching_enabled ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  | 				//save the output to post meta for later use | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  | 				update_post_meta( $foogallery_id, FOOGALLERY_META_CACHE, $gallery_html ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  | 			$foogallery_force_gallery_cache = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  | 		function is_caching_enabled() { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |             global $current_foogallery_arguments; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  | 			//do some checks if we are using arguments | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  | 			if ( isset( $current_foogallery_arguments ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |                 //never cache if showing a preview | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |                 if ( array_key_exists( 'preview', $current_foogallery_arguments ) && | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |                     true === $current_foogallery_arguments['preview'] ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |                     return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |                 //never cache if we are passing in extra arguments via the shortcode | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |                 $array_keys = array_keys( $current_foogallery_arguments ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  | 			    if ( $array_keys != array( 'id', 'gallery' ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |                     return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  | 			//next, check the settings | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  | 			if ( 'on' === foogallery_get_setting( 'enable_html_cache' ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  | 				return true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  | 			return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  | 		/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  | 		 * Override the template output | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  | 		 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  | 		 * @param $override | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  | 		 * @param $gallery | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  | 		 * @param $template_location | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  | 		 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  | 		 * @return bool | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 129 |  |  | 		 */ | 
            
                                                                        
                            
            
                                    
            
            
                | 130 |  |  | 		function fetch_gallery_html_from_cache( $override, $gallery, $template_location ) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 131 |  |  | 			global $foogallery_force_gallery_cache; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 132 |  |  | 			if ( $foogallery_force_gallery_cache ) { | 
            
                                                                        
                            
            
                                    
            
            
                | 133 |  |  | 				return false; | 
            
                                                                        
                            
            
                                    
            
            
                | 134 |  |  | 			} | 
            
                                                                        
                            
            
                                    
            
            
                | 135 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 136 |  |  | 			//check if caching is disabled and quit early | 
            
                                                                        
                            
            
                                    
            
            
                | 137 |  |  | 			if ( !$this->is_caching_enabled() ) { | 
            
                                                                        
                            
            
                                    
            
            
                | 138 |  |  | 				return false; | 
            
                                                                        
                            
            
                                    
            
            
                | 139 |  |  | 			} | 
            
                                                                        
                            
            
                                    
            
            
                | 140 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 141 |  |  | 			//allow extensions of others disable the html cache | 
            
                                                                        
                            
            
                                    
            
            
                | 142 |  |  | 			if ( apply_filters( 'foogallery_html_cache_disabled', false, $gallery ) ) { | 
            
                                                                        
                            
            
                                    
            
            
                | 143 |  |  | 				return false; | 
            
                                                                        
                            
            
                                    
            
            
                | 144 |  |  | 			} | 
            
                                                                        
                            
            
                                    
            
            
                | 145 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 146 |  |  | 			$gallery_cache = get_post_meta( $gallery->ID, FOOGALLERY_META_CACHE, true ); | 
            
                                                                        
                            
            
                                    
            
            
                | 147 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 148 |  |  | 			if ( !empty( $gallery_cache ) && is_string( $gallery_cache ) ) { | 
            
                                                                        
                            
            
                                    
            
            
                | 149 |  |  | 				//output the cached gallery html | 
            
                                                                        
                            
            
                                    
            
            
                | 150 |  |  | 				echo $gallery_cache; | 
            
                                                                        
                            
            
                                    
            
            
                | 151 |  |  | 				return true; //return that we will override | 
            
                                                                        
                            
            
                                    
            
            
                | 152 |  |  | 			} else { | 
            
                                                                        
                            
            
                                    
            
            
                | 153 |  |  | 				//we should cache the result for next time | 
            
                                                                        
                            
            
                                    
            
            
                | 154 |  |  | 				$this->cache_gallery_html_output( $gallery->ID ); | 
            
                                                                        
                            
            
                                    
            
            
                | 155 |  |  | 			} | 
            
                                                                        
                            
            
                                    
            
            
                | 156 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 157 |  |  | 			return false; | 
            
                                                                        
                            
            
                                    
            
            
                | 158 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  | 		/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  | 		 * Add some caching settings | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  | 		 * @param $settings | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  | 		 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  | 		 * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  | 		 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  | 		function add_cache_settings( $settings ) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  | 			$cache_settings[] = array( | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  | 				'id'      => 'enable_html_cache', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  | 				'title'   => __( 'Enable HTML Cache', 'foogallery' ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  | 				'desc'    => __( 'The gallery HTML that is generated can be cached. This can reduce the number of calls to the database when displaying a gallery and can increase site performance.', 'foogallery' ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  | 				'type'    => 'checkbox', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  | 				'tab'     => 'general', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  | 				'section' => __( 'Cache', 'foogallery' ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  | 			); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  | 			$cache_settings[] = array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  | 				'id'      => 'clear_html_cache', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 |  |  | 				'title'   => __( 'Clear HTML Cache', 'foogallery' ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  | 				'desc'    => __( 'If you enable the HTML cache, then you can use this button to clear the gallery HTML that has been cached for all galleries.', 'foogallery' ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  | 				'type'    => 'clear_gallery_cache_button', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  | 				'tab'     => 'general', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  | 				'section' => __( 'Cache', 'foogallery' ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  | 			); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  | 			$new_settings = array_merge( $cache_settings, $settings['settings'] ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 |  |  | 			$settings['settings'] = $new_settings; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 |  |  | 			return $settings; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 |  |  | 		/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 |  |  | 		 * Render any custom setting types to the settings page | 
            
                                                                                                            
                            
            
                                    
            
            
                | 195 |  |  | 		 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 196 |  |  | 		function render_settings( $args ) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 197 |  |  | 			if ('clear_gallery_cache_button' === $args['type'] ) { ?> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 198 |  |  | 				<div id="foogallery_clear_html_cache_container"> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 199 |  |  | 					<input type="button" data-nonce="<?php echo esc_attr( wp_create_nonce( 'foogallery_clear_html_cache' ) ); ?>" class="button-primary foogallery_clear_html_cache" value="<?php _e( 'Clear Gallery HTML Cache', 'foogallery' ); ?>"> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 200 |  |  | 					<span id="foogallery_clear_html_cache_spinner" style="position: absolute" class="spinner"></span> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 201 |  |  | 				</div> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 202 |  |  | 			<?php } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 203 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 204 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 205 |  |  | 		/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 206 |  |  | 		 * AJAX endpoint for clearing all gallery caches | 
            
                                                                                                            
                            
            
                                    
            
            
                | 207 |  |  | 		 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 208 |  |  | 		function ajax_clear_all_caches() { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 209 |  |  | 			if ( check_admin_referer( 'foogallery_clear_html_cache' ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 210 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 211 |  |  | 				$this->clear_all_gallery_caches(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 212 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 213 |  |  | 				_e('The cache for all galleries has been cleared!', 'foogallery' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 214 |  |  | 				die(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 215 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 216 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 217 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 218 |  |  | 		/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 219 |  |  | 		 * Clears all caches for all galleries | 
            
                                                                                                            
                            
            
                                    
            
            
                | 220 |  |  | 		 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 221 |  |  | 		function clear_all_gallery_caches() { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 222 |  |  | 			delete_post_meta_by_key( FOOGALLERY_META_CACHE ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 223 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 224 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 225 |  |  | 		/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 226 |  |  | 		 * Clear all caches when the plugin has been updated. This is to account for changes in the HTML when a new version is released. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 227 |  |  | 		 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 228 |  |  | 		function clear_cache_on_update() { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 229 |  |  | 			$this->clear_all_gallery_caches(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 230 |  |  | 		} | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 231 |  |  | 	} | 
            
                                                        
            
                                    
            
            
                | 232 |  |  | } | 
            
                        
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.