ExpressionEngine Accessories only on certain pages


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <?php
  2.  
  3. function set_sections()
  4. {
  5. // Remove the tab. This is lame.
  6. $script = '
  7. $("#'. $this->id .'.accessory").remove();
  8. $("#accessoryTabs").find("a.'. $this->id .'").parent("li").remove();
  9. ';
  10.  
  11. // Only show this on 1 page of the CP
  12. if($this->EE->input->get('C') == 'members' AND $this->EE->input->get('M') == 'view_all_members')
  13. {
  14. $script .= '
  15. $("#mainContent").prepend(\'
  16. <div class="rightNav">
  17. <div style="float: left; width: 100%;">
  18. <span class="button"><a title="Export Members" class="submit" href="'.BASE.AMP.'C=addons_accessories'.AMP.'M=process_request'.AMP.'accessory=member_export'.AMP.'method=process_export">Export Members</a></span>
  19. </div>
  20. <div class="clear_left">
  21. </div>\')';
  22. }
  23.  
  24. // Output JS, and remove extra white space and line breaks
  25. $this->EE->javascript->output('$(function(){'. preg_replace("/\s+/", " ", $script) .'});');
  26. $this->EE->javascript->compile();
  27. }
  28.  
  29.  
  30.  
  31. /*
  32. OR
  33.  
  34. In the install of your Accessory/Extension, update it's controller field,
  35. so it only shows in that controller, then the hide tab script above never runs unless needed,
  36. and your hidden tab does not flash.
  37. */
  38.  
  39. $this->EE->db->where('class', 'My_cool_acc');
  40. $this->EE->db->update('accessories', array('controllers' => 'admin_content'));

URL: http://forrst.com/posts/Show_Accessories_only_on_pages_they_need_to_be_use-BJ6

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.