PluginProbe
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor / 4.0.0
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor v4.0.0
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 / 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.0, at form-builder/multiple-forms/register-forms.php

311 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 ( $post->post_type == 'wppb-rf-cpt' ){
79 unset( $actions['view'] );
80
81 if ( wppb_get_post_number ( $post->post_type, 'singular_action' ) )
82 unset( $actions['trash'] );
83 }
84
85 return $actions;
86 }
87 add_filter( 'post_row_actions', 'wppb_remove_rf_view_link', 10, 1 );
88
89
90 /**
91 * Remove view/trash bulk actions for Register Forms.
92 *
93 * @param array $actions
94 * @return array
95 */
96 function wppb_remove_trash_bulk_option_rf( $actions ){
97 global $post;
98 if( !empty( $post ) ){
99 if ( $post->post_type == 'wppb-rf-cpt' ){
100 unset( $actions['view'] );
101
102 if ( wppb_get_post_number ( $post->post_type, 'bulk_action' ) )
103 unset( $actions['trash'] );
104 }
105 }
106
107 return $actions;
108 }
109 add_filter( 'bulk_actions-edit-wppb-rf-cpt', 'wppb_remove_trash_bulk_option_rf' );
110
111
112 /** Hide publishing UI chrome on Register Form edit screens. */
113 function wppb_hide_rf_publishing_actions(){
114 global $post;
115
116 if ( $post->post_type == 'wppb-rf-cpt' ){
117 echo '<style type="text/css">#misc-publishing-actions, #minor-publishing-actions{display:none;}</style>';
118
119 $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' ) );
120 if ( count( $rf ) == 1 )
121 echo '<style type="text/css">#major-publishing-actions #delete-action{display:none;}</style>';
122 }
123 }
124 add_action('admin_head-post.php', 'wppb_hide_rf_publishing_actions');
125 add_action('admin_head-post-new.php', 'wppb_hide_rf_publishing_actions');
126
127
128 /**
129 * Add Shortcode column to Register Forms list.
130 *
131 * @param array $columns
132 * @return array
133 */
134 function wppb_add_extra_column_for_rf( $columns ){
135 $columns['rf-shortcode'] = __( 'Shortcode', 'profile-builder' );
136
137 return $columns;
138 }
139 add_filter( 'manage_wppb-rf-cpt_posts_columns', 'wppb_add_extra_column_for_rf' );
140
141
142 /**
143 * Render Shortcode column content for Register Forms.
144 *
145 * @param string $column_name
146 * @param integer $post_id
147 */
148 function wppb_rf_custom_column_content( $column_name, $post_id ){
149 if( $column_name == 'rf-shortcode' ){
150 $post = get_post( $post_id );
151
152 if( empty( $post->post_title ) )
153 $post->post_title = __( '(no title)', 'profile-builder' );
154
155 // Default forms embed via a bare [wppb-register]; custom forms
156 // keep their title-derived form_name. wppb_fb_build_form_shortcode()
157 // owns that distinction.
158 $shortcode = function_exists( 'wppb_fb_build_form_shortcode' )
159 ? wppb_fb_build_form_shortcode( $post )
160 : '[wppb-register form_name="' . Wordpress_Creation_Kit_PB::wck_generate_slug( $post->post_title ) . '"]';
161
162 // An unpublished form has no working shortcode (the front-end resolver is
163 // publish-only), so offer a hint instead of an empty copy field.
164 if ( $shortcode === '' ) {
165 echo '<span class="wppb-shortcode-unavailable">&mdash; ' . esc_html__( 'available after publishing', 'profile-builder' ) . '</span>';
166 return;
167 }
168
169 echo "<input readonly spellcheck='false' type='text' title='Click to copy' class='wppb-shortcode_copy wppb-shortcode input' value='" . esc_attr( $shortcode ) . "' />";
170 echo "<span style='display: none; margin-left: 10px' class='wppb-copy-message'>Shortcode copied</span>";
171 }
172 }
173 add_action("manage_wppb-rf-cpt_posts_custom_column", "wppb_rf_custom_column_content", 10, 2);
174
175 /**
176 * Add side metaboxes
177 *
178 * @since v.2.0
179 *
180 * @return void
181 */
182 function wppb_rf_content(){
183 global $post;
184
185 $shortcode = function_exists( 'wppb_fb_build_form_shortcode' )
186 ? wppb_fb_build_form_shortcode( $post )
187 : '[wppb-register form_name="' . trim( Wordpress_Creation_Kit_PB::wck_generate_slug( $post->post_title ) ) . '"]';
188 $is_default = function_exists( 'wppb_fb_is_default_form' ) && wppb_fb_is_default_form( $post );
189
190 if ( $shortcode === '' ) {
191 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>';
192 } else {
193 echo '<p class="cozmoslabs-description">' . esc_html__( 'Use this shortcode on the page you want the form to be displayed.', 'profile-builder' ) . '</p>';
194 echo '<div class="cozmoslabs-form-field-wrapper">';
195 echo "<textarea readonly spellcheck='false' class='wppb-shortcode textarea' >" . esc_html( $shortcode ) . "</textarea>";
196 // Default forms embed via a bare shortcode, so the title-change caveat
197 // does not apply to them.
198 if ( ! $is_default ) {
199 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>';
200 }
201 echo '</div>';
202 }
203 }
204
205 function wppb_rf_side_box(){
206 add_meta_box( 'wppb-rf-side', __( 'Form Shortcode', 'profile-builder' ), 'wppb_rf_content', 'wppb-rf-cpt', 'side', 'low' );
207 }
208 add_action( 'add_meta_boxes', 'wppb_rf_side_box' );
209
210 /**
211 * Function that manages the Register CPT
212 *
213 * @since v.2.0
214 *
215 * @return void
216 */
217 function wppb_manage_rf_cpt(){
218 // Skip WCK on modern mode — constructing it registers wp_ajax_wck_* that
219 // write wppb_rf_fields and bypass the save projection / meta-name resolver.
220 if ( wppb_fb_is_active_for( 'wppb-rf-cpt' ) ) return;
221
222 global $wp_roles;
223
224 $available_roles = $available_time = array();
225
226 foreach ( $wp_roles->roles as $slug => $role )
227 $available_roles[$slug] = '%'. wppb_prepare_wck_labels( $role['name'] ).'%'.$slug;
228
229 /* put the roles subscriber contributor author editor administrator in this order at the start of the options */
230 $desired_order_reversed = array( 'administrator', 'editor', 'author', 'contributor', 'subscriber' );
231 foreach( $desired_order_reversed as $key ){
232 if( !empty( $available_roles[$key] ) ){
233 $value = $available_roles[$key];
234 unset( $available_roles[$key] );
235 array_unshift( $available_roles , $value );
236 }
237 }
238 /* add the default role at the start of the options */
239 array_unshift( $available_roles , '%'.__( 'Default Role', 'profile-builder' ).'%'.'default role' );
240
241
242
243 for( $i=0; $i<=250; $i++ )
244 $available_time[] = $i;
245
246 // set up the fields array
247 $settings_fields = array(
248 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' ) ),
249 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' ) ),
250 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' ) ),
251 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' ) ),
252 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' ) ),
253 );
254
255 if( defined( 'WPPB_PAID_PLUGIN_DIR' ) ) {
256 $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' ) );
257 }
258
259 // set up the box arguments
260 $args = array(
261 'metabox_id' => 'wppb-rf-settings-args',
262 'metabox_title' => __( 'After Registration...', 'profile-builder' ),
263 'post_type' => 'wppb-rf-cpt',
264 'meta_name' => 'wppb_rf_page_settings',
265 'meta_array' => $settings_fields,
266 'sortable' => false,
267 'single' => true
268 );
269 new Wordpress_Creation_Kit_PB( $args );
270
271 $rf_fields = array ();
272
273 $all_fields = get_option ( 'wppb_manage_fields', 'not_set' );
274 if ( ( $all_fields != 'not_set' ) && ( ( is_array( $all_fields ) ) && ( !empty( $all_fields ) ) ) ){
275 foreach ( $all_fields as $key => $value ) {
276 if ( $value['field'] != 'Default - Display name publicly as' )
277 array_push( $rf_fields, wppb_field_format( $value['field-title'], $value['field'] ) );
278 }
279 }
280
281 $rf_fields = apply_filters( 'wppb_rf_fields_types', $rf_fields );
282
283 // set up the box arguments for the register forms and create them
284 $args = array(
285 'metabox_id' => 'wppb-rf-fields',
286 'metabox_title' => __( 'Add New Field to the List', 'profile-builder' ),
287 'post_type' => 'wppb-rf-cpt',
288 'meta_name' => 'wppb_rf_fields',
289 'meta_array' => $rf_fields = apply_filters ( 'wppb_rf_fields', array(
290 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' ) ) ),
291 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 )
292 )
293 )
294 );
295 new Wordpress_Creation_Kit_PB( $args );
296
297
298 }
299 add_action( 'admin_init', 'wppb_manage_rf_cpt', 1 );
300
301
302 add_filter( "wck_before_listed_wppb_rf_fields_element_0", 'wppb_manage_fields_display_field_title_slug', 10, 3 );
303 add_filter( 'wck_update_container_class_wppb_rf_fields', 'wppb_update_container_class', 10, 4 );
304 add_filter( 'wck_element_class_wppb_rf_fields', 'wppb_element_class', 10, 4 );
305
306
307 /** Re-hide delete on mandatory fields after list refresh. */
308 function wppb_rf_after_refresh_list( $id ){
309 echo "<script type=\"text/javascript\">wppb_disable_delete_on_default_mandatory_fields();</script>";
310 }
311 add_action( "wck_refresh_list_wppb_rf_fields", "wppb_rf_after_refresh_list" );