*/ class Notifications { use Date; public $manager; public $conflict_days = 5; public $slug; /** * Construction method */ public function __construct() { $this->manager = new Manager(); $this->slug = Helper::slug_cleanup(); add_action('admin_print_scripts', array($this, 'init_notifications'), 99999999); add_action( 'pxlbsadminify_display_notice', array( $this, 'display_notice' ), 10, 2 ); add_action( 'pxlbsadminify_display_popup', array( $this, 'display_popup' ), 10, 2 ); add_action( 'wp_ajax_pxlbsadminify_notification_action', array( $this, 'pxlbsadminify_notification_action' ) ); } /** * Notification Action * * @author Jewel Theme */ public function pxlbsadminify_notification_action() { check_ajax_referer( 'pxlbsadminify_notification_nonce' ); // Security check - only administrators can manage notifications if (!current_user_can('manage_options')) { wp_send_json_error(array('message' => __('You do not have permission to perform this action.', 'adminify'))); } $action_type = ! empty( $_REQUEST['action_type'] ) ? sanitize_key( $_REQUEST['action_type'] ) : ''; $notification_type = ! empty( $_REQUEST['notification_type'] ) ? sanitize_key( $_REQUEST['notification_type'] ) : ''; $trigger_time = ! empty( $_REQUEST['trigger_time'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['trigger_time'] ) ) : ''; $exec_notifications = $this->manager->get_exec_notifications( $trigger_time, $notification_type ); // No Executable Notifications found . if ( empty( $exec_notifications ) ) { die( 0 ); } $count = 0; foreach ( $exec_notifications as $index => $notification ) { if ( 0 === $index ) { if ( 'disable' === $action_type ) { $notification->is_active = false; } $notification->fire( $trigger_time, $notification_type )->save(); } else { $count++; $notification->maybe_delay( $this->date_increment( $trigger_time, $this->conflict_days * $count ) )->save(); } } die( 0 ); } /** * Notification Setup * * @param [type] $type . * * @author Jewel Theme */ public function setup_notifications_by_type( $type ) { // $trigger_time should be today . $trigger_time = $this->current_time(); // Block if necessary . $notification_last_fired = get_option( "pxlbsadminify_{$type}_last_interact" ); if ( $notification_last_fired ) { $notification_enable_date = $this->date_increment( $notification_last_fired, $this->conflict_days ); if ( $this->date_is_prev( $trigger_time, $notification_enable_date ) ) { return; } } // Get Executable Notifications . $exec_notifications = $this->manager->get_exec_notifications( $trigger_time, $type ); // No Executable Notifications found . if ( empty( $exec_notifications ) ) { return; } $notification = $exec_notifications[0]; do_action( "pxlbsadminify_display_{$type}", $notification, $trigger_time ); } /** * Notification initialization * * @author Jewel Theme */ public function init_notifications() { add_action('admin_notices', array($this, 'setup_notifications')); add_action('network_admin_notices', array($this, 'setup_notifications')); } /** * Notification setup * * @author Jewel Theme */ public function setup_notifications() { $this->setup_notifications_by_type( 'notice' ); $this->setup_notifications_by_type( 'popup' ); } /** * Display notice * * @param [type] $notice . * @param [type] $trigger_time . * * @return void * @author Jewel Theme */ public function display_notice( $notice, $trigger_time ) { $notice->notice_header(); $notice->notice_content(); $notice->notice_footer(); $notice->core_script( $trigger_time ); } /** * Display Popup * * @param [type] $popup . * @param [type] $trigger_time . * * @return void * @author Jewel Theme */ public function display_popup( $popup, $trigger_time ) { // Premium users only see a campaign flagged "Show For Premium". if ( jltwp_adminify()->can_use_premium_code() && ! wp_validate_boolean( $popup->get_content( 'show_for_premium' ) ) ) { return ''; } $screen = get_current_screen(); if( !in_array($screen->id, ['toplevel_page_wp-adminify-settings', 'dashboard']) ) return; $image_url = $popup->get_content( 'image_url' ); ?>