'dashicons-cart', 'admin' => 'dashicons-megaphone', ); $class = isset( $map[ $source ] ) ? $map[ $source ] : 'dashicons-bell'; return apply_filters( 'forwp_notifications_item_icon_class', $class, $source ); } /** * Resolve the "View all" URL. * * @param string $all_url Optional override URL. * @return string */ public static function resolve_all_url( $all_url = '' ) { $all_url = apply_filters( 'forwp_notifications_bell_all_url', $all_url ); if ( '' !== $all_url ) { return $all_url; } $page_id = (int) get_option( 'forwp_notifications_page_id', 0 ); if ( $page_id <= 0 ) { return ''; } $url = get_permalink( $page_id ); return $url ? $url : ''; } /** * Render bell widget HTML. * * @param array $args all_url, limit. * @return string */ public static function render( $args = array() ) { if ( ! is_user_logged_in() ) { return ''; } $args = wp_parse_args( $args, array( 'all_url' => '', 'limit' => 20, ) ); $all_url = self::resolve_all_url( (string) $args['all_url'] ); $limit = absint( $args['limit'] ); $limit = $limit > 0 ? min( $limit, 50 ) : 20; self::enqueue_assets(); $manager = new ForWP_Notifications_Manager(); $items = $manager->get_for_user( null, $limit, 0 ); $unread = $manager->count_unread( null ); $rest_url = rest_url( ForWP_Notifications_REST_Controller::NAMESPACE ); $nonce = wp_create_nonce( 'wp_rest' ); $icon_url = apply_filters( 'forwp_notifications_bell_icon_url', '' ); $i18n = array( 'empty' => __( 'No new notifications', '4wp-notifications' ), 'markRead' => __( 'Mark as read', '4wp-notifications' ), 'markUnread' => __( 'Mark as unread', '4wp-notifications' ), 'notification' => __( 'Notification', '4wp-notifications' ), 'goToPage' => __( 'Go to page', '4wp-notifications' ), 'justNow' => __( 'just now', '4wp-notifications' ), 'minAgo' => __( 'min ago', '4wp-notifications' ), 'hrAgo' => __( 'hr ago', '4wp-notifications' ), 'dAgo' => __( 'd ago', '4wp-notifications' ), ); wp_localize_script( 'forwp-notifications-bell-widget', 'forwpNotificationsBellI18n', $i18n ); ob_start(); ?>

>

'; } return ''; } /** * Output a single dropdown item. * * @param array $item Notification row. */ public static function render_item( $item ) { $payload = isset( $item['payload'] ) && is_array( $item['payload'] ) ? $item['payload'] : array(); $source = isset( $item['source'] ) ? $item['source'] : ''; $title = isset( $payload['title'] ) ? $payload['title'] : __( 'Notification', '4wp-notifications' ); $message = isset( $payload['message'] ) ? $payload['message'] : ''; $url = isset( $payload['url'] ) ? $payload['url'] : '#'; $is_read = ( (int) $item['is_read'] ) === 1; $created = isset( $item['created_at'] ) ? $item['created_at'] : ''; $time_ago = $created ? human_time_diff( strtotime( $created ), current_time( 'timestamp' ) ) . ' ' . __( 'ago', '4wp-notifications' ) : ''; $class = 'forwp-notifications-bell__item'; $toggle_label = $is_read ? __( 'Mark as unread', '4wp-notifications' ) : __( 'Mark as read', '4wp-notifications' ); $toggle_icon = $is_read ? 'dashicons-hidden' : 'dashicons-visibility'; $toggle_class = 'forwp-notifications-bell__item-toggle' . ( $is_read ? ' forwp-notifications-bell__item-toggle--read' : '' ); $icon_class = self::get_item_icon_class( $source ); $has_link = $url && '#' !== $url; if ( ! $is_read ) { $class .= ' forwp-notifications-bell__item--unread'; } ?>