Awesome Stuff You Can Do With WordPress (Part Two)

So here I am. As promised, with the second installment of our “Awesome Stuff You Can Do With WordPress” series. I’ve cleverly titled this one; “Awesome Stuff You Can Do With WordPress (Part Two)”. A BuddyPress project for a medium-sized company; just one example of what’s possible – but perhaps enough to get the wheels turning. This one uses a stock database and is relatively simple, but fun nonetheless. The LiteCure Clinician’s Corner is essentially this client’s CRM portal and paid support vehicle. If you’re curious about the nature of this project or the client, I encourage you to read more here.

For now, I’ll be sticking to methods – in an effort to trim this down and make it more interesting. I’ll skip the theme framework stuff, and move right to the parts of this project that are most interesting. Namely, how to accomplish a private multiuser portal for multiple client brands, using stock WP and Buddypress. A lot of this project was accomplished using Custom Post Types and uniform logic for WP taxonomy. The goal was to provide service and support for two separate medical device companies the client owned, using a single solution.

We did this by first dividing the users into two groups. To streamline things, we added employees as front end users, as well. However, these folks required a higher level of access than the customers. In abbreviated fashion, those looked something like this:

 

Group 1

+ Veterinary Customer
+ Veterinary Customer (Premium)
+ Veterinary Customer Representative
+ Veterinary Sales Representative

 

Group 2

+ Medical Customer
+ Medical Customer (Premium)
+ Medical Customer Representative
+ Medical Sales Representative

 

Now we tackled the tougher stuff. Our first major challenge was to make the portal interface render differently; depending on the customer’s brand (by using headers and CSS) and the specific level of support each one had purchased for their brand (navigation). When they signed in, veterinary users needed to see the “red” color scheme and branding, while medical customers had to see a “green” branded version.

 

Something like this.

 

 

color_scheme_red

color_scheme_green

 

 

Here’s the snippet we used to add a class to the “body” element so that the correct branding was loaded.

 

 // add body class for medical users
         $current_user       = wp_get_current_user();
         $current_user_roles = $current_user->roles;
         $look_for           = 'medical';
         if( !current_user_can( 'manage_options' ) ){
             if( is_array($current_user_roles) && count($current_user_roles) ){
             foreach( $current_user_roles as $role ){
                  $pos = strpos($role, $look_for);
                  if ( !($pos === false) ){
                            add_filter( 'body_class', function( $classes ) {
                                return array_merge( $classes, array( 'is-medical-user' ) );
                            } );
                  }
             }
             }       
         }

 

Within these two larger groups, each user also gets access to specific content and software updates.

 

This is important, because it’s based on the plan they’ve purchased with their equipment. The client also had a Magento store and wanted to use the existing user database there so customers only had to sign in once. Different user levels were only allowed to see the content they’d paid for.

 

 

menu_red

menu_green

 

 

We used the “menu” field position and generated the navigation for each role.

Here’s the snippet that outputs the custom menus.

 

// get WP menu per role - used by magento
function cc_menu_for_magento(  $template  ){
 
     if(  isset($_GET['role'])
         && $_GET['role'] != '' ){
 
         // init
         $role = $_GET['role'];
 
         // load menu by location
         $menu_location = 'role_' . $role;
 
 
         // output menu
         echo '


<div class="menu-main-navigation-container">';
         echo '


<ul id="menu-main-navigation" class="main">';
         wp_nav_menu( array( 'theme_location' => $menu_location, 'menu_class' => 'main', 'items_wrap' => '%3$s', 'container' => '' , 'fallback_cb' => false ) );
         echo '</ul>



';
         echo '</div>



';
 
         // exit
         exit(); 
 
     }   
 
     return  $template ;
 
}
add_action('template_include', 'cc_menu_for_magento');

 

And a look at how these are edited on the WP back end.

 

menu_per_role

 

Next, we tackled user access.

We’d already taken care of the Custom Post Types.

 

