Profile.php
2.1 KB
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
<?php
namespace ACA\BP\Settings;
use AC;
use AC\View;
use ACA\BP\Column;
use BP_XProfile_Field;
use BP_XProfile_Group;
/**
* @property Column\Profile $column
*/
class Profile extends AC\Settings\Column {
/**
* @var string
*/
private $profile_field;
protected function define_options() {
return [ 'profile_field' ];
}
public function create_view() {
$select = $this->create_element( 'select' );
$select
->set_no_result( sprintf( __( 'No %s fields available.', 'codepress-admin-columns' ), __( 'BuddyPress', 'codepress-admin-columns' ) ) )
->set_options( $this->get_field_types() )
->set_attribute( 'data-refresh', 'column' )
->set_attribute( 'data-label', 'update' );
$view = new View( [
'label' => __( 'Field', 'codepress-admin-columns' ),
'description' => sprintf( __( 'Select your %s field.', 'codepress-admin-columns' ), __( 'BuddyPress profile', 'codepress-admin-columns' ) ),
'setting' => $select,
] );
return $view;
}
public function get_dependent_settings() {
return $this->column->get_field()->get_dependent_settings();
}
/**
* @return string
*/
public function get_profile_field() {
if ( null === $this->profile_field ) {
$this->set_profile_field( $this->get_first_profile_field() );
}
return $this->profile_field;
}
/**
* @param string $profile_field
*
* @return true
*/
public function set_profile_field( $profile_field ) {
$this->profile_field = $profile_field;
return true;
}
/**
* @return string
*/
private function get_first_profile_field() {
$fields = $this->get_field_types();
reset( $fields );
return key( $fields );
}
private function get_field_types() {
$option_groups = [];
/** @var BP_XProfile_Group[] $groups */
$groups = BP_XProfile_Group::get( [ 'fetch_fields' => true ] );
foreach ( $groups as $group ) {
$options = [];
foreach ( $group->fields as $field ) {
/** @var BP_XProfile_Field $field */
$options[ $field->id ] = $field->name;
}
$option_groups[ $group->id ] = [
'title' => $group->name,
'options' => $options,
];
}
return $option_groups;
}
}