COMPUTAT//ON

Awesome stuff you can do with WordPress (part two)

2016-11-03

So here I am. As promised, with the second installment of our “Awesome Stuff You Can Do With WordPress” series. I’ve clever

ly 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: 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.
Here’s the snippet we used to add a class to the “body” element so that the correct branding was loaded.
|
|1 // add body class for medical users
|2       $current_user       = wp_get_current_user();
|3          $current_user_roles = $current_user->roles;
|4  $look_for           = 'medical';
|5   if( !current_user_can( 'manage_options' ) ){
|6   if( is_array($current_user_roles) && count($current_user_roles) ){
|7   foreach( $current_user_roles as $role ){
|8   $pos = strpos($role, $look_for);
|9     if ( !($pos === false) ){
|10    add_filter( 'body_class', function( $classes ) {
|11  return array_merge( $classes, array( 'is-medical-user' ) );
|12     } );
|13      }
|14      }
|15         }
|16          }
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.

Here’s the snippet that outputs the custom menus.

1 // get WP menu per role - used by magento
2 function cc_menu_for_magento(  $template  ){
3
4     if(  isset($_GET['role'])
5         && $_GET['role'] != '' ){
6
7         // init
8         $role = $_GET['role'];
9
10
11         // load menu by location
12         $menu_location = 'role_' . $role;
13
14
15         // output menu
16
17
18
19        echo '
20
21
22 <div class="menu-main-navigation-container">';
23         echo '
24
25
26 <ul id="menu-main-navigation" class="main">';
27         wp_nav_menu( array( 'theme_location' => $menu_location, 'menu_class' => 'main', 'items_wrap' => '%3$s', 'container' => '' , 'fallback_cb' => false ) );
28         echo '</ul>
29
30
31
32 ';
33         echo '</div>
34
35
36
37 ';
38
39         // exit
40         exit();
41
42     }
43
44     return  $template ;

45}
add_action('template_include', 'cc_menu_for_magento');
And a look at how these are edited on the WP back end.
Next, we tackled user access.
  • Events Manager
  • Video Manager
  • Document Manager
  • Software Manage
  • 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.
And the code that checks the permissions.
1      function cc_video_get_list_of_available_categories_for_user(){
2
3           $enabled_video_categories = array();
4
5          // load all video categories
6         $video_categories = get_terms( array(
7            'taxonomy' => 'cc-video-category'
8       ) );
9      if( is_array($video_categories) && count($video_categories) ){
10
11
12               foreach ($video_categories as $num => $video_category) {
13
14                    // permissions are defined on TOP LEVEL category only - child categories inherit permissions
15
16                    // if is parent category
17                    if( !$video_category->parent ){
18
19                         $access_roles = array_filter( get_field('allow_access_for_user_roles', 'cc-video-category_' . $video_category->term_id ) );
20
21
22                         // and has no permissions - assign access rights to this parent and all child categories (PUBLIC)
23                         if( (count($access_roles) == 0) /* PUBLIC */
24                              ||
25                              user_with_role_has_access($access_roles) /* WITH ACCESS LIMITS */
26                              ){
27
28                              // and all child categories
29                              $video_category_children     = get_term_children( $video_category->term_id, 'cc-video-category' );
30                              $enabled_video_categories    = array_merge( $enabled_video_categories  , $video_category_children );
31
32
33                              // mark this category as enabled
34                              $enabled_video_categories[] = $video_category->term_id;
35
36                         }
37
38                    }
39
40               }
41
42           }
43
44           return $enabled_video_categories;
45
46      }

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!

Sign

Jon Gifford

jgifford@redsqware.com

I co-founded Redsqware in 2012 after 15 years in digital and advertising (plus a painful learning experience in the startup game). Having searched at great length (and without success), we decided to just become the kickass agency development partner we'd always wanted for ourselves. We've always had the same three goals; to uplift clients, empower people, and to create extraordinary tools together. I know that acting in the best interest of customers and team members is always the right thing to do. Because they're usually the same thing if you're doing it right. I know in time companies who do quality work, act with integrity, and provide phenomenal service set themselves apart. I believe in my heart that the more open the web is, the better off we'll all eventually be. I don't own a self-driving car, but my pickup truck is old enough to drive itself. I'm not into accolades. I'm into fairness. I'm into people who care. I'm a father to three amazing children, and a husband to a wonderful woman. In my free time, I skate our backyard miniramp with the kids (ow), and lurk online for new foster dogs.

FEATURED CLIENT STORIES