1 | | <?php |
2 | | |
3 | | /** |
4 | | * BuddyPress XProfile Template Tags |
5 | | * |
6 | | * @package BuddyPress |
7 | | * @subpackage XProfileTemplate |
8 | | */ |
9 | | |
10 | | // Exit if accessed directly |
11 | | if ( !defined( 'ABSPATH' ) ) exit; |
12 | | |
13 | | class BP_XProfile_Data_Template { |
14 | | var $current_group = -1; |
15 | | var $group_count; |
16 | | var $groups; |
17 | | var $group; |
18 | | |
19 | | var $current_field = -1; |
20 | | var $field_count; |
21 | | var $field_has_data; |
22 | | var $field; |
23 | | |
24 | | var $in_the_loop; |
25 | | var $user_id; |
26 | | |
27 | | function __construct( $user_id, $profile_group_id, $hide_empty_groups = false, $fetch_fields = false, $fetch_field_data = false, $exclude_groups = false, $exclude_fields = false, $hide_empty_fields = false, $fetch_visibility_level = false, $update_meta_cache = true ) { |
28 | | $this->groups = BP_XProfile_Group::get( array( |
29 | | 'profile_group_id' => $profile_group_id, |
30 | | 'user_id' => $user_id, |
31 | | 'hide_empty_groups' => $hide_empty_groups, |
32 | | 'hide_empty_fields' => $hide_empty_fields, |
33 | | 'fetch_fields' => $fetch_fields, |
34 | | 'fetch_field_data' => $fetch_field_data, |
35 | | 'fetch_visibility_level' => $fetch_visibility_level, |
36 | | 'exclude_groups' => $exclude_groups, |
37 | | 'exclude_fields' => $exclude_fields, |
38 | | 'update_meta_cache' => $update_meta_cache, |
39 | | ) ); |
40 | | |
41 | | $this->group_count = count($this->groups); |
42 | | $this->user_id = $user_id; |
43 | | } |
44 | | |
45 | | function has_groups() { |
46 | | if ( $this->group_count ) |
47 | | return true; |
48 | | |
49 | | return false; |
50 | | } |
51 | | |
52 | | function next_group() { |
53 | | $this->current_group++; |
54 | | |
55 | | $this->group = $this->groups[$this->current_group]; |
56 | | $this->field_count = 0; |
57 | | |
58 | | if( ! empty( $this->group->fields ) ) { |
59 | | $this->group->fields = apply_filters( 'xprofile_group_fields', $this->group->fields, $this->group->id ); |
60 | | $this->field_count = count( $this->group->fields ); |
61 | | } |
62 | | |
63 | | return $this->group; |
64 | | } |
65 | | |
66 | | function rewind_groups() { |
67 | | $this->current_group = -1; |
68 | | if ( $this->group_count > 0 ) { |
69 | | $this->group = $this->groups[0]; |
70 | | } |
71 | | } |
72 | | |
73 | | function profile_groups() { |
74 | | if ( $this->current_group + 1 < $this->group_count ) { |
75 | | return true; |
76 | | } elseif ( $this->current_group + 1 == $this->group_count ) { |
77 | | do_action('xprofile_template_loop_end'); |
78 | | // Do some cleaning up after the loop |
79 | | $this->rewind_groups(); |
80 | | } |
81 | | |
82 | | $this->in_the_loop = false; |
83 | | return false; |
84 | | } |
85 | | |
86 | | function the_profile_group() { |
87 | | global $group; |
88 | | |
89 | | $this->in_the_loop = true; |
90 | | $group = $this->next_group(); |
91 | | |
92 | | if ( 0 == $this->current_group ) // loop has just started |
93 | | do_action('xprofile_template_loop_start'); |
94 | | } |
95 | | |
96 | | /**** FIELDS ****/ |
97 | | |
98 | | function next_field() { |
99 | | $this->current_field++; |
100 | | |
101 | | $this->field = $this->group->fields[$this->current_field]; |
102 | | return $this->field; |
103 | | } |
104 | | |
105 | | function rewind_fields() { |
106 | | $this->current_field = -1; |
107 | | if ( $this->field_count > 0 ) { |
108 | | $this->field = $this->group->fields[0]; |
109 | | } |
110 | | } |
111 | | |
112 | | function has_fields() { |
113 | | $has_data = false; |
114 | | |
115 | | for ( $i = 0, $count = count( $this->group->fields ); $i < $count; ++$i ) { |
116 | | $field = &$this->group->fields[$i]; |
117 | | |
118 | | if ( !empty( $field->data ) && $field->data->value != null ) { |
119 | | $has_data = true; |
120 | | } |
121 | | } |
122 | | |
123 | | if ( $has_data ) |
124 | | return true; |
125 | | |
126 | | return false; |
127 | | } |
128 | | |
129 | | function profile_fields() { |
130 | | if ( $this->current_field + 1 < $this->field_count ) { |
131 | | return true; |
132 | | } elseif ( $this->current_field + 1 == $this->field_count ) { |
133 | | // Do some cleaning up after the loop |
134 | | $this->rewind_fields(); |
135 | | } |
136 | | |
137 | | return false; |
138 | | } |
139 | | |
140 | | function the_profile_field() { |
141 | | global $field; |
142 | | |
143 | | $field = $this->next_field(); |
144 | | |
145 | | $value = !empty( $field->data ) && !empty( $field->data->value ) ? maybe_unserialize( $field->data->value ) : false; |
146 | | |
147 | | if ( !empty( $value ) ) { |
148 | | $this->field_has_data = true; |
149 | | } else { |
150 | | $this->field_has_data = false; |
151 | | } |
152 | | } |
153 | | } |
154 | | |
155 | | function bp_has_profile( $args = '' ) { |
156 | | global $profile_template; |
157 | | |
158 | | // Only show empty fields if we're on the Dashboard, or we're on a user's profile edit page, |
159 | | // or this is a registration page |
160 | | $hide_empty_fields_default = ( !is_network_admin() && !is_admin() && !bp_is_user_profile_edit() && !bp_is_register_page() ); |
161 | | |
162 | | // We only need to fetch visibility levels when viewing your own profile |
163 | | if ( bp_is_my_profile() || bp_current_user_can( 'bp_moderate' ) || bp_is_register_page() ) { |
164 | | $fetch_visibility_level_default = true; |
165 | | } else { |
166 | | $fetch_visibility_level_default = false; |
167 | | } |
168 | | |
169 | | $defaults = array( |
170 | | 'user_id' => bp_displayed_user_id(), |
171 | | 'profile_group_id' => false, |
172 | | 'hide_empty_groups' => true, |
173 | | 'hide_empty_fields' => $hide_empty_fields_default, |
174 | | 'fetch_fields' => true, |
175 | | 'fetch_field_data' => true, |
176 | | 'fetch_visibility_level' => $fetch_visibility_level_default, |
177 | | 'exclude_groups' => false, // Comma-separated list of profile field group IDs to exclude |
178 | | 'exclude_fields' => false, // Comma-separated list of profile field IDs to exclude |
179 | | 'update_meta_cache' => true, |
180 | | ); |
181 | | |
182 | | $r = bp_parse_args( $args, $defaults, 'has_profile' ); |
183 | | extract( $r, EXTR_SKIP ); |
184 | | |
185 | | $profile_template = new BP_XProfile_Data_Template( $user_id, $profile_group_id, $hide_empty_groups, $fetch_fields, $fetch_field_data, $exclude_groups, $exclude_fields, $hide_empty_fields, $fetch_visibility_level, $update_meta_cache ); |
186 | | return apply_filters( 'bp_has_profile', $profile_template->has_groups(), $profile_template ); |
187 | | } |
188 | | |
189 | | function bp_profile_groups() { |
190 | | global $profile_template; |
191 | | return $profile_template->profile_groups(); |
192 | | } |
193 | | |
194 | | function bp_the_profile_group() { |
195 | | global $profile_template; |
196 | | return $profile_template->the_profile_group(); |
197 | | } |
198 | | |
199 | | function bp_profile_group_has_fields() { |
200 | | global $profile_template; |
201 | | return $profile_template->has_fields(); |
202 | | } |
203 | | |
204 | | function bp_field_css_class( $class = false ) { |
205 | | echo bp_get_field_css_class( $class ); |
206 | | } |
207 | | function bp_get_field_css_class( $class = false ) { |
208 | | global $profile_template; |
209 | | |
210 | | $css_classes = array(); |
211 | | |
212 | | if ( $class ) |
213 | | $css_classes[] = sanitize_title( esc_attr( $class ) ); |
214 | | |
215 | | // Set a class with the field ID |
216 | | $css_classes[] = 'field_' . $profile_template->field->id; |
217 | | |
218 | | // Set a class with the field name (sanitized) |
219 | | $css_classes[] = 'field_' . sanitize_title( $profile_template->field->name ); |
220 | | |
221 | | if ( $profile_template->current_field % 2 == 1 ) |
222 | | $css_classes[] = 'alt'; |
223 | | |
224 | | $css_classes[] = 'field_type_' . sanitize_title( $profile_template->field->type ); |
225 | | $css_classes = apply_filters_ref_array( 'bp_field_css_classes', array( &$css_classes ) ); |
226 | | |
227 | | return apply_filters( 'bp_get_field_css_class', ' class="' . implode( ' ', $css_classes ) . '"' ); |
228 | | } |
229 | | |
230 | | function bp_field_has_data() { |
231 | | global $profile_template; |
232 | | return $profile_template->field_has_data; |
233 | | } |
234 | | |
235 | | function bp_field_has_public_data() { |
236 | | global $profile_template; |
237 | | |
238 | | if ( $profile_template->field_has_data ) |
239 | | return true; |
240 | | |
241 | | return false; |
242 | | } |
243 | | |
244 | | function bp_the_profile_group_id() { |
245 | | echo bp_get_the_profile_group_id(); |
246 | | } |
247 | | function bp_get_the_profile_group_id() { |
248 | | global $group; |
249 | | return apply_filters( 'bp_get_the_profile_group_id', $group->id ); |
250 | | } |
251 | | |
252 | | function bp_the_profile_group_name() { |
253 | | echo bp_get_the_profile_group_name(); |
254 | | } |
255 | | function bp_get_the_profile_group_name() { |
256 | | global $group; |
257 | | return apply_filters( 'bp_get_the_profile_group_name', $group->name ); |
258 | | } |
259 | | |
260 | | function bp_the_profile_group_slug() { |
261 | | echo bp_get_the_profile_group_slug(); |
262 | | } |
263 | | function bp_get_the_profile_group_slug() { |
264 | | global $group; |
265 | | return apply_filters( 'bp_get_the_profile_group_slug', sanitize_title( $group->name ) ); |
266 | | } |
267 | | |
268 | | function bp_the_profile_group_description() { |
269 | | echo bp_get_the_profile_group_description(); |
270 | | } |
271 | | function bp_get_the_profile_group_description() { |
272 | | global $group; |
273 | | return apply_filters( 'bp_get_the_profile_group_description', $group->description ); |
274 | | } |
275 | | |
276 | | function bp_the_profile_group_edit_form_action() { |
277 | | echo bp_get_the_profile_group_edit_form_action(); |
278 | | } |
279 | | function bp_get_the_profile_group_edit_form_action() { |
280 | | global $bp, $group; |
281 | | |
282 | | return apply_filters( 'bp_get_the_profile_group_edit_form_action', trailingslashit( bp_displayed_user_domain() . $bp->profile->slug . '/edit/group/' . $group->id ) ); |
283 | | } |
284 | | |
285 | | function bp_the_profile_group_field_ids() { |
286 | | echo bp_get_the_profile_group_field_ids(); |
287 | | } |
288 | | function bp_get_the_profile_group_field_ids() { |
289 | | global $group; |
290 | | |
291 | | $field_ids = ''; |
292 | | |
293 | | if ( !empty( $group->fields ) ) { |
294 | | foreach ( (array) $group->fields as $field ) { |
295 | | $field_ids .= $field->id . ','; |
296 | | } |
297 | | } |
298 | | |
299 | | return substr( $field_ids, 0, -1 ); |
300 | | } |
301 | | |
302 | | function bp_profile_fields() { |
303 | | global $profile_template; |
304 | | return $profile_template->profile_fields(); |
305 | | } |
306 | | |
307 | | function bp_the_profile_field() { |
308 | | global $profile_template; |
309 | | return $profile_template->the_profile_field(); |
310 | | } |
311 | | |
312 | | function bp_the_profile_field_id() { |
313 | | echo bp_get_the_profile_field_id(); |
314 | | } |
315 | | function bp_get_the_profile_field_id() { |
316 | | global $field; |
317 | | return apply_filters( 'bp_get_the_profile_field_id', $field->id ); |
318 | | } |
319 | | |
320 | | function bp_the_profile_field_name() { |
321 | | echo bp_get_the_profile_field_name(); |
322 | | } |
323 | | function bp_get_the_profile_field_name() { |
324 | | global $field; |
325 | | |
326 | | return apply_filters( 'bp_get_the_profile_field_name', $field->name ); |
327 | | } |
328 | | |
329 | | function bp_the_profile_field_value() { |
330 | | echo bp_get_the_profile_field_value(); |
331 | | } |
332 | | function bp_get_the_profile_field_value() { |
333 | | global $field; |
334 | | |
335 | | $field->data->value = bp_unserialize_profile_field( $field->data->value ); |
336 | | |
337 | | return apply_filters( 'bp_get_the_profile_field_value', $field->data->value, $field->type, $field->id ); |
338 | | } |
339 | | |
340 | | function bp_the_profile_field_edit_value() { |
341 | | echo bp_get_the_profile_field_edit_value(); |
342 | | } |
343 | | function bp_get_the_profile_field_edit_value() { |
344 | | global $field; |
345 | | |
346 | | /** |
347 | | * Check to see if the posted value is different, if it is re-display this |
348 | | * value as long as it's not empty and a required field. |
349 | | */ |
350 | | if ( !isset( $field->data ) ) { |
351 | | $field->data = new stdClass; |
352 | | } |
353 | | |
354 | | if ( !isset( $field->data->value ) ) { |
355 | | $field->data->value = ''; |
356 | | } |
357 | | |
358 | | if ( isset( $_POST['field_' . $field->id] ) && $field->data->value != $_POST['field_' . $field->id] ) { |
359 | | if ( !empty( $_POST['field_' . $field->id] ) ) |
360 | | $field->data->value = $_POST['field_' . $field->id]; |
361 | | else |
362 | | $field->data->value = ''; |
363 | | } |
364 | | |
365 | | $field_value = isset( $field->data->value ) ? bp_unserialize_profile_field( $field->data->value ) : ''; |
366 | | |
367 | | return apply_filters( 'bp_get_the_profile_field_edit_value', $field_value, $field->type, $field->id ); |
368 | | } |
369 | | |
370 | | function bp_the_profile_field_type() { |
371 | | echo bp_get_the_profile_field_type(); |
372 | | } |
373 | | function bp_get_the_profile_field_type() { |
374 | | global $field; |
375 | | |
376 | | return apply_filters( 'bp_the_profile_field_type', $field->type ); |
377 | | } |
378 | | |
379 | | function bp_the_profile_field_description() { |
380 | | echo bp_get_the_profile_field_description(); |
381 | | } |
382 | | function bp_get_the_profile_field_description() { |
383 | | global $field; |
384 | | |
385 | | return apply_filters( 'bp_get_the_profile_field_description', $field->description ); |
386 | | } |
387 | | |
388 | | function bp_the_profile_field_input_name() { |
389 | | echo bp_get_the_profile_field_input_name(); |
390 | | } |
391 | | function bp_get_the_profile_field_input_name() { |
392 | | global $field; |
393 | | |
394 | | return apply_filters( 'bp_get_the_profile_field_input_name', 'field_' . $field->id ); |
395 | | } |
396 | | |
397 | | /** |
398 | | * Returns the action name for any signup errors related to this profile field |
399 | | * |
400 | | * In the registration templates, signup errors are pulled from the global |
401 | | * object and rendered at actions that look like 'bp_field_12_errors'. This |
402 | | * function allows the action name to be easily concatenated and called in the |
403 | | * following fashion: |
404 | | * do_action( bp_get_the_profile_field_errors_action() ); |
405 | | * |
406 | | * @since BuddyPress (1.8) |
407 | | * @return string The _errors action name corresponding to this profile field |
408 | | */ |
409 | | function bp_get_the_profile_field_errors_action() { |
410 | | global $field; |
411 | | return 'bp_field_' . $field->id . '_errors'; |
412 | | } |
413 | | |
414 | | /** |
415 | | * bp_the_profile_field_options() |
416 | | * |
417 | | * Displays field options HTML for field types of 'selectbox', 'multiselectbox', |
418 | | * 'radio', 'checkbox', and 'datebox'. |
419 | | * |
420 | | * @package BuddyPress Xprofile |
421 | | * @since BuddyPress (1.1) |
422 | | * |
423 | | * @uses bp_get_the_profile_field_options() |
424 | | * |
425 | | * @param array $args Specify type for datebox. Allowed 'day', 'month', 'year'. |
426 | | */ |
427 | | function bp_the_profile_field_options( $args = array() ) { |
428 | | echo bp_get_the_profile_field_options( $args ); |
429 | | } |
430 | | /** |
431 | | * bp_get_the_profile_field_options() |
432 | | * |
433 | | * Retrieves field options HTML for field types of 'selectbox', 'multiselectbox', 'radio', 'checkbox', and 'datebox'. |
434 | | * |
435 | | * @package BuddyPress Xprofile |
436 | | * @since BuddyPress (1.1) |
437 | | * |
438 | | * @uses BP_XProfile_Field::get_children() |
439 | | * @uses BP_XProfile_ProfileData::get_value_byid() |
440 | | * |
441 | | * @param array $args { |
442 | | * Array of optional arguments. |
443 | | * @type string|bool $type Type of datebox. False if it's not a |
444 | | * datebox, otherwise 'day, 'month', or 'year'. Default: false. |
445 | | * @type int $user_id ID of the user whose profile values should be |
446 | | * used when rendering options. Default: displayed user. |
447 | | * } |
448 | | */ |
449 | | function bp_get_the_profile_field_options( $args = array() ) { |
450 | | global $field; |
451 | | |
452 | | $args = bp_parse_args( $args, array( |
453 | | 'type' => false, |
454 | | 'user_id' => bp_displayed_user_id(), |
455 | | ), 'get_the_profile_field_options' ); |
456 | | |
457 | | /** |
458 | | * In some cases, the $field global is not an instantiation of the BP_XProfile_Field class. |
459 | | * However, we have to make sure that all data originally in $field gets merged back in, after reinstantiation. |
460 | | */ |
461 | | if ( ! method_exists( $field, 'get_children' ) ) { |
462 | | $field_obj = new BP_XProfile_Field( $field->id ); |
463 | | |
464 | | foreach ( $field as $field_prop => $field_prop_value ) { |
465 | | if ( ! isset( $field_obj->{$field_prop} ) ) |
466 | | $field_obj->{$field_prop} = $field_prop_value; |
467 | | } |
468 | | |
469 | | $field = $field_obj; |
470 | | } |
471 | | |
472 | | ob_start(); |
473 | | $field->type_obj->edit_field_options_html( $args ); |
474 | | $html = ob_get_contents(); |
475 | | ob_end_clean(); |
476 | | |
477 | | return $html; |
478 | | } |
479 | | |
480 | | function bp_the_profile_field_is_required() { |
481 | | echo bp_get_the_profile_field_is_required(); |
482 | | } |
483 | | function bp_get_the_profile_field_is_required() { |
484 | | global $field; |
485 | | |
486 | | // Define locale variable(s) |
487 | | $retval = false; |
488 | | |
489 | | // Super admins can skip required check |
490 | | if ( bp_current_user_can( 'bp_moderate' ) && !is_admin() ) |
491 | | $retval = false; |
492 | | |
493 | | // All other users will use the field's setting |
494 | | elseif ( isset( $field->is_required ) ) |
495 | | $retval = $field->is_required; |
496 | | |
497 | | return apply_filters( 'bp_get_the_profile_field_is_required', (bool) $retval ); |
498 | | } |
499 | | |
500 | | /** |
501 | | * Echo the visibility level of this field |
502 | | */ |
503 | | function bp_the_profile_field_visibility_level() { |
504 | | echo bp_get_the_profile_field_visibility_level(); |
505 | | } |
506 | | /** |
507 | | * Return the visibility level of this field |
508 | | */ |
509 | | function bp_get_the_profile_field_visibility_level() { |
510 | | global $field; |
511 | | |
512 | | // On the registration page, values stored in POST should take |
513 | | // precedence over default visibility, so that submitted values |
514 | | // are not lost on failure |
515 | | if ( bp_is_register_page() && ! empty( $_POST['field_' . $field->id . '_visibility'] ) ) { |
516 | | $retval = esc_attr( $_POST['field_' . $field->id . '_visibility'] ); |
517 | | } else { |
518 | | $retval = ! empty( $field->visibility_level ) ? $field->visibility_level : 'public'; |
519 | | } |
520 | | |
521 | | return apply_filters( 'bp_get_the_profile_field_visibility_level', $retval ); |
522 | | } |
523 | | |
524 | | /** |
525 | | * Echo the visibility level label of this field |
526 | | */ |
527 | | function bp_the_profile_field_visibility_level_label() { |
528 | | echo bp_get_the_profile_field_visibility_level_label(); |
529 | | } |
530 | | /** |
531 | | * Return the visibility level label of this field |
532 | | */ |
533 | | function bp_get_the_profile_field_visibility_level_label() { |
534 | | global $field; |
535 | | |
536 | | // On the registration page, values stored in POST should take |
537 | | // precedence over default visibility, so that submitted values |
538 | | // are not lost on failure |
539 | | if ( bp_is_register_page() && ! empty( $_POST['field_' . $field->id . '_visibility'] ) ) { |
540 | | $level = esc_html( $_POST['field_' . $field->id . '_visibility'] ); |
541 | | } else { |
542 | | $level = ! empty( $field->visibility_level ) ? $field->visibility_level : 'public'; |
543 | | } |
544 | | |
545 | | $fields = bp_xprofile_get_visibility_levels(); |
546 | | |
547 | | return apply_filters( 'bp_get_the_profile_field_visibility_level_label', $fields[$level]['label'] ); |
548 | | } |
549 | | |
550 | | |
551 | | function bp_unserialize_profile_field( $value ) { |
552 | | if ( is_serialized($value) ) { |
553 | | $field_value = maybe_unserialize($value); |
554 | | $field_value = implode( ', ', $field_value ); |
555 | | return $field_value; |
556 | | } |
557 | | |
558 | | return $value; |
559 | | } |
560 | | |
561 | | function bp_profile_field_data( $args = '' ) { |
562 | | echo bp_get_profile_field_data( $args ); |
563 | | } |
564 | | function bp_get_profile_field_data( $args = '' ) { |
565 | | |
566 | | $defaults = array( |
567 | | 'field' => false, // Field name or ID. |
568 | | 'user_id' => bp_displayed_user_id() |
569 | | ); |
570 | | |
571 | | $r = wp_parse_args( $args, $defaults ); |
572 | | extract( $r, EXTR_SKIP ); |
573 | | |
574 | | return apply_filters( 'bp_get_profile_field_data', xprofile_get_field_data( $field, $user_id ) ); |
575 | | } |
576 | | |
577 | | function bp_profile_group_tabs() { |
578 | | global $bp, $group_name; |
579 | | |
580 | | if ( !$groups = wp_cache_get( 'xprofile_groups_inc_empty', 'bp' ) ) { |
581 | | $groups = BP_XProfile_Group::get( array( 'fetch_fields' => true ) ); |
582 | | wp_cache_set( 'xprofile_groups_inc_empty', $groups, 'bp' ); |
583 | | } |
584 | | |
585 | | if ( empty( $group_name ) ) |
586 | | $group_name = bp_profile_group_name(false); |
587 | | |
588 | | $tabs = array(); |
589 | | for ( $i = 0, $count = count( $groups ); $i < $count; ++$i ) { |
590 | | if ( $group_name == $groups[$i]->name ) |
591 | | $selected = ' class="current"'; |
592 | | else |
593 | | $selected = ''; |
594 | | |
595 | | if ( !empty( $groups[$i]->fields ) ) { |
596 | | $link = trailingslashit( bp_displayed_user_domain() . $bp->profile->slug . '/edit/group/' . $groups[$i]->id ); |
597 | | $tabs[] = sprintf( '<li %1$s><a href="%2$s">%3$s</a></li>', $selected, $link, esc_html( $groups[$i]->name ) ); |
598 | | } |
599 | | } |
600 | | |
601 | | $tabs = apply_filters( 'xprofile_filter_profile_group_tabs', $tabs, $groups, $group_name ); |
602 | | foreach ( (array) $tabs as $tab ) |
603 | | echo $tab; |
604 | | |
605 | | do_action( 'xprofile_profile_group_tabs' ); |
606 | | } |
607 | | |
608 | | function bp_profile_group_name( $deprecated = true ) { |
609 | | if ( !$deprecated ) { |
610 | | return bp_get_profile_group_name(); |
611 | | } else { |
612 | | echo bp_get_profile_group_name(); |
613 | | } |
614 | | } |
615 | | function bp_get_profile_group_name() { |
616 | | if ( !$group_id = bp_action_variable( 1 ) ) |
617 | | $group_id = 1; |
618 | | |
619 | | if ( !is_numeric( $group_id ) ) |
620 | | $group_id = 1; |
621 | | |
622 | | if ( !$group = wp_cache_get( 'xprofile_group_' . $group_id, 'bp' ) ) { |
623 | | $group = new BP_XProfile_Group($group_id); |
624 | | wp_cache_set( 'xprofile_group_' . $group_id, $group, 'bp' ); |
625 | | } |
626 | | |
627 | | return apply_filters( 'bp_get_profile_group_name', $group->name ); |
628 | | } |
629 | | |
630 | | function bp_avatar_upload_form() { |
631 | | global $bp; |
632 | | |
633 | | if ( !(int) $bp->site_options['bp-disable-avatar-uploads'] ) |
634 | | bp_core_avatar_admin( null, bp_loggedin_user_domain() . $bp->profile->slug . '/change-avatar/', bp_loggedin_user_domain() . $bp->profile->slug . '/delete-avatar/' ); |
635 | | else |
636 | | _e( 'Avatar uploads are currently disabled. Why not use a <a href="http://gravatar.com" target="_blank">gravatar</a> instead?', 'buddypress' ); |
637 | | } |
638 | | |
639 | | function bp_profile_last_updated() { |
640 | | |
641 | | $last_updated = bp_get_profile_last_updated(); |
642 | | |
643 | | if ( !$last_updated ) { |
644 | | _e( 'Profile not recently updated', 'buddypress' ) . '.'; |
645 | | } else { |
646 | | echo $last_updated; |
647 | | } |
648 | | } |
649 | | function bp_get_profile_last_updated() { |
650 | | |
651 | | $last_updated = bp_get_user_meta( bp_displayed_user_id(), 'profile_last_updated', true ); |
652 | | |
653 | | if ( $last_updated ) |
654 | | return apply_filters( 'bp_get_profile_last_updated', sprintf( __('Profile updated %s', 'buddypress'), bp_core_time_since( strtotime( $last_updated ) ) ) ); |
655 | | |
656 | | return false; |
657 | | } |
658 | | |
659 | | function bp_current_profile_group_id() { |
660 | | echo bp_get_current_profile_group_id(); |
661 | | } |
662 | | function bp_get_current_profile_group_id() { |
663 | | if ( !$profile_group_id = bp_action_variable( 1 ) ) |
664 | | $profile_group_id = 1; |
665 | | |
666 | | return apply_filters( 'bp_get_current_profile_group_id', $profile_group_id ); // admin/profile/edit/[group-id] |
667 | | } |
668 | | |
669 | | function bp_avatar_delete_link() { |
670 | | echo bp_get_avatar_delete_link(); |
671 | | } |
672 | | function bp_get_avatar_delete_link() { |
673 | | global $bp; |
674 | | |
675 | | return apply_filters( 'bp_get_avatar_delete_link', wp_nonce_url( bp_displayed_user_domain() . $bp->profile->slug . '/change-avatar/delete-avatar/', 'bp_delete_avatar_link' ) ); |
676 | | } |
677 | | |
678 | | function bp_edit_profile_button() { |
679 | | global $bp; |
680 | | |
681 | | bp_button( array ( |
682 | | 'id' => 'edit_profile', |
683 | | 'component' => 'xprofile', |
684 | | 'must_be_logged_in' => true, |
685 | | 'block_self' => true, |
686 | | 'link_href' => trailingslashit( bp_displayed_user_domain() . $bp->profile->slug . '/edit' ), |
687 | | 'link_class' => 'edit', |
688 | | 'link_text' => __( 'Edit Profile', 'buddypress' ), |
689 | | 'link_title' => __( 'Edit Profile', 'buddypress' ), |
690 | | ) ); |
691 | | } |
692 | | |
693 | | /** Visibility ****************************************************************/ |
694 | | |
695 | | /** |
696 | | * Echo the field visibility radio buttons |
697 | | */ |
698 | | function bp_profile_visibility_radio_buttons( $args = '' ) { |
699 | | echo bp_profile_get_visibility_radio_buttons( $args ); |
700 | | } |
701 | | /** |
702 | | * Return the field visibility radio buttons |
703 | | */ |
704 | | function bp_profile_get_visibility_radio_buttons( $args = '' ) { |
705 | | |
706 | | // Parse optional arguments |
707 | | $r = bp_parse_args( $args, array( |
708 | | 'field_id' => bp_get_the_profile_field_id(), |
709 | | 'before' => '<ul class="radio">', |
710 | | 'after' => '</ul>', |
711 | | 'before_radio' => '<li>', |
712 | | 'after_radio' => '</li>', |
713 | | 'class' => 'bp-xprofile-visibility' |
714 | | ), 'xprofile_visibility_radio_buttons' ); |
715 | | |
716 | | // Empty return value, filled in below if a valid field ID is found |
717 | | $retval = ''; |
718 | | |
719 | | // Only do-the-do if there's a valid field ID |
720 | | if ( ! empty( $r['field_id'] ) ) : |
721 | | |
722 | | // Start the output buffer |
723 | | ob_start(); |
724 | | |
725 | | // Output anything before |
726 | | echo $r['before']; ?> |
727 | | |
728 | | <?php if ( bp_current_user_can( 'bp_xprofile_change_field_visibility' ) ) : ?> |
729 | | |
730 | | <?php foreach( bp_xprofile_get_visibility_levels() as $level ) : ?> |
731 | | |
732 | | <?php echo $r['before_radio']; ?> |
733 | | |
734 | | <label for="<?php esc_attr( 'see-field_' . $r['field_id'] . '_' . $level['id'] ); ?>"> |
735 | | <input type="radio" id="<?php echo esc_attr( 'see-field_' . $r['field_id'] . '_' . $level['id'] ); ?>" name="<?php echo esc_attr( 'field_' . $r['field_id'] . '_visibility' ); ?>" value="<?php echo esc_attr( $level['id'] ); ?>" <?php checked( $level['id'], bp_get_the_profile_field_visibility_level() ); ?> /> |
736 | | <span class="field-visibility-text"><?php echo esc_html( $level['label'] ); ?></span> |
737 | | </label> |
738 | | |
739 | | <?php echo $r['after_radio']; ?> |
740 | | |
741 | | <?php endforeach; ?> |
742 | | |
743 | | <?php endif; |
744 | | |
745 | | // Output anything after |
746 | | echo $r['after']; |
747 | | |
748 | | // Get the output buffer and empty it |
749 | | $retval = ob_get_clean(); |
750 | | endif; |
751 | | |
752 | | return apply_filters( 'bp_profile_get_visibility_radio_buttons', $retval, $r, $args ); |
753 | | } |
754 | | |
755 | | /** |
756 | | * Output the XProfile field visibility select list for settings |
757 | | * |
758 | | * @since BuddyPress (2.0.0) |
759 | | */ |
760 | | function bp_profile_settings_visibility_select( $args = '' ) { |
761 | | echo bp_profile_get_settings_visibility_select( $args ); |
762 | | } |
763 | | /** |
764 | | * Return the XProfile field visibility select list for settings |
765 | | * |
766 | | * @since BuddyPress (2.0.0) |
767 | | */ |
768 | | function bp_profile_get_settings_visibility_select( $args = '' ) { |
769 | | |
770 | | // Parse optional arguments |
771 | | $r = bp_parse_args( $args, array( |
772 | | 'field_id' => bp_get_the_profile_field_id(), |
773 | | 'before' => '', |
774 | | 'after' => '', |
775 | | 'class' => 'bp-xprofile-visibility' |
776 | | ), 'xprofile_settings_visibility_select' ); |
777 | | |
778 | | // Empty return value, filled in below if a valid field ID is found |
779 | | $retval = ''; |
780 | | |
781 | | // Only do-the-do if there's a valid field ID |
782 | | if ( ! empty( $r['field_id'] ) ) : |
783 | | |
784 | | // Start the output buffer |
785 | | ob_start(); |
786 | | |
787 | | // Output anything before |
788 | | echo $r['before']; ?> |
789 | | |
790 | | <?php if ( bp_current_user_can( 'bp_xprofile_change_field_visibility' ) ) : ?> |
791 | | |
792 | | <select class="<?php echo esc_attr( $r['class'] ); ?>" name="<?php echo esc_attr( 'field_' . $r['field_id'] ) ; ?>_visibility"> |
793 | | |
794 | | <?php foreach ( bp_xprofile_get_visibility_levels() as $level ) : ?> |
795 | | |
796 | | <option value="<?php echo esc_attr( $level['id'] ); ?>" <?php selected( $level['id'], bp_get_the_profile_field_visibility_level() ); ?>><?php echo esc_html( $level['label'] ); ?></option> |
797 | | |
798 | | <?php endforeach; ?> |
799 | | |
800 | | </select> |
801 | | |
802 | | <?php else : ?> |
803 | | |
804 | | <span class="field-visibility-settings-notoggle" title="<?php esc_attr_e( "This field's visibility cannot be changed.", 'buddypress' ); ?>"><?php bp_the_profile_field_visibility_level_label(); ?></span> |
805 | | |
806 | | <?php endif; |
807 | | |
808 | | // Output anything after |
809 | | echo $r['after']; |
810 | | |
811 | | // Get the output buffer and empty it |
812 | | $retval = ob_get_clean(); |
813 | | endif; |
814 | | |
815 | | // Output the dropdown list |
816 | | return apply_filters( 'bp_profile_settings_visibility_select', $retval, $r, $args ); |
817 | | } |