PluginProbe
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor / 4.0.2
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor v4.0.2
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 2.0.7 All 340 releases
profile-builder / form-builder / multiple-forms / register-forms.php

register-forms.php in User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor 4.0.2, at form-builder/multiple-forms/register-forms.php

313 lines 13.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 // Exit if accessed directly
3 if ( ! defined( 'ABSPATH' ) ) exit;
4
5 /**
6 * Function that creates the "Registration Forms" post type
7 *
8 * @since v.2.0
9 *
10 * @return void
11 */
12 function wppb_create_registration_forms_cpt(){
13 $labels = array(
14 'name' => __( 'Registration Form', 'profile-builder'),
15 'singular_name' => __( 'Registration Form', 'profile-builder'),
16 'add_new' => __( 'Add New', 'profile-builder' ),
17 'add_new_item' => __( 'Add new Registration Form', 'profile-builder' ),
18 'edit_item' => __( 'Edit the Registration Forms', 'profile-builder' ) ,
19 'new_item' => __( 'New Registration Form', 'profile-builder' ),
20 'all_items' => __( 'Registration Forms', 'profile-builder' ),
21 'view_item' => __( 'View the Registration Form', 'profile-builder' ),
22 'search_items' => __( 'Search the Registration Forms', 'profile-builder' ),
23 'not_found' => __( 'No Registration Form found', 'profile-builder' ),
24 'not_found_in_trash' => __( 'No Registration Forms found in trash', 'profile-builder' ),
25 'parent_item_colon' => '',
26 'menu_name' => __( 'Registration Forms', 'profile-builder' )
27 );
28
29 $args = array(
30 'labels' => $labels,
31 'public' => false,
32 'publicly_queryable' => false,
33 'show_ui' => true,
34 'query_var' => true,
35 'show_in_menu' => 'profile-builder',
36 'has_archive' => false,
37 'hierarchical' => false,
38 'capability_type' => 'post',
39 'supports' => array( 'title' )
40 );
41
42 /* Free installs get the default forms only -- see form-builder-licensing.php.
43 Same override the modern registration applies, so the gate holds in classic
44 editor mode too. */
45 $wppb_fb_cap_overrides = function_exists( 'wppb_fb_form_cpt_capability_overrides' ) ? wppb_fb_form_cpt_capability_overrides() : array();
46 if ( ! empty( $wppb_fb_cap_overrides ) )
47 $args['capabilities'] = $wppb_fb_cap_overrides;
48
49 /* hide from admin bar for non administrators */
50 if( !current_user_can( 'manage_options' ) )
51 $args['show_in_admin_bar'] = false;
52
53 $wppb_addonOptions = get_option('wppb_module_settings');
54 if( !empty( $wppb_addonOptions['wppb_multipleRegistrationForms'] ) && $wppb_addonOptions['wppb_multipleRegistrationForms'] == 'show' )
55 register_post_type( 'wppb-rf-cpt', $args );
56 }
57 add_action( 'init', 'wppb_create_registration_forms_cpt', 9);
58
59 /* Register Form change classes based on Redirect field start */
60 add_filter( 'wck_add_form_class_wppb_rf_page_settings', 'wppb_register_add_form_change_class_based_on_redirect_field', 10, 3 );
61 function wppb_register_add_form_change_class_based_on_redirect_field($wck_update_container_css_class, $meta, $results ) {
62 if( !empty( $results ) ){
63 $redirect = Wordpress_Creation_Kit_PB::wck_generate_slug( $results[0]["redirect"] );
64 return "update_container_$meta update_container_$redirect redirect_$redirect";
65 }
66 }
67 /* Register Form change classes based on Redirect field end */
68
69 /**
70 * Remove view/trash row actions for Register Forms.
71 *
72 * @param array $actions
73 * @return array
74 */
75 function wppb_remove_rf_view_link( $actions ){
76 global $post;
77
78 if ( ! empty( $post ) ) {
79 if ( $post->post_type == 'wppb-rf-cpt' ){
80 unset( $actions['view'] );
81
82 if ( wppb_get_post_number ( $post->post_type, 'singular_action' ) )
83 unset( $actions['trash'] );
84 }
85 }
86
87 return $actions;
88 }
89 add_filter( 'post_row_actions', 'wppb_remove_rf_view_link', 10, 1 );
90
91
92 /**
93 * Remove view/trash bulk actions for Register Forms.
94 *
95 * @param array $actions
96 * @return array
97 */
98 function wppb_remove_trash_bulk_option_rf( $actions ){
99 global $post;
100 if( !empty( $post ) ){
101 if ( $post->post_type == 'wppb-rf-cpt' ){
102 unset( $actions['view'] );
103
104 if ( wppb_get_post_number ( $post->post_type, 'bulk_action' ) )
105 unset( $actions['trash'] );
106 }
107 }
108
109 return $actions;
110 }
111 add_filter( 'bulk_actions-edit-wppb-rf-cpt', 'wppb_remove_trash_bulk_option_rf' );
112
113
114 /** Hide publishing UI chrome on Register Form edit screens. */
115 function wppb_hide_rf_publishing_actions(){
116 global $post;
117
118 if ( $post->post_type == 'wppb-rf-cpt' ){
119 echo '<style type="text/css">#misc-publishing-actions, #minor-publishing-actions{display:none;}</style>';
120
121 $rf = get_posts( array( 'posts_per_page' => -1, 'post_status' => apply_filters ( 'wppb_check_singular_rf_form_publishing_options', array( 'publish' ) ) , 'post_type' => 'wppb-rf-cpt' ) );
122 if ( count( $rf ) == 1 )
123 echo '<style type="text/css">#major-publishing-actions #delete-action{display:none;}</style>';
124 }
125 }
126 add_action('admin_head-post.php', 'wppb_hide_rf_publishing_actions');
127 add_action('admin_head-post-new.php', 'wppb_hide_rf_publishing_actions');
128
129
130 /**
131 * Add Shortcode column to Register Forms list.
132 *
133 * @param array $columns
134 * @return array
135 */
136 function wppb_add_extra_column_for_rf( $columns ){
137 $columns['rf-shortcode'] = __( 'Shortcode', 'profile-builder' );
138
139 return $columns;
140 }
141 add_filter( 'manage_wppb-rf-cpt_posts_columns', 'wppb_add_extra_column_for_rf' );
142
143
144 /**
145 * Render Shortcode column content for Register Forms.
146 *
147 * @param string $column_name
148 * @param integer $post_id
149 */
150 function wppb_rf_custom_column_content( $column_name, $post_id ){
151 if( $column_name == 'rf-shortcode' ){
152 $post = get_post( $post_id );
153
154 if( empty( $post->post_title ) )
155 $post->post_title = __( '(no title)', 'profile-builder' );
156
157 // Default forms embed via a bare [wppb-register]; custom forms
158 // keep their title-derived form_name. wppb_fb_build_form_shortcode()
159 // owns that distinction.
160 $shortcode = function_exists( 'wppb_fb_build_form_shortcode' )
161 ? wppb_fb_build_form_shortcode( $post )
162 : '[wppb-register form_name="' . Wordpress_Creation_Kit_PB::wck_generate_slug( $post->post_title ) . '"]';
163
164 // An unpublished form has no working shortcode (the front-end resolver is
165 // publish-only), so offer a hint instead of an empty copy field.
166 if ( $shortcode === '' ) {
167 echo '<span class="wppb-shortcode-unavailable">&mdash; ' . esc_html__( 'available after publishing', 'profile-builder' ) . '</span>';
168 return;
169 }
170
171 echo "<input readonly spellcheck='false' type='text' title='Click to copy' class='wppb-shortcode_copy wppb-shortcode input' value='" . esc_attr( $shortcode ) . "' />";
172 echo "<span style='display: none; margin-left: 10px' class='wppb-copy-message'>Shortcode copied</span>";
173 }
174 }
175 add_action("manage_wppb-rf-cpt_posts_custom_column", "wppb_rf_custom_column_content", 10, 2);
176
177 /**
178 * Add side metaboxes
179 *
180 * @since v.2.0
181 *
182 * @return void
183 */
184 function wppb_rf_content(){
185 global $post;
186
187 $shortcode = function_exists( 'wppb_fb_build_form_shortcode' )
188 ? wppb_fb_build_form_shortcode( $post )
189 : '[wppb-register form_name="' . trim( Wordpress_Creation_Kit_PB::wck_generate_slug( $post->post_title ) ) . '"]';
190 $is_default = function_exists( 'wppb_fb_is_default_form' ) && wppb_fb_is_default_form( $post );
191
192 if ( $shortcode === '' ) {
193 echo '<p class="cozmoslabs-description"><span style="color: #e76054;">NOTE: </span>' . esc_html__( 'The shortcode will be available after you publish this form.', 'profile-builder' ) . '</p>';
194 } else {
195 echo '<p class="cozmoslabs-description">' . esc_html__( 'Use this shortcode on the page you want the form to be displayed.', 'profile-builder' ) . '</p>';
196 echo '<div class="cozmoslabs-form-field-wrapper">';
197 echo "<textarea readonly spellcheck='false' class='wppb-shortcode textarea' >" . esc_html( $shortcode ) . "</textarea>";
198 // Default forms embed via a bare shortcode, so the title-change caveat
199 // does not apply to them.
200 if ( ! $is_default ) {
201 echo '<p class="cozmoslabs-description">'. wp_kses_post( __( '<span style="color: #e76054;">NOTE:</span> Changing the form title also changes the shortcode!', 'profile-builder' ) ) .'</p>';
202 }
203 echo '</div>';
204 }
205 }
206
207 function wppb_rf_side_box(){
208 add_meta_box( 'wppb-rf-side', __( 'Form Shortcode', 'profile-builder' ), 'wppb_rf_content', 'wppb-rf-cpt', 'side', 'low' );
209 }
210 add_action( 'add_meta_boxes', 'wppb_rf_side_box' );
211
212 /**
213 * Function that manages the Register CPT
214 *
215 * @since v.2.0
216 *
217 * @return void
218 */
219 function wppb_manage_rf_cpt(){
220 // Skip WCK on modern mode — constructing it registers wp_ajax_wck_* that
221 // write wppb_rf_fields and bypass the save projection / meta-name resolver.
222 if ( wppb_fb_is_active_for( 'wppb-rf-cpt' ) ) return;
223
224 global $wp_roles;
225
226 $available_roles = $available_time = array();
227
228 foreach ( $wp_roles->roles as $slug => $role )
229 $available_roles[$slug] = '%'. wppb_prepare_wck_labels( $role['name'] ).'%'.$slug;
230
231 /* put the roles subscriber contributor author editor administrator in this order at the start of the options */
232 $desired_order_reversed = array( 'administrator', 'editor', 'author', 'contributor', 'subscriber' );
233 foreach( $desired_order_reversed as $key ){
234 if( !empty( $available_roles[$key] ) ){
235 $value = $available_roles[$key];
236 unset( $available_roles[$key] );
237 array_unshift( $available_roles , $value );
238 }
239 }
240 /* add the default role at the start of the options */
241 array_unshift( $available_roles , '%'.__( 'Default Role', 'profile-builder' ).'%'.'default role' );
242
243
244
245 for( $i=0; $i<=250; $i++ )
246 $available_time[] = $i;
247
248 // set up the fields array
249 $settings_fields = array(
250 array( 'type' => 'select', 'slug' => 'set-role', 'title' => __( 'Set Role', 'profile-builder' ), 'options' => $available_roles, 'description' => __( 'Choose what role the user will have after (s)he registered<br/>If not specified, defaults to the role set in the WordPress settings', 'profile-builder' ) ),
251 array( 'type' => 'select', 'slug' => 'automatically-log-in', 'title' => __( 'Automatically Log In', 'profile-builder' ), 'options' => array( '%'.__('No', 'profile-builder').'%No', '%'.__('Yes', 'profile-builder').'%Yes' ), 'default' => 'No', 'description' => __( 'Whether to automatically log in the newly registered user or not<br/>Only works on single-sites without "Admin Approval" feature activated<br/>WARNING: Caching the registration form will make automatic login not work', 'profile-builder' ) ),
252 array( 'type' => 'select', 'slug' => 'redirect', 'title' => __( 'Redirect', 'profile-builder' ), 'options' => array( '%'.__('Default', 'profile-builder').'%-', '%'.__('No', 'profile-builder').'%No', '%'.__('Yes', 'profile-builder').'%Yes' ), 'default' => '-', 'description' => __( 'Whether to redirect the user to a specific page or not', 'profile-builder' ) ),
253 array( 'type' => 'select', 'slug' => 'display-messages', 'title' => __( 'Display Messages', 'profile-builder' ), 'options' => $available_time, 'default' => 1, 'description' => __( 'Allowed time to display any success messages (in seconds)', 'profile-builder' ) ),
254 array( 'type' => 'text', 'slug' => 'url', 'title' => __( 'URL', 'profile-builder' ), 'description' => __( 'Specify the URL of the page users will be redirected once registered using this form<br/>Use the following format: http://www.mysite.com', 'profile-builder' ) ),
255 );
256
257 if( defined( 'WPPB_PAID_PLUGIN_DIR' ) ) {
258 $settings_fields[] = array( 'type' => 'checkbox', 'slug' => 'ajax', 'title' => __( 'Ajax Validation', 'profile-builder' ), 'options' => array( '%' . __( 'Yes', 'profile-builder' ) . '%true' ), 'description' => __( 'Use AJAX to validate this form without reloading the page', 'profile-builder' ) );
259 }
260
261 // set up the box arguments
262 $args = array(
263 'metabox_id' => 'wppb-rf-settings-args',
264 'metabox_title' => __( 'After Registration...', 'profile-builder' ),
265 'post_type' => 'wppb-rf-cpt',
266 'meta_name' => 'wppb_rf_page_settings',
267 'meta_array' => $settings_fields,
268 'sortable' => false,
269 'single' => true
270 );
271 new Wordpress_Creation_Kit_PB( $args );
272
273 $rf_fields = array ();
274
275 $all_fields = get_option ( 'wppb_manage_fields', 'not_set' );
276 if ( ( $all_fields != 'not_set' ) && ( ( is_array( $all_fields ) ) && ( !empty( $all_fields ) ) ) ){
277 foreach ( $all_fields as $key => $value ) {
278 if ( $value['field'] != 'Default - Display name publicly as' )
279 array_push( $rf_fields, wppb_field_format( $value['field-title'], $value['field'] ) );
280 }
281 }
282
283 $rf_fields = apply_filters( 'wppb_rf_fields_types', $rf_fields );
284
285 // set up the box arguments for the register forms and create them
286 $args = array(
287 'metabox_id' => 'wppb-rf-fields',
288 'metabox_title' => __( 'Add New Field to the List', 'profile-builder' ),
289 'post_type' => 'wppb-rf-cpt',
290 'meta_name' => 'wppb_rf_fields',
291 'meta_array' => $rf_fields = apply_filters ( 'wppb_rf_fields', array(
292 array( 'type' => 'select', 'slug' => 'field', 'title' => __( 'Field', 'profile-builder' ), 'options' => $rf_fields, 'default-option' => true, 'description' => sprintf( __( 'Choose one of the supported fields you manage <a href="%s">here</a>', 'profile-builder' ), admin_url( 'admin.php?page=manage-fields' ) ) ),
293 array( 'type' => 'text', 'slug' => 'id', 'title' => __( 'ID', 'profile-builder' ), 'default' => '', 'description' => __( "A unique, auto-generated ID for this particular field<br/>You can use this in conjuction with filters to target this element if needed<br/>Can't be edited", 'profile-builder' ), 'readonly' => true )
294 )
295 )
296 );
297 new Wordpress_Creation_Kit_PB( $args );
298
299
300 }
301 add_action( 'admin_init', 'wppb_manage_rf_cpt', 1 );
302
303
304 add_filter( "wck_before_listed_wppb_rf_fields_element_0", 'wppb_manage_fields_display_field_title_slug', 10, 3 );
305 add_filter( 'wck_update_container_class_wppb_rf_fields', 'wppb_update_container_class', 10, 4 );
306 add_filter( 'wck_element_class_wppb_rf_fields', 'wppb_element_class', 10, 4 );
307
308
309 /** Re-hide delete on mandatory fields after list refresh. */
310 function wppb_rf_after_refresh_list( $id ){
311 echo "<script type=\"text/javascript\">wppb_disable_delete_on_default_mandatory_fields();</script>";
312 }
313 add_action( "wck_refresh_list_wppb_rf_fields", "wppb_rf_after_refresh_list" );