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-notices.php
329 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_foobar_notice' ) ); |
| 18 | add_action( 'wp_ajax_foogallery_admin_foobar_notice_dismiss', array( $this, 'admin_foobar_notice_dismiss' ) ); |
| 19 | } |
| 20 | |
| 21 | function should_run_tests() { |
| 22 | $option = get_option( FOOGALLERY_OPTION_THUMB_TEST ); |
| 23 | $option_value = $this->generate_option_value(); |
| 24 | |
| 25 | if ( $option === false ) { |
| 26 | //we have never run tests before |
| 27 | return true; |
| 28 | } else { |
| 29 | if ( is_array( $option ) && array_key_exists( 'key', $option ) ) { |
| 30 | $option_key = $option['key']; |
| 31 | if ( $option_value !== $option_key ) { |
| 32 | //either the PHP version or Host has changed. In either case, we should run tests again! |
| 33 | return true; |
| 34 | } |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | return false; |
| 39 | } |
| 40 | |
| 41 | function should_show_alert() { |
| 42 | $option = get_option( FOOGALLERY_OPTION_THUMB_TEST ); |
| 43 | |
| 44 | if ( isset( $option ) && array_key_exists( 'results', $option ) ) { |
| 45 | $results = $option['results']; |
| 46 | |
| 47 | //should show the alert if the tests were not a success |
| 48 | return ! $results['success']; |
| 49 | } |
| 50 | |
| 51 | return false; |
| 52 | } |
| 53 | |
| 54 | function generate_option_value() { |
| 55 | $php_version = phpversion(); |
| 56 | $host = home_url(); |
| 57 | |
| 58 | return "php$($php_version}-{$host}"; |
| 59 | } |
| 60 | |
| 61 | function save_test_results( $results ) { |
| 62 | update_option( FOOGALLERY_OPTION_THUMB_TEST, array( |
| 63 | 'key' => $this->generate_option_value(), |
| 64 | 'results' => $results, |
| 65 | ) ); |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Dismiss the admin rating notice forever |
| 70 | */ |
| 71 | function admin_rating_notice_dismiss() { |
| 72 | if ( check_admin_referer( 'foogallery_admin_rating_notice_dismiss' ) ) { |
| 73 | update_option( 'foogallery_admin_rating_notice_dismiss', 'hide' ); |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | function should_show_rating_message() { |
| 78 | //first try to get the saved option |
| 79 | $show_message = get_option( 'foogallery_admin_rating_notice_dismiss', 0 ); |
| 80 | |
| 81 | if ( 'hide' === $show_message ) { |
| 82 | return false; //never show - user has dismissed |
| 83 | } |
| 84 | |
| 85 | if ( 'show' === $show_message ) { |
| 86 | return true; //always show - user has created 5 or more galleries |
| 87 | } |
| 88 | |
| 89 | //do not show the notice if on activation page |
| 90 | if ( foogallery_is_activation_page() ) { |
| 91 | return false; |
| 92 | } |
| 93 | |
| 94 | //we must show the message - get out early |
| 95 | if ( 0 === $show_message ) { |
| 96 | $galleries = get_posts( array( |
| 97 | 'post_type' => FOOGALLERY_CPT_GALLERY, |
| 98 | 'post_status' => array( 'publish', 'draft' ), |
| 99 | 'cache_results' => false, |
| 100 | 'nopaging' => true, |
| 101 | ) ); |
| 102 | |
| 103 | $gallery_count = $this->count_excluding_demos( $galleries ); |
| 104 | |
| 105 | if ( $gallery_count >= 5 ) { |
| 106 | update_option( 'foogallery_admin_rating_notice_dismiss', 'show' ); |
| 107 | return true; |
| 108 | } else { |
| 109 | return false; |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | return true; |
| 114 | } |
| 115 | |
| 116 | /** |
| 117 | * Get a count of galleries that are not auto-generated demos |
| 118 | * |
| 119 | * @param $galleries |
| 120 | * |
| 121 | * @return int |
| 122 | */ |
| 123 | function count_excluding_demos( $galleries ) { |
| 124 | if ( ! is_array( $galleries ) ) { |
| 125 | return 0; |
| 126 | } |
| 127 | |
| 128 | $count = 0; |
| 129 | foreach ( $galleries as $gallery ) { |
| 130 | if ( strpos( $gallery->post_title, 'Demo : ' ) === false ) { |
| 131 | $count++; |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | return $count; |
| 136 | } |
| 137 | |
| 138 | function display_rating_notice() { |
| 139 | if ( $this->should_show_rating_message() ) { |
| 140 | |
| 141 | $url = 'https://fooplugins.link/please-rate-foogallery'; |
| 142 | ?> |
| 143 | <script type="text/javascript"> |
| 144 | (function( $ ) { |
| 145 | $( document ).ready( function() { |
| 146 | $( '.foogallery-rating-notice.is-dismissible' ) |
| 147 | .on( 'click', '.notice-dismiss', function( e ) { |
| 148 | e.preventDefault(); |
| 149 | $.post( ajaxurl, { |
| 150 | action: 'foogallery_admin_rating_notice_dismiss', |
| 151 | url: "<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>", |
| 152 | _wpnonce: "<?php echo esc_attr( wp_create_nonce( 'foogallery_admin_rating_notice_dismiss' )); ?>" |
| 153 | } ); |
| 154 | } ); |
| 155 | } ); |
| 156 | })( jQuery ); |
| 157 | </script> |
| 158 | <style> |
| 159 | .foogallery-rating-notice { |
| 160 | border-left-color: #ff69b4; |
| 161 | } |
| 162 | |
| 163 | .foogallery-rating-notice .dashicons-heart { |
| 164 | color: #ff69b4; |
| 165 | } |
| 166 | </style> |
| 167 | <div class="foogallery-rating-notice notice notice-success is-dismissible"> |
| 168 | <p> |
| 169 | <strong><?php esc_html_e( 'Thanks for using FooGallery', 'foogallery' ) ?> <span class="dashicons dashicons-heart"></span></strong> |
| 170 | <br/> |
| 171 | <?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' ); ?> |
| 172 | <br/> |
| 173 | <br/> |
| 174 | <a class="button button-primary button-large" target="_blank" href="<?php echo esc_url( $url ); ?>"><?php esc_html_e( 'Rate FooGallery', 'foogallery' ); ?></a> |
| 175 | </p> |
| 176 | </div> |
| 177 | <?php |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | function display_thumb_test_notice() { |
| 182 | //check if we are on specific admin pages |
| 183 | if ( FOOGALLERY_CPT_GALLERY === foo_current_screen_post_type() ) { |
| 184 | |
| 185 | if ( $this->should_run_tests() ) { |
| 186 | $thumbs = new FooGallery_Thumbnails(); |
| 187 | $thumbs->run_thumbnail_generation_tests(); |
| 188 | } |
| 189 | |
| 190 | if ( $this->should_show_alert() ) { |
| 191 | ?> |
| 192 | <div class="notice error"> |
| 193 | <p> |
| 194 | <strong><?php esc_html_e( 'Thumbnail Generation Alert!', 'foogallery' ); ?></strong><br/> |
| 195 | <?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' ); ?> |
| 196 | <br/> |
| 197 | <?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' ); ?> |
| 198 | <br/> |
| 199 | <a target="_blank" |
| 200 | href="https://fooplugins.com/documentation/foogallery/troubleshooting-foogallery/thumbnail-generation-alert-help/"><?php esc_html_e( 'View Troubleshooting Documentation', 'foogallery' ); ?></a> |
| 201 | <br/> |
| 202 | </p> |
| 203 | </div> |
| 204 | <?php |
| 205 | } |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | function display_foobar_notice() { |
| 210 | if ( $this->should_display_foobar_notice() ) { |
| 211 | |
| 212 | $install_foobar = wp_nonce_url( add_query_arg( array( |
| 213 | 'action' => 'install-plugin', |
| 214 | 'plugin' => 'foobar-notifications-lite', |
| 215 | ), admin_url( 'update.php' ) ), 'install-plugin_foobar-notifications-lite' ); |
| 216 | ?> |
| 217 | <script type="text/javascript"> |
| 218 | (function( $ ) { |
| 219 | $( document ).ready( function() { |
| 220 | $( '.foogallery-foobar-notice.is-dismissible' ) |
| 221 | .on( 'click', '.notice-dismiss', function( e ) { |
| 222 | e.preventDefault(); |
| 223 | $.post( ajaxurl, { |
| 224 | action: 'foogallery_admin_foobar_notice_dismiss', |
| 225 | url: "<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>", |
| 226 | _wpnonce: "<?php echo esc_attr( wp_create_nonce( 'foogallery_admin_foobar_notice_dismiss' )); ?>" |
| 227 | } ); |
| 228 | } ); |
| 229 | } ); |
| 230 | })( jQuery ); |
| 231 | </script> |
| 232 | <style> |
| 233 | .foogallery-foobar-notice { |
| 234 | border-left-color: #ff4800; |
| 235 | } |
| 236 | |
| 237 | .foogallery-foobar-notice .dashicons-megaphone { |
| 238 | color: #ff4800; |
| 239 | } |
| 240 | </style> |
| 241 | <div class="foogallery-foobar-notice notice notice-success is-dismissible"> |
| 242 | <p> |
| 243 | <strong><span class="dashicons dashicons-megaphone"></span> Do you want to grow your business?</strong> |
| 244 | FooBar can help! |
| 245 | <br/> |
| 246 | FooBar is a free plugin to help grow your business by showing sticky notification bars with |
| 247 | call-to-actions. Add unlimited notifications to your site to increase visitor engagement and get your message across! |
| 248 | <br/> |
| 249 | <br/> |
| 250 | <a class="button button-primary button-large" target="_blank" |
| 251 | href="<?php echo wp_kses_post( $install_foobar ); ?>">Install FooBar</a> |
| 252 | <a class="button" target="_blank" |
| 253 | href="https://wordpress.org/plugins/foobar-notifications-lite/">View Details</a> |
| 254 | </p> |
| 255 | </div> |
| 256 | <?php |
| 257 | } |
| 258 | } |
| 259 | |
| 260 | function should_display_foobar_notice() { |
| 261 | //do not show the notice to people who have foobar installed and activated |
| 262 | if ( class_exists( 'FooPlugins\FooBar\Init' ) ) { |
| 263 | return false; |
| 264 | } |
| 265 | |
| 266 | //do not show the notice to pro users |
| 267 | if ( foogallery_is_pro() ) { |
| 268 | return false; |
| 269 | } |
| 270 | |
| 271 | //do not show the notice if on activation page |
| 272 | if ( foogallery_is_activation_page() ) { |
| 273 | return false; |
| 274 | } |
| 275 | |
| 276 | //only show on foogallery pages |
| 277 | if ( function_exists( 'get_current_screen' ) ) { |
| 278 | $screen = get_current_screen(); |
| 279 | if ( isset( $screen ) ) { |
| 280 | if ( $screen->post_type === FOOGALLERY_CPT_GALLERY || $screen->post_type === FOOGALLERY_CPT_ALBUM || $screen->id === FOOGALLERY_ADMIN_MENU_SETTINGS_SLUG ) { |
| 281 | |
| 282 | //first try to get the saved option |
| 283 | $show_message = get_option( 'foogallery_admin_foobar_notice_dismiss', 0 ); |
| 284 | |
| 285 | if ( 'hide' === $show_message ) { |
| 286 | return false; //never show - user has dismissed |
| 287 | } |
| 288 | |
| 289 | if ( 'show' === $show_message ) { |
| 290 | return true; //always show - user has created 5 or more galleries |
| 291 | } |
| 292 | |
| 293 | if ( 0 === $show_message ) { |
| 294 | $oldest_gallery = get_posts( array( |
| 295 | 'post_type' => FOOGALLERY_CPT_GALLERY, |
| 296 | 'post_status' => array( 'publish', 'draft' ), |
| 297 | 'order_by' => 'publish_date', |
| 298 | 'order' => 'ASC', |
| 299 | 'numberposts' => 1, |
| 300 | ) ); |
| 301 | |
| 302 | if ( is_array( $oldest_gallery ) && count( $oldest_gallery ) > 0 ) { |
| 303 | $oldest_gallery = $oldest_gallery[0]; |
| 304 | |
| 305 | if ( strtotime( $oldest_gallery->post_date ) < strtotime( '-7 days' ) ) { |
| 306 | //The oldest gallery is older than 7 days - so show the admin notice |
| 307 | update_option( 'foogallery_admin_foobar_notice_dismiss', 'show' ); |
| 308 | |
| 309 | return true; |
| 310 | } |
| 311 | } |
| 312 | } |
| 313 | } |
| 314 | } |
| 315 | } |
| 316 | |
| 317 | return false; |
| 318 | } |
| 319 | |
| 320 | /** |
| 321 | * Dismiss the admin foobar notice forever |
| 322 | */ |
| 323 | function admin_foobar_notice_dismiss() { |
| 324 | if ( check_admin_referer( 'foogallery_admin_foobar_notice_dismiss' ) ) { |
| 325 | update_option( 'foogallery_admin_foobar_notice_dismiss', 'hide', false ); |
| 326 | } |
| 327 | } |
| 328 | } |
| 329 | } |