| 1 |
<?php |
| 2 |
/** |
| 3 |
* Function that creates the Manage Fields submenu and populates it with a repeater field form |
| 4 |
* |
| 5 |
* @since v.2.0 |
| 6 |
* |
| 7 |
* @return void |
| 8 |
*/ |
| 9 |
function wppb_manage_fields_submenu(){ |
| 10 |
// create a new sub_menu page which holds the data for the default + extra fields |
| 11 |
$args = array( |
| 12 |
'menu_title' => __( 'Manage Fields', 'profilebuilder' ), |
| 13 |
'page_title' => __( 'Manage Default and Extra Fields', 'profilebuilder' ), |
| 14 |
'menu_slug' => 'manage-fields', |
| 15 |
'page_type' => 'submenu_page', |
| 16 |
'capability' => 'manage_options', |
| 17 |
'priority' => 5, |
| 18 |
'parent_slug' => 'profile-builder' |
| 19 |
); |
| 20 |
$all_fields = new WCK_Page_Creator_PB( $args ); |
| 21 |
|
| 22 |
|
| 23 |
// populate this page |
| 24 |
$manage_field_types[] = 'Default - Name (Heading)'; |
| 25 |
$manage_field_types[] = 'Default - Contact Info (Heading)'; |
| 26 |
$manage_field_types[] = 'Default - About Yourself (Heading)'; |
| 27 |
$manage_field_types[] = 'Default - Username'; |
| 28 |
$manage_field_types[] = 'Default - First Name'; |
| 29 |
$manage_field_types[] = 'Default - Last Name'; |
| 30 |
$manage_field_types[] = 'Default - Nickname'; |
| 31 |
$manage_field_types[] = 'Default - E-mail'; |
| 32 |
$manage_field_types[] = 'Default - Website'; |
| 33 |
|
| 34 |
// Default contact methods were removed in WP 3.6. A filter dictates contact methods. |
| 35 |
if ( apply_filters( 'wppb_remove_default_contact_methods', get_site_option( 'initial_db_version' ) < 23588 ) ){ |
| 36 |
$manage_field_types[] = 'Default - AIM'; |
| 37 |
$manage_field_types[] = 'Default - Yahoo IM'; |
| 38 |
$manage_field_types[] = 'Default - Jabber / Google Talk'; |
| 39 |
} |
| 40 |
|
| 41 |
$manage_field_types[] = 'Default - Password'; |
| 42 |
$manage_field_types[] = 'Default - Repeat Password'; |
| 43 |
$manage_field_types[] = 'Default - Biographical Info'; |
| 44 |
$manage_field_types[] = 'Default - Display name publicly as'; |
| 45 |
|
| 46 |
if( PROFILE_BUILDER != 'Profile Builder Free' ) { |
| 47 |
$manage_field_types[] = 'Heading'; |
| 48 |
$manage_field_types[] = 'Input'; |
| 49 |
$manage_field_types[] = 'Input (Hidden)'; |
| 50 |
$manage_field_types[] = 'Textarea'; |
| 51 |
$manage_field_types[] = 'Select'; |
| 52 |
$manage_field_types[] = 'Select (Multiple)'; |
| 53 |
$manage_field_types[] = 'Select (Country)'; |
| 54 |
$manage_field_types[] = 'Select (Timezone)'; |
| 55 |
$manage_field_types[] = 'Checkbox'; |
| 56 |
$manage_field_types[] = 'Checkbox (Terms and Conditions)'; |
| 57 |
$manage_field_types[] = 'Radio'; |
| 58 |
$manage_field_types[] = 'Upload'; |
| 59 |
$manage_field_types[] = 'Avatar'; |
| 60 |
$manage_field_types[] = 'Datepicker'; |
| 61 |
$manage_field_types[] = 'reCAPTCHA'; |
| 62 |
} |
| 63 |
|
| 64 |
|
| 65 |
//Free to Pro call to action on Manage Fields page |
| 66 |
$field_description = 'Choose one of the supported field types'; |
| 67 |
if( PROFILE_BUILDER == 'Profile Builder Free' ) { |
| 68 |
$field_description .='. Extra Field Types are available in %1$sHobbyist or PRO versions%2$s.'; |
| 69 |
} |
| 70 |
|
| 71 |
// set up the fields array |
| 72 |
$fields = apply_filters( 'wppb_manage_fields', array( |
| 73 |
|
| 74 |
array( 'type' => 'text', 'slug' => 'field-title', 'title' => __( 'Field Title', 'profilebuilder' ), 'description' => __( 'Title of the field', 'profilebuilder' ) ), |
| 75 |
array( 'type' => 'select', 'slug' => 'field', 'title' => __( 'Field', 'profilebuilder' ), 'options' => apply_filters( 'wppb_manage_fields_types', $manage_field_types ), 'default-option' => true, 'description' => sprintf(__( $field_description, 'profilebuilder' ), '<a href="http://www.cozmoslabs.com/wordpress-profile-builder/?utm_source=wpbackend&utm_medium=clientsite&utm_content=manage-fields-link&utm_campaign=PBFree">', '</a>') ), |
| 76 |
array( 'type' => 'text', 'slug' => 'meta-name', 'title' => __( 'Meta-name', 'profilebuilder' ), 'default' => wppb_get_meta_name(), 'description' => __( 'Use this in conjuction with WordPress functions to display the value in the page of your choosing<br/>Auto-completed but in some cases editable (in which case it must be uniqe)<br/>Changing this might take long in case of a very big user-count', 'profilebuilder' ) ), |
| 77 |
array( 'type' => 'text', 'slug' => 'id', 'title' => __( 'ID', 'profilebuilder' ), 'default' => wppb_get_unique_id(), '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", 'profilebuilder' ), 'readonly' => true ), |
| 78 |
array( 'type' => 'textarea', 'slug' => 'description', 'title' => __( 'Description', 'profilebuilder' ), 'description' => __( 'Enter a (detailed) description of the option for end users to read<br/>Optional', 'profilebuilder') ), |
| 79 |
array( 'type' => 'text', 'slug' => 'row-count', 'title' => __( 'Row Count', 'profilebuilder' ), 'default' => 5, 'description' => __( "Specify the number of rows for a 'Textarea' field<br/>If not specified, defaults to 5", 'profilebuilder' ) ), |
| 80 |
array( 'type' => 'text', 'slug' => 'allowed-image-extensions', 'title' => __( 'Allowed Image Extensions', 'profilebuilder' ), 'default' => '.*', 'description' => __( 'Specify the extension(s) you want to limit to upload<br/>Example: .ext1,.ext2,.ext3<br/>If not specified, defaults to all existing image extensions (.*)', 'profilebuilder' ) ), |
| 81 |
array( 'type' => 'text', 'slug' => 'allowed-upload-extensions', 'title' => __( 'Allowed Upload Extensions', 'profilebuilder' ), 'default' => '.*', 'description' => __( 'Specify the extension(s) you want to limit to upload<br/>Example: .ext1,.ext2,.ext3<br/>If not specified, defaults to all existing extensions (.*)', 'profilebuilder' ) ), |
| 82 |
array( 'type' => 'text', 'slug' => 'avatar-size', 'title' => __( 'Avatar Size', 'profilebuilder' ), 'default' => 100, 'description' => __( "Enter a value (between 20 and 200) for the size of the 'Avatar'<br/>If not specified, defaults to 100", 'profilebuilder' ) ), |
| 83 |
array( 'type' => 'text', 'slug' => 'date-format', 'title' => __( 'Date-format', 'profilebuilder' ), 'default' => 'mm/dd/yy', 'description' => __( 'Specify the format of the date when using Datepicker<br/>Valid options: mm/dd/yy, mm/yy/dd, dd/yy/mm, dd/mm/yy, yy/dd/mm, yy/mm/dd<br/>If not specified, defaults to mm/dd/yy', 'profilebuilder' ) ), |
| 84 |
array( 'type' => 'textarea', 'slug' => 'terms-of-agreement', 'title' => __( 'Terms of Agreement', 'profilebuilder' ), 'description' => __( 'Enter a detailed description of the temrs of agreement for the user to read.<br/>Links can be inserted by using standard HTML syntax: <a href="custom_url">custom_text</a>', 'profilebuilder' ) ), |
| 85 |
array( 'type' => 'text', 'slug' => 'options', 'title' => __( 'Options', 'profilebuilder' ), 'description' => __( "Enter a comma separated list of values<br/>This can be anything, as it is hidden from the user, but should not contain special characters or apostrophes", 'profilebuilder' ) ), |
| 86 |
array( 'type' => 'text', 'slug' => 'labels', 'title' => __( 'Labels', 'profilebuilder' ), 'description' => __( "Enter a comma separated list of labels<br/>Visible for the user", 'profilebuilder' ) ), |
| 87 |
array( 'type' => 'text', 'slug' => 'public-key', 'title' => __( 'Public Key', 'profilebuilder' ), 'description' => __( 'The public key from Google, <a href="http://www.google.com/recaptcha" target="_blank">www.google.com/recaptcha</a>', 'profilebuilder' ) ), |
| 88 |
array( 'type' => 'text', 'slug' => 'private-key', 'title' => __( 'Private Key', 'profilebuilder' ), 'description' => __( 'The private key from Google, <a href="http://www.google.com/recaptcha" target="_blank">www.google.com/recaptcha</a>', 'profilebuilder' ) ), |
| 89 |
array( 'type' => 'text', 'slug' => 'default-value', 'title' => __( 'Default Value', 'profilebuilder' ), 'description' => __( "Default value of the field", 'profilebuilder' ) ), |
| 90 |
array( 'type' => 'text', 'slug' => 'default-option', 'title' => __( 'Default Option', 'profilebuilder' ), 'description' => __( "Specify the option which should be selected by default", 'profilebuilder' ) ), |
| 91 |
array( 'type' => 'text', 'slug' => 'default-options', 'title' => __( 'Default Option(s)', 'profilebuilder' ), 'description' => __( "Specify the option which should be checked by default<br/>If there are multiple values, separate them with a ',' (comma)", 'profilebuilder' ) ), |
| 92 |
array( 'type' => 'textarea', 'slug' => 'default-content', 'title' => __( 'Default Content', 'profilebuilder' ), 'description' => __( "Default value of the textarea", 'profilebuilder' ) ), |
| 93 |
array( 'type' => 'select', 'slug' => 'required', 'title' => __( 'Required', 'profilebuilder' ), 'options' => array( 'No', 'Yes' ), 'default' => 'No', 'description' => __( 'Whether the field is required or not', 'profilebuilder' ) ), |
| 94 |
array( 'type' => 'select', 'slug' => 'overwrite-existing', 'title' => __( 'Overwrite Existing', 'profilebuilder' ), 'options' => array( 'No', 'Yes' ), 'default' => 'No', 'description' => __( "Selecting 'Yes' will add the field to the list, but will overwrite any other field in the database that has the same meta-name<br/>Use this at your own risk", 'profilebuilder' ) ), |
| 95 |
) ); |
| 96 |
|
| 97 |
// create the new submenu with the above options |
| 98 |
$args = array( |
| 99 |
'metabox_id' => 'manage-fields', |
| 100 |
'metabox_title' => __( 'Field Properties', 'profilebuilder' ), |
| 101 |
'post_type' => 'manage-fields', |
| 102 |
'meta_name' => 'wppb_manage_fields', |
| 103 |
'meta_array' => $fields, |
| 104 |
'context' => 'option' |
| 105 |
); |
| 106 |
new Wordpress_Creation_Kit_PB( $args ); |
| 107 |
|
| 108 |
wppb_prepopulate_fields(); |
| 109 |
|
| 110 |
// create the info side meta-box |
| 111 |
$args = array( |
| 112 |
'metabox_id' => 'manage-fields-info', |
| 113 |
'metabox_title' => __( 'Registration & Edit Profile', 'profilebuilder' ), |
| 114 |
'post_type' => 'manage-fields', |
| 115 |
'meta_name' => 'wppb_manage_fields_info', |
| 116 |
'meta_array' => '', |
| 117 |
'context' => 'option', |
| 118 |
'mb_context' => 'side' |
| 119 |
); |
| 120 |
new Wordpress_Creation_Kit_PB( $args ); |
| 121 |
} |
| 122 |
add_action( 'init', 'wppb_manage_fields_submenu', 10 ); |
| 123 |
|
| 124 |
/** |
| 125 |
* Function that prepopulates the manage fields list with the default fields of WP |
| 126 |
* |
| 127 |
* @since v.2.0 |
| 128 |
* |
| 129 |
* @return void |
| 130 |
*/ |
| 131 |
function wppb_prepopulate_fields(){ |
| 132 |
$prepopulated_fields[] = array( 'field' => 'Default - Name (Heading)', 'field-title' => __( 'Name', 'profilebuilder' ), 'meta-name' => '', 'overwrite-existing' => 'No', 'id' => '1', 'description' => '', 'row-count' => '5', 'allowed-image-extensions' => '.*', 'allowed-upload-extensions' => '.*', 'avatar-size' => '100', 'date-format' => 'mm/dd/yy', 'terms-of-agreement' => '', 'options' => '', 'labels' => '', 'public-key' => '', 'private-key' => '', 'default-value' => '', 'default-option' => '', 'default-options' => '', 'default-content' => '', 'required' => 'No' ); |
| 133 |
$prepopulated_fields[] = array( 'field' => 'Default - Username', 'field-title' => __( 'Username', 'profilebuilder' ), 'meta-name' => '', 'overwrite-existing' => 'No', 'id' => '2', 'description' => __( 'Usernames cannot be changed.', 'profilebuilder' ), 'row-count' => '5', 'allowed-image-extensions' => '.*', 'allowed-upload-extensions' => '.*', 'avatar-size' => '100', 'date-format' => 'mm/dd/yy', 'terms-of-agreement' => '', 'options' => '', 'labels' => '', 'public-key' => '', 'private-key' => '', 'default-value' => '', 'default-option' => '', 'default-options' => '', 'default-content' => '', 'required' => 'Yes' ); |
| 134 |
$prepopulated_fields[] = array( 'field' => 'Default - First Name', 'field-title' => __( 'First Name', 'profilebuilder' ), 'meta-name' => 'first_name', 'overwrite-existing' => 'No', 'id' => '3', 'description' => '', 'row-count' => '5', 'allowed-image-extensions' => '.*', 'allowed-upload-extensions' => '.*', 'avatar-size' => '100', 'date-format' => 'mm/dd/yy', 'terms-of-agreement' => '', 'options' => '', 'labels' => '', 'public-key' => '', 'private-key' => '', 'default-value' => '', 'default-option' => '', 'default-options' => '', 'default-content' => '', 'required' => 'No' ); |
| 135 |
$prepopulated_fields[] = array( 'field' => 'Default - Last Name', 'field-title' => __( 'Last Name', 'profilebuilder' ), 'meta-name' => 'last_name', 'overwrite-existing' => 'No', 'id' => '4', 'description' => '', 'row-count' => '5', 'allowed-image-extensions' => '.*', 'allowed-upload-extensions' => '.*', 'avatar-size' => '100', 'date-format' => 'mm/dd/yy', 'terms-of-agreement' => '', 'options' => '', 'labels' => '', 'public-key' => '', 'private-key' => '', 'default-value' => '', 'default-option' => '', 'default-options' => '', 'default-content' => '', 'required' => 'No' ); |
| 136 |
$prepopulated_fields[] = array( 'field' => 'Default - Nickname', 'field-title' => __( 'Nickname', 'profilebuilder' ), 'meta-name' => 'nickname', 'overwrite-existing' => 'No', 'id' => '5', 'description' => '', 'row-count' => '5', 'allowed-image-extensions' => '.*', 'allowed-upload-extensions' => '.*', 'avatar-size' => '100', 'date-format' => 'mm/dd/yy', 'terms-of-agreement' => '', 'options' => '', 'labels' => '', 'public-key' => '', 'private-key' => '', 'default-value' => '', 'default-option' => '', 'default-options' => '', 'default-content' => '', 'required' => 'Yes' ); |
| 137 |
$prepopulated_fields[] = array( 'field' => 'Default - Display name publicly as', 'field-title' => __( 'Display name publicly as', 'profilebuilder' ), 'meta-name' => '', 'overwrite-existing' => 'No', 'id' => '6', 'description' => '', 'row-count' => '5', 'allowed-image-extensions' => '.*', 'allowed-upload-extensions' => '.*', 'avatar-size' => '100', 'date-format' => 'mm/dd/yy', 'terms-of-agreement' => '', 'options' => '', 'labels' => '', 'public-key' => '', 'private-key' => '', 'default-value' => '', 'default-option' => '', 'default-options' => '', 'default-content' => '', 'required' => 'No' ); |
| 138 |
$prepopulated_fields[] = array( 'field' => 'Default - Contact Info (Heading)', 'field-title' => __( 'Contact Info', 'profilebuilder' ), 'meta-name' => '', 'overwrite-existing' => 'No', 'id' => '7', 'description' => '', 'row-count' => '5', 'allowed-image-extensions' => '.*', 'allowed-upload-extensions' => '.*', 'avatar-size' => '100', 'date-format' => 'mm/dd/yy', 'terms-of-agreement' => '', 'options' => '', 'labels' => '', 'public-key' => '', 'private-key' => '', 'default-value' => '', 'default-option' => '', 'default-options' => '', 'default-content' => '', 'required' => 'No' ); |
| 139 |
$prepopulated_fields[] = array( 'field' => 'Default - E-mail', 'field-title' => __( 'E-mail', 'profilebuilder' ), 'meta-name' => '', 'overwrite-existing' => 'No', 'id' => '8', 'description' => '', 'row-count' => '5', 'allowed-image-extensions' => '.*', 'allowed-upload-extensions' => '.*', 'avatar-size' => '100', 'date-format' => 'mm/dd/yy', 'terms-of-agreement' => '', 'options' => '', 'labels' => '', 'public-key' => '', 'private-key' => '', 'default-value' => '', 'default-option' => '', 'default-options' => '', 'default-content' => '', 'required' => 'Yes' ); |
| 140 |
$prepopulated_fields[] = array( 'field' => 'Default - Website', 'field-title' => __( 'Website', 'profilebuilder' ), 'meta-name' => '', 'overwrite-existing' => 'No', 'id' => '9', 'description' => '', 'row-count' => '5', 'allowed-image-extensions' => '.*', 'allowed-upload-extensions' => '.*', 'avatar-size' => '100', 'date-format' => 'mm/dd/yy', 'terms-of-agreement' => '', 'options' => '', 'labels' => '', 'public-key' => '', 'private-key' => '', 'default-value' => '', 'default-option' => '', 'default-options' => '', 'default-content' => '', 'required' => 'No' ); |
| 141 |
|
| 142 |
// Default contact methods were removed in WP 3.6. A filter dictates contact methods. |
| 143 |
if ( apply_filters( 'wppb_remove_default_contact_methods', get_site_option( 'initial_db_version' ) < 23588 ) ){ |
| 144 |
$prepopulated_fields[] = array( 'field' => 'Default - AIM', 'field-title' => __( 'AIM', 'profilebuilder' ), 'meta-name' => 'aim', 'overwrite-existing' => 'No', 'id' => '10', 'description' => '', 'row-count' => '5', 'allowed-image-extensions' => '.*', 'allowed-upload-extensions' => '.*', 'avatar-size' => '100', 'date-format' => 'mm/dd/yy', 'terms-of-agreement' => '', 'options' => '', 'labels' => '', 'public-key' => '', 'private-key' => '', 'default-value' => '', 'default-option' => '', 'default-options' => '', 'default-content' => '', 'required' => 'No' ); |
| 145 |
$prepopulated_fields[] = array( 'field' => 'Default - Yahoo IM', 'field-title' => __( 'Yahoo IM', 'profilebuilder' ), 'meta-name' => 'yim', 'overwrite-existing' => 'No', 'id' => '11', 'description' => '', 'row-count' => '5', 'allowed-image-extensions' => '.*', 'allowed-upload-extensions' => '.*', 'avatar-size' => '100', 'date-format' => 'mm/dd/yy', 'terms-of-agreement' => '', 'options' => '', 'labels' => '', 'public-key' => '', 'private-key' => '', 'default-value' => '', 'default-option' => '', 'default-options' => '', 'default-content' => '', 'required' => 'No' ); |
| 146 |
$prepopulated_fields[] = array( 'field' => 'Default - Jabber / Google Talk', 'field-title' => __( 'Jabber / Google Talk', 'profilebuilder' ), 'meta-name' => 'jabber', 'overwrite-existing' => 'No', 'id' => '12', 'description' => '', 'row-count' => '5', 'allowed-image-extensions' => '.*', 'allowed-upload-extensions' => '.*', 'avatar-size' => '100', 'date-format' => 'mm/dd/yy', 'terms-of-agreement' => '', 'options' => '', 'labels' => '', 'public-key' => '', 'private-key' => '', 'default-value' => '', 'default-option' => '', 'default-options' => '', 'default-content' => '', 'required' => 'No' ); |
| 147 |
} |
| 148 |
|
| 149 |
$prepopulated_fields[] = array( 'field' => 'Default - About Yourself (Heading)', 'field-title' => __( 'About Yourself', 'profilebuilder' ), 'meta-name' => '', 'overwrite-existing' => 'No', 'id' => '13', 'description' => '', 'row-count' => '5', 'allowed-image-extensions' => '.*', 'allowed-upload-extensions' => '.*', 'avatar-size' => '100', 'date-format' => 'mm/dd/yy', 'terms-of-agreement' => '', 'options' => '', 'labels' => '', 'public-key' => '', 'private-key' => '', 'default-value' => '', 'default-option' => '', 'default-options' => '', 'default-content' => '', 'required' => 'No' ); |
| 150 |
$prepopulated_fields[] = array( 'field' => 'Default - Biographical Info', 'field-title' => __( 'Biographical Info', 'profilebuilder' ), 'meta-name' => 'description', 'overwrite-existing' => 'No', 'id' => '14', 'description' => __( 'Share a little biographical information to fill out your profile. This may be shown publicly.', 'profilebuilder' ), 'row-count' => '5', 'allowed-image-extensions' => '.*', 'allowed-upload-extensions' => '.*', 'avatar-size' => '100', 'date-format' => 'mm/dd/yy', 'terms-of-agreement' => '', 'options' => '', 'labels' => '', 'public-key' => '', 'private-key' => '', 'default-value' => '', 'default-option' => '', 'default-options' => '', 'required' => 'No' ); |
| 151 |
$prepopulated_fields[] = array( 'field' => 'Default - Password', 'field-title' => __( 'Password', 'profilebuilder' ), 'meta-name' => '', 'overwrite-existing' => 'No', 'id' => '15', 'description' => __( 'Type your password.', 'profilebuilder' ), 'row-count' => '5', 'allowed-image-extensions' => '.*', 'allowed-upload-extensions' => '.*', 'avatar-size' => '100', 'date-format' => 'mm/dd/yy', 'terms-of-agreement' => '', 'options' => '', 'labels' => '', 'public-key' => '', 'private-key' => '', 'default-value' => '', 'default-option' => '', 'default-options' => '', 'default-content' => '', 'required' => 'Yes' ); |
| 152 |
$prepopulated_fields[] = array( 'field' => 'Default - Repeat Password', 'field-title' => __( 'Repeat Password', 'profilebuilder' ), 'meta-name' => '', 'overwrite-existing' => 'No', 'id' => '16', 'description' => __( 'Type your password again. ', 'profilebuilder' ), 'row-count' => '5', 'allowed-image-extensions' => '.*', 'allowed-upload-extensions' => '.*', 'avatar-size' => '100', 'date-format' => 'mm/dd/yy', 'terms-of-agreement' => '', 'options' => '', 'labels' => '', 'public-key' => '', 'private-key' => '', 'default-value' => '', 'default-option' => '', 'default-options' => '', 'default-content' => '', 'required' => 'Yes' ); |
| 153 |
|
| 154 |
add_option ( 'wppb_manage_fields', apply_filters ( 'wppb_prepopulated_fields', $prepopulated_fields ) ); |
| 155 |
} |
| 156 |
|
| 157 |
/** |
| 158 |
* Function that returns a unique meta-name |
| 159 |
* |
| 160 |
* @since v.2.0 |
| 161 |
* |
| 162 |
* @return string |
| 163 |
*/ |
| 164 |
function wppb_get_meta_name(){ |
| 165 |
$id = 1; |
| 166 |
|
| 167 |
$wppb_manage_fields = get_option( 'wppb_manage_fields', 'not_found' ); |
| 168 |
|
| 169 |
if ( ( $wppb_manage_fields === 'not_found' ) || ( empty( $wppb_manage_fields ) ) ){ |
| 170 |
return 'custom_field_' . $id; |
| 171 |
} |
| 172 |
else{ |
| 173 |
$meta_names = array(); |
| 174 |
foreach( $wppb_manage_fields as $value ){ |
| 175 |
if ( strpos( $value['meta-name'], 'custom_field' ) === 0 ){ |
| 176 |
$meta_names[] = $value['meta-name']; |
| 177 |
} |
| 178 |
} |
| 179 |
|
| 180 |
if( !empty( $meta_names ) ){ |
| 181 |
$meta_numbers = array(); |
| 182 |
foreach( $meta_names as $meta_name ){ |
| 183 |
$number = str_replace( 'custom_field', '', $meta_name ); |
| 184 |
/* we should have an underscore present in custom_field_# so remove it */ |
| 185 |
$number = str_replace( '_', '', $number ); |
| 186 |
|
| 187 |
$meta_numbers[] = $number; |
| 188 |
} |
| 189 |
if( !empty( $meta_numbers ) ){ |
| 190 |
rsort( $meta_numbers ); |
| 191 |
$id = $meta_numbers[0]+1; |
| 192 |
} |
| 193 |
} |
| 194 |
|
| 195 |
return 'custom_field_' . $id; |
| 196 |
} |
| 197 |
} |
| 198 |
|
| 199 |
|
| 200 |
/** |
| 201 |
* Function that returns a unique, incremented ID |
| 202 |
* |
| 203 |
* @since v.2.0 |
| 204 |
* |
| 205 |
* @return integer id |
| 206 |
*/ |
| 207 |
function wppb_get_unique_id(){ |
| 208 |
$id = 1; |
| 209 |
|
| 210 |
$wppb_manage_fields = get_option( 'wppb_manage_fields', 'not_found' ); |
| 211 |
if ( ( $wppb_manage_fields === 'not_found' ) || ( empty( $wppb_manage_fields ) ) ){ |
| 212 |
return $id; |
| 213 |
} |
| 214 |
else{ |
| 215 |
$ids_array = array(); |
| 216 |
foreach( $wppb_manage_fields as $value ){ |
| 217 |
$ids_array[] = $value['id']; |
| 218 |
} |
| 219 |
if( !empty( $ids_array ) ){ |
| 220 |
rsort( $ids_array ); |
| 221 |
$id = $ids_array[0] + 1; |
| 222 |
} |
| 223 |
} |
| 224 |
return $id; |
| 225 |
} |
| 226 |
|
| 227 |
/** |
| 228 |
* Function that checks to see if the id is unique when saving the new field |
| 229 |
* |
| 230 |
* @param array $values |
| 231 |
* |
| 232 |
* @return array |
| 233 |
*/ |
| 234 |
function wppb_check_unique_id_on_saving( $values ) { |
| 235 |
$wppb_manage_fields = get_option( 'wppb_manage_fields', 'not_found' ); |
| 236 |
|
| 237 |
if( $wppb_manage_fields != 'not_found' ) { |
| 238 |
|
| 239 |
$ids_array = array(); |
| 240 |
foreach( $wppb_manage_fields as $field ){ |
| 241 |
$ids_array[] = $field['id']; |
| 242 |
} |
| 243 |
|
| 244 |
if( in_array( $values['id'], $ids_array ) ) { |
| 245 |
rsort( $ids_array ); |
| 246 |
$values['id'] = $ids_array[0] + 1; |
| 247 |
} |
| 248 |
|
| 249 |
} |
| 250 |
|
| 251 |
return $values; |
| 252 |
} |
| 253 |
add_filter( 'wck_add_meta_filter_values_wppb_manage_fields', 'wppb_check_unique_id_on_saving' ); |
| 254 |
|
| 255 |
|
| 256 |
function wppb_return_unique_field_list( $only_default_fields = false ){ |
| 257 |
|
| 258 |
$unique_field_list[] = 'Default - Name (Heading)'; |
| 259 |
$unique_field_list[] = 'Default - Contact Info (Heading)'; |
| 260 |
$unique_field_list[] = 'Default - About Yourself (Heading)'; |
| 261 |
$unique_field_list[] = 'Default - Username'; |
| 262 |
$unique_field_list[] = 'Default - First Name'; |
| 263 |
$unique_field_list[] = 'Default - Last Name'; |
| 264 |
$unique_field_list[] = 'Default - Nickname'; |
| 265 |
$unique_field_list[] = 'Default - E-mail'; |
| 266 |
$unique_field_list[] = 'Default - Website'; |
| 267 |
|
| 268 |
// Default contact methods were removed in WP 3.6. A filter dictates contact methods. |
| 269 |
if ( apply_filters( 'wppb_remove_default_contact_methods', get_site_option( 'initial_db_version' ) < 23588 ) ){ |
| 270 |
$unique_field_list[] = 'Default - AIM'; |
| 271 |
$unique_field_list[] = 'Default - Yahoo IM'; |
| 272 |
$unique_field_list[] = 'Default - Jabber / Google Talk'; |
| 273 |
} |
| 274 |
|
| 275 |
$unique_field_list[] = 'Default - Password'; |
| 276 |
$unique_field_list[] = 'Default - Repeat Password'; |
| 277 |
$unique_field_list[] = 'Default - Biographical Info'; |
| 278 |
$unique_field_list[] = 'Default - Display name publicly as'; |
| 279 |
if( !$only_default_fields ){ |
| 280 |
$unique_field_list[] = 'Avatar'; |
| 281 |
$unique_field_list[] = 'reCAPTCHA'; |
| 282 |
} |
| 283 |
|
| 284 |
return apply_filters ( 'wppb_unique_field_list', $unique_field_list ); |
| 285 |
} |
| 286 |
|
| 287 |
|
| 288 |
/** |
| 289 |
* Function that checks several things when adding/editing the fields |
| 290 |
* |
| 291 |
* @since v.2.0 |
| 292 |
* |
| 293 |
* @param string $message - the message to be displayed |
| 294 |
* @param array $fields - the added fields |
| 295 |
* @param array $required_fields |
| 296 |
* @param string $meta - the meta-name of the option |
| 297 |
* @param string $values - The values entered for each option |
| 298 |
* @param integer $post_id |
| 299 |
* @return boolean |
| 300 |
*/ |
| 301 |
function wppb_check_field_on_edit_add( $message, $fields, $required_fields, $meta_name, $posted_values, $post_id ){ |
| 302 |
global $wpdb; |
| 303 |
|
| 304 |
if ( $meta_name == 'wppb_manage_fields' ){ |
| 305 |
|
| 306 |
// check for a valid field-type (fallback) |
| 307 |
if ( $posted_values['field'] == '' ) |
| 308 |
$message .= __( "You must select a field\n", 'profilebuilder' ); |
| 309 |
// END check for a valid field-type (fallback) |
| 310 |
|
| 311 |
$unique_field_list = wppb_return_unique_field_list(); |
| 312 |
$all_fields = get_option ( $meta_name, 'not_set' ); |
| 313 |
|
| 314 |
// check if the unique fields are only added once |
| 315 |
if( $all_fields != 'not_set' ){ |
| 316 |
foreach( $all_fields as $field ){ |
| 317 |
if ( ( in_array ( $posted_values['field'], $unique_field_list ) ) && ( $posted_values['field'] == $field['field'] ) && ( $posted_values['id'] != $field['id'] ) ){ |
| 318 |
$message .= __( "Please choose a different field type as this one already exists in your form (must be unique)\n", 'profilebuilder' ); |
| 319 |
break; |
| 320 |
} |
| 321 |
} |
| 322 |
} |
| 323 |
// END check if the unique fields are only added once |
| 324 |
|
| 325 |
// check for avatar size |
| 326 |
if ( $posted_values['field'] == 'Avatar' ){ |
| 327 |
if ( is_numeric( $posted_values['avatar-size'] ) ){ |
| 328 |
if ( ( $posted_values['avatar-size'] < 20 ) || ( $posted_values['avatar-size'] > 200 ) ) |
| 329 |
$message .= __( "The entered avatar size is not between 20 and 200\n", 'profilebuilder' ); |
| 330 |
|
| 331 |
}else |
| 332 |
$message .= __( "The entered avatar size is not numerical\n", 'profilebuilder' ); |
| 333 |
|
| 334 |
} |
| 335 |
// END check for avatar size |
| 336 |
|
| 337 |
// check for correct row value |
| 338 |
if ( ( $posted_values['field'] == 'Default - Biographical Info' ) || ( $posted_values['field'] == 'Textarea' ) ){ |
| 339 |
if ( !is_numeric( $posted_values['row-count'] ) ) |
| 340 |
$message .= __( "The entered row number is not numerical\n", 'profilebuilder' ); |
| 341 |
|
| 342 |
elseif ( trim( $posted_values['row-count'] ) == '' ) |
| 343 |
$message .= __( "You must enter a value for the row number\n", 'profilebuilder' ); |
| 344 |
} |
| 345 |
// END check for correct row value |
| 346 |
|
| 347 |
|
| 348 |
// check for the public and private keys |
| 349 |
if ( $posted_values['field'] == 'reCAPTCHA'){ |
| 350 |
if ( trim( $posted_values['public-key'] ) == '' ) |
| 351 |
$message .= __( "You must enter the public key\n", 'profilebuilder' ); |
| 352 |
if ( trim( $posted_values['private-key'] ) == '' ) |
| 353 |
$message .= __( "You must enter the private key\n", 'profilebuilder' ); |
| 354 |
} |
| 355 |
// END check for the public and private keys |
| 356 |
|
| 357 |
// check for the correct the date-format |
| 358 |
if ( $posted_values['field'] == 'Datepicker' ){ |
| 359 |
$date_format = strtolower( $posted_values['date-format'] ); |
| 360 |
if ( ( trim( $date_format ) != 'mm/dd/yy' ) && ( trim( $date_format ) != 'mm/yy/dd' ) && ( trim( $date_format ) != 'dd/yy/mm' ) && ( trim( $date_format ) != 'dd/mm/yy' ) && ( trim( $date_format ) != 'yy/dd/mm' ) && ( trim( $date_format ) != 'yy/mm/dd' ) ) |
| 361 |
$message .= __( "The entered value for the Datepicker is not a valid date-format\n", 'profilebuilder' ); |
| 362 |
|
| 363 |
elseif ( trim( $date_format ) == '' ) |
| 364 |
$message .= __( "You must enter a value for the date-format\n", 'profilebuilder' ); |
| 365 |
} |
| 366 |
// END check for the correct the date-format |
| 367 |
|
| 368 |
//check for empty meta-name and duplicate meta-name |
| 369 |
if ( $posted_values['overwrite-existing'] == 'No' ){ |
| 370 |
$skip_check_for_fields = wppb_return_unique_field_list(true); |
| 371 |
$skip_check_for_fields = apply_filters ( 'wppb_skip_check_for_fields', $skip_check_for_fields ); |
| 372 |
|
| 373 |
if ( !in_array( trim( $posted_values['field'] ), $skip_check_for_fields ) ){ |
| 374 |
$unique_meta_name_list = array( 'first_name', 'last_name', 'nickname', 'description' ); |
| 375 |
|
| 376 |
//check to see if meta-name is empty |
| 377 |
$skip_empty_check_for_fields = array('Heading'); |
| 378 |
|
| 379 |
if( !in_array( $posted_values['field'], $skip_empty_check_for_fields ) && empty( $posted_values['meta-name'] ) ) { |
| 380 |
$message .= __( "The meta-name cannot be empty\n", 'profilebuilder' ); |
| 381 |
} |
| 382 |
|
| 383 |
// Default contact methods were removed in WP 3.6. A filter dictates contact methods. |
| 384 |
if ( apply_filters( 'wppb_remove_default_contact_methods', get_site_option( 'initial_db_version' ) < 23588 ) ){ |
| 385 |
$unique_meta_name_list[] = 'aim'; |
| 386 |
$unique_meta_name_list[] = 'yim'; |
| 387 |
$unique_meta_name_list[] = 'jabber'; |
| 388 |
} |
| 389 |
|
| 390 |
// if the desired meta-name is one of the following, automatically give an error |
| 391 |
if ( in_array( trim( $posted_values['meta-name'] ), apply_filters ( 'wppb_unique_meta_name_list', $unique_meta_name_list ) ) ) |
| 392 |
$message .= __( "That meta-name is already in use\n", 'profilebuilder' ); |
| 393 |
|
| 394 |
else{ |
| 395 |
$found_in_custom_fields = false; |
| 396 |
|
| 397 |
if( $all_fields != 'not_set' ) |
| 398 |
foreach( $all_fields as $field ){ |
| 399 |
if ( $posted_values['meta-name'] != '' && ( $field['meta-name'] == $posted_values['meta-name'] ) && ( $field['id'] != $posted_values['id'] ) ){ |
| 400 |
$message .= __( "That meta-name is already in use\n", 'profilebuilder' ); |
| 401 |
$found_in_custom_fields = true; |
| 402 |
|
| 403 |
}elseif ( ( $field['meta-name'] == $posted_values['meta-name'] ) && ( $field['id'] == $posted_values['id'] ) ) |
| 404 |
$found_in_custom_fields = true; |
| 405 |
} |
| 406 |
|
| 407 |
if ( $found_in_custom_fields === false ){ |
| 408 |
$found_meta_name = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->usermeta WHERE meta_key = %s", $posted_values['meta-name'] ) ); |
| 409 |
if ( $found_meta_name != null ) |
| 410 |
$message .= __( "That meta-name is already in use\n", 'profilebuilder' ); |
| 411 |
} |
| 412 |
} |
| 413 |
} |
| 414 |
} |
| 415 |
//END check duplicate meta-name |
| 416 |
|
| 417 |
// check for valid default option (checkbox, select, radio) |
| 418 |
if ( ( $posted_values['field'] == 'Checkbox' ) || ( $posted_values['field'] == 'Select (Multiple)' ) ) { |
| 419 |
$options = array_map( 'trim', explode( ',', $posted_values['options'] ) ); |
| 420 |
$default_options = ( ( trim( $posted_values['default-options'] ) == '' ) ? array() : array_map( 'trim', explode( ',', $posted_values['default-options'] ) ) ); |
| 421 |
|
| 422 |
/* echo "<script>console.log( Posted options: " . print_r($options, true) . "' );</script>"; |
| 423 |
echo "<script>console.log( Default options: " . print_r($default_options, true) . "' );</script>"; */ |
| 424 |
|
| 425 |
$not_found = ''; |
| 426 |
foreach ( $default_options as $key => $value ){ |
| 427 |
if ( !in_array( $value, $options ) ) |
| 428 |
$not_found .= $value . ', '; |
| 429 |
} |
| 430 |
|
| 431 |
if ( $not_found != '' ) |
| 432 |
$message .= sprintf( __( "The following option(s) did not coincide with the ones in the options list: %s\n", 'profilebuilder' ), trim( $not_found, ', ' ) ); |
| 433 |
|
| 434 |
}elseif ( ( $posted_values['field'] == 'Radio' ) || ( $posted_values['field'] == 'Select' ) ){ |
| 435 |
if ( ( trim( $posted_values['default-option'] ) != '' ) && ( !in_array( $posted_values['default-option'], array_map( 'trim', explode( ',', $posted_values['options'] ) ) ) ) ) |
| 436 |
$message .= sprintf( __( "The following option did not coincide with the ones in the options list: %s\n", 'profilebuilder' ), $posted_values['default-option'] ); |
| 437 |
} |
| 438 |
// END check for valid default option (checkbox, select, radio) |
| 439 |
|
| 440 |
$message = apply_filters( 'wppb_check_extra_manage_fields', $message, $posted_values ); |
| 441 |
|
| 442 |
}elseif ( ( $meta_name == 'wppb_rf_fields' ) || ( $meta_name == 'wppb_epf_fields' ) ){ |
| 443 |
if ( $posted_values['field'] == '' ){ |
| 444 |
$message .= __( "You must select a field\n", 'profilebuilder' ); |
| 445 |
|
| 446 |
}else{ |
| 447 |
$fields_so_far = get_post_meta ( $post_id, $meta_name, true ); |
| 448 |
|
| 449 |
foreach ( $fields_so_far as $key => $value ){ |
| 450 |
if ( $value['field'] == $posted_values['field'] ) |
| 451 |
$message .= __( "That field is already added in this form\n", 'profilebuilder' ); |
| 452 |
} |
| 453 |
} |
| 454 |
} |
| 455 |
return $message; |
| 456 |
} |
| 457 |
add_filter( 'wck_extra_message', 'wppb_check_field_on_edit_add', 10, 6 ); |
| 458 |
|
| 459 |
|
| 460 |
/** |
| 461 |
* Function that calls the wppb_hide_properties_for_already_added_fields after a field-update |
| 462 |
* |
| 463 |
* @since v.2.0 |
| 464 |
* |
| 465 |
* @param void |
| 466 |
* |
| 467 |
* @return string |
| 468 |
*/ |
| 469 |
function wppb_manage_fields_after_refresh_list( $id ){ |
| 470 |
echo "<script type=\"text/javascript\">wppb_hide_properties_for_already_added_fields( '#container_wppb_manage_fields' );</script>"; |
| 471 |
} |
| 472 |
add_action( "wck_refresh_list_wppb_manage_fields", "wppb_manage_fields_after_refresh_list" ); |
| 473 |
add_action( "wck_refresh_entry_wppb_manage_fields", "wppb_manage_fields_after_refresh_list" ); |
| 474 |
|
| 475 |
|
| 476 |
/** |
| 477 |
* Function that calls the wppb_hide_all |
| 478 |
* |
| 479 |
* @since v.2.0 |
| 480 |
* |
| 481 |
* @param void |
| 482 |
* |
| 483 |
* @return string |
| 484 |
*/ |
| 485 |
function wppb_hide_all_after_add( $id ){ |
| 486 |
echo "<script type=\"text/javascript\">wppb_hide_all( '#wppb_manage_fields' );</script>"; |
| 487 |
} |
| 488 |
add_action("wck_ajax_add_form_wppb_manage_fields", "wppb_hide_all_after_add" ); |
| 489 |
|
| 490 |
/** |
| 491 |
* Function that modifies the table header in Manage Fields to add Field Name, Field Type, Meta Key, Required |
| 492 |
* |
| 493 |
* @since v.2.0 |
| 494 |
* |
| 495 |
* @param $list, $id |
| 496 |
* |
| 497 |
* @return string |
| 498 |
*/ |
| 499 |
function wppb_manage_fields_header( $list_header ){ |
| 500 |
return '<thead><tr><th class="wck-number">#</th><th class="wck-content">'. __( '<pre>Title</pre><pre>Type</pre><pre>Meta Name</pre><pre class="wppb-mb-head-required">Required</pre>', 'profilebuilder' ) .'</th><th class="wck-edit">'. __( 'Edit', 'profilebuilder' ) .'</th><th class="wck-delete">'. __( 'Delete', 'profilebuilder' ) .'</th></tr></thead>'; |
| 501 |
} |
| 502 |
add_action( 'wck_metabox_content_header_wppb_manage_fields', 'wppb_manage_fields_header' ); |
| 503 |
|
| 504 |
/** |
| 505 |
* Add contextual help to the side of manage fields for the shortcodes |
| 506 |
* |
| 507 |
* @since v.2.0 |
| 508 |
* |
| 509 |
* @param $hook |
| 510 |
* |
| 511 |
* @return string |
| 512 |
*/ |
| 513 |
function wppb_add_content_before_manage_fields(){ |
| 514 |
?> |
| 515 |
<p><?php _e('Use these shortcodes on the pages you want the forms to be displayed:', 'profilebuilder'); ?></p> |
| 516 |
<ul> |
| 517 |
<li><strong class="nowrap">[wppb-register]</strong></li> |
| 518 |
<li><strong class="nowrap">[wppb-edit-profile]</strong></li> |
| 519 |
<li><strong class="nowrap">[wppb-register role="author"]</strong></li> |
| 520 |
</ul> |
| 521 |
<p><?php _e("If you're interested in displaying different fields in the registration and edit profile forms, please use the Multiple Registration & Edit Profile Forms Addon.", 'profilebuilder'); ?></p> |
| 522 |
<?php |
| 523 |
} |
| 524 |
add_action('wck_metabox_content_wppb_manage_fields_info', 'wppb_add_content_before_manage_fields'); |
| 525 |
|
| 526 |
|
| 527 |
/** |
| 528 |
* Function that calls the wppb_edit_form_properties |
| 529 |
* |
| 530 |
* @since v.2.0 |
| 531 |
* |
| 532 |
* @param void |
| 533 |
* |
| 534 |
* @return string |
| 535 |
*/ |
| 536 |
function wppb_remove_properties_from_added_form( $meta_name, $id, $element_id ){ |
| 537 |
if ( ( $meta_name == 'wppb_epf_fields' ) || ( $meta_name == 'wppb_rf_fields' ) ) |
| 538 |
echo "<script type=\"text/javascript\">wppb_disable_delete_on_default_mandatory_fields();</script>"; |
| 539 |
|
| 540 |
if ( $meta_name == 'wppb_manage_fields' ) |
| 541 |
echo "<script type=\"text/javascript\">wppb_edit_form_properties( '#container_wppb_manage_fields', 'update_container_wppb_manage_fields_".$element_id."' );</script>"; |
| 542 |
} |
| 543 |
add_action("wck_after_adding_form", "wppb_remove_properties_from_added_form", 10, 3); |
| 544 |
|