| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * Class to help users who also use Autoptomize plugin | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * Date: 2017/11/12 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | if ( !class_exists( 'FooGallery_Autoptimize_Compatibility' ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |     class FooGallery_Autoptimize_Compatibility { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |         const transient_key = 'foogallery_autoptimize_notice'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |         function __construct() { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |             if ( is_admin() ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |                 add_action( 'admin_notices', array( $this, 'admin_notice' ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |                 add_action( 'foogallery_admin_new_version_detected', array( $this, 'set_to_show_admin_notice' ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |                 add_action( 'wp_ajax_foogallery_autoptimize_dismiss', array( $this, 'admin_notice_dismiss' ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |         /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |          * Set the transient for 3 days to display the message to flush the cache | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 24 |  |  |          */ | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  |         function set_to_show_admin_notice() { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  |             if ( class_exists( 'autoptimizeCache' ) ) { | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  |                 set_transient(FooGallery_Autoptimize_Compatibility::transient_key, true, 3 * 24 * 60 * 60); | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |             } | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |         /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |          * Display the admin notice | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |          */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |         function admin_notice() { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |             if ( !class_exists( 'autoptimizeCache' ) ) return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |             $show_notice = get_transient( FooGallery_Autoptimize_Compatibility::transient_key ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |             if ( false === $show_notice ) return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |             ?> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |             <script type="text/javascript"> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |                 ( function ( $ ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |                     $( document ).ready( function () { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |                         $( '.foogallery-autoptimize-notice.is-dismissible' ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |                             .on( 'click', '.notice-dismiss', function ( e ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |                                 e.preventDefault(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |                                 $.post( ajaxurl, { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |                                     action: 'foogallery_autoptimize_dismiss', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |                                     url: '<?php echo admin_url( 'admin-ajax.php' ); ?>', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |                                     _wpnonce: '<?php echo wp_create_nonce( 'foogallery_autoptimize_dismiss' ); ?>' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |                                 } ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |                             } ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |                     } ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |                 } )( jQuery ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |             </script> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |             <div class="foogallery-autoptimize-notice notice error is-dismissible"> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |                 <p> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |                     <strong><?php _e( 'FooGallery + Autoptimize : ', 'foobox-image-lightbox' ); ?></strong> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |                     <?php _e( 'We noticed that you have the Autoptimize plugin installed. After updating FooGallery, please make sure you delete the Autoptimize cache from the admin bar above to make sure your galleries continue to display correctly.' ); ?> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |                     <br /> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |                     <?php _e( 'If you continue to have issues using FooGallery and Autoptimize together, then please goto Autoptimize Plugin settings –> Java Script Options –> Exclude Scripts and add foogallery.min.js' ); ?> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |                 </p> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |             </div> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |             <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |          * Dismiss the admin notice | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |          */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |         function admin_notice_dismiss() { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |             if ( check_admin_referer( 'foogallery_autoptimize_dismiss' ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |                 delete_transient( FooGallery_Autoptimize_Compatibility::transient_key ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |         } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 73 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 74 |  |  | } | 
            
                        
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.