notice_url ) ) ); $_data = json_decode( $data, true ); if ( ! isset( $_data['show'] ) ) { return; } if ( $_data['show'] == false ) { return; } if ( is_wp_error( $_data ) ) { return false; } if ( $_data['msg'] == '""' ) { return; } $notice = $_COOKIE['quomodo-notice-adirectory'] ?? false; if ( 'is_dismissed' === $notice ) { return ''; } ?>
<?php echo esc_attr__( 'Cyber Monday Promo', 'adirectory' ); ?>
legacy_directory_content_exists() ) { return; } // Only show in admin area if ( ! is_admin() ) { return; } // Check if user has dismissed the notice $user_id = get_current_user_id(); if ( get_user_meta( $user_id, 'adqs_migration_notice_dismissed', true ) ) { return; } $migration_plugin_url = 'https://adirectory.io/global-source/admigrator.zip'; ?>

' . esc_html__( 'aDirectory', 'adirectory' ) . '', '' . esc_html__( '3.0.0', 'adirectory' ) . '' ); ?>

__( 'User not logged in.', 'adirectory' ) ] ); } $updated = update_user_meta( $user_id, 'adqs_migration_notice_dismissed', true ); if ( $updated ) { wp_send_json_success( [ 'message' => __( 'Notice dismissed successfully.', 'adirectory' ) ] ); } wp_send_json_error( [ 'message' => __( 'Failed to dismiss notice.', 'adirectory' ) ] ); } /** * Handle AJAX request to dismiss Cyber Monday notice * * @return void */ public function dismiss_black_friday_notice() { // Verify nonce check_ajax_referer( 'adqs_dismiss_notice_nonce', 'nonce' ); $user_id = get_current_user_id(); if ( ! $user_id ) { wp_send_json_error( [ 'message' => __( 'User not logged in.', 'adirectory' ) ] ); } $updated = update_user_meta( $user_id, 'adqs_black_friday_notice_dismissed', true ); if ( $updated ) { wp_send_json_success( [ 'message' => __( 'Notice dismissed successfully.', 'adirectory' ) ] ); } else { wp_send_json_error( [ 'message' => __( 'Failed to dismiss notice.', 'adirectory' ) ] ); } } /** * Enqueue scripts and styles for notices * * @return void */ public function enqueue_notice_assets() { $user_id = get_current_user_id(); $demo_notice_dismissed = get_user_meta( $user_id, 'adqs_demo_import_notice_dismissed', true ); $migration_notice_dismissed = get_user_meta( $user_id, 'adqs_migration_notice_dismissed', true ); $black_friday_notice_dismissed = get_user_meta( $user_id, 'adqs_black_friday_notice_dismissed', true ); $migration_needed = $this->legacy_directory_content_exists(); // If all notices are not visible, skip enqueue if ( $demo_notice_dismissed && ( ! $migration_needed || $migration_notice_dismissed ) && $black_friday_notice_dismissed ) { return; } // Enqueue inline script for AJAX dismissal wp_add_inline_script( 'jquery', $this->get_notice_dismiss_script() ); } /** * Get the JavaScript code for notice dismissal * * @return string */ private function get_notice_dismiss_script() { $ajax_url = admin_url( 'admin-ajax.php' ); $nonce = wp_create_nonce( 'adqs_dismiss_notice_nonce' ); return " jQuery(document).ready(function($) { // Handle demo import notice dismissal $(document).on('click', '.adqs-demo-import-notice .notice-dismiss', function(e) { var noticeElement = $(this).closest('.adqs-demo-import-notice'); var noticeId = noticeElement.data('notice-id'); $.ajax({ url: '" . esc_js( $ajax_url ) . "', type: 'POST', data: { action: 'adqs_dismiss_demo_import_notice', nonce: '" . esc_js( $nonce ) . "' }, success: function(response) { if (response.success) { console.log('Demo import notice dismissed successfully'); } }, error: function(xhr, status, error) { console.error('Error dismissing demo import notice:', error); } }); }); // Handle migration notice dismissal $(document).on('click', '.adqs-migration-notice .notice-dismiss', function(e) { var noticeElement = $(this).closest('.adqs-migration-notice'); var noticeId = noticeElement.data('notice-id'); $.ajax({ url: '" . esc_js( $ajax_url ) . "', type: 'POST', data: { action: 'adqs_dismiss_migration_notice', nonce: '" . esc_js( $nonce ) . "' }, success: function(response) { if (response.success) { console.log('Migration notice dismissed successfully'); } }, error: function(xhr, status, error) { console.error('Error dismissing migration notice:', error); } }); }); // Handle Cyber Monday notice dismissal $(document).on('click', '.adqs-black-friday-notice .notice-dismiss', function(e) { var noticeElement = $(this).closest('.adqs-black-friday-notice'); var noticeId = noticeElement.data('notice-id'); $.ajax({ url: '" . esc_js( $ajax_url ) . "', type: 'POST', data: { action: 'adqs_dismiss_black_friday_notice', nonce: '" . esc_js( $nonce ) . "' }, success: function(response) { if (response.success) { noticeElement.fadeOut(300, function() { $(this).remove(); }); console.log('Cyber Monday notice dismissed successfully'); } }, error: function(xhr, status, error) { console.error('Error dismissing Cyber Monday notice:', error); } }); }); }); "; } /** * Determine if legacy directory table exists. * * @return bool */ private function legacy_directory_content_exists() { global $wpdb; $legacy_post_count = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(1) FROM {$wpdb->posts} WHERE post_type = %s AND post_status NOT IN ('auto-draft')", 'adqs_directory' ) ); if ( $legacy_post_count > 0 ) { return true; } $directory_terms = get_terms( [ 'taxonomy' => 'adqs_listing_types', 'hide_empty' => false, 'fields' => 'ids', ] ); if ( is_wp_error( $directory_terms ) || empty( $directory_terms ) ) { return false; } foreach ( $directory_terms as $term_id ) { $post_type = get_term_meta( $term_id, 'adqs_directory_post_type', true ); if ( empty( $post_type ) || $post_type === 'adqs_directory' ) { return true; } } return false; } }