0 ) { $menu_title .= sprintf( '%d', absint( $notification_info['count'] ) ); } } add_dashboard_page( esc_html__( 'Notifications', 'unagi' ), $menu_title, required_capability(), 'notification', __NAMESPACE__ . '\notification_screen' ); } /** * Notification page */ function notification_screen() { global $unagi_nags; $output = $unagi_nags; if ( show_notifications_nicely() ) { $notification_info = prepare_notification_info(); $output = $notification_info['content']; } if ( empty( $output ) ) { $output = sprintf( '

%s

', esc_html__( 'Woohoo! There aren\'t any notifications for you.', 'unagi' ) ); } $output = apply_filters( 'unagi_notification_output', $output ); ?>

0, 'content' => '', ]; } $doc = new DOMDocument( '1.0', 'UTF-8' ); libxml_use_internal_errors( true ); $doc->loadHTML( $notification_content ); $xpath = new DOMXPath( $doc ); /** * Don't care if the notices don't respect default "notice" classes. * But adding a filter just in case someone else needed * * @since 0.1.0 */ $expression = apply_filters( 'unagi_xpath_expression', "//*[contains(@class, 'notice ') or contains(@class, ' notice') ]" ); $nodes = $xpath->query( $expression ); // notification nodes $collector = new DOMDocument( '1.0', 'UTF-8' ); $count = (int) $nodes->length; foreach ( $nodes as $node ) { $collector->appendChild( $collector->importNode( $node, true ) ); } $content = trim( $collector->saveHTML() ); return [ 'count' => $count, 'content' => $content, ]; }