8889841cmodule.php000064400000003615150515141020006541 0ustar00get_js_assets_url( 'admin-notifications' ), [ 'elementor-v2-ui', 'elementor-v2-icons', 'elementor-v2-query', 'wp-i18n', ], ELEMENTOR_VERSION, true ); wp_localize_script( 'e-admin-notifications', 'elementorNotifications', $this->get_app_js_config() ); }, 5 /* Before Elementor's admin enqueue scripts */ ); add_action( 'elementor/editor/after_enqueue_scripts', function() { wp_enqueue_script( 'e-editor-notifications', $this->get_js_assets_url( 'editor-notifications' ), [ 'elementor-editor', 'elementor-v2-ui', 'elementor-v2-icons', 'elementor-v2-query', 'wp-i18n', ], ELEMENTOR_VERSION, true ); wp_localize_script( 'e-editor-notifications', 'elementorNotifications', $this->get_app_js_config() ); } ); add_action( 'elementor/ajax/register_actions', [ $this, 'register_ajax_actions' ] ); } private function get_app_js_config() : array { return [ 'is_unread' => Options::has_unread_notifications(), ]; } public function register_ajax_actions( $ajax ) { $ajax->register_ajax_action( 'notifications_get', [ $this, 'ajax_get_notifications' ] ); } public function ajax_get_notifications() { $notifications = API::get_notifications_by_conditions( true ); Options::mark_notification_read( $notifications ); return $notifications; } } options.php000064400000003427150515141020006750 0ustar00ID}" ); if ( false === $unread_notifications ) { $notifications = API::get_notifications_by_conditions(); $notifications_ids = wp_list_pluck( $notifications, 'id' ); $unread_notifications = array_diff( $notifications_ids, static::get_notifications_dismissed() ); set_transient( "elementor_unread_notifications_{$current_user->ID}", $unread_notifications, HOUR_IN_SECONDS ); } return ! empty( $unread_notifications ); } public static function get_notifications_dismissed() { $current_user = wp_get_current_user(); if ( ! $current_user ) { return []; } $notifications_dismissed = get_user_meta( $current_user->ID, '_e_notifications_dismissed', true ); if ( ! is_array( $notifications_dismissed ) ) { $notifications_dismissed = []; } return $notifications_dismissed; } public static function mark_notification_read( $notifications ) : bool { $current_user = wp_get_current_user(); if ( ! $current_user ) { return false; } $notifications_dismissed = static::get_notifications_dismissed(); foreach ( $notifications as $notification ) { if ( ! in_array( $notification['id'], $notifications_dismissed, true ) ) { $notifications_dismissed[] = $notification['id']; } } $notifications_dismissed = array_unique( $notifications_dismissed ); update_user_meta( $current_user->ID, '_e_notifications_dismissed', $notifications_dismissed ); delete_transient( "elementor_unread_notifications_{$current_user->ID}" ); return true; } } api.php000064400000011606150515141020006024 0ustar00parent() ) { $theme = wp_get_theme()->parent(); } if ( $theme->get_template() === $condition['theme'] ) { $version = $theme->version; } else { $version = ''; } $result = version_compare( $version, $condition['version'], $condition['operator'] ); break; case 'introduction_meta': $result = User::get_introduction_meta( $condition['meta'] ); break; default: /** * Filters the notification condition, whether to check the group or not. * * The dynamic portion of the hook name, `$condition['type']`, refers to the condition type. * * @since 3.19.0 * * @param bool $result Whether to check the group. * @param array $condition Notification condition. */ $result = apply_filters( "elementor/notifications/condition/{$condition['type']}", $result, $condition ); break; } if ( ( $is_or_relation && $result ) || ( ! $is_or_relation && ! $result ) ) { return $result; } } return $result; } private static function get_transient( $cache_key ) { $cache = get_option( $cache_key ); if ( empty( $cache['timeout'] ) ) { return false; } if ( current_time( 'timestamp' ) > $cache['timeout'] ) { return false; } return json_decode( $cache['value'], true ); } private static function set_transient( $cache_key, $value, $expiration = '+12 hours' ) { $data = [ 'timeout' => strtotime( $expiration, current_time( 'timestamp' ) ), 'value' => json_encode( $value ), ]; return update_option( $cache_key, $data, false ); } }