'boldpost', 'easy-bookmark' => 'Easy bookmark', 'easy-currency' => 'Easy Currency', 'easy-elements' => 'Easy Elements', 'easy-hotel' => 'easy hotel', 'easy-menu-icons' => 'easy menu icons', 'easy-wishlist' => 'easy wishlist', 'themewant-product-gallery' => 'easy product gallery', 'rt-mega-menu' => 'RT Mega Menu', ); private static $instance = null; public static function get_instance() { if ( self::$instance === null ) { self::$instance = new self(); } return self::$instance; } public function __construct() { add_action( 'admin_notices', array( $this, 'easyel_notice_add_to_notice_bar' ) ); add_action( 'wp_dashboard_setup', array( $this, 'easyel_notice_add_to_dashboard_widget' ), 0 ); add_action( 'wp_ajax_easyel_notice_ignore_plugin_notice', array( $this, 'easyel_notice_ignore_plugin_notice' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'easyel_notice_enqueue_widget_assets' ) ); add_filter( 'get_user_option_meta-box-order_dashboard', array( $this, 'easyel_notice_force_widget_to_top' ) ); } /** * Load CSS on every admin page so notice-bar (which can render * anywhere) is styled correctly. Dashboard widget styles are also * included in the same file — harmless on non-dashboard pages. */ public function easyel_notice_enqueue_widget_assets( $hook ) { wp_register_style( 'easyel-notice-admin-style', EASYELEMENTS_DIR_URL . 'includes/NoticeDashboard/notice.css', array( 'dashicons' ), EASYELEMENTS_VER ); wp_enqueue_style( 'easyel-notice-admin-style' ); wp_register_script( 'easyel-notice-admin-script', EASYELEMENTS_DIR_URL . 'includes/NoticeDashboard/notice.js', array( 'jquery' ), EASYELEMENTS_VER, true ); wp_localize_script( 'easyel-notice-admin-script', 'easyelNoticeData', array( 'ajaxUrl' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'easyel_notice_nonce' ), ) ); wp_enqueue_script( 'easyel-notice-admin-script' ); } public function easyel_notice_ignore_plugin_notice() { $user_id = get_current_user_id(); check_ajax_referer( 'easyel_notice_nonce', 'nonce' ); if ( isset( $_POST['notice_id'] ) && ! empty( $_POST['notice_id'] ) ) { $notice_id = sanitize_text_field( wp_unslash( $_POST['notice_id'] ) ); // NOTE: user_meta key kept as `thewtmc_notice_ignore_*` for // backward compatibility with previously dismissed notices. if ( $user_id && ! get_user_meta( $user_id, 'thewtmc_notice_ignore_' . $notice_id, true ) ) { add_user_meta( $user_id, 'thewtmc_notice_ignore_' . $notice_id, 'true', true ); } else { update_user_meta( $user_id, 'thewtmc_notice_ignore_' . $notice_id, 'true' ); } wp_send_json_success(); } wp_die(); } public function get_notice_status( $notice_id ) { $user_id = get_current_user_id(); return get_user_meta( $user_id, 'thewtmc_notice_ignore_' . $notice_id, true ); } /** * Return the display name for the currently consuming plugin (based on * PLUGIN_SLUG). Empty string if the slug isn't in the known list. */ public function get_active_plugin_display_name() { if ( isset( self::$plugin_slug_titles[ self::PLUGIN_SLUG ] ) ) { return self::$plugin_slug_titles[ self::PLUGIN_SLUG ]; } return ''; } /** * Fetch notices from the central source. Always tags requests with this * plugin's own slug so the API returns global + plugin-targeted notices. */ public function easyel_notice_get_notices( $args = array() ) { if ( empty( $args['plugin'] ) ) { $args['plugin'] = self::PLUGIN_SLUG; } // API endpoint path stays as `/get_thewtmc` because it's the server // contract; renaming it would break the connection to the API. $notice_source_url = trailingslashit( EASYEL_NOTICE_SOURCE_URL ) . 'wp-json/reacthemes/v1/get_thewtmc'; $response = wp_remote_post( $notice_source_url, array( 'headers' => array( 'Content-Type' => 'application/json' ), 'timeout' => 30, 'redirection' => 5, 'blocking' => true, 'sslverify' => false, 'data_format' => 'body', 'body' => wp_json_encode( $args ), ) ); if ( is_wp_error( $response ) ) { return ''; } return wp_remote_retrieve_body( $response ); } public function expire_notice_by_date( $notice_id, $expire_timestamp ) { $today_date = gmdate( 'Y-m-d' ); $today_timestamp = strtotime( $today_date ); if ( $today_timestamp >= $expire_timestamp ) { $user_id = get_current_user_id(); delete_user_meta( $user_id, 'thewtmc_notice_ignore_' . $notice_id ); } } public function easyel_notice_add_to_notice_bar() { $args = array( 'screen' => 'notice-bar' ); $all_notice = $this->easyel_notice_get_notices( $args ); if ( empty( $all_notice ) ) { return; } $today_date = gmdate( 'Y-m-d' ); $today_timestamp = strtotime( $today_date ); $all_notice = json_decode( $all_notice, true ); if ( ! is_array( $all_notice ) ) { return; } foreach ( $all_notice as $notice ) { $notice_id = isset( $notice['notice_id'] ) ? $notice['notice_id'] : ''; $thumbnail_url = isset( $notice['thumbnail_url'] ) ? $notice['thumbnail_url'] : ''; $thumbnail_link = isset( $notice['thumbnail_link'] ) ? $notice['thumbnail_link'] : ''; $content = isset( $notice['content'] ) ? $notice['content'] : ''; $action_buttons = isset( $notice['action_buttons'] ) ? $notice['action_buttons'] : array(); $expire_timestamp = isset( $notice['expire_date'] ) ? strtotime( $notice['expire_date'] ) : ''; $this->expire_notice_by_date( $notice_id, $expire_timestamp ); $notice_ignore_status = $this->get_notice_status( $notice_id ); if ( $notice_ignore_status !== 'true' && $today_timestamp <= $expire_timestamp ) : ?>
$high_widgets['easyel_notice_widget'] ); unset( $high_widgets['easyel_notice_widget'] ); $wp_meta_boxes['dashboard']['normal']['high'] = $our_widget + $high_widgets; } /** * Override the user's saved meta-box order so the Stories widget always * appears at the top of the 'normal' column. Without this filter, a user * who has previously dragged widgets around would keep the saved order * and our widget would end up wherever they left it. */ public function easyel_notice_force_widget_to_top( $order ) { if ( ! is_array( $order ) || empty( $order['normal'] ) ) { return $order; } $ids = array_filter( explode( ',', $order['normal'] ) ); $ids = array_values( array_diff( $ids, array( 'easyel_notice_widget' ) ) ); array_unshift( $ids, 'easyel_notice_widget' ); $order['normal'] = implode( ',', $ids ); return $order; } public function easyel_notice_widget_callback() { $args = array( 'screen' => 'in-widget' ); $all_notice = $this->easyel_notice_get_notices( $args ); if ( empty( $all_notice ) ) { echo '

No stories available right now.

'; return; } $today_date = gmdate( 'Y-m-d' ); $today_timestamp = strtotime( $today_date ); $all_notice = json_decode( $all_notice, true ); if ( ! is_array( $all_notice ) ) { echo '

No stories available right now.

'; return; } echo '
'; foreach ( $all_notice as $notice ) { $notice_id = isset( $notice['notice_id'] ) ? $notice['notice_id'] : ''; $sub_title = isset( $notice['sub_title'] ) ? $notice['sub_title'] : ''; $thumbnail_url = isset( $notice['thumbnail_url'] ) ? $notice['thumbnail_url'] : ''; $thumbnail_link = isset( $notice['thumbnail_link'] ) ? $notice['thumbnail_link'] : ''; $content = isset( $notice['content'] ) ? $notice['content'] : ''; $action_buttons = isset( $notice['action_buttons'] ) ? $notice['action_buttons'] : array(); $expire_timestamp = isset( $notice['expire_date'] ) ? strtotime( $notice['expire_date'] ) : ''; if ( empty( $sub_title ) ) { $sub_title = $this->get_active_plugin_display_name(); } $this->expire_notice_by_date( $notice_id, $expire_timestamp ); $notice_ignore_status = $this->get_notice_status( $notice_id ); if ( $notice_ignore_status !== 'true' && $today_timestamp <= $expire_timestamp ) : ?>
'; } }