class-admin-notice-custom-css.php
2 months ago
class-admin-notices.php
2 months ago
class-admin.php
2 months ago
class-attachment-fields.php
2 months ago
class-columns.php
2 months ago
class-demo-content.php
2 months ago
class-extensions.php
2 months ago
class-gallery-attachment-modal.php
2 months ago
class-gallery-datasources.php
2 months ago
class-gallery-editor.php
2 months ago
class-gallery-metabox-fields.php
2 months ago
class-gallery-metabox-items.php
2 months ago
class-gallery-metabox-settings-helper.php
2 months ago
class-gallery-metabox-settings.php
2 months ago
class-gallery-metabox-template.php
2 months ago
class-gallery-metaboxes.php
2 months ago
class-menu.php
2 months ago
class-pro-promotion.php
2 months ago
class-settings.php
2 months ago
class-silent-installer-skin.php
2 months ago
class-trial-mode.php
2 months ago
demo-content-galleries.php
2 months ago
demo-content-images.php
2 months ago
index.php
2 months ago
pro-features.php
2 months ago
view-features.php
2 months ago
view-help-demos.php
2 months ago
view-help-getting-started.php
2 months ago
view-help-pro.php
2 months ago
view-help.php
2 months ago
view-system-info.php
2 months ago
class-admin-notices.php
395 lines
| 1 | <?php |
| 2 | /* |
| 3 | * FooGallery Admin Notices class |
| 4 | */ |
| 5 | |
| 6 | if ( ! class_exists( 'FooGallery_Admin_Notices' ) ) { |
| 7 | |
| 8 | class FooGallery_Admin_Notices { |
| 9 | |
| 10 | public function __construct() { |
| 11 | add_action( 'admin_notices', array( $this, 'display_thumb_test_notice' ) ); |
| 12 | add_action( 'admin_notices', array( $this, 'display_rating_notice' ) ); |
| 13 | |
| 14 | add_action( 'foogallery_thumbnail_generation_test', array( $this, 'save_test_results' ) ); |
| 15 | add_action( 'wp_ajax_foogallery_admin_rating_notice_dismiss', array( $this, 'admin_rating_notice_dismiss' ) ); |
| 16 | |
| 17 | add_action( 'admin_notices', array( $this, 'display_fooconvert_notice' ) ); |
| 18 | add_action( 'wp_ajax_foogallery_admin_fooconvert_notice_dismiss', array( $this, 'admin_fooconvert_notice_dismiss' ) ); |
| 19 | } |
| 20 | |
| 21 | function get_thumb_test_option() { |
| 22 | $option = get_option( FOOGALLERY_OPTION_THUMB_TEST ); |
| 23 | |
| 24 | if ( ! is_array( $option ) ) { |
| 25 | return false; |
| 26 | } |
| 27 | |
| 28 | return $option; |
| 29 | } |
| 30 | |
| 31 | function should_run_tests() { |
| 32 | $option = $this->get_thumb_test_option(); |
| 33 | $option_value = $this->generate_option_value(); |
| 34 | |
| 35 | if ( $option === false ) { |
| 36 | //we have never run tests before, or the saved option is malformed. |
| 37 | return true; |
| 38 | } |
| 39 | |
| 40 | if ( ! array_key_exists( 'key', $option ) || $option_value !== $option['key'] ) { |
| 41 | //either the PHP version or Host has changed. In either case, we should run tests again! |
| 42 | return true; |
| 43 | } |
| 44 | |
| 45 | if ( |
| 46 | ! array_key_exists( 'results', $option ) || |
| 47 | ! is_array( $option['results'] ) || |
| 48 | ! array_key_exists( 'success', $option['results'] ) |
| 49 | ) { |
| 50 | return true; |
| 51 | } |
| 52 | |
| 53 | return false; |
| 54 | } |
| 55 | |
| 56 | function should_show_alert() { |
| 57 | $option = $this->get_thumb_test_option(); |
| 58 | |
| 59 | if ( |
| 60 | false === $option || |
| 61 | ! array_key_exists( 'results', $option ) || |
| 62 | ! is_array( $option['results'] ) || |
| 63 | ! array_key_exists( 'success', $option['results'] ) |
| 64 | ) { |
| 65 | return false; |
| 66 | } |
| 67 | |
| 68 | $results = $option['results']; |
| 69 | |
| 70 | //should show the alert if the tests were not a success |
| 71 | return ! (bool) $results['success']; |
| 72 | } |
| 73 | |
| 74 | function generate_option_value() { |
| 75 | $php_version = phpversion(); |
| 76 | $host = home_url(); |
| 77 | |
| 78 | return "php$($php_version}-{$host}"; |
| 79 | } |
| 80 | |
| 81 | function save_test_results( $results ) { |
| 82 | update_option( FOOGALLERY_OPTION_THUMB_TEST, array( |
| 83 | 'key' => $this->generate_option_value(), |
| 84 | 'results' => $results, |
| 85 | ) ); |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Dismiss the admin rating notice forever |
| 90 | */ |
| 91 | function admin_rating_notice_dismiss() { |
| 92 | if ( ! check_ajax_referer( 'foogallery_admin_rating_notice_dismiss', false, false ) ) { |
| 93 | wp_send_json_error( array( |
| 94 | 'message' => __( 'Invalid security token.', 'foogallery' ), |
| 95 | ), 403 ); |
| 96 | } |
| 97 | |
| 98 | if ( ! current_user_can( 'manage_options' ) ) { |
| 99 | wp_send_json_error( array( |
| 100 | 'message' => __( 'Insufficient permissions.', 'foogallery' ), |
| 101 | ), 403 ); |
| 102 | } |
| 103 | |
| 104 | update_option( 'foogallery_admin_rating_notice_dismiss', 'hide' ); |
| 105 | wp_send_json_success(); |
| 106 | } |
| 107 | |
| 108 | function should_show_rating_message() { |
| 109 | //first try to get the saved option |
| 110 | $show_message = get_option( 'foogallery_admin_rating_notice_dismiss', 0 ); |
| 111 | |
| 112 | if ( 'hide' === $show_message ) { |
| 113 | return false; //never show - user has dismissed |
| 114 | } |
| 115 | |
| 116 | if ( 'show' === $show_message ) { |
| 117 | return true; //always show - user has created 5 or more galleries |
| 118 | } |
| 119 | |
| 120 | //do not show the notice if on activation page |
| 121 | if ( foogallery_is_activation_page() ) { |
| 122 | return false; |
| 123 | } |
| 124 | |
| 125 | //we must show the message - get out early |
| 126 | if ( 0 === $show_message ) { |
| 127 | $galleries = get_posts( array( |
| 128 | 'post_type' => FOOGALLERY_CPT_GALLERY, |
| 129 | 'post_status' => array( 'publish', 'draft' ), |
| 130 | 'cache_results' => false, |
| 131 | 'nopaging' => true, |
| 132 | ) ); |
| 133 | |
| 134 | $gallery_count = $this->count_excluding_demos( $galleries ); |
| 135 | |
| 136 | if ( $gallery_count >= 5 ) { |
| 137 | update_option( 'foogallery_admin_rating_notice_dismiss', 'show' ); |
| 138 | return true; |
| 139 | } else { |
| 140 | return false; |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | return true; |
| 145 | } |
| 146 | |
| 147 | /** |
| 148 | * Get a count of galleries that are not auto-generated demos |
| 149 | * |
| 150 | * @param $galleries |
| 151 | * |
| 152 | * @return int |
| 153 | */ |
| 154 | function count_excluding_demos( $galleries ) { |
| 155 | if ( ! is_array( $galleries ) ) { |
| 156 | return 0; |
| 157 | } |
| 158 | |
| 159 | $count = 0; |
| 160 | foreach ( $galleries as $gallery ) { |
| 161 | if ( strpos( $gallery->post_title, 'Demo : ' ) === false ) { |
| 162 | $count++; |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | return $count; |
| 167 | } |
| 168 | |
| 169 | function display_rating_notice() { |
| 170 | if ( $this->should_show_rating_message() ) { |
| 171 | |
| 172 | $url = 'https://fooplugins.link/please-rate-foogallery'; |
| 173 | ?> |
| 174 | <script type="text/javascript"> |
| 175 | (function( $ ) { |
| 176 | $( document ).ready( function() { |
| 177 | $( '.foogallery-rating-notice.is-dismissible' ) |
| 178 | .on( 'click', '.notice-dismiss', function( e ) { |
| 179 | e.preventDefault(); |
| 180 | $.post( ajaxurl, { |
| 181 | action: 'foogallery_admin_rating_notice_dismiss', |
| 182 | url: "<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>", |
| 183 | _wpnonce: "<?php echo esc_attr( wp_create_nonce( 'foogallery_admin_rating_notice_dismiss' )); ?>" |
| 184 | } ); |
| 185 | } ); |
| 186 | } ); |
| 187 | })( jQuery ); |
| 188 | </script> |
| 189 | <style> |
| 190 | .foogallery-rating-notice { |
| 191 | border-left-color: #ff69b4; |
| 192 | } |
| 193 | |
| 194 | .foogallery-rating-notice .dashicons-heart { |
| 195 | color: #ff69b4; |
| 196 | } |
| 197 | </style> |
| 198 | <div class="foogallery-rating-notice notice notice-success is-dismissible"> |
| 199 | <p> |
| 200 | <strong><?php esc_html_e( 'Thanks for using FooGallery', 'foogallery' ) ?> <span class="dashicons dashicons-heart"></span></strong> |
| 201 | <br/> |
| 202 | <?php esc_html_e( 'We noticed you have created 5 galleries in FooGallery. If you love FooGallery, please consider giving it a 5 star rating. Your positive ratings help spread the word and help us grow.', 'foogallery' ); ?> |
| 203 | <br/> |
| 204 | <br/> |
| 205 | <a class="button button-primary button-large" target="_blank" href="<?php echo esc_url( $url ); ?>"><?php esc_html_e( 'Rate FooGallery', 'foogallery' ); ?></a> |
| 206 | </p> |
| 207 | </div> |
| 208 | <?php |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | function display_thumb_test_notice() { |
| 213 | $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null; |
| 214 | if ( ! is_object( $screen ) ) { |
| 215 | return; |
| 216 | } |
| 217 | |
| 218 | // Only run on the galleries list page, not other FooGallery admin screens. |
| 219 | if ( 'edit-foogallery' === $screen->id ) { |
| 220 | |
| 221 | if ( $this->should_run_tests() ) { |
| 222 | $thumbs = new FooGallery_Thumbnails(); |
| 223 | $thumbs->run_thumbnail_generation_tests(); |
| 224 | } |
| 225 | |
| 226 | if ( $this->should_show_alert() ) { |
| 227 | ?> |
| 228 | <div class="notice error"> |
| 229 | <p> |
| 230 | <strong><?php esc_html_e( 'Thumbnail Generation Alert!', 'foogallery' ); ?></strong><br/> |
| 231 | <?php esc_html_e( 'There is a problem generating thumbnails for your galleries. There could be a number of reasons which could cause this problem.', 'foogallery' ); ?> |
| 232 | <br/> |
| 233 | <?php esc_html_e( 'If thumbnails cannot be generated, then full-sized, uncropped images will be used instead. This will result in slow page load times, and thumbnails that do not look correct.', 'foogallery' ); ?> |
| 234 | <br/> |
| 235 | <a target="_blank" |
| 236 | href="https://fooplugins.com/documentation/foogallery/troubleshooting-foogallery/thumbnail-generation-alert-help/"><?php esc_html_e( 'View Troubleshooting Documentation', 'foogallery' ); ?></a> |
| 237 | <br/> |
| 238 | </p> |
| 239 | </div> |
| 240 | <?php |
| 241 | } |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | function display_fooconvert_notice() { |
| 246 | if ( $this->should_display_fooconvert_notice() ) { |
| 247 | |
| 248 | $install_fooconvert = wp_nonce_url( add_query_arg( array( |
| 249 | 'action' => 'install-plugin', |
| 250 | 'plugin' => 'fooconvert', |
| 251 | ), admin_url( 'update.php' ) ), 'install-plugin_fooconvert' ); |
| 252 | ?> |
| 253 | <script type="text/javascript"> |
| 254 | (function( $ ) { |
| 255 | $( document ).ready( function() { |
| 256 | $( '.foogallery-fooconvert-notice.is-dismissible' ) |
| 257 | .on( 'click', '.notice-dismiss', function( e ) { |
| 258 | e.preventDefault(); |
| 259 | $.post( ajaxurl, { |
| 260 | action: 'foogallery_admin_fooconvert_notice_dismiss', |
| 261 | url: "<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>", |
| 262 | _wpnonce: "<?php echo esc_attr( wp_create_nonce( 'foogallery_admin_fooconvert_notice_dismiss' )); ?>" |
| 263 | } ); |
| 264 | } ); |
| 265 | } ); |
| 266 | })( jQuery ); |
| 267 | </script> |
| 268 | <style> |
| 269 | .foogallery-fooconvert-notice { |
| 270 | border-left-color: #7c3aed; |
| 271 | } |
| 272 | |
| 273 | .foogallery-fooconvert-notice .dashicons-format-chat { |
| 274 | color: #7c3aed; |
| 275 | } |
| 276 | </style> |
| 277 | <div class="foogallery-fooconvert-notice notice is-dismissible"> |
| 278 | <p> |
| 279 | <strong><span class="dashicons dashicons-format-chat"></span> <?php esc_html_e( 'Are you looking for a Popup Builder for the block editor?', 'foogallery' ); ?></strong> |
| 280 | <?php esc_html_e( 'FooConvert can help!', 'foogallery' ); ?> |
| 281 | <br/> |
| 282 | <?php esc_html_e( 'FooConvert is a free plugin for building bars, flyouts, and overlays in the WordPress block editor. Create conversion-focused campaigns with triggers, display rules, lead capture, and analytics.', 'foogallery' ); ?> |
| 283 | <br/> |
| 284 | <br/> |
| 285 | <a class="button button-primary button-large" target="_blank" |
| 286 | href="<?php echo esc_url( $install_fooconvert ); ?>"><?php esc_html_e( 'Install FooConvert', 'foogallery' ); ?></a> |
| 287 | <a class="button" target="_blank" |
| 288 | href="https://wordpress.org/plugins/fooconvert/"><?php esc_html_e( 'View Details', 'foogallery' ); ?></a> |
| 289 | </p> |
| 290 | </div> |
| 291 | <?php |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | function should_display_fooconvert_notice() { |
| 296 | //do not show the notice to people who have FooConvert installed and activated |
| 297 | if ( class_exists( 'FooPlugins\FooConvert\Init' ) ) { |
| 298 | return false; |
| 299 | } |
| 300 | |
| 301 | //do not show the notice to pro users |
| 302 | if ( foogallery_is_pro() ) { |
| 303 | return false; |
| 304 | } |
| 305 | |
| 306 | //do not show the notice if on activation page |
| 307 | if ( foogallery_is_activation_page() ) { |
| 308 | return false; |
| 309 | } |
| 310 | |
| 311 | //only show on foogallery pages |
| 312 | if ( function_exists( 'get_current_screen' ) ) { |
| 313 | $screen = get_current_screen(); |
| 314 | if ( isset( $screen ) ) { |
| 315 | if ( $screen->post_type === FOOGALLERY_CPT_GALLERY || $screen->post_type === FOOGALLERY_CPT_ALBUM || $screen->id === FOOGALLERY_ADMIN_MENU_SETTINGS_SLUG ) { |
| 316 | |
| 317 | //first try to get the saved option |
| 318 | $show_message = get_option( 'foogallery_admin_fooconvert_notice_dismiss', 0 ); |
| 319 | |
| 320 | if ( 'hide' === $show_message ) { |
| 321 | return false; //never show - user has dismissed |
| 322 | } |
| 323 | |
| 324 | if ( ! $this->has_fooconvert_notice_update_grace_period_elapsed() ) { |
| 325 | return false; |
| 326 | } |
| 327 | |
| 328 | if ( 'show' === $show_message ) { |
| 329 | return true; //always show - user has created 5 or more galleries |
| 330 | } |
| 331 | |
| 332 | if ( 0 === $show_message ) { |
| 333 | $oldest_gallery = get_posts( array( |
| 334 | 'post_type' => FOOGALLERY_CPT_GALLERY, |
| 335 | 'post_status' => array( 'publish', 'draft' ), |
| 336 | 'order_by' => 'publish_date', |
| 337 | 'order' => 'ASC', |
| 338 | 'numberposts' => 1, |
| 339 | ) ); |
| 340 | |
| 341 | if ( is_array( $oldest_gallery ) && count( $oldest_gallery ) > 0 ) { |
| 342 | $oldest_gallery = $oldest_gallery[0]; |
| 343 | |
| 344 | if ( strtotime( $oldest_gallery->post_date ) < strtotime( '-7 days' ) ) { |
| 345 | //The oldest gallery is older than 7 days - so show the admin notice |
| 346 | update_option( 'foogallery_admin_fooconvert_notice_dismiss', 'show' ); |
| 347 | |
| 348 | return true; |
| 349 | } |
| 350 | } |
| 351 | } |
| 352 | } |
| 353 | } |
| 354 | } |
| 355 | |
| 356 | return false; |
| 357 | } |
| 358 | |
| 359 | /** |
| 360 | * Check whether enough time has passed since the latest FooGallery update. |
| 361 | * |
| 362 | * @return bool |
| 363 | */ |
| 364 | function has_fooconvert_notice_update_grace_period_elapsed() { |
| 365 | $updated_at = class_exists( 'FooGallery_Version_Check' ) ? FooGallery_Version_Check::get_last_update_time() : 0; |
| 366 | |
| 367 | if ( 0 === $updated_at ) { |
| 368 | return false; |
| 369 | } |
| 370 | |
| 371 | return ( time() - $updated_at ) >= ( 3 * DAY_IN_SECONDS ); |
| 372 | } |
| 373 | |
| 374 | /** |
| 375 | * Dismiss the admin FooConvert notice forever |
| 376 | */ |
| 377 | function admin_fooconvert_notice_dismiss() { |
| 378 | if ( ! check_ajax_referer( 'foogallery_admin_fooconvert_notice_dismiss', false, false ) ) { |
| 379 | wp_send_json_error( array( |
| 380 | 'message' => __( 'Invalid security token.', 'foogallery' ), |
| 381 | ), 403 ); |
| 382 | } |
| 383 | |
| 384 | if ( ! current_user_can( 'manage_options' ) ) { |
| 385 | wp_send_json_error( array( |
| 386 | 'message' => __( 'Insufficient permissions.', 'foogallery' ), |
| 387 | ), 403 ); |
| 388 | } |
| 389 | |
| 390 | update_option( 'foogallery_admin_fooconvert_notice_dismiss', 'hide', false ); |
| 391 | wp_send_json_success(); |
| 392 | } |
| 393 | } |
| 394 | } |
| 395 |