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