+ Events Manager
+ Video Manager
+ Document Manager
+ Software Manager
+ Webinars Manager
+ FAQs Manager
+ Products manager
+ Testimonials manager
+ Webinars manager

 

So we worked on assigning permissions to each.

Here’s an example of how user permissions are assigned to a post type on the back end.

 

 

perm_video_categoy

 

 

And the code that checks the permissions.

 

 

function cc_video_get_list_of_available_categories_for_user(){
 
     $enabled_video_categories = array();
 
     // load all video categories
     $video_categories = get_terms( array(
         'taxonomy' => 'cc-video-category'
     ) );
     if( is_array($video_categories) && count($video_categories) ){
 
         foreach ($video_categories as $num => $video_category) {
 
              // permissions are defined on TOP LEVEL category only - child categories inherit permissions
 
              // if is parent category 
              if( !$video_category->parent ){
 
                   $access_roles = array_filter( get_field('allow_access_for_user_roles', 'cc-video-category_' . $video_category->term_id ) );
 
                   
                   // and has no permissions - assign access rights to this parent and all child categories (PUBLIC)
                   if( (count($access_roles) == 0) /* PUBLIC */
                        || 
                        user_with_role_has_access($access_roles) /* WITH ACCESS LIMITS */
                        ){
 
                        // and all child categories
                        $video_category_children     = get_term_children( $video_category->term_id, 'cc-video-category' );
                        $enabled_video_categories    = array_merge( $enabled_video_categories  , $video_category_children );
 
 
                        // mark this category as enabled
                        $enabled_video_categories[] = $video_category->term_id;
 
                   }
 
              }
 
         }
 
     }
 
     return $enabled_video_categories;
 
}

 

There was a lot more to this particular project, including a function that automatically added each customer to an interactive map of partners for SEO purposes, and some back office integration. But I’ve tried to stick to some of the more unique WP-specific stuff to keep this manageable and worth reading.

Once we’d completed initial testing, we asked a few select customers to help us with the Beta. After we’d completed regression, we were ready to polish and deploy. With a bit of additional minifying, optimization, engineering, and QA, we got things up and running smoothly on the client’s hardware. We prefer to handle training remotely, with separate sessions for a client’s IT and administrative teams. A third and fourth session were provided for CSRs and the sales team. All sessions were recorded for future reference, and provided to the client through our own support portal.

The new Clinician’s Corner is a vast improvement over the old one. It’s branded to perfectly match the client’s other WordPress sites, and uses the same universal dashboard for administration. Instead of paying for third-party software, LiteCure is now able to manage and maintain their own system; by themselves. Even better, they can keep incremental deployments uniform across all their enterprise sites. At last count, they had over 10,000 users and were still going strong. The CSRs employed the new system to survey customers about additional features they wanted to see, and got a very positive response. Based on their input, we now have some new features in the works for 2017.

 

As always, I’m more than happy to reply to any direct questions or comments. Thanks for reading!

 

Jon Gifford

jgifford@redsqware.com

After more than 21 years of experience in the digital marketing and advertising industries (including some painful learning experiences in the tech startup game) I co-founded Redsqware in early 2012. Having searched at great length (and without success), we decided to just give up – and became the kickass agency development partner we'd always wanted for ourselves. Our goals were threefold: to uplift our clients, to empower our people, and to put extraordinary tools within the reach of anyone. My philosophy is that given time, quality work and great service will always rise to the top. I believe that doing right by customers and employees is always the right thing to do. I loathe chest beating of any kind, but I love innovation – and the people all around us who drive it. I believe wholeheartedly that the more open the web is, the better off we'll all eventually be. I don't have an autonomous car, but my pickup truck is old enough to drive itself. I'm a father to three amazing kids, and a husband to a wonderful woman. In my free time I can be found wandering the beaches of either coast in search of waves and new friends; or prowling the streets of Philadelphia looking for our family's next dog rehab project.

No Comments

Sorry, the comment form is closed at this time.

Positive SSL Wildcard