PDA

View Full Version : Help with hiding postbit buttons from guests


thetechgenius
07-17-2014, 06:38 PM
I added 2 plugins to add a "Send PM" button and a "Add Friend" button to the bottom of the postbit. The only problem is, they are visible to everyone, including users not logged in. The other default buttons are only visible to Logged-In users, so it looks weird to see only the 2 buttons visible.


Here is my code for the "Add Friend" button:

Plugin PHP Code


$postuserinfo = fetch_userinfo($post['userid'], 128);
$isfriend = $postuserinfo['isfriend'];
if (!$isfriend)
{
$template_hook['postbit_controls'] .= '<span class="addfriend"><a href="profile.php? ' . $vbulletin->session->vars['sessionurl'] . 'do=addlist&amp;userlist=friend&amp;u=' . $post['userid'] . '">' . construct_phrase($vbphrase['add_as_friend'], $post['username']) . '<img class="addimg" alt="Add as Friend" src="images/site_icons/add.png"></a><span class="seperator"></span></span>';
}





Here is my code for the "Send PM" button:

Plugin PHP Code


$postuserinfo = fetch_userinfo($post['userid'], 128);

{
$template_hook['postbit_controls'] .= '<span class="sendpm"><a href="private.php? ' . $vbulletin->session->vars['sessionurl'] . 'do=newpm&u=' . $post['userid'] . '">' . construct_phrase($vbphrase['send_pm'], $post['username']) . '<img class="pmimg2" alt="Send PM" src="images/site_icons/pm.png"></a><span class="seperator"></span></span>';
}



What code do I add to these plugins to make them only visible to Registered Users?

The uploaded attachment is a screenshot of the postbit buttons from Guest View.

Dave
07-17-2014, 07:02 PM
I believe a way to check if the user is logged in is to check if the $vbulletin->userinfo['userid'] variable is set

thetechgenius
07-17-2014, 09:09 PM
I believe a way to check if the user is logged in is to check if the $vbulletin->userinfo['userid'] variable is set


I tried that, but nothing happens.

Dave
07-17-2014, 09:09 PM
Can you copypaste the code here?

thetechgenius
07-17-2014, 09:38 PM
Can you copypaste the code here?

The code is in the first post.

I tried this:



$postuserinfo = fetch_userinfo($post['userid'], 128);
$isfriend = $postuserinfo['isfriend'];
if (!$isfriend)
if ($vbulletin->userinfo['userid'])
{
$template_hook['postbit_controls'] .= '<span class="addfriend"><a href="profile.php? ' . $vbulletin->session->vars['sessionurl'] . 'do=addlist&amp;userlist=friend&amp;u=' . $post['userid'] . '">' . construct_phrase($vbphrase['add_as_friend'], $post['username']) . '<img class="addimg" alt="Add as Friend" src="images/site_icons/add.png"></a><span class="seperator"></span></span>';



And that removes the "Add Friend" button completely from the postbit, so no usergroups can see it.

Lynne
07-18-2014, 12:50 AM
We want to see the code with your added condition that you tried.

Also, what hook locations? What was the result? What is the full code (your's don't have closing "if" tags)?

Can you explain exactly what your code is supposed to do?

thetechgenius
07-18-2014, 01:34 AM
We want to see the code with your added condition that you tried.

Also, what hook locations? What was the result? What is the full code (your's don't have closing "if" tags)?

Can you explain exactly what your code is supposed to do?


Here is a screenshot of the plugin I created. The plugin just adds an "Add Friend" button at the bottom of the postbit, right next to the "Edit Post" and "Quote" buttons:

https://vborg.vbsupport.ru/external/2014/07/33.png



Here is an image of the plugin being rendered on the postbit:

https://vborg.vbsupport.ru/external/2014/07/34.png


I just need to know how to get the buttons to show only to "Registered Users". Right now everyone can see the button, including Guests. As you can see in the second screenshot, just the 2 buttons are being shown, and not the rest. Thats because the other buttons are the default buttons, and they only show up if the User is Logged-In.

--------------- Added 1405653842 at 1405653842 ---------------

Never mind. I found out a way to do this. I disabled the plugins I created, and just put the code directly into the template.

Right before the "Edit Post" button is rendered, I added this code for the PM and Add Friend buttons:



<!-- Add Friend Button - Begin -->
<vb:if condition="!is_member_of($bbuserinfo, 1,8)">
<vb:if condition="$show['pmlink']">
<span class="addfriend"><a href="profile.php?{vb:raw session.sessionurl}do=addlist&amp;userlist=friend&amp;u={v b:raw post.userid}"><img class="addimg" alt="Add as Friend" src="images/site_icons/add.png">Add as Friend</a><span class="seperator">&nbsp;</span></span></vb:if></vb:if>
<!-- Add Friend Button - End -->


<!-- Send PM Button - Begin -->
<vb:if condition="!is_member_of($bbuserinfo, 1,8)">
<vb:if condition="$show['pmlink']"><a class='pminpostbit' href="private.php?{vb:raw session.sessionurl}do=newpm&amp;u={vb:raw post.userid}" rel="nofollow"><img src="{vb:raw vboptions.cleargifurl}" alt="{vb:rawphrase send_pm}" />PM</a><span class="seperator">&nbsp;</span></vb:if></vb:if>
<!-- Send PM Button - End -->



And I added some CSS to the Span Classes for the buttons in additional.css

Anyways, Thank you everyone for trying to help me!! I greatly appreciate your time!