• Hi
    in the functions.php
    If I write this line of code, than it works and I get no admin bar for simple users:

    if (get_current_user_id() != ‘1’) {
    add_filter(‘show_admin_bar’, ‘__return_false’);
    }

    But if I put the line above in a function like this, nothing happens:
    // Remove admin items
    function optimize_editor() {

    if (get_current_user_id() != ‘1’) {
    add_filter(‘show_admin_bar’, ‘__return_false’);

    }
    add_action(‘admin_menu’,’optimize_editor’);

    I double checked (by using an echo) and the code inside the function is being called and the current user id is ‘2’.

    – using “show_admin_bar(false);” yields the same results..

    Thanks for any help!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator t-p

    (@t-p)

    Please review this on posting code: http://codex.wordpress.org/Forum_Welcome#Posting_Code

    Thread Starter Twinkey

    (@twinkey)

    Thanks Tara, here I hope is the fixed post:

    Hi
    in the functions.php
    If I write this line of code, than it works and I get no admin bar for simple users:

    if (get_current_user_id() != '1') {
    add_filter('show_admin_bar', '__return_false');
    }

    But if I put the line above in a function like this, nothing happens:

    // Remove admin items
    function optimize_editor() {
    if (get_current_user_id() != '1') {
    add_filter('show_admin_bar', '__return_false');
    }
    add_action('admin_menu','optimize_editor');

    I double checked (by using an echo) and the code inside the function is being called and the current user id is ‘2’.

    – using
    show_admin_bar(false);
    yields the same results..

    Thanks for any help!

    Moderator t-p

    (@t-p)

    what exactly are you tryinging to accomplish?

    Calling add_filter inside add_action is not a good idea. You should read up on these hooks before using them:
    http://codex.wordpress.org/Function_Reference/add_filter
    http://codex.wordpress.org/Function_Reference/add_action

    This may solve your problem:

    // Remove admin items
    function optimize_editor() {
    if (get_current_user_id() != '1') {
    show_admin_bar( false );
    }
    add_action('admin_menu','optimize_editor');

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘simple code problem in functions.php’ is closed to new replies.