register_default_entries(); $notifications = NotificationManager::get()->get_admin_bar_items(); if ( empty( $notifications ) ) { return; } $bar->add_node( [ 'id' => 'adpresso-notifications', 'title' => 'AdPresso', 'href' => false, ] ); foreach ( $notifications as $item ) { $item['badge'] = $item['badge'] ?? false; $onclick = $item['onclick'] ?? ''; $args = [ 'parent' => $item['context'] ?? 'adpresso-notifications', 'id' => sanitize_title( $item['slug'] ?? uniqid() ), 'title' => esc_html( $item['message'] ), 'href' => $item['link'] ?? '#', 'onclick' => $onclick, 'tooltip' => $item['tooltip'] ?? '', 'meta' => [ 'class' => 'adpresso-adminbar-notice adpresso-notice-' . esc_attr( $item['type'] ?? 'info' ), 'title' => wp_strip_all_tags( $item['message'] ), 'target' => '_blank', ], ]; if ( $item['badge'] ) { $args['title'] = wp_kses_post( sprintf( '%sNEW', esc_attr( $this->get_icon_for_type( $args['badge'] ) ), $args['title'] ) ); } if ( ! empty( $onclick ) ) { $args['href'] = '#'; $args['data-action'] = esc_attr( $onclick ); $args['class'] .= ' adpresso-notice-action'; } elseif ( ! empty( $args['href'] ) && $args['href'] !== '#' ) { $args['href'] = esc_url( $args['href'] ); $args['target'] = str_starts_with( $args['href'], 'http' ) ? '_blank' : '_self'; $args['rel'] = 'noopener noreferrer'; } else { $args['href'] = '#'; } $bar->add_node( $args ); } } /** * Returns the icon class for a given notification type. * * @param string $type * * @return string */ protected function get_icon_for_type( string $type ): string { $icons = [ 'info' => 'dashicons-info', 'warning' => 'dashicons-warning', 'error' => 'dashicons-dismiss', 'success' => 'dashicons-yes-alt', 'debug' => 'dashicons-editor-code', 'action' => 'dashicons-controls-play', 'link' => 'dashicons-external', 'help' => 'dashicons-sos', ]; return $icons[ $type ] ?? 'dashicons-info'; } /** * Registers default entries in the admin bar. * * @return void */ public function register_default_entries(): void { NotificationManager::get()->register( 'get-help', __('⚠️ Adblocker detected. Ads could be blocked.', 'adpresso'), [ 'location' => 'admin_bar', 'context' => 'adpresso-notifications', 'type' => 'info', 'link' => 'https://wpadpresso.com/contact?utm_source=plugin-backend&utm_medium=description-link&utm_campaign=contact&utm_content=description', ] ); } }