forked from sbrajesh/bp-default-ajaxed-profile-tab
/
functions.php
116 lines (93 loc) · 3.64 KB
/
functions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php
//include javascript
add_action( 'wp_enqueue_scripts', 'bp_ajaxed_profile_enqueue_scripts' );
function bp_ajaxed_profile_enqueue_scripts(){
wp_enqueue_script( 'ajaxed-tab-profile-js', get_stylesheet_directory_uri() . '/_inc/theme.js', array( 'jquery','dtheme-ajax-js' ));
}
/**
* Get current component
* @return string
*/
function bpcustom_get_current_component(){
$object = esc_attr( $_POST['object'] );
if($object=='xprofile')
$object='profile';
else if($object=='members')
$object='friends';
return $object;
}
//get current action
function bpcustom_get_current_action(){
$action=$_POST['extras'];
if(!empty($action)&&$action=='favs')//a fix for activity
$action='favorites';
return $action;
}
//init action/component override
function bpcustom_setup_components(){
global $bp;
//check for action too
$component=bpcustom_get_current_component();
$action=bpcustom_get_current_action();
if($component=='settings'&&empty($action))
$action='general';
global $bp;
$bp->current_component=$component;//hack
if(!empty($action))
$bp->current_action=$action;
return $component;// just to avoid another call, not a good pattern though
}
/**
* Load content via ajax
*/
add_action( 'wp_ajax_profile_xprofile_filter', 'bpcustom_profile_sub_template_loader');
add_action( 'wp_ajax_profile_blogs_filter', 'bpcustom_profile_sub_template_loader');
add_action( 'wp_ajax_profile_members_filter', 'bpcustom_profile_sub_template_loader');
add_action( 'wp_ajax_profile_groups_filter', 'bpcustom_profile_sub_template_loader' );
add_action( 'wp_ajax_profile_messages_filter', 'bpcustom_profile_sub_template_loader' );
add_action( 'wp_ajax_profile_activity_filter', 'bpcustom_activity_template_loader');
add_action( 'wp_ajax_profile_settings_filter', 'bpcustom_profile_sub_template_loader');
//for pages having componentName.php
function bpcustom_profile_sub_template_loader() {
$object=bpcustom_setup_components();
locate_template( array( "members/single/{$object}.php" ), true );
}
//lets do some magic for Activity
//a copy of bp_dtheme_activity_template_loader
function bpcustom_activity_template_loader() {
global $bp;
// Bail if not a POST action
if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
return;
bpcustom_setup_components();
$action=bpcustom_get_current_action();
$scope = $action;
// We need to calculate and return the feed URL for each scope
switch ( $scope ) {
case 'friends':
$feed_url = $bp->loggedin_user->domain . bp_get_activity_slug() . '/friends/feed/';
break;
case 'groups':
$feed_url = $bp->loggedin_user->domain . bp_get_activity_slug() . '/groups/feed/';
break;
case 'favorites':
$feed_url = $bp->loggedin_user->domain . bp_get_activity_slug() . '/favorites/feed/';
break;
case 'mentions':
$feed_url = $bp->loggedin_user->domain . bp_get_activity_slug() . '/mentions/feed/';
bp_activity_clear_new_mentions( $bp->loggedin_user->id );
break;
default:
$feed_url = home_url( bp_get_activity_root_slug() . '/feed/' );
break;
}
/* Buffer the loop in the template to a var for JS to spit out. */
ob_start();
locate_template( array( 'members/single/activity.php' ), true );
$result = array();
$result['contents'] = ob_get_contents();
$result['feed_url'] = apply_filters( 'bp_dtheme_activity_feed_url', $feed_url, $scope );
ob_end_clean();
echo json_encode( $result );
}
?>