Support Forum

Changing Inbox Button Color If Unread Messages

JI jim
jim
Member

I’ve always wanted to change the background color for the PM Inbox button, if there are unread messages.

I know there is a style for the unread message count, and I have changed that number to red. But I’m wondering if there is a way to assign a different style to that button itself so it stands out more when the user has unread private messages.

It looks like all those buttons share the same style: #spMainContainer a.spButton

I’m thinking we could apply a new style like: #spMainContainer a.spButton-pmunread

Another option would be to just change the Inbox icon, if user has unread messages.

But I’m guessing there would need to be some sort of hook or trigger to call that style(s) when messages await…can you tell I’m over my head yet?

Any thoughts or direction are appreciated. Thanks!

Screen-shot-2015-08-30-at-11.20.56-AM.png

17 Answers

New Answer

MP Mr Papa
Mr Papa
Member

two ways you could do this…

first, filter sph_PmInboxButton and change spButton to another class like you mention…

two, change the class in the call to pm inbox template tag from the theme head template file…

in both cases, you need to know if there are unread… so something like this:

    $newPM = sp_pm_get_inbox_unread_count($spThisUser->ID);

that will give you the count… so change

            if (function_exists('sp_PmInboxButton')) sp_PmInboxButton('tagClass=spButton spRight', __sp('Inbox:'), __sp('Go to PM inbox'));

to

            if (function_exists('sp_PmInboxButton')) {
                $newPM = sp_pm_get_inbox_unread_count($spThisUser->ID);
                $class = ($newPM > 0) ? 'spButtonUnread' : 'spButton';
                sp_PmInboxButton("tagClass=$class spRight", __sp('Inbox:'), __sp('Go to PM inbox'));
            }

and see if that does the trick…

JI jim
jim
Member

Mr Papa said
…see if that does the trick…

That was fun.

Screen-shot-2015-08-30-at-2.29.00-PM.png

 

I’ll need to come up with something more challenging next time…

Changing the inbox icon is proving to be a bit more tricky! wink

MP Mr Papa
Mr Papa
Member

it shouldnt be… its an argument to the sp_PmInboxButton() function, so change it just like you did the button..

JI jim
jim
Member

Mr Papa said
…its an argument to the sp_PmInboxButton() function…

So I thought, but I am not finding how or where the actual image file is being assigned or called. A search of all /simple-press and /reboot files for sp_PmInboxButton.png yields no results.

No biggie, but now I am curious!

MP Mr Papa
Mr Papa
Member

something like this:

            if (function_exists('sp_PmInboxButton')) {
                $newPM = sp_pm_get_inbox_unread_count($spThisUser->ID);
                $icon = ($newPM > 0) ? 'sp_PmInboxButton.png' : 'sp_PmInboxButtonUnread.png';
                $class = ($newPM > 0) ? 'spButtonUnread' : 'spButton';
                sp_PmInboxButton("tagClass=$class spRight&icon=$icon", __sp('Inbox:'), __sp('Go to PM inbox'));
            }
JI jim
jim
Member

Sweeet… y’all make it look so easy.

SpPmButton_Read-Unread.png

 

Thanks for the lesson!

If anyone ever questions the value of a SimplePress membership, tell them to message me.cool

JI jim
jim
Member

FYI: I just had to swap the icon $icon files as follows to get the right one to display for unread messages…

            if (function_exists('sp_PmInboxButton')) {
                $newPM = sp_pm_get_inbox_unread_count($spThisUser->ID);
                $icon = ($newPM > 0) ? 'sp_PmInboxButtonUnread.png' : 'sp_PmInboxButton.png';
                $class = ($newPM > 0) ? 'spButtonUnread' : 'spButton';
                sp_PmInboxButton("tagClass=$class spRight&icon=$icon", __sp('Inbox:'), __sp('Go to PM inbox'));
            }
MP Mr Papa
Mr Papa
Member

ah, yes… that would be correct…  glad it worked!

JI jim
jim
Member

Mr Papa said
…glad it worked!

Me too! But unfortunately it breaks in SP 6.0.

I actually forgot we did this, and submitted a private ticket after getting an Invalid Database Query error on all forum pages after activating the updated Private Messaging plugin.

I’m hoping we can get this working again, and am posting here publicly for anyone else who may have implemented this or those who may want to.

rebootkid (child theme) spHeadDesktop.php:111

This worked for us with SP 5.x using the attached image.

sp_PmInboxButtonUnread.png
if (function_exists(‘sp_PmInboxButton’)) {
$newPM = sp_pm_get_inbox_unread_count($spThisUser->ID);
$icon = ($newPM > 0) ? ‘sp_PmInboxButtonUnread.png’ : ‘sp_PmInboxButton.png’;
$class = ($newPM > 0) ? ‘spButtonUnread’ : ‘spButton’;
sp_PmInboxButton(“tagClass=$class spRight&icon=$icon”, __sp(‘Inbox:’), __sp(‘Go to PM inbox’));
}

It no longer works in SP 6.x so we reverted the the following copied from the Reboot 2.0 parent theme…

Reboot v.2.0 spHeadDesktop.php:111

if (function_exists(‘sp_PmInboxButton’)) sp_PmInboxButton(‘tagClass=spButton spRight’, __sp(‘Inbox:’), __sp(‘Go to PM inbox’));

Would love to get that working again…thanks!

MP Mr Papa
Mr Papa
Member

Jim, 

your code still should work… just need to adjust how you get the current user id…  try changing:

$spThisUser->ID

to be

SP()->user->thisUser->user_id

everything is class based now instead of bunch of globals…

JI jim
jim
Member

Mr Papa said
try changing…

Perfect, that did the trick. Thank you for the prompt response!

Just in case anyone is looking for help with this same issue, here’s the complete edit:

spHeadDesktop.php:111

# start reboot unread pm hack
if (function_exists('sp_PmInboxButton')) {
$newPM = sp_pm_get_inbox_unread_count(SP()->user->thisUser->user_id);
$icon = ($newPM > 0) ? 'sp_PmInboxButtonUnread.png' : 'sp_PmInboxButton.png';
$class = ($newPM > 0) ? 'spButtonUnread' : 'spButton';
sp_PmInboxButton("tagClass=$class spRight&icon=$icon", __sp('Inbox:'), __sp('Go to PM inbox'));
}
# end reboot pm hack
JI jim
jim
Member

Sigh…

So I just discovered this issue persists for any user not logged in.

The hack above works fine when the user is logged in, all pages load fine with no error.

Invalid Database Query error occurs on all forum pages for any user not logged in.

From the SP Error Log:

December 10, 2018 12:36 pm | spaErrError | 60 | database


file: …/public_html/wp-content/sp-resources/forum-plugins/private-messaging/library/sp-pm-database.php
line: 114
function: count
error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘AND read_status=0’ at line 1

JI jim
jim
Member

So, I figure the invalid db query error must have something to do with this:

$newPM = sp_pm_get_inbox_unread_count(SP()->user->thisUser->user_id);

Because if users are not logged in, they they have no ID. Right?

The previous use of “globals” @mr-papa mentioned must have addressed this, because we never experienced it before. Is there some class used to identify guests that can be applied in this scenario?