BuddyPress Implementation For A Global OER Community

  • Post published:August 21, 2015

A global Open Educational Resource (OER) community of educators, parents, and students enables teachers to make learning more personalized and helps students reach their full potential.  As a community website, it was required from vteam #453 that users should get notifications for major actions/changes on Dashboard. BuddyPress although manages this for its component actions, but this functionality was required for application’s custom actions too. BuddyPress integration was done in the following cases:

Case – I

When a blog post is updated from admin panel, it was required to record and show the update to users on dashboard with default activity streams. For this, we utilized “bp_activity_add” method.

Code Sample:
$post_content = strip_tags($post->post_content);
$post_content = strlen( $post_content ) > 550 ? (substr($post_content,0,550)." ......") : ($post_content);
$post_content = 'Blog Update: ' . $post_content;

$post_title = $post->post_title;

$bpActAction = '<a href="'. site_url().'/'.$post->post_name.'">' . $post_title . '</a>';
$component = "postactivity";
$bpActType = "postsave";
 $activity_id = bp_activity_add(array(
 'action' => $bpActAction,
 'content' => $post_content,
 'component' => $component,
 'type' => $bpActType,
 ));

Case – II

When a user Created/Updated curriculum resources (libraries), it was required to record and show the updates to users on Dashboard with default activity streams. For this, we utilized BuddyPress method “bp_activity_add”.

Code Sample:
$bpActType = "resource_insert";
   $resource_activity_title = '<a href="' . site_url() . '/oer/' . $data['pageurl'] . '">' . $_REQUEST['title'] . '</a>';
   $bpActAction = '<a href="' . $profile_url . '">' . $user_display_name . '</a> created ' . $resource_activity_title;

   $activity_id = bp_activity_add(array(
    'action' => $bpActAction,
    'content' => $resource_activity_content,
    'component' => $component,
    'type' => $bpActType,
   ));

Groups Feature For Community:

Following group features were also required by Client for this community website:

Groups Association With Curriculum Resources (Libraries):

It was required that users can  create groups and should have their association with the curriculum resources. For this, we implemented BuddyPress Groups. We also integrated curriculum resources (libraries) using “Group Extension API”.

function curr_group_library_init() {
     if (!class_exists( 'BP_Group_Extension' ))
         return;

     class Crurriki_group_library extends BP_Group_Extension {
         public function __construct() {
           $args = array(
             'slug' => 'library',
             'name' => 'Group Library',
           );
           parent::init( $args );
         }

         public function display( $group_id = NULL ) {
           // loading template from theme
           bp_core_load_template("groups/library/index");
         }
     }
     bp_register_group_extension( 'Crurriki_group_library' );
  }
  add_action('bp_init', 'curr_group_library_init');
Create Group With Custom Data:

When a user creates a group, its association with curriculum resources categories was required. For this, we utilized groups_created_group function to hook the existing functionality. Following is the sample code for this:

add_action( 'groups_created_group',&nbsp; array($this , 'curr_group_on_create') );
public function curr_group_on_create() {
             …...............................
            if( is_array($_POST['subjectarea']) && count($_POST['subjectarea']) > 0 )
            {
                $subjectarea_arr = $_POST['subjectarea'];
                foreach ($subjectarea_arr as $subject_area_id)
                {
                   $groupid = $group_record->id;
                   $wpdb->insert( 'group_subjectareas', array("groupid"=> $groupid , 'subjectareaid' => $subject_area_id ));
                }
            }
             …...............................
     }
Group Invitations:

Group invitation feature was added by using Invite-Anyone Plugin. We also customized user search function with additional user checks:

add_action( 'wp_ajax_invite_anyone_autocomplete_ajax_handler', array($this , 'invite_anyone_ajax_autocomplete_results') );
public function invite_anyone_ajax_autocomplete_results() {

            …...............................
$bd_user_table = $wpdb->prefix."users";
$query = "SELECT $bd_user_table.display_name as suggestions , $bd_user_table.ID as data , $bd_user_table.user_login FROM ".
$bd_user_table;
         $query .= " LEFT JOIN users ON $bd_user_table.ID = users.userid";
         $query .= " WHERE user_status = 0";
         $query .= ' AND display_name like "%'.$search_terms.'%"';
         $query .= ' AND ID NOT IN ('.$group_members_ids.')';
         $query .= ' AND users.active=\'T\'';
         $records = $wpdb->get_results($query,OBJECT);
           …...............................
}