This is searchable archive of our old support forums, which operated from 2012 - 2016. To find out how to get support for your current theme, please visit our support page.

Hide Theme Options Tab

  • Creator
    Topic
  • #1647
    5oclock
    Participant

    Hello,

    Is there a way to hide certain tabs in the theme options page from anyone not an admin?

    Thanks

Viewing 1 replies (of 1 total)
  • Author
    Replies
  • #1648
    Jason Bobich
    Keymaster

    Hello,

    Hmm, interesting question. You’d have to think of way of doing it so you hide them with CSS, or else when the non-admin user saved the options page, the options the admin saves would all be lost.

    One approach might be to add the class “hide” to each option if the user is not an admin. I can only think of how this could be applied to individual options.

    function my_options(){
    	// If user is not an admin
    	if( ! current_user_can( 'edit_theme_options' ) ){
    		themeblvd_edit_option( 'tab_id', 'section_id', 'option_1', 'class', 'hide' );
    		themeblvd_edit_option( 'tab_id', 'section_id', 'option_2', 'class', 'hide' );
    		themeblvd_edit_option( 'tab_id', 'section_id', 'option_3', 'class', 'hide' );
    		themeblvd_edit_option( 'tab_id', 'section_id', 'option_4', 'class', 'hide' );
    	}
    }
    add_action( 'after_setup_theme', 'my_options' );

    http://dev.themeblvd.com/tutorial/add-remove-edit-theme-option/#themeblvd_edit_option

    http://dev.themeblvd.com/tutorial/default-framework-options/

    Another approach might be to just target specific sections or tabs by looking at their markup and just writing out your own CSS you stuff in the head.

    function hide_options(){
    	// If user is not an admin
    	if( ! current_user_can( 'edit_theme_options' ) ){
    		?>
    		
    		<?php
    	}
    }
    add_action( 'admin_head', 'hide_options' );

    Or maybe just creating your own stylesheet would be a little nicer.

    function load_custom_wp_admin_style() {
    	// If user is not an admin
    	if( ! current_user_can( 'edit_theme_options' ) ){
    		wp_register_style( 'custom_wp_admin_css', get_stylesheet_directory_uri() . '/whatever.css' );
    		wp_enqueue_style( 'custom_wp_admin_css' );
    	}
    }
    add_action( 'admin_enqueue_scripts', 'load_custom_wp_admin_style' );

    http://codex.wordpress.org/Plugin_API/Action_Reference/admin_enqueue_scripts

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.