• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Pull alerts onto external page

LPH

Well-known member
#1
I realize this topic has been discussed but there has never been a resolution. I'm looking for a way to pull the alert counts from XenForo to show on a WordPress blog.

There is a public function countAlertsForUser($userId) and I'm trying to figure out the best way to echo that count.

echo XenForo_Model_Alert::countAlertsForUser($userId)

Does anyone have any suggestions?

Should I just simply use the SELECT COUNT(*) FROM xf_user_alert and build this or use the public function?

Thank you for the guidance.
 

xf_phantom

Well-known member
#3
Do you want all alerts or only the unread?

For the unread, you don't need a query because the value is already available in the visitor object
PHP:
$visitor['alerts_unread'];
//even unread conversations will work;)
$visitor['conversations_unread'];
 

LPH

Well-known member
#4
Oh My Gosh! xf_phantom, thank you very much. This led me to what I wanted - unread conversations and alerts on the WordPress side.

PHP:
//unread alerts
$XF->visitor->get('alerts_unread')
//unread conversations
$XF->visitor->get('conversations_unread')
Adding those two codes to the WordPress child theme header file gives me the proper alerts and conversations.

PHP:
            <?php
                if ( is_user_logged_in() ) {
 
                    global $current_user, $XF;
                    get_currentuserinfo();
                   
                    echo '
                        <span id="member" class="loggedIn_menu_class"><a href="/community/conversations/">Inbox</a>  ' . $XF->visitor->get('conversations_unread') . '
                        <a href="/community/account/alerts">Alerts</a> ' . $XF->visitor->get('alerts_unread') . '
                        <a href="/community/logout">Log Out</a></span>
                        ';
 
                    echo '
                        <span id="member" class="loggedIn_menu_class">
                        ';
                   
                    echo '
                       
                        <a href="/community/members/' . strtolower($XF->visitor->get('username')) . '.' . $XF->visitor->get('user_id') .'"> '. $current_user->display_name .'</a></span>
                        ';
                   
                   
                        if ( $site_admins = array ( 'LPH', 'Robert Heiny', 'CMK', 'Lora', 'Joan Heiny', 'emheiny' ) ){
                            echo '
                                <span id="member" class="admin"><a href="/wp-admin">WordPress Admin Panel</a>
                                <a href="/wp-admin/post-new.php">WordPress Add New Blog Post</a>
                                <a href="/community/admin.php">XenForo Admin Panel</a></span>
                                ';
                        }
                 
                   
                   
                } else {
 
                    echo '
                        <script>XenForo.LoginBar = function(a){};</script>
                     
                        ';
                       
                        if ($_SERVER['HTTP_HOST'] == 'tuxnotes.tuxreportsnetwork.com') {
                           
                            echo '<span id="member" class="logIn_menu_class"><a href="http://www.tuxreportsnetwork.com/community/login" class="OverlayTrigger inner">Log In or Sign Up</a></span>';
                           
                        } else {
                       
                       
                        echo '<span id="member" class="logIn_menu_class"><a href="/community/login" class="OverlayTrigger inner">Log In or Sign Up</a></span>
                    ';
                } }                ?>
The Alerts and Conversations are now showing on the WordPress side!

Now I just need to add in the CSS to make it look like the XenForo side. Once again - you are the man!