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