Skip to:
Content

BuddyPress.org

Ticket #8332: bp-custom.php

File bp-custom.php, 9.8 KB (added by imath, 6 years ago)

Content of the bp-custom.php file

Line 
1<?php
2
3if ( !defined( 'ABSPATH' ) ) exit;
4
5add_action( 'bp_setup_nav', 'vibe_bp_hide_tabs', 15 );
6function vibe_bp_hide_tabs(){
7
8 $flag=1;
9 $hide=vibe_get_option('activity_tab');
10 if(isset($hide)){
11 $flag=0;
12 switch($hide){
13 case 1:
14 if(is_user_logged_in()) $flag=1;
15 break;
16 case 2:
17 if(current_user_can('edit_posts')) $flag=1;
18 break;
19 case 3:
20 if(current_user_can('manage_options')) $flag=1;
21 break;
22 case 0: $flag=1;
23 break;
24 }
25 }
26 if(!$flag && bp_is_active( 'activity' ) && !bp_is_my_profile()){
27 bp_core_remove_nav_item('activity');
28 }
29
30 $flag=1;
31 $hide=vibe_get_option('groups_tab');
32 if(isset($hide)){
33 $flag=0;
34 switch($hide){
35 case 1:
36 if(is_user_logged_in()) $flag=1;
37 break;
38 case 2:
39 if(current_user_can('edit_posts')) $flag=1;
40 break;
41 case 3:
42 if(current_user_can('manage_options')) $flag=1;
43 break;
44 case 0: $flag=1;
45 break;
46 }
47 }
48 if(!$flag && bp_is_active( 'groups' ) && !bp_is_my_profile()){
49 bp_core_remove_nav_item('groups');
50 }
51
52 $flag=1;
53 $hide=vibe_get_option('forums_tab');
54 if(isset($hide)){
55 $flag=0;
56 switch($hide){
57 case 1:
58 if(is_user_logged_in()) $flag=1;
59 break;
60 case 2:
61 if(current_user_can('edit_posts')) $flag=1;
62 break;
63 case 3:
64 if(current_user_can('manage_options')) $flag=1;
65 break;
66 case 0: $flag=1;
67 break;
68 }
69 }
70 if(!$flag && !bp_is_my_profile()){
71 bp_core_remove_nav_item('forums');
72 }
73}
74
75add_action('bp_before_profile_content','wplms_show_instructor_courses',11);
76function wplms_show_instructor_courses(){
77 global $bp;
78 $user_id=bp_displayed_user_id();
79 if(function_exists('bp_current_action') && bp_current_action() !== 'public')
80 return;
81
82 if(!user_can($user_id,'edit_posts')){
83 return;
84 }
85
86 $block_style = vibe_get_option('default_course_block_style');
87 $n = vibe_get_option('loop_number');
88 if($n<4){$n=4;}
89 if ( function_exists('get_coauthors')) {
90 $user = get_user_by('ID',$user_id);
91 $args = array(
92 'post_type' => 'course',
93 'posts_per_page' => $n,
94 'post_status' => 'publish',
95 'author_name' => $user->user_nicename,
96 );
97 }else{
98 $args = array(
99 'post_type'=>'course',
100 'post_status'=>'publish',
101 'posts_per_page' => $n,
102 'author'=> $user_id,
103 );
104 }
105
106 $args = apply_filters('wplms_show_instructor_courses',$args);
107
108 $query = new WP_Query($args);
109 if($query->have_posts()){
110
111 $instructing_courses=apply_filters('wplms_instructing_courses_endpoint','instructing-courses');
112
113 echo '<div class="instructor_courses">
114 <h3 class="heading"><span>'._x('Courses by Instructor','courses by instructor title in profile','vibe').'</span><a href="'.get_author_posts_url($user_id).$instructing_courses.'/" class="tip" title="'.sprintf(_x('Check all Courses created by %s','link help text in instructor profile','vibe'),bp_core_get_user_displayname($user_id)).'"><i class="icon-plus-1"></i></a></h3>
115 </div>';
116
117
118 echo '<div class="vibe_carousel flexslider" data-controlnav="1" data-block-width="240" data-block-max="4" data-block-min="1"><ul class="slides">';
119 $block_style = vibe_get_option('default_course_block_style');
120 if(empty($block_style)){$block_style = 'course';}
121 while($query->have_posts()){
122 $query->the_post();
123 global $post;
124 echo '<li>';
125 echo thumbnail_generator($post,$block_style,4,0);
126 echo '</li>';
127 }
128 wp_reset_postdata();
129 echo '</ul></div><br><hr>';
130 }
131
132}
133add_action('bp_before_profile_content','wplms_show_profile_snapshot');
134
135function wplms_show_profile_snapshot(){
136 global $bp;
137
138 $user_id=bp_displayed_user_id();
139
140 if(function_exists('bp_current_action') && bp_current_action() !== 'public')
141 return;
142
143 if(function_exists('bp_course_get_user_badges')){
144 $bids=bp_course_get_user_badges($user_id);
145 }else{
146 $bids=vibe_sanitize(get_user_meta($user_id,'badges',false));
147 }
148
149 if(isset($bids) && is_Array($bids) && count($bids)){
150 $badges_html = array();
151
152 foreach($bids as $bid){
153 $b='';
154 if(function_exists('bp_get_course_badge')){
155 $b=bp_get_course_badge($bid);
156 if(!empty($b)){
157 if(is_numeric($b)){
158 if(function_exists('bp_course_get_badge')){
159 $badges_html[]= bp_course_get_badge($b,$bid);
160 }else{
161 $badge=wp_get_attachment_info($b);
162 $badge_url=wp_get_attachment_image_src($b,'full');
163 $badges_html[]='<a class="tip ajax-badge" data-course="'.get_the_title($bid).'" title="'.get_post_meta($bid,'vibe_course_badge_title',true).'"><img src="'.$badge_url[0].'" title="'.$badge['title'].'"/></a>';
164 }
165 }
166 }
167 }
168 }
169
170 if(!empty($badges_html)){
171 echo '<div class="badges"><h6>'.__('Badges','vibe').'</h6>';
172 echo '<ul>';
173 foreach($badges_html as $b_html){
174 echo '<li>';
175 echo vibe_sanitizer($b_html);
176 echo '</li>';
177 }
178 echo '</ul>';
179 echo '</div>';
180 }
181 }
182
183
184 $certis=vibe_sanitize(get_user_meta($user_id,'certificates',false));
185
186 if(isset($certis) && is_Array($certis) && count($certis)){
187 echo '<div class="certifications"><h6>'.__('Certifications','vibe').'</h6><ul class="slides">';
188 if(isset($certis) && is_Array($certis))
189 foreach($certis as $certi){
190 if(function_exists('bp_get_course_certificate')){
191
192 if(!empty($certi) && get_post_type($certi) == 'course'){
193
194 $url = bp_get_course_certificate('user_id='.$user_id.'&course_id='.$certi);
195 $class = '';
196 $class = apply_filters('bp_course_certificate_class','',array('course_id'=>$certi,'user_id'=>$user_id));
197 if(isset($_GET['regenerate_certificate']) || (strpos($url, 'jpeg') === false) ) {
198 $class .=' regenerate_certificate';
199 }
200
201 echo '<li><a href="'.$url.'" class="ajax-certificate '.$class.'" data-user="'.$user_id.'" data-course="'.$certi.'" data-security="'.wp_create_nonce($user_id).'"><i class="icon-certificate-file"></i><span>'.get_the_title($certi).'</span></a></li>';
202 }
203 }
204 }
205 echo '</ul></div>';
206 }
207
208}
209
210add_action('bp_group_options_nav','vibe_course_group_link',1,1);
211
212function vibe_course_group_link(){
213 global $bp,$wpdb;
214 $course_query= $wpdb->get_results( $wpdb->prepare("SELECT post_id from {$wpdb->postmeta} WHERE meta_key='vibe_group' AND meta_value='%d'",$bp->groups->current_group->id));
215 if(is_array($course_query) && isset($course_query[0]->post_id))
216 echo '<li id="course-li"><a id="admin" href="'.get_permalink($course_query[0]->post_id).'" title="'.get_the_title($course_query[0]->post_id).'">'.__('Course ','vibe').'</a></li>';
217}
218
219function bp_dtheme_setup() {
220 if ( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
221 // Group buttons
222 if ( bp_is_active( 'groups' ) ) {
223 $groups_check = vibe_get_option('enable_groups_join_button');
224
225 if(isset($groups_check) && $groups_check)
226 add_action( 'bp_directory_groups_actions', 'bp_group_join_button' );
227 }
228
229 }
230}
231
232add_action( 'after_setup_theme', 'bp_dtheme_setup' );
233
234
235/* === Course Specific ===== */
236
237class WPLMS_BP_Cover_Image{
238
239 function __construct(){
240 add_action( 'bp_after_setup_theme',array($this,'cover_image'));
241 add_action('wp_enqueue_scripts',array($this,'display_cover_image'));
242 }
243
244 function cover_image() {
245 if(function_exists('bp_set_theme_compat_feature')){
246 bp_set_theme_compat_feature( 'legacy', array(
247 'name' => 'cover_image',
248 'settings' => array(
249 'components' => array( 'xprofile','groups' ),
250 'width' => 1300,
251 'height' => 500,
252 'callback' => array($this,'record_cover_image'), // See line 845
253 'theme_handle' => 'bp-default-main',
254 ),
255 ) );
256 }
257 }
258 function record_cover_image( $params = array() ) {
259 if ( empty( $params ) ) {
260 return;
261 }
262
263 // avatar height - padding - 1/2 avatar height
264 $avatar_offset = $params['height'] - 5 - round( (int) bp_core_avatar_full_height() / 2 );
265
266 // header content offset + spacing
267 $top_offset = bp_core_avatar_full_height() - 10;
268 $left_offset = bp_core_avatar_full_width() + 20;
269
270 $this->cover_image = $params['cover_image'];
271 }
272
273 function display_cover_image(){
274 global $bp;
275
276 if(bp_is_user() || bp_is_group()){
277 if(!empty($this->cover_image)){
278 echo '<style>
279 #item-header{background:url("'.$this->cover_image.'") !important;}
280 #buddypress div#item-header.light div#item-header-content,
281 #buddypress div#item-header.light #latest-update h6,
282 #buddypress div#item-header.light div#item-header-content a,
283 #buddypress div#item-header.light div#item-header-content h3 a
284 {
285 color:#FFF !important;
286 }
287 #buddypress div#item-header.dark div#item-header-content,
288 #buddypress div#item-header.dark #latest-update h6,
289 #buddypress div#item-header.dark div#item-header-content a,
290 #buddypress div#item-header.dark div#item-header-content h3 a
291 {
292 color:#222 !important;
293 }
294 </style>';
295 }
296 }
297 }
298}
299
300new WPLMS_BP_Cover_Image;