Only Show to Admins

LPH

Well-known member
I'm building my first XenForo add-on and have manually set the Listener. The HTML code shows to everyone. I'd like to get this code to only show to admins. How do I wrap the echo so that only the admins see it?

I know this is basic - so the question is - what is the best method for making sure this is only seen by admins?

Maybe this approach is wrong, too. Please let me know if you can think of a better approach.

PHP:
<?php
/**
* This is the view for showing html to admin
*/

class TuxReports_XenFeature_ViewAdmin_Promotes extends XenForo_Model
{
   public static function showPromoteButton($hookName, &$contents, array $hookParams, XenFro_template_Abstract $template)
   {
     if( $hookName == 'ad_above_content' )
     {

     ob_start();

     echo '

     <div style="float:right; margin-top:-50px;"><button type="button">Promote</button></div>

     ';

     $contents .= ob_get_contents();
     ob_end_clean();

     }
   }
}

The CSS is just temporary until other parts of the code are set.

Update: Guess it would be helpful to give an idea ...

Update 2:
delete

Update 3: This seems to work and only shows to admins but it's showing everywhere and will need to get it to simply show on the thread ...

PHP:
$visitor = XenForo_Visitor::getInstance();
     if ( $visitor['is_moderator'] AND $visitor['is_admin'] )
     {

Hope this helps someone else struggling with an XF add-on.
 
Last edited:
Back
Top Bottom