PluginProbe
StreamCast – bring live radio to your site with a sleek player / 2.1.2
StreamCast – bring live radio to your site with a sleek player v2.1.2
2.4.5 2.4.4 trunk 1.0 1.1 2.0.0 2.1.10 2.1.2 2.1.4 2.1.5 2.1.8 2.2.1 2.2.3 2.2.4 2.2.5 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 2.3.5 2.3.6 2.3.7 2.3.8 2.3.9 All 29 releases
streamcast / admin / codestar-framework / classes / profile-options.class.php

profile-options.class.php in StreamCast – bring live radio to your site with a sleek player 2.1.2, at admin/codestar-framework/classes/profile-options.class.php

245 lines 7.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
2 /**
3 *
4 * Profile Option Class
5 *
6 * @since 1.0.0
7 * @version 1.0.0
8 *
9 */
10 if ( ! class_exists( 'CSF_Profile_Options' ) ) {
11 class CSF_Profile_Options extends CSF_Abstract{
12
13 // constans
14 public $unique = '';
15 public $abstract = 'profile';
16 public $sections = array();
17 public $args = array(
18 'data_type' => 'serialize',
19 'class' => '',
20 'defaults' => array(),
21 );
22
23 // run profile construct
24 public function __construct( $key, $params ) {
25
26 $this->unique = $key;
27 $this->args = apply_filters( "csf_{$this->unique}_args", wp_parse_args( $params['args'], $this->args ), $this );
28 $this->sections = apply_filters( "csf_{$this->unique}_sections", $params['sections'], $this );
29
30 add_action( 'admin_init', array( &$this, 'add_profile_options' ) );
31
32 }
33
34 // instance
35 public static function instance( $key, $params ) {
36 return new self( $key, $params );
37 }
38
39 // add profile add/edit fields
40 public function add_profile_options() {
41
42 add_action( 'show_user_profile', array( &$this, 'render_profile_form_fields' ) );
43 add_action( 'edit_user_profile', array( &$this, 'render_profile_form_fields' ) );
44
45 add_action( 'personal_options_update', array( &$this, 'save_profile' ) );
46 add_action( 'edit_user_profile_update', array( &$this, 'save_profile' ) );
47
48 }
49
50 // get default value
51 public function get_default( $field ) {
52
53 $default = ( isset( $field['default'] ) ) ? $field['default'] : '';
54 $default = ( isset( $this->args['defaults'][$field['id']] ) ) ? $this->args['defaults'][$field['id']] : $default;
55
56 return $default;
57
58 }
59
60 // get meta value
61 public function get_meta_value( $user_id, $field ) {
62
63 $value = null;
64
65 if ( ! empty( $user_id ) && ! empty( $field['id'] ) ) {
66
67 if ( $this->args['data_type'] !== 'serialize' ) {
68 $meta = get_user_meta( $user_id, $field['id'] );
69 $value = ( isset( $meta[0] ) ) ? $meta[0] : null;
70 } else {
71 $meta = get_user_meta( $user_id, $this->unique, true );
72 $value = ( isset( $meta[$field['id']] ) ) ? $meta[$field['id']] : null;
73 }
74
75 }
76
77 $default = ( isset( $field['id'] ) ) ? $this->get_default( $field ) : '';
78 $value = ( isset( $value ) ) ? $value : $default;
79
80 return $value;
81
82 }
83
84 // render profile add/edit form fields
85 public function render_profile_form_fields( $profileuser ) {
86
87 $is_profile = ( is_object( $profileuser ) && isset( $profileuser->ID ) ) ? true : false;
88 $profile_id = ( $is_profile ) ? $profileuser->ID : 0;
89 $errors = ( ! empty( $profile_id ) ) ? get_user_meta( $profile_id, '_csf_errors_'. $this->unique, true ) : array();
90 $errors = ( ! empty( $errors ) ) ? $errors : array();
91 $class = ( $this->args['class'] ) ? ''. $this->args['class'] : '';
92
93 if ( ! empty( $errors ) ) {
94 delete_user_meta( $profile_id, '_csf_errors_'. $this->unique );
95 }
96
97 echo '<div class="csf csf-profile-options csf-onload'. esc_attr( $class ) .'">';
98
99 wp_nonce_field( 'csf_profile_nonce', 'csf_profile_nonce'. $this->unique );
100
101 foreach ( $this->sections as $section ) {
102
103 $section_icon = ( ! empty( $section['icon'] ) ) ? '<i class="csf-section-icon '. esc_attr( $section['icon'] ) .'"></i>' : '';
104 $section_title = ( ! empty( $section['title'] ) ) ? $section['title'] : '';
105
106 echo ( $section_title || $section_icon ) ? '<h2>'. $section_icon . $section_title .'</h2>' : '';
107
108 if ( ! empty( $section['fields'] ) ) {
109
110 foreach ( $section['fields'] as $field ) {
111
112 if ( ! empty( $field['id'] ) && ! empty( $errors['fields'][$field['id']] ) ) {
113 $field['_error'] = $errors['fields'][$field['id']];
114 }
115
116 if ( ! empty( $field['id'] ) ) {
117 $field['default'] = $this->get_default( $field );
118 }
119
120 CSF::field( $field, $this->get_meta_value( $profile_id, $field ), $this->unique, 'profile' );
121
122 }
123
124 }
125
126 }
127
128 echo '</div>';
129
130 }
131
132 // save profile form fields
133 public function save_profile( $user_id ) {
134
135 $count = 1;
136 $data = array();
137 $errors = array();
138 $noncekey = 'csf_profile_nonce'. $this->unique;
139 $nonce = ( ! empty( $_POST[ $noncekey ] ) ) ? sanitize_text_field( wp_unslash( $_POST[ $noncekey ] ) ) : '';
140
141 if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || ! wp_verify_nonce( $nonce, 'csf_profile_nonce' ) ) {
142 return $user_id;
143 }
144
145 // XSS ok.
146 // No worries, This "POST" requests is sanitizing in the below foreach.
147 $request = ( ! empty( $_POST[ $this->unique ] ) ) ? $_POST[ $this->unique ] : array();
148
149 if ( ! empty( $request ) ) {
150
151 foreach ( $this->sections as $section ) {
152
153 if ( ! empty( $section['fields'] ) ) {
154
155 foreach ( $section['fields'] as $field ) {
156
157 if ( ! empty( $field['id'] ) ) {
158
159 $field_id = $field['id'];
160 $field_value = isset( $request[$field_id] ) ? $request[$field_id] : '';
161
162 // Sanitize "post" request of field.
163 if ( ! isset( $field['sanitize'] ) ) {
164
165 if( is_array( $field_value ) ) {
166 $data[$field_id] = wp_kses_post_deep( $field_value );
167 } else {
168 $data[$field_id] = wp_kses_post( $field_value );
169 }
170
171 } else if( isset( $field['sanitize'] ) && is_callable( $field['sanitize'] ) ) {
172
173 $data[$field_id] = call_user_func( $field['sanitize'], $field_value );
174
175 } else {
176
177 $data[$field_id] = $field_value;
178
179 }
180
181 // Validate "post" request of field.
182 if ( isset( $field['validate'] ) && is_callable( $field['validate'] ) ) {
183
184 $has_validated = call_user_func( $field['validate'], $field_value );
185
186 if ( ! empty( $has_validated ) ) {
187
188 $errors['sections'][$count] = true;
189 $errors['fields'][$field_id] = $has_validated;
190 $data[$field_id] = $this->get_meta_value( $user_id, $field );
191
192 }
193
194 }
195
196 }
197
198 }
199
200 }
201
202 $count++;
203
204 }
205
206 }
207
208 $data = apply_filters( "csf_{$this->unique}_save", $data, $user_id, $this );
209
210 do_action( "csf_{$this->unique}_save_before", $data, $user_id, $this );
211
212 if ( empty( $data ) ) {
213
214 if ( $this->args['data_type'] !== 'serialize' ) {
215 foreach ( $data as $key => $value ) {
216 delete_user_meta( $user_id, $key );
217 }
218 } else {
219 delete_user_meta( $user_id, $this->unique );
220 }
221
222 } else {
223
224 if ( $this->args['data_type'] !== 'serialize' ) {
225 foreach ( $data as $key => $value ) {
226 update_user_meta( $user_id, $key, $value );
227 }
228 } else {
229 update_user_meta( $user_id, $this->unique, $data );
230 }
231
232 if ( ! empty( $errors ) ) {
233 update_user_meta( $user_id, '_csf_errors_'. $this->unique, $errors );
234 }
235
236 }
237
238 do_action( "csf_{$this->unique}_saved", $data, $user_id, $this );
239
240 do_action( "csf_{$this->unique}_save_after", $data, $user_id, $this );
241
242 }
243 }
244 }
245