PluginProbe ʕ •ᴥ•ʔ
Photo Gallery by FooGallery : Responsive Image Gallery, Masonry Gallery & Carousel / trunk
Photo Gallery by FooGallery : Responsive Image Gallery, Masonry Gallery & Carousel vtrunk
trunk 1.10.3 2.0.24 2.1.34 2.2.44 2.3.3 2.4.32 3.0.6 3.1.11 3.1.12 3.1.13 3.1.20 3.1.25 3.1.26 3.1.26.1 3.1.26.2
foogallery / includes / admin / class-admin-notice-custom-css.php
foogallery / includes / admin Last commit date
class-admin-notice-custom-css.php 7 months ago class-admin-notices.php 7 months ago class-admin.php 7 months ago class-attachment-fields.php 7 months ago class-columns.php 7 months ago class-demo-content.php 7 months ago class-extensions.php 7 months ago class-gallery-attachment-modal.php 7 months ago class-gallery-datasources.php 7 months ago class-gallery-editor.php 7 months ago class-gallery-metabox-fields.php 7 months ago class-gallery-metabox-items.php 7 months ago class-gallery-metabox-settings-helper.php 7 months ago class-gallery-metabox-settings.php 7 months ago class-gallery-metabox-template.php 7 months ago class-gallery-metaboxes.php 7 months ago class-menu.php 7 months ago class-pro-promotion.php 7 months ago class-settings.php 7 months ago class-silent-installer-skin.php 7 months ago class-trial-mode.php 7 months ago demo-content-galleries.php 7 months ago demo-content-images.php 7 months ago index.php 11 years ago pro-features.php 7 months ago view-features.php 7 months ago view-help-demos.php 7 months ago view-help-getting-started.php 7 months ago view-help-pro.php 7 months ago view-help.php 7 months ago view-system-info.php 7 months ago
class-admin-notice-custom-css.php
279 lines
1 <?php
2 /*
3 * FooGallery Admin Custom CSS Notice class
4 */
5
6 if ( ! class_exists( 'FooGallery_Admin_Notice_CustomCSS' ) ) {
7
8 class FooGallery_Admin_Notice_CustomCSS {
9
10 private $option_name = FOOGALLERY_OPTION_CUSTOM_CSS;
11 private $notice_id = 'customcss';
12 private $notice_class = 'notice-info';
13 private $css_classes_to_check = array( 'fg-caption' );
14
15 public function __construct() {
16 // We only need to check this after v2.5.0
17 if ( version_compare( FOOGALLERY_VERSION, '2.5.0', '<' ) ) {
18 return;
19 }
20
21 // display the notice
22 add_action( 'admin_notices', array( $this, 'display_notice' ) );
23 // ajax handler to dismiss the notice
24 add_action( 'wp_ajax_foogallery_admin_notice_dismiss-' . $this->notice_id, array( $this, 'dismiss_notice' ) );
25 // clear the saved data if a gallery is saved, or settings are updated
26 add_action( 'foogallery_after_save_gallery', array( $this, 'determine_and_save_option' ) );
27 add_action( 'update_option_foogallery', array( $this, 'after_settings_updated' ), 10, 3 );
28 // override the settings
29 add_filter( 'foogallery_admin_settings_override', array( $this, 'override_settings' ) );
30 //render the custom css settings
31 add_action( 'foogallery_admin_settings_custom_type_render_setting', array( $this, 'render_settings' ) );
32
33 }
34
35 /**
36 * Override the settings
37 */
38 function override_settings( $settings ) {
39 $option = $this->get_option();
40
41 if ( count( $option['galleries'] ) > 0 || $option['setting'] ) {
42
43 $index = foogallery_admin_fields_find_index_of_field( $settings['settings'], 'custom_js' );
44
45 $link_html = '<a target="_blank" href="' . esc_url( 'https://fooplugins.com/documentation/foogallery/troubleshooting-foogallery/foogallery-v3-0-custom-css-migration-guide/' ) . '">' . __( 'Custom CSS v3 Migration Guide', 'foogallery' ) . '</a>';
46
47 $new_settings[] = array(
48 'id' => 'custom_css_update',
49 'title' => __( 'Custom CSS Review!', 'foogallery' ),
50 'desc' => __( 'We found custom CSS that needs to be reviewed. Since FooGallery update v3, custom CSS related to captions (specifically when using `fg-caption`), nees to be reivewed and in some cases updated.', 'foogallery' ) . '<br />' .
51 __( 'Changes are not always needed, so if you review your Custom CSS and all seems correct, you can safely dismiss the admin notice, and ignore this message.', 'foogallery' ) . '<br />' .
52 sprintf( __( 'For more info, please read our %s.', 'foogallery' ), $link_html ),
53 'type' => 'custom_css_update',
54 'tab' => 'custom_assets',
55 );
56
57 array_splice( $settings['settings'], $index, 0, $new_settings );
58 }
59
60 return $settings;
61 }
62
63 /**
64 * Render any custom setting types to the settings page
65 */
66 function render_settings( $args ) {
67 if ( 'custom_css_update' === $args['type'] ) {
68 $option = $this->get_option();
69
70 if ( is_array( $option ) && count( $option ) > 0 ) {
71 $galleries = $option['galleries'];
72 if ( count( $galleries ) > 0 ) {
73 ?>
74 <p><?php esc_html_e( 'You will need to update the custom CSS on the following galleries:', 'foogallery' ); ?></p>
75 <ul class="ul-disc">
76 <?php foreach ( $galleries as $gallery_id => $gallery_name ) { ?>
77 <li><a href="<?php echo esc_url( get_edit_post_link( $gallery_id ) ); ?>"><?php echo esc_html( $gallery_name ); ?></a></li>
78 <?php } ?>
79 </ul>
80 <?php
81 }
82 if ( $option['setting'] ) {
83 ?>
84 <p><?php esc_html_e( 'You have outdated custom CSS saved in the Custom Stylesheet setting below that needs to be updated.', 'foogallery' ); ?></p>
85 <?php
86 }
87 }
88 }
89 }
90
91 /**
92 * Clear the saved data after settings are updated.
93 */
94 function after_settings_updated( $old_value, $value, $option ) {
95 if ( !is_admin() ) {
96 return;
97 }
98
99 if ( !current_user_can( 'manage_options' ) ) {
100 return;
101 }
102
103 $this->determine_and_save_option();
104 }
105
106 /**
107 * Display the admin notice.
108 */
109 function display_notice() {
110 if ( $this->should_show_notice() ) {
111 ?>
112 <script type="text/javascript">
113 (function( $ ) {
114 $( document ).ready( function() {
115 $( '.foogallery-admin-notice-<?php echo esc_attr( $this->notice_id ); ?>.is-dismissible' )
116 .on( 'click', '.notice-dismiss', function( e ) {
117 e.preventDefault();
118 $.post( ajaxurl, {
119 action: 'foogallery_admin_notice_dismiss-<?php echo esc_js( $this->notice_id ); ?>',
120 url: "<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>",
121 _wpnonce: "<?php echo esc_attr( wp_create_nonce( 'foogallery_admin_notice_dismiss-' . $this->notice_id )); ?>"
122 } );
123 } );
124 } );
125 })( jQuery );
126 </script>
127 <div class="notice <?php echo esc_attr( $this->notice_class ); ?> is-dismissible foogallery-admin-notice-<?php echo esc_attr( $this->notice_id ); ?>">
128 <?php $this->display_notice_inner_html(); ?>
129 </div>
130 <?php
131 }
132 }
133
134 /**
135 * Display the inner HTML of the admin notice.
136 */
137 function display_notice_inner_html() {
138 $option = $this->get_option();
139 $url = foogallery_admin_settings_url() . '#custom_assets';
140 $link = '<a href="'. $url . '">' . __( 'FooGallery Settings', 'foogallery' ) . '</a>';
141 if ( is_array( $option ) && count( $option ) > 0 ) { ?>
142 <h3><?php esc_html_e( 'FooGallery - Custom CSS Update Required', 'foogallery' ); ?></h3>
143 <?php
144 $galleries = $option['galleries'];
145 if ( count( $galleries ) > 0 ) {
146 ?>
147 <p><?php printf( esc_html__( 'We found outdated custom CSS in %s galleries that needs to be updated.', 'foogallery' ), count( $galleries ) ); ?></p>
148 <?php
149 }
150 if ( $option['setting'] ) {
151 ?>
152 <p><?php printf( esc_html__( 'You have outdated custom CSS saved in settings that needs to be updated.', 'foogallery' ) ); ?></p>
153 <?php
154 }
155 ?>
156 <p><?php printf( esc_html__( 'You will need to update your custom CSS! Visit %s to see what needs updating', 'foogallery' ), wp_kses_post( $link ) ); ?></p>
157 <?php }
158 }
159
160 /**
161 * Determine if the notice should be shown.
162 */
163 function should_show_notice() {
164 $option = $this->get_option( true );
165
166 if ( !is_array( $option ) ) {
167 return false;
168 }
169
170 if ( count( $option['galleries'] ) === 0 && !$option['setting'] ) {
171 // we have previously checked and the results were clear.
172 return false;
173 } else if ( $option['hide'] ) {
174 // the user has hidden the notice. Never show!
175 return false;
176 }
177
178 // If we get here, then the notice should be shown.
179 return true;
180 }
181
182 /**
183 * Get the option.
184 */
185 function get_option( $determine = false ) {
186 $option = get_option( $this->option_name );
187
188 // If false, then the option doesn't exist.
189 if ( $option === false ) {
190 if ( $determine ) {
191 $this->determine_and_save_option();
192 $option = get_option( $this->option_name );
193 }
194 }
195
196 if ( !is_array( $option ) ) {
197 // Malformed.
198 $option = array(
199 'galleries' => array(),
200 'setting' => false,
201 'hide' => false
202 );
203 }
204
205 return $option;
206 }
207
208 /**
209 * Get the hidden state of the option.
210 */
211 function get_option_hidden() {
212 $option = get_option( $this->option_name );
213
214 return isset( $option['hide'] ) ? $option['hide'] : false;
215 }
216
217 /**
218 * Ajax handler to dismiss the notice.
219 */
220 function dismiss_notice() {
221 if ( check_admin_referer( 'foogallery_admin_notice_dismiss-' . $this->notice_id ) ) {
222 // Just update the hide flag.
223 $option = $this->get_option();
224 $option['hide'] = true;
225 update_option( $this->option_name, $option, false );
226 }
227 }
228
229 /**
230 * Determine and save the option.
231 */
232 function determine_and_save_option() {
233 $option = $option = array(
234 'galleries' => array(),
235 'setting' => false,
236 'hide' => $this->get_option_hidden()
237 );
238
239 $galleries = foogallery_get_all_galleries();
240
241 $galleries_with_css = array();
242 $custom_css_setting_contains = false;
243
244 if ( ! empty( $galleries ) ) {
245 foreach ( $galleries as $gallery ) {
246 $custom_css = get_post_meta( $gallery->ID, FOOGALLERY_META_CUSTOM_CSS, true );
247
248 if ( $this->does_contain_css_classes( $custom_css ) ) {
249 $galleries_with_css[$gallery->ID] = $gallery->name;
250 }
251 }
252 }
253
254 $custom_css_setting = foogallery_get_setting( 'custom_css' );
255
256 if ( !empty( $custom_css_setting ) ) {
257 if ( $this->does_contain_css_classes( $custom_css_setting ) ) {
258 $custom_css_setting_contains = true;
259 }
260 }
261
262 $option['galleries'] = $galleries_with_css;
263 $option['setting'] = $custom_css_setting_contains;
264 update_option( $this->option_name, $option, false );
265 }
266
267 /**
268 * Check if the CSS contains any of the classes we are looking for.
269 */
270 function does_contain_css_classes( $css ) {
271 foreach ( $this->css_classes_to_check as $class ) {
272 if ( strpos( $css, $class ) !== false ) {
273 return true;
274 }
275 }
276 return false;
277 }
278 }
279 }