PluginProbe
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor / 3.16.4
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor v3.16.4
4.0.3 4.0.2 4.0.1 4.0.0 3.16.6 3.16.5 3.16.4 3.16.3 3.16.2 3.16.1 3.16.0 3.15.9 3.9.9 3.9.5 3.9.6 3.9.7 3.9.8 1.1.7 1.1.8 1.1.9 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 All 341 releases
profile-builder / front-end / default-fields / blog-details / blog-details.php

blog-details.php in User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor 3.16.4, at front-end/default-fields/blog-details/blog-details.php

245 lines 12.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3
4 /* handle field output */
5 function wppb_blog_details_handler( $output, $form_location, $field, $user_id, $field_check_errors, $request_data ){
6
7 // Display "Yes, I'd like to create a new site" checkbox if we're on the PB Register form and we are on Multisite with Network setting "Both sites and user accounts can be registered".
8 if ( ( $form_location != 'register' ) || ( ! wppb_can_users_signup_blog() ) ){
9 return $output;
10 }
11
12 //Check if Blog Details field is added in Manage Fields
13 $in_manage_fields = false;
14 $wppb_manage_fields = get_option( 'wppb_manage_fields', 'not_set' );
15 if ( $wppb_manage_fields != 'not_set' ){
16 foreach ( $wppb_manage_fields as $field ) {
17 if ( $field['field'] == 'Default - Blog Details' ) {
18 $in_manage_fields = true;
19 break;
20 }
21 }
22 }
23 if ( ! $in_manage_fields ) {
24 return $output;
25 }
26
27
28 $output = '<ul>';
29
30 $item_description = wppb_icl_t( 'plugin profile-builder-pro', 'default_field_'.$field['id'].'_description_translation', $field['description'], true );
31 $heading = '<li class="wppb-form-field wppb-blog-details-heading"><h4>'.wppb_icl_t('plugin profile-builder-pro', 'default_field_'.$field['id'].'_title_translation', $field['field-title'], true).'</h4><span class="wppb-description-delimiter">'.$item_description.'</span></li>';
32 $output .= apply_filters( 'wppb_blog_details_heading', $heading );
33
34 if( !wp_script_is('jquery', 'done') && !is_admin() ){
35 wp_print_scripts('jquery');
36 }
37
38 ?><script type="text/javascript">
39 jQuery(document).ready(function(){
40
41 wppb_toggle_required_attrbute_for_blog_details();
42 jQuery("#wppb_create_new_site_checkbox").on("click",function(){
43
44 wppb_toggle_required_attrbute_for_blog_details();
45 jQuery(".wppb-blog-details-fields").toggle();
46 });
47 function wppb_toggle_required_attrbute_for_blog_details(){
48
49 // Trigger a custom event that will remove the HTML attribute -required- for hidden fields. This is necessary for browsers to allow form submission.
50 if(document.getElementById('wppb_create_new_site_checkbox').checked) {
51 jQuery(".wppb-blog-details-fields input" ).trigger( "wppbAddRequiredAttributeEvent" );
52 } else {
53 jQuery(".wppb-blog-details-fields input" ).trigger( "wppbRemoveRequiredAttributeEvent" );
54 }
55 }
56 });
57 </script> <?php
58 $checked = '';
59 if ( isset( $request_data['wppb_create_new_site_checkbox']) && ( $request_data['wppb_create_new_site_checkbox'] == 'yes') ) {
60 $checked = 'checked';
61 }else{
62 echo '<style> .wppb-blog-details-fields {display:none;} </style>';
63 }
64 $create_new_site_checkbox = '
65 <li class=" wppb-form-field wppb-create-new-site " id="wppb-create-new-site">
66 <label for="wppb_create_new_site_checkbox">
67 <input id="wppb_create_new_site_checkbox" type="checkbox" name="wppb_create_new_site_checkbox" value="yes" '.$checked.' autocomplete="off">
68 <span>'. __('Yes, I\'d like to create a new site','profile-builder').'</span> </label>
69 </li>';
70 $output .= apply_filters( 'wppb_blog_details_checkbox', $create_new_site_checkbox );
71
72 $output .= '<ul class="wppb-blog-details-fields">';
73
74 // Site URL
75 $item_description = __( 'Your site url will look like this: ', 'profile-builder' );
76 if ( is_subdomain_install() ) {
77 global $current_site;
78 $subdomain_base = apply_filters( 'wppb_blogs_subdomain_base', preg_replace( '|^www\.|', '', $current_site->domain ) . $current_site->path );
79 $domain = '"http://'. esc_attr( '<your-slug>.' ) . $subdomain_base . '"';
80 } else {
81 $domain = '"' . esc_url( home_url( '/' ) ) . esc_attr( '<your-slug>' ) . '"';
82 }
83 $blog_url_input_value = '';
84 $blog_url_input_value = ( isset( $request_data['wppb_blog_url'] ) ? trim( $request_data['wppb_blog_url'] ) : $blog_url_input_value );
85 $error_mark = '<span class="wppb-required" title="'.wppb_required_field_error($field["field-title"]).'">*</span>';
86
87 $extra_attr = apply_filters( 'wppb_extra_attribute', '', $field, $form_location );
88
89 $error_class = '';
90 $is_error = wppb_check_individual_blog_fields( 'wppb_blog_url', $request_data, $form_location );
91 if ($is_error != '') {
92 $error_mark = '<img src="' . WPPB_PLUGIN_URL . 'assets/images/pencil_delete.png" title="' . wppb_required_field_error('') . '"/>';
93 $error_class = ' wppb-field-error';
94 }
95
96 $blog_url_css_classes = apply_filters( 'wppb_blog_details_field_css_class', 'wppb-form-field wppb-blog-url ' . $error_class, $field );
97 $label = esc_html__( 'Site URL slug', 'profile-builder' );
98 $placeholder_attr = apply_filters( 'wppb_blog_details_field_placeholder', '', 'default_field_blog_url', $label );
99
100 $output .= '
101 <li class="' . $blog_url_css_classes . '">
102 <label for="blog-url">' . $label . $error_mark.'</label>
103 <input class="text-input default_field_blog_url" name="wppb_blog_url" maxlength="'. apply_filters( 'wppb_maximum_character_length', 70, $field ) .'" type="text" id="wppb_blog_url" value="'. esc_attr( wp_unslash( $blog_url_input_value ) ) .'" '. $placeholder_attr . $extra_attr .' />';
104 $output .= '<span class="wppb-description-delimiter">'. $item_description . $domain . '</span>';
105 $output .= $is_error .'</li>';
106
107
108
109 // Site title
110 $blog_title_input_value = '';
111 $blog_title_input_value = ( isset( $request_data['wppb_blog_title'] ) ? trim( $request_data['wppb_blog_title'] ) : $blog_title_input_value );
112 $error_mark = '<span class="wppb-required" title="'.wppb_required_field_error($field["field-title"]).'">*</span>';
113
114 $extra_attr = apply_filters( 'wppb_extra_attribute', '', $field, $form_location );
115
116 $error_class = '';
117 $is_error = wppb_check_individual_blog_fields( 'wppb_blog_title', $request_data, $form_location );
118 if ($is_error != '') {
119 $error_mark = '<img src="' . WPPB_PLUGIN_URL . 'assets/images/pencil_delete.png" title="' . wppb_required_field_error('') . '"/>';
120 $error_class = ' wppb-field-error';
121 }
122
123 $blog_title_css_classes = apply_filters( 'wppb_blog_details_field_css_class', 'wppb-form-field wppb-blog-url ' . $error_class, $field );
124 $label = esc_html__( 'Site Title', 'profile-builder' );
125 $placeholder_attr = apply_filters( 'wppb_blog_details_field_placeholder', '', 'default_field_blog_title', $label );
126
127 $output .= '
128 <li class="' . $blog_title_css_classes . '">
129 <label for="blog-title">' . $label . $error_mark.'</label>
130 <input class="text-input default_field_blog_title" name="wppb_blog_title" maxlength="'. apply_filters( 'wppb_maximum_character_length', 70, $field ) .'" type="text" id="wppb_blog_title" value="'. esc_attr( wp_unslash( $blog_title_input_value ) ) .'" '. $placeholder_attr . $extra_attr .' />' .
131 $is_error . '</li>';
132
133
134
135 // Privacy
136 $blog_privacy_input_value = 'Yes';
137 $blog_privacy_input_value = ( isset( $request_data['wppb_blog_privacy'] ) ? trim( $request_data['wppb_blog_privacy'] ) : $blog_privacy_input_value );
138 $error_mark = '<span class="wppb-required" title="'.wppb_required_field_error($field["field-title"]).'">*</span>';
139
140 $radio_values = array( 'Yes', 'No' );
141
142 $error_class = '';
143 $is_error = wppb_check_individual_blog_fields( 'wppb_blog_privacy', $request_data, $form_location );
144 if ($is_error != '') {
145 $error_mark = '<img src="' . WPPB_PLUGIN_URL . 'assets/images/pencil_delete.png" title="' . wppb_required_field_error('') . '"/>';
146 $error_class = ' wppb-field-error';
147 }
148
149 $output .= '
150 <li class=" wppb-form-field wppb-blog-privacy ' . $error_class . ' ">
151 <label for="blog-privacy">'. __( 'Privacy: I would like my site to appear in search engines, and in public listings around this network.', 'profile-builder' ) . $error_mark.'</label>';
152 $output .= '<ul class="wppb-radios">';
153 foreach( $radio_values as $key => $value){
154 $output .= '<li><input value="'.esc_attr( trim( $value ) ).'" class="blog_privacy_radio '. apply_filters( 'wppb_fields_extra_css_class', '', $field ) .'" id="'.Wordpress_Creation_Kit_PB::wck_generate_slug( trim( $value ) ).'_'.$field['id'].'" name="wppb_blog_privacy" type="radio" '. $extra_attr .' ';
155
156 if ( $blog_privacy_input_value === trim( $value ) )
157 $output .= ' checked';
158
159 $output .= ' /><label for="'.Wordpress_Creation_Kit_PB::wck_generate_slug( trim( $value ) ).'_'.$field['id'].'" class="wppb-rc-value">'. trim( $radio_values[$key] ) .'</label></li>';
160 }
161 $output .= '</ul>' . $is_error . '</li>';
162
163 // end wppb-blog-details-fields
164 $output .= '</ul>';
165
166 $output .= '</ul>';
167
168 return apply_filters( 'wppb_blog_details_output', $output, $form_location, $field, $user_id, $field_check_errors, $request_data );
169
170 }
171 add_filter( 'wppb_output_form_field_default-blog-details', 'wppb_blog_details_handler', 10, 6 );
172
173 /* handle field save */
174 function wppb_create_blog_on_registration( $field, $user_id, $request_data, $form_location ){
175 if( $form_location == 'register' && $field['field'] == 'Default - Blog Details' && isset( $request_data['wppb_create_new_site_checkbox'] ) && $request_data['wppb_create_new_site_checkbox'] == 'yes' ) {
176 $blog_url = $request_data['wppb_blog_url'];
177 $blog_title = $request_data['wppb_blog_title'];
178
179 $usermeta['public'] = ( isset( $request_data['wppb_blog_privacy'] ) && 'Yes' == $request_data['wppb_blog_privacy'] ) ? true : false;
180 $blog_details = wpmu_validate_blog_signup( $blog_url, $blog_title );
181 if ( empty($blog_details['errors']->errors['blogname']) && empty($blog_details['errors']->errors['blog_title'])) {
182 wpmu_create_blog( $blog_details['domain'], $blog_details['path'], $blog_details['blog_title'], $user_id, $usermeta );
183 }
184 }
185 }
186 add_action( 'wppb_save_form_field', 'wppb_create_blog_on_registration', 10, 4 );
187
188 /* handle field validation */
189 function wppb_check_blog_details_values( $message, $field, $request_data, $form_location ){
190 if ( isset( $request_data['wppb_create_new_site_checkbox'] ) && $request_data['wppb_create_new_site_checkbox'] == 'yes' ){
191 $blog_fields_array = wppb_blog_details_fields_array();
192 foreach ( $blog_fields_array as $blog_field ){
193 if( ( isset( $request_data[$blog_field] ) && ( trim( $request_data[$blog_field] ) == '' ) ) || !isset( $request_data[$blog_field] ) ){
194 return wppb_required_field_error($blog_field);
195 }
196 }
197 }
198 return $message;
199 }
200 add_filter( 'wppb_check_form_field_default-blog-details', 'wppb_check_blog_details_values', 10, 4 );
201
202 /* Add blog details information to wp_signups table (when Email Confirmation is active) */
203 function wppb_add_blog_details_to_signup_table( $meta, $global_request, $role ){
204 if ( isset( $global_request['wppb_create_new_site_checkbox'] ) && $global_request['wppb_create_new_site_checkbox'] == 'yes' ) {
205 $blog_details_fields_array = wppb_blog_details_fields_array();
206
207 foreach ($blog_details_fields_array as $blog_field) {
208 $meta[$blog_field] = $global_request[$blog_field];
209 }
210 }
211 return $meta;
212 }
213 add_filter( 'wppb_add_to_user_signup_form_meta', 'wppb_add_blog_details_to_signup_table',10, 3 );
214
215
216
217 function wppb_blog_details_fields_array(){
218 return array(
219 'wppb_blog_title',
220 'wppb_blog_url',
221 'wppb_blog_privacy',
222 'wppb_create_new_site_checkbox'
223 );
224 }
225
226 function wppb_check_individual_blog_fields( $field_key, $request_data, $form_location ){
227 if ( isset( $request_data['wppb_create_new_site_checkbox'] ) && $request_data['wppb_create_new_site_checkbox'] == 'yes' ) {
228 if ( $field_key == 'wppb_blog_privacy' && ( ! isset( $request_data[$field_key] ) || ( isset( $request_data[$field_key] ) && ( trim( $request_data[$field_key] ) == '' ) ) ) ) {
229 return '<span class="wppb-form-error">' . wppb_required_field_error($field_key) . '</span>';
230 }
231
232 $wp_error = wpmu_validate_blog_signup($request_data['wppb_blog_url'], $request_data['wppb_blog_title']);
233
234 if ( $field_key == 'wppb_blog_url' && !empty($wp_error['errors']->errors['blogname'])){
235 return '<span class="wppb-form-error">' . $wp_error['errors']->errors['blogname'][0] . '</span>';
236 }
237 if ( $field_key == 'wppb_blog_title' && !empty($wp_error['errors']->errors['blog_title'])){
238 return '<span class="wppb-form-error">' . $wp_error['errors']->errors['blog_title'][0] . '</span>';
239 }
240
241 }
242 return '';
243 }
244
245