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.

Short Code Error?

  • Creator
    Topic
  • #25753
    kennethfeldman
    Participant

    HI Jason,

    Now getting the following error on the overlay screen that pops up with the TB SHORTCODES button:

    Fatal error: [] operator not supported for strings in /home/greenhedges/public_html/ghswp/wp-content/themes/jumpstart/framework/compat/gravityforms/class-tb-compat-gravity-forms.php on line 76

    …and I get no shortcode configuration tools visible anywhere in the white overlay.

    If I deactivate Gravity Forms, then the error changes to:

    Warning: in_array() expects parameter 2 to be array, string given in /home/greenhedges/public_html/ghswp/wp-content/plugins/theme-blvd-shortcodes/includes/admin/generator/class-tb-shortcode-generator.php on line 3148

    (But this is only seen on the BUTTONS section)

    But I do see (can use) the shortcode tools there and in all other sections..

    This is new in WP4.5 I think — as I’ve been developing this site for a few months with no other changes.

    Using WordPress 4.5, with Jump Start Version: 2.0.4

Viewing 3 replies - 1 through 3 (of 3 total)
  • Author
    Replies
  • #25754
    kennethfeldman
    Participant

    Ahhh, never mind — kind of…

    I had recently added the following bit to my functions.php — in an attempt to get a unique body class for all admin pages of a certain user level.

    This is an extension of the attempt to HIDE the DELETE buttons in the Builder, discussed recently.

    My idea was to simply hide them in the builder from non-admin users — and my plan was to add a unique class to the body for each user level with which I could target the DELETE links with CSS.

    I found the following on the ‘net somewhere, and unfortunately, this is what is breaking the TB Shortcodes pop up.

    I know this is off-topic — but do you have a way for me to add a unique user-level-class to the body of admin pages?

    (e.g. body class=”editor” body class=”administrator” etc.)

    if ( is_user_logged_in() ) {
        add_filter('body_class','add_role_to_body');
        add_filter('admin_body_class','add_role_to_body');
    }
    function add_role_to_body($classes) {
        $current_user = new WP_User(get_current_user_id());
        $user_role = array_shift($current_user->roles);
        if (is_admin()) {
            $classes .= 'role-'. $user_role;
        } else {
            $classes[] = 'role-'. $user_role;
        }
        return $classes;
    }
    • This reply was modified 3 years, 6 months ago by kennethfeldman. Reason: typo
    #25756
    Jason Bobich
    Keymaster

    Your code above attaches the same function to two different filters that return different kinds of variables, and it relies on the is_admin() … which is not always correct.

    I would just split it up into two different functions, and I wouldn’t just have is_user_logged_in() floating out there in your functions file.

    Maybe give something like this a try:

    /**
     * Add class to admin <body>
     */
    function my_admin_body_class( $class ) {
    
        if ( is_user_logged_in() ) {
            $user = new WP_User( get_current_user_id() );
            $class .= ' ' . array_shift( $user->roles );
        }
    
        return $class;
    }
    add_filter('admin_body_class', 'my_admin_body_class');
    
    /**
     * Add class to frontend <body>
     */
    function my_body_class( $class ) {
    
        if ( is_user_logged_in() ) {
            $user = new WP_User( get_current_user_id() );
            $class[] = array_shift( $user->roles );
        }
    
        return $class;
    }
    add_filter('body_class', 'my_body_class');
    #25757
    kennethfeldman
    Participant

    Great! All I needed was the admin body.

    Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.