| 1 |
<?php |
| 2 |
// Exit if accessed directly |
| 3 |
if ( ! defined( 'ABSPATH' ) ) exit; |
| 4 |
|
| 5 |
/** |
| 6 |
* Function that creates the "Edit Profile Forms" post type |
| 7 |
* |
| 8 |
* @since v.2.0 |
| 9 |
* |
| 10 |
* @return void |
| 11 |
*/ |
| 12 |
function wppb_create_edit_profile_forms_cpt(){ |
| 13 |
$labels = array( |
| 14 |
'name' => __( 'Edit-profile Form', 'profile-builder'), |
| 15 |
'singular_name' => __( 'Edit-profile Form', 'profile-builder'), |
| 16 |
'add_new' => __( 'Add New', 'profile-builder' ), |
| 17 |
'add_new_item' => __( 'Add new Edit-profile Form', 'profile-builder' ), |
| 18 |
'edit_item' => __( 'Edit the Edit-profile Forms', 'profile-builder' ) , |
| 19 |
'new_item' => __( 'New Edit-profile Form', 'profile-builder' ), |
| 20 |
'all_items' => __( 'Edit-profile Forms', 'profile-builder' ), |
| 21 |
'view_item' => __( 'View the Edit-profile Form', 'profile-builder' ), |
| 22 |
'search_items' => __( 'Search the Edit-profile Forms', 'profile-builder' ), |
| 23 |
'not_found' => __( 'No Edit-profile Form found', 'profile-builder' ), |
| 24 |
'not_found_in_trash' => __( 'No Edit-profile Forms found in trash', 'profile-builder' ), |
| 25 |
'parent_item_colon' => '', |
| 26 |
'menu_name' => __( 'Edit-profile 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_multipleEditProfileForms'] ) && $wppb_addonOptions['wppb_multipleEditProfileForms'] == 'show' ) |
| 55 |
register_post_type( 'wppb-epf-cpt', $args ); |
| 56 |
} |
| 57 |
add_action( 'init', 'wppb_create_edit_profile_forms_cpt' ); |
| 58 |
|
| 59 |
/* EditProfile Form change classes based on Redirect field start */ |
| 60 |
add_filter( 'wck_add_form_class_wppb_epf_page_settings', 'wppb_epf_add_form_change_class_based_on_redirect_field', 10, 3 ); |
| 61 |
function wppb_epf_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 |
/* EditProfile Form change classes based on Redirect field end */ |
| 68 |
|
| 69 |
/** |
| 70 |
* Remove certain actions from post list view |
| 71 |
* |
| 72 |
* @since v.2.0 |
| 73 |
* |
| 74 |
* @param array $actions |
| 75 |
* |
| 76 |
* return array |
| 77 |
*/ |
| 78 |
function wppb_remove_epf_view_link( $actions ){ |
| 79 |
global $post; |
| 80 |
|
| 81 |
if ( ! empty( $post ) ) { |
| 82 |
if ( $post->post_type == 'wppb-epf-cpt' ){ |
| 83 |
unset( $actions['view'] ); |
| 84 |
|
| 85 |
if ( wppb_get_post_number ( $post->post_type, 'singular_action' ) ) |
| 86 |
unset( $actions['trash'] ); |
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
return $actions; |
| 91 |
} |
| 92 |
add_filter( 'post_row_actions', 'wppb_remove_epf_view_link', 10, 1 ); |
| 93 |
|
| 94 |
/** |
| 95 |
* Remove certain bulk actions from post list view |
| 96 |
* |
| 97 |
* @since v.2.0 |
| 98 |
* |
| 99 |
* @param array $actions |
| 100 |
* |
| 101 |
* return array |
| 102 |
*/ |
| 103 |
function wppb_remove_trash_bulk_option_epf( $actions ){ |
| 104 |
global $post; |
| 105 |
if( !empty( $post ) ){ |
| 106 |
if ( $post->post_type == 'wppb-epf-cpt' ){ |
| 107 |
unset( $actions['view'] ); |
| 108 |
|
| 109 |
if ( wppb_get_post_number ( $post->post_type, 'bulk_action' ) ) |
| 110 |
unset( $actions['trash'] ); |
| 111 |
} |
| 112 |
} |
| 113 |
return $actions; |
| 114 |
} |
| 115 |
add_filter( 'bulk_actions-edit-wppb-epf-cpt', 'wppb_remove_trash_bulk_option_epf' ); |
| 116 |
|
| 117 |
/** |
| 118 |
* Function to hide certain publishing options |
| 119 |
* |
| 120 |
* @since v.2.0 |
| 121 |
* |
| 122 |
*/ |
| 123 |
function wppb_hide_epf_publishing_actions(){ |
| 124 |
global $post; |
| 125 |
|
| 126 |
if ( $post->post_type == 'wppb-epf-cpt' ){ |
| 127 |
echo '<style type="text/css">#misc-publishing-actions, #minor-publishing-actions{display:none;}</style>'; |
| 128 |
|
| 129 |
$epf = get_posts( array( 'posts_per_page' => -1, 'post_status' => apply_filters ( 'wppb_check_singular_epf_form_publishing_options', array( 'publish' ) ) , 'post_type' => 'wppb-epf-cpt' ) ); |
| 130 |
if ( count( $epf ) == 1 ) |
| 131 |
echo '<style type="text/css">#major-publishing-actions #delete-action{display:none;}</style>'; |
| 132 |
} |
| 133 |
} |
| 134 |
add_action('admin_head-post.php', 'wppb_hide_epf_publishing_actions'); |
| 135 |
add_action('admin_head-post-new.php', 'wppb_hide_epf_publishing_actions'); |
| 136 |
|
| 137 |
|
| 138 |
/** |
| 139 |
* Add custom columns to listing |
| 140 |
* |
| 141 |
* @since v.2.0 |
| 142 |
* |
| 143 |
* @param array $columns |
| 144 |
* @return array $columns |
| 145 |
*/ |
| 146 |
function wppb_add_extra_column_for_epf( $columns ){ |
| 147 |
$columns['epf-shortcode'] = __( 'Shortcode', 'profile-builder' ); |
| 148 |
|
| 149 |
return $columns; |
| 150 |
} |
| 151 |
add_filter( 'manage_wppb-epf-cpt_posts_columns', 'wppb_add_extra_column_for_epf' ); |
| 152 |
|
| 153 |
/** |
| 154 |
* Add content to the displayed column |
| 155 |
* |
| 156 |
* @since v.2.0 |
| 157 |
* |
| 158 |
* @param string $column_name |
| 159 |
* @param integer $post_id |
| 160 |
* @return void |
| 161 |
*/ |
| 162 |
function wppb_epf_custom_column_content( $column_name, $post_id ){ |
| 163 |
if( $column_name == 'epf-shortcode' ){ |
| 164 |
$post = get_post( $post_id ); |
| 165 |
|
| 166 |
if( empty( $post->post_title ) ) |
| 167 |
$post->post_title = __( '(no title)', 'profile-builder' ); |
| 168 |
|
| 169 |
// Default forms embed via a bare [wppb-edit-profile]; custom |
| 170 |
// forms keep their title-derived form_name. |
| 171 |
$shortcode = function_exists( 'wppb_fb_build_form_shortcode' ) |
| 172 |
? wppb_fb_build_form_shortcode( $post ) |
| 173 |
: '[wppb-edit-profile form_name="' . Wordpress_Creation_Kit_PB::wck_generate_slug( $post->post_title ) . '"]'; |
| 174 |
|
| 175 |
// An unpublished form has no working shortcode (the front-end resolver is |
| 176 |
// publish-only), so offer a hint instead of an empty copy field. |
| 177 |
if ( $shortcode === '' ) { |
| 178 |
echo '<span class="wppb-shortcode-unavailable">— ' . esc_html__( 'available after publishing', 'profile-builder' ) . '</span>'; |
| 179 |
return; |
| 180 |
} |
| 181 |
|
| 182 |
echo "<input readonly spellcheck='false' type='text' title='Click to copy' class='wppb-shortcode_copy wppb-shortcode input' value='" . esc_attr( $shortcode ) . "' />"; |
| 183 |
echo "<span style='display: none; margin-left: 10px' class='wppb-copy-message'>Shortcode copied</span>"; |
| 184 |
} |
| 185 |
} |
| 186 |
add_action( "manage_wppb-epf-cpt_posts_custom_column", "wppb_epf_custom_column_content", 10, 2 ); |
| 187 |
|
| 188 |
|
| 189 |
/** |
| 190 |
* Add side metaboxes |
| 191 |
* |
| 192 |
* @since v.2.0 |
| 193 |
* |
| 194 |
* @return void |
| 195 |
*/ |
| 196 |
function wppb_epf_content(){ |
| 197 |
global $post; |
| 198 |
|
| 199 |
$shortcode = function_exists( 'wppb_fb_build_form_shortcode' ) |
| 200 |
? wppb_fb_build_form_shortcode( $post ) |
| 201 |
: '[wppb-edit-profile form_name="' . trim( Wordpress_Creation_Kit_PB::wck_generate_slug( $post->post_title ) ) . '"]'; |
| 202 |
$is_default = function_exists( 'wppb_fb_is_default_form' ) && wppb_fb_is_default_form( $post ); |
| 203 |
|
| 204 |
if ( $shortcode === '' ) { |
| 205 |
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>'; |
| 206 |
} else { |
| 207 |
echo '<p class="cozmoslabs-description">' . esc_html__( 'Use this shortcode on the page you want the form to be displayed.', 'profile-builder' ) . '</p>'; |
| 208 |
echo '<div class="cozmoslabs-form-field-wrapper">'; |
| 209 |
echo "<textarea readonly spellcheck='false' class='wppb-shortcode textarea'>" . esc_html( $shortcode ) . "</textarea>"; |
| 210 |
// Default forms embed via a bare shortcode -> no title-change caveat. |
| 211 |
if ( ! $is_default ) { |
| 212 |
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>'; |
| 213 |
} |
| 214 |
echo '</div>'; |
| 215 |
} |
| 216 |
} |
| 217 |
|
| 218 |
function wppb_epf_side_box(){ |
| 219 |
add_meta_box( 'wppb-epf-side', __( 'Form Shortcode', 'profile-builder' ), 'wppb_epf_content', 'wppb-epf-cpt', 'side', 'low' ); |
| 220 |
} |
| 221 |
add_action( 'add_meta_boxes', 'wppb_epf_side_box' ); |
| 222 |
|
| 223 |
/** |
| 224 |
* Function that manages the Edit Profile CPT |
| 225 |
* |
| 226 |
* @since v.2.0 |
| 227 |
* |
| 228 |
* @return void |
| 229 |
*/ |
| 230 |
function wppb_manage_epf_cpt(){ |
| 231 |
// Skip WCK on modern mode — see register-forms.php wppb_manage_rf_cpt(). |
| 232 |
if ( wppb_fb_is_active_for( 'wppb-epf-cpt' ) ) return; |
| 233 |
|
| 234 |
$available_time = array(); |
| 235 |
for( $i=0; $i<=250; $i++ ) |
| 236 |
$available_time[] = $i; |
| 237 |
|
| 238 |
// set up the fields array |
| 239 |
$settings_fields = array( |
| 240 |
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' ) ), |
| 241 |
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' ) ), |
| 242 |
array( 'type' => 'text', 'slug' => 'url', 'title' => __( 'URL', 'profile-builder' ), 'description' => __( 'Specify the URL of the page users will be redirected once they updated their profile using this form<br/>Use the following format: http://www.mysite.com', 'profile-builder' ) ), |
| 243 |
); |
| 244 |
|
| 245 |
if( defined( 'WPPB_PAID_PLUGIN_DIR' ) ) { |
| 246 |
$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' ) ); |
| 247 |
} |
| 248 |
|
| 249 |
|
| 250 |
// set up the box arguments |
| 251 |
$args = array( |
| 252 |
'metabox_id' => 'wppb-epf-settings-args', |
| 253 |
'metabox_title' => __( 'After Profile Update...', 'profile-builder' ), |
| 254 |
'post_type' => 'wppb-epf-cpt', |
| 255 |
'meta_name' => 'wppb_epf_page_settings', |
| 256 |
'meta_array' => $settings_fields, |
| 257 |
'sortable' => false, |
| 258 |
'single' => true |
| 259 |
); |
| 260 |
new Wordpress_Creation_Kit_PB( $args ); |
| 261 |
|
| 262 |
$epf_fields = array (); |
| 263 |
|
| 264 |
$wppb_manage_fields = get_option ( 'wppb_manage_fields', 'not_set' ); |
| 265 |
if ( ( $wppb_manage_fields != 'not_set' ) && ( ( is_array( $wppb_manage_fields ) ) && ( !empty( $wppb_manage_fields ) ) ) ){ |
| 266 |
$wppb_epf_unwanted_fields = array( 'reCAPTCHA', 'Validation' ); |
| 267 |
|
| 268 |
foreach ( $wppb_manage_fields as $key => $value ){ |
| 269 |
if ( !in_array( $value['field'], $wppb_epf_unwanted_fields ) ) |
| 270 |
array_push( $epf_fields, wppb_field_format( $value['field-title'], $value['field'] ) ); |
| 271 |
} |
| 272 |
} |
| 273 |
|
| 274 |
$epf_fields = apply_filters( 'wppb_epf_fields_types', $epf_fields ); |
| 275 |
|
| 276 |
// set up the box arguments for the edit profile forms and create them |
| 277 |
$args = array( |
| 278 |
'metabox_id' => 'wppb-epf-fields', |
| 279 |
'metabox_title' => __( 'Add New Field to the List', 'profile-builder' ), |
| 280 |
'post_type' => 'wppb-epf-cpt', |
| 281 |
'meta_name' => 'wppb_epf_fields', |
| 282 |
'meta_array' => apply_filters( 'wppb_epf_fields', array( |
| 283 |
array( 'type' => 'select', 'slug' => 'field', 'title' => __( 'Field', 'profile-builder' ), 'options' => $epf_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' ) ) ), |
| 284 |
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 ) |
| 285 |
) |
| 286 |
) |
| 287 |
); |
| 288 |
new Wordpress_Creation_Kit_PB( $args ); |
| 289 |
} |
| 290 |
add_action( 'admin_init', 'wppb_manage_epf_cpt', 1 ); |
| 291 |
|
| 292 |
|
| 293 |
add_filter( "wck_before_listed_wppb_epf_fields_element_0", 'wppb_manage_fields_display_field_title_slug', 10, 3 ); |
| 294 |
add_filter( 'wck_update_container_class_wppb_epf_fields', 'wppb_update_container_class', 10, 4 ); |
| 295 |
add_filter( 'wck_element_class_wppb_epf_fields', 'wppb_element_class', 10, 4 ); |
| 296 |
|
| 297 |
/** |
| 298 |
* Function that displays a message in the footer of the edit form fields table in case there are no fields present |
| 299 |
* |
| 300 |
* @since v.2.0.5 |
| 301 |
* |
| 302 |
* @param string $footer |
| 303 |
* @param int $id |
| 304 |
* |
| 305 |
* @return string |
| 306 |
* |
| 307 |
*/ |
| 308 |
function wppb_empty_epf_fields_display_message( $footer, $id ){ |
| 309 |
$post_meta = get_post_meta( $id, 'wppb_epf_fields', true); |
| 310 |
|
| 311 |
if( empty($post_meta) ) { |
| 312 |
return '<tfoot><tr><td>' . __('This form is empty.', 'profile-builder') . '</td></tr></tfoot>'; |
| 313 |
} |
| 314 |
|
| 315 |
} |
| 316 |
add_filter('wck_metabox_content_footer_wppb_epf_fields', 'wppb_empty_epf_fields_display_message', 10, 2); |