public function hipchat_send_activity_notification($post) { if (empty($post)) { return; } // We need to display only new posts if ($post->type !== 'activity_update') { return; } try { $auth_token = ''; $room = ''; $from = ''; $r = ''; // Get Plugin Options $anbph_options = get_option('anbph_hipchat'); $message_length = !empty($anbph_options['message_length']) ? $anbph_options['message_length'] : 10; if (!empty($anbph_options['auth_token'])) { $auth_token = $anbph_options['auth_token']; } // Return if plugin is not configured propery if (empty($auth_token)) { return; } if (!empty($anbph_options['room_name'])) { $room = $anbph_options['room_name']; } if (!empty($anbph_options['from_name'])) { $from = $anbph_options['from_name']; } $user = ''; $activity_url = bp_activity_get_permalink($post->id); $user_data = get_userdata($post->user_id); $activity_content = $post->content; if (!empty($activity_content)) { $activity_content = wp_trim_words($activity_content, $message_length); } else { $activity_content = __('No Title', ANBPH_TEXTDOMAIN); } if (!empty($user_data)) { $user = $user_data->display_name; } $message = $user . ' just posted <a href="' . $activity_url . '">' . $activity_content . '</a>'; if (!empty($room) && !empty($from) && !empty($message)) { $bp_hc = new Anpbp_HipChat($auth_token); $r = $bp_hc->message_room($room, $from, $message); } if (empty($r)) { // Something went wrong, not sure what to do here? } } catch (Anpbp_HipChat_Exception $e) { // Something went wrong, not sure what to do here? } return $post; }
// Get some plugin details $anbph_options = get_option('anbph_hipchat'); $auth_token = !empty($anbph_options['auth_token']) ? $anbph_options['auth_token'] : ''; $from_name = !empty($anbph_options['from_name']) ? $anbph_options['from_name'] : ''; $room_name = !empty($anbph_options['room_name']) ? $anbph_options['room_name'] : ''; $message_length = !empty($anbph_options['message_length']) ? $anbph_options['message_length'] : ''; $updated = null; $error = null; if (!isset($_REQUEST['settings-updated'])) { $_REQUEST['settings-updated'] = false; } // Not the best way to handle this, but still if (isset($_POST['anbph_check_integration'])) { $successful = false; // make sure token is valid and room exists $hc = new Anpbp_HipChat($auth_token); try { $r = $hc->message_room($room_name, $from_name, "Plugin enabled successfully."); if (!empty($r)) { $successful = true; } } catch (Anpbp_HipChat_Exception $e) { // token must have failed } if ($successful !== true) { $error = __('Bad auth token or room name.', ANBPH_TEXTDOMAINN); } else { if (empty($from_name)) { $error = __('Please enter a "From Name"', ANBPH_TEXTDOMAIN); } else { if (strlen($from_name) > 15) {