$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>plugin development - Adding body class in author page for custom role|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

plugin development - Adding body class in author page for custom role

matteradmin8PV0评论

I am trying to add a unique body class using body_class filter if the role is a custom one via my plugin. I have a custom role called trip_vendor and the url for its profile page is abc/operator/tripvendor. Now, I want to add a custom body class if this url is visited. I have over-ridden the author.php from my plugin because the layout needs to be different. My code works in local but fails on live server. Body class as of the live server when the above url visited is hfeed full-width

Below is my code:

function vendor_body_class( $classes ) {
        global $post;
        $author = get_queried_object();
        if( is_author() )
        {
            if( end( $author->roles ) == 'trip_vendor' ){
               $classes[] = 'trip-vendor'; 
            }
        } 
        return $classes;
}
add_filter( 'body_class', 'vendor_body_class' );

This is how the author template is over-ridden from plugin:

$author = get_user_by( 'slug', get_query_var( 'author_name' ) );
if( is_object($author) )
{
   $role = $author->roles[0];
   if( is_author() )
   {
                if( 'trip_vendor' === $role )
                {
                    if ( $theme_file = locate_template( array ( 'author.php' ) ) ) {
                        $template_path = $theme_file;
                    } else {
                        $template_path = WP_TRAVEL_ENGINE_VENDOR_BASE_PATH . '/public/vendor-templates/profile/author.php';
                    }
                }
                return $template_path;
   }


}

Any help would be more than appreciable.

Post a comment

comment list (0)

  1. No comments so far