diff --git a/admin/form-builder/assets/js/components/field-options/index.js b/admin/form-builder/assets/js/components/field-options/index.js
index 85f65fcaf..84bf6acf3 100644
--- a/admin/form-builder/assets/js/components/field-options/index.js
+++ b/admin/form-builder/assets/js/components/field-options/index.js
@@ -33,8 +33,8 @@ Vue.component('field-options', {
return self.$store.state.form_fields[i];
}
- // check if the editing field belong to column field
- if (self.$store.state.form_fields[i].template === 'column_field') {
+ // check if the editing field belong to column field or repeat field
+ if (self.$store.state.form_fields[i].template.match(/^(column|repeat)_field$/)) {
var innerColumnFields = self.$store.state.form_fields[i].inner_fields;
for (const columnFields in innerColumnFields) {
diff --git a/admin/form-builder/assets/js/components/form-column_field/index.js b/admin/form-builder/assets/js/components/form-column_field/index.js
index c1adddbb8..6c17f423e 100644
--- a/admin/form-builder/assets/js/components/form-column_field/index.js
+++ b/admin/form-builder/assets/js/components/form-column_field/index.js
@@ -162,7 +162,8 @@ Vue.component('form-column_field', {
return ( field.recaptcha_type && 'invisible_recaptcha' === field.recaptcha_type ) ? true : false;
},
- isAllowedInClolumnField: function(field_template) {
+
+ isAllowedInColumnField: function(field_template) {
var restrictedFields = ['column_field', 'custom_hidden_field', 'step_start'];
if ( $.inArray(field_template, restrictedFields) >= 0 ) {
@@ -180,7 +181,7 @@ Vue.component('form-column_field', {
toWhichColumn: data.to_column
};
- if (this.isAllowedInClolumnField(data.field_template)) {
+ if (this.isAllowedInColumnField(data.field_template)) {
Swal.fire({
title: "Oops...",
text: "You cannot add this field as inner column field"
diff --git a/admin/form-builder/assets/js/form-builder.js b/admin/form-builder/assets/js/form-builder.js
index 8349eb77a..4d89d5437 100644
--- a/admin/form-builder/assets/js/form-builder.js
+++ b/admin/form-builder/assets/js/form-builder.js
@@ -129,8 +129,8 @@
}
- // check if the editing field belong to a column field
- if (state.form_fields[i].template === 'column_field') {
+ // check if the editing field belong to a column field or repeat field
+ if (state.form_fields[i].template.match(/^(column|repeat)_field$/)) {
var innerColumnFields = state.form_fields[i].inner_fields;
for (const columnFields in innerColumnFields) {
@@ -138,6 +138,12 @@
var columnFieldIndex = 0;
while (columnFieldIndex < innerColumnFields[columnFields].length) {
+ // don't modify existing meta key
+ if (payload.field_name === 'name' && ! innerColumnFields[columnFields][columnFieldIndex].hasOwnProperty('is_new') ) {
+ columnFieldIndex++;
+ continue;
+ }
+
if (innerColumnFields[columnFields][columnFieldIndex].id === parseInt(payload.editing_field_id)) {
innerColumnFields[columnFields][columnFieldIndex][payload.field_name] = payload.value;
}
diff --git a/admin/form-builder/assets/js/mixins/global.js b/admin/form-builder/assets/js/mixins/global.js
index 60ecffd03..9efcfc1b7 100644
--- a/admin/form-builder/assets/js/mixins/global.js
+++ b/admin/form-builder/assets/js/mixins/global.js
@@ -58,8 +58,8 @@ Vue.mixin({
return true;
}
- // check if the single instance field exist in column fields
- if (self.$store.state.form_fields[i].template === 'column_field') {
+ // check if the single instance field exist in column fields or repeat field
+ if (self.$store.state.form_fields[i].template.match(/^(column|repeat)_field$/)) {
var innerColumnFields = self.$store.state.form_fields[i].inner_fields;
for (const columnFields in innerColumnFields) {
diff --git a/assets/css/admin.css b/assets/css/admin.css
index 5007b5d0d..0112f7f1a 100644
--- a/assets/css/admin.css
+++ b/assets/css/admin.css
@@ -645,7 +645,8 @@ ul.wpuf-form .wpuf-field-columns .wpuf-column-field-inner-columns .wpuf-column .
margin: 0;
padding: 15px 0;
}
-#form-preview-stage .field-items .wpuf-field-columns + div.control-buttons {
+#form-preview-stage .field-items .wpuf-field-columns + div.control-buttons,
+#form-preview-stage .field-items .wpuf-repeat-field + div.control-buttons {
top: 10px;
z-index: 10;
height: auto;
diff --git a/assets/css/frontend-forms.css b/assets/css/frontend-forms.css
index 6d14755f2..81cfc2e03 100644
--- a/assets/css/frontend-forms.css
+++ b/assets/css/frontend-forms.css
@@ -504,24 +504,29 @@ body ul.wpuf-form li .wpuf-fields .wpuf-fields-list.wpuf-list-inline li {
padding-left: 5px;
padding-right: 5px;
}
-body ul.wpuf-form li .wpuf-fields table.wpuf-repeatable-field {
+body ul.wpuf-form li .wpuf-fields .wpuf-repeatable-field {
border-collapse: collapse;
}
-body ul.wpuf-form li .wpuf-fields table.wpuf-repeatable-field * {
- box-sizing: border-box;
+body ul.wpuf-form li .wpuf-fields .wpuf-repeatable-field.wpuf-field-columns {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
}
-body ul.wpuf-form li .wpuf-fields table.wpuf-repeatable-field input {
+body ul.wpuf-form li .wpuf-fields .wpuf-repeatable-field .wpuf-column-field-inner-columns {
width: 100%;
}
-body ul.wpuf-form li .wpuf-fields table.wpuf-repeatable-field .wpuf-repeater-buttons {
+body ul.wpuf-form li .wpuf-fields .wpuf-repeatable-field * {
+ box-sizing: border-box;
+}
+body ul.wpuf-form li .wpuf-fields .wpuf-repeatable-field .wpuf-repeater-buttons {
width: 75px;
padding-left: 12px;
}
-body ul.wpuf-form li .wpuf-fields table.wpuf-repeatable-field .wpuf-repeater-buttons img {
+body ul.wpuf-form li .wpuf-fields .wpuf-repeatable-field .wpuf-repeater-buttons img {
width: 100%;
height: auto;
}
-body ul.wpuf-form li .wpuf-fields table.wpuf-repeatable-field .wpuf-repeater-buttons i {
+body ul.wpuf-form li .wpuf-fields .wpuf-repeatable-field .wpuf-repeater-buttons i {
display: inline-block;
width: 15px;
height: 15px;
@@ -1755,7 +1760,6 @@ body ul.wpuf-form .wpuf-field-columns .wpuf-column-field-inner-columns .wpuf-col
border: 0;
float: none;
width: 100%;
- overflow: hidden;
}
body ul.wpuf-form .wpuf-field-columns .wpuf-column-field-inner-columns .wpuf-column .wpuf-column-inner-fields {
padding: 0 5px 0 0;
diff --git a/assets/js/frontend-form.js b/assets/js/frontend-form.js
index 32c6948e1..6a8b3aa25 100644
--- a/assets/js/frontend-form.js
+++ b/assets/js/frontend-form.js
@@ -18,12 +18,15 @@
//enable multistep
this.enableMultistep(this);
+ var form = $('.wpuf-form');
// clone and remove repeated field
- $('.wpuf-form').on('click', 'img.wpuf-clone-field', this.cloneField);
- $('.wpuf-form').on('click', 'img.wpuf-remove-field', this.removeField);
- $('.wpuf-form').on('click', 'a.wpuf-delete-avatar', this.deleteAvatar);
- $('.wpuf-form').on('click', 'a#wpuf-post-draft', this.draftPost);
- $('.wpuf-form').on('click', 'button#wpuf-account-update-profile', this.account_update_profile);
+ form.on('click', 'img.wpuf-clone-field', this.cloneField);
+ form.on('click', 'img.wpuf-clone-repeat-field', this.cloneRepeatField);
+ form.on('click', 'img.wpuf-remove-field', this.removeField);
+ form.on('click', 'img.wpuf-remove-repeat-field', this.removeRepeatField);
+ form.on('click', 'a.wpuf-delete-avatar', this.deleteAvatar);
+ form.on('click', 'a#wpuf-post-draft', this.draftPost);
+ form.on('click', 'button#wpuf-account-update-profile', this.account_update_profile);
$('.wpuf-form-add').on('submit', this.formSubmit);
$('form#post').on('submit', this.adminPostSubmit);
@@ -342,6 +345,71 @@
}
},
+ cloneRepeatField: function( e ) {
+ e.preventDefault();
+
+ var div = $( this ).closest( '.wpuf-column-field-inner-columns.column-repeat' );
+ var clone = div.clone();
+
+ // clear the inputs
+ clone.find( 'input:not(:checkbox):not(:radio)' ).val( '' );
+ clone.find( 'textarea' ).val( '' );
+ clone.find( ':checked' ).prop( 'checked', false );
+ div.after( clone );
+
+ WP_User_Frontend.calculateFieldsName( $( this ).parents( '.wpuf-field-columns' ) );
+ WP_User_Frontend.setRowNumber( $( this ).closest( '.wpuf-field-columns' ) );
+ },
+
+ removeRepeatField: function () {
+ //check if it's the only item
+ var parent = $( this ).closest( '.wpuf-column-field-inner-columns.column-repeat' );
+ var allItems = parent.siblings().addBack();
+ var itemsLength = allItems.length;
+
+ var fieldIndex = $( allItems ).index( $( this ).closest( '.wpuf-column-field-inner-columns.column-repeat' ) );
+
+ if ( itemsLength > 1 ) {
+ WP_User_Frontend.setRowNumber( $( parent ).closest( '.wpuf-field-columns' ), itemsLength - 1 );
+ parent.remove();
+ }
+
+ // calculate only if the removed item is not the last item
+ if ( fieldIndex + 1 !== itemsLength ) {
+ WP_User_Frontend.calculateFieldsName( parent );
+ }
+ },
+
+ setRowNumber: function ( parent, length ) {
+ if ( ! length ) {
+ length = $( parent ).children().length;
+ }
+
+ $( parent ).parent( '.wpuf-fields' ).find( 'input.repeat_row_numbers' ).val( length );
+ },
+
+ calculateFieldsName: function( parentItem ) {
+ var field_rows = parentItem.children();
+ var field_names = [];
+ var field_ids = [];
+ var field_classes = [];
+ var fields_selector = '.wpuf-column input, .wpuf-column textarea, .wpuf-column select, .wpuf-column .wpuf-rich-validation';
+
+ $( field_rows[0] ).find( fields_selector ).each( function ( i, item ) {
+ field_names.push( $( item ).attr( 'name' ).split( '_0_' ) );
+ field_ids.push( $( item ).attr( 'id' ).split( '_0_' ) );
+ field_classes.push( $( item ).attr( 'class' ).split( '_0_' ) );
+ });
+
+ field_rows.each( function( i, row ) {
+ $( row ).find( fields_selector ).each( function( y, field ) {
+ $( field ).attr( 'name', field_names[y][0] + '_' + i + '_' + field_names[y][1] );
+ $( field ).attr( 'id', field_ids[y][0] + '_' + i + '_' + field_ids[y][1] );
+ $( field ).attr( 'class', field_classes[y][0] + '_' + i + '_' + field_classes[y][1] );
+ });
+ });
+ },
+
adminPostSubmit: function(e) {
e.preventDefault();
diff --git a/assets/js/wpuf-form-builder-components.js b/assets/js/wpuf-form-builder-components.js
index 6d0eb5d92..ec01451b1 100644
--- a/assets/js/wpuf-form-builder-components.js
+++ b/assets/js/wpuf-form-builder-components.js
@@ -451,8 +451,8 @@ Vue.component('field-options', {
return self.$store.state.form_fields[i];
}
- // check if the editing field belong to column field
- if (self.$store.state.form_fields[i].template === 'column_field') {
+ // check if the editing field belong to column field or repeat field
+ if (self.$store.state.form_fields[i].template.match(/^(column|repeat)_field$/)) {
var innerColumnFields = self.$store.state.form_fields[i].inner_fields;
for (const columnFields in innerColumnFields) {
@@ -929,7 +929,8 @@ Vue.component('form-column_field', {
return ( field.recaptcha_type && 'invisible_recaptcha' === field.recaptcha_type ) ? true : false;
},
- isAllowedInClolumnField: function(field_template) {
+
+ isAllowedInColumnField: function(field_template) {
var restrictedFields = ['column_field', 'custom_hidden_field', 'step_start'];
if ( $.inArray(field_template, restrictedFields) >= 0 ) {
@@ -947,7 +948,7 @@ Vue.component('form-column_field', {
toWhichColumn: data.to_column
};
- if (this.isAllowedInClolumnField(data.field_template)) {
+ if (this.isAllowedInColumnField(data.field_template)) {
Swal.fire({
title: "Oops...",
text: "You cannot add this field as inner column field"
diff --git a/assets/js/wpuf-form-builder-mixins.js b/assets/js/wpuf-form-builder-mixins.js
index ef8d9bbee..1e39b4efd 100644
--- a/assets/js/wpuf-form-builder-mixins.js
+++ b/assets/js/wpuf-form-builder-mixins.js
@@ -165,8 +165,8 @@ Vue.mixin({
return true;
}
- // check if the single instance field exist in column fields
- if (self.$store.state.form_fields[i].template === 'column_field') {
+ // check if the single instance field exist in column fields or repeat field
+ if (self.$store.state.form_fields[i].template.match(/^(column|repeat)_field$/)) {
var innerColumnFields = self.$store.state.form_fields[i].inner_fields;
for (const columnFields in innerColumnFields) {
diff --git a/assets/js/wpuf-form-builder-wpuf-forms.js b/assets/js/wpuf-form-builder-wpuf-forms.js
index 1bcfa3312..d6aa476be 100644
--- a/assets/js/wpuf-form-builder-wpuf-forms.js
+++ b/assets/js/wpuf-form-builder-wpuf-forms.js
@@ -28,7 +28,7 @@
}
// check in column field
- if (form_field.template === 'column_field' ) {
+ if (form_field.template.match(/^(column|repeat)_field$/)) {
var innerColumnFields = form_field.inner_fields;
for (const columnFields in innerColumnFields) {
diff --git a/assets/js/wpuf-form-builder.js b/assets/js/wpuf-form-builder.js
index 8349eb77a..4d89d5437 100644
--- a/assets/js/wpuf-form-builder.js
+++ b/assets/js/wpuf-form-builder.js
@@ -129,8 +129,8 @@
}
- // check if the editing field belong to a column field
- if (state.form_fields[i].template === 'column_field') {
+ // check if the editing field belong to a column field or repeat field
+ if (state.form_fields[i].template.match(/^(column|repeat)_field$/)) {
var innerColumnFields = state.form_fields[i].inner_fields;
for (const columnFields in innerColumnFields) {
@@ -138,6 +138,12 @@
var columnFieldIndex = 0;
while (columnFieldIndex < innerColumnFields[columnFields].length) {
+ // don't modify existing meta key
+ if (payload.field_name === 'name' && ! innerColumnFields[columnFields][columnFieldIndex].hasOwnProperty('is_new') ) {
+ columnFieldIndex++;
+ continue;
+ }
+
if (innerColumnFields[columnFields][columnFieldIndex].id === parseInt(payload.editing_field_id)) {
innerColumnFields[columnFields][columnFieldIndex][payload.field_name] = payload.value;
}
diff --git a/assets/less/admin.less b/assets/less/admin.less
index 99485b3a5..92cd29023 100644
--- a/assets/less/admin.less
+++ b/assets/less/admin.less
@@ -839,7 +839,8 @@ ul.wpuf-form{
}
}
-#form-preview-stage .field-items .wpuf-field-columns + div.control-buttons{
+#form-preview-stage .field-items .wpuf-field-columns + div.control-buttons,
+#form-preview-stage .field-items .wpuf-repeat-field + div.control-buttons{
top: 10px;
z-index: 10;
height: auto;
diff --git a/assets/less/frontend-forms.less b/assets/less/frontend-forms.less
index 06f637d1e..3bd5544a1 100644
--- a/assets/less/frontend-forms.less
+++ b/assets/less/frontend-forms.less
@@ -562,17 +562,23 @@ ul.wpuf-form {
}
}
- table.wpuf-repeatable-field {
+ .wpuf-repeatable-field {
border-collapse: collapse;
- & * {
- box-sizing: border-box;
+ &.wpuf-field-columns {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
}
- input {
+ .wpuf-column-field-inner-columns {
width: 100%;
}
+ & * {
+ box-sizing: border-box;
+ }
+
.wpuf-repeater-buttons {
width: 75px;
padding-left: 12px;
@@ -2033,7 +2039,6 @@ ul.wpuf-form{
border: 0;
float: none;
width: 100%;
- overflow: hidden;
.wpuf-column-inner-fields{
padding: 0 5px 0 0;
diff --git a/includes/Ajax/Admin_Form_Builder_Ajax.php b/includes/Ajax/Admin_Form_Builder_Ajax.php
index 7b56c180c..78b983c2f 100644
--- a/includes/Ajax/Admin_Form_Builder_Ajax.php
+++ b/includes/Ajax/Admin_Form_Builder_Ajax.php
@@ -50,7 +50,6 @@ public function save_form() {
$integrations = (array) json_decode( $post_data['integrations'] );
}
-
$form_fields = json_decode( $form_fields, true );
$notifications = json_decode( $notifications, true );
diff --git a/includes/Ajax/Frontend_Form_Ajax.php b/includes/Ajax/Frontend_Form_Ajax.php
index 630617651..d70d309e4 100644
--- a/includes/Ajax/Frontend_Form_Ajax.php
+++ b/includes/Ajax/Frontend_Form_Ajax.php
@@ -294,44 +294,516 @@ public function submit_post() {
$this->wpuf_user_subscription_pack( $this->form_settings, $post_id );
// set the post form_id for later usage
update_post_meta( $post_id, self::$config_id, $form_id );
-
// save post formats if have any
if ( isset( $this->form_settings['post_format'] ) && $this->form_settings['post_format'] !== '0' ) {
if ( post_type_supports( $this->form_settings['post_type'], 'post-formats' ) ) {
set_post_format( $post_id, $this->form_settings['post_format'] );
}
}
-
// find our if any images in post content and associate them
if ( ! empty( $postarr['post_content'] ) ) {
$dom = new DOMDocument();
@$dom->loadHTML( $postarr['post_content'] );
$images = $dom->getElementsByTagName( 'img' );
-
if ( $images->length ) {
foreach ( $images as $img ) {
- $url = $img->getAttribute( 'src' );
- $url = str_replace( [ '"', "'", '\\' ], '', $url );
+ $url = $img->getAttribute( 'src' );
+ $url = str_replace( [ '"', "'", '\\' ], '', $url );
$attachment_id = wpuf_get_attachment_id_from_url( $url );
-
if ( $attachment_id ) {
wpuf_associate_attachment( $attachment_id, $post_id );
}
}
}
}
-
if ( ! empty( $taxonomy_vars ) ) {
$this->set_custom_taxonomy( $post_id, $taxonomy_vars );
} else {
$this->set_default_taxonomy( $post_id );
}
-
- $response = $this->send_mail_for_guest( $charging_enabled, $post_id, $form_id, $is_update, $post_author, $meta_vars );
+ $response = $this->send_mail_for_guest(
+ $charging_enabled, $post_id, $form_id, $is_update, $post_author, $meta_vars
+ );
wpuf_clear_buffer();
wp_send_json( $response );
}
- wpuf()->ajax->send_error( __( 'Something went wrong', 'wp-user-frontend' ) );
+ $this->send_error( __( 'Something went wrong', 'wp-user-frontend' ) );
+ }
+
+ public function wpuf_get_post_user() {
+ $nonce = isset( $_REQUEST['_wpnonce'] ) ? sanitize_key( wp_unslash( $_REQUEST['_wpnonce'] ) ) : '';
+
+ if ( isset( $nonce ) && ! wp_verify_nonce( $nonce, 'wpuf_form_add' ) ) {
+ return;
+ }
+
+ $default_post_author = wpuf_get_option( 'default_post_owner', 'wpuf_frontend_posting', 1 );
+
+ if ( ! is_user_logged_in() ) {
+ if ( isset( $this->form_settings['guest_post'] ) && $this->form_settings['guest_post'] === 'true' && $this->form_settings['guest_details'] === 'true' ) {
+ $guest_name = isset( $_POST['guest_name'] ) ? sanitize_text_field( wp_unslash( $_POST['guest_name'] ) ) : '';
+
+ $guest_email = isset( $_POST['guest_email'] ) ? sanitize_email( wp_unslash( $_POST['guest_email'] ) ) : '';
+ $page_id = isset( $_POST['page_id'] ) ? sanitize_text_field( wp_unslash( $_POST['page_id'] ) ) : '';
+
+ // is valid email?
+ if ( ! is_email( $guest_email ) ) {
+ $this->send_error( __( 'Invalid email address.', 'wp-user-frontend' ) );
+ }
+
+ // check if the user email already exists
+ $user = get_user_by( 'email', $guest_email );
+
+ if ( $user ) {
+ // $post_author = $user->ID;
+ wp_send_json(
+ [
+ 'success' => false,
+ 'error' => __( "You already have an account in our site. Please login to continue.\n\nClicking 'OK' will redirect you to the login page and you will lose the form data.\nClick 'Cancel' to stay at this page.", 'wp-user-frontend' ),
+ 'type' => 'login',
+ 'redirect_to' => wp_login_url( get_permalink( $page_id ) ),
+ ]
+ );
+ } else {
+
+ // user not found, lets register him
+ // username from email address
+ $username = $this->guess_username( $guest_email );
+
+ $user_pass = wp_generate_password( 12, false );
+
+ $errors = new WP_Error();
+
+ do_action( 'register_post', $username, $guest_email, $errors );
+
+ $user_id = wp_create_user( $username, $user_pass, $guest_email );
+
+ // if its a success and no errors found
+
+ if ( $user_id && ! is_wp_error( $user_id ) ) {
+ update_user_option( $user_id, 'default_password_nag', true, true ); //Set up the Password change nag.
+
+ if ( class_exists( 'Theme_My_Login_Custom_Email' ) ) {
+ do_action( 'tml_new_user_registered', $user_id, $user_pass );
+ } else {
+ wp_send_new_user_notifications( $user_id );
+ }
+
+ // update display name to full name
+ wp_update_user(
+ [
+ 'ID' => $user_id,
+ 'display_name' => $guest_name,
+ ]
+ );
+
+ $post_author = $user_id;
+ } else {
+ //something went wrong creating the user, set post author to the default author
+ $post_author = $default_post_author;
+ }
+ }
+
+ // guest post is enabled and details are off
+ } elseif ( isset( $this->form_settings['guest_post'] ) && $this->form_settings['guest_post'] === 'true' && $this->form_settings['guest_details'] === 'false' ) {
+ $post_author = $default_post_author;
+ } elseif ( isset( $this->form_settings['guest_post'] ) && $this->form_settings['guest_post'] !== 'true' ) {
+ $this->send_error( $this->form_settings['message_restrict'] );
+ }
+
+ // the user must be logged in already
+ } elseif ( isset( $this->form_settings['role_base'] ) && $this->form_settings['role_base'] === 'true' && ! wpuf_user_has_roles( $this->form_settings['roles'] ) ) {
+ $this->send_error( __( 'You do not have sufficient permissions to access this form.', 'wp-user-frontend' ) );
+ } else {
+ $post_author = get_current_user_id();
+ }
+
+ return $post_author;
+ }
+
+ /**
+ * Add post shortcode handler
+ *
+ * @param array $atts
+ * @return string
+ */
+
+ public function add_post_shortcode( $atts ) {
+ add_filter( 'wpuf-form-fields', [ $this, 'add_field_settings' ] );
+
+ // @codingStandardsIgnoreStart
+ extract( shortcode_atts( [ 'id' => 0 ], $atts ) );
+
+ // @codingStandardsIgnoreEnd
+ ob_start();
+ $form = new WPUF_Form( $id );
+ $this->form_fields = $form->get_fields();
+ $this->form_settings = $form->get_settings();
+ $this->generate_auth_link(); // Translate tag %login% %registration% to login registartion url
+ [ $user_can_post, $info ] = $form->is_submission_open( $form, $this->form_settings );
+ $info = apply_filters( 'wpuf_addpost_notice', $info, $id, $this->form_settings );
+ $user_can_post = apply_filters( 'wpuf_can_post', $user_can_post, $id, $this->form_settings );
+
+ if ( $user_can_post === 'yes' ) {
+ $this->render_form( $id, null, $atts, $form );
+ } else {
+ echo wp_kses_post( '
' . $info . '
' );
+ }
+ $content = ob_get_contents();
+ ob_end_clean();
+
+ return $content;
+ }
+
+ public static function update_post_meta( $meta_vars, $post_id ) {
+ // check_ajax_referer( 'wpuf_form_add' );
+ // prepare the meta vars
+ [ $meta_key_value, $multi_repeated, $files ] = self::prepare_meta_fields( $meta_vars );
+ // set featured image if there's any
+
+ // @codingStandardsIgnoreStart
+ $wpuf_files = isset( $_POST['wpuf_files'] ) ? $_POST['wpuf_files'] : [];
+
+ if ( isset( $wpuf_files['featured_image'] ) ) {
+ $attachment_id = $wpuf_files['featured_image'][0];
+
+ wpuf_associate_attachment( $attachment_id, $post_id );
+ set_post_thumbnail( $post_id, $attachment_id );
+
+ $file_data = isset( $_POST['wpuf_files_data'][ $attachment_id ] ) ? $_POST['wpuf_files_data'][ $attachment_id ] : false;
+
+ // @codingStandardsIgnoreEnd
+ if ( $file_data ) {
+ $args = [
+ 'ID' => $attachment_id,
+ 'post_title' => $file_data['title'],
+ 'post_content' => $file_data['desc'],
+ 'post_excerpt' => $file_data['caption'],
+ ];
+ wpuf_update_post( $args );
+
+ update_post_meta( $attachment_id, '_wp_attachment_image_alt', $file_data['title'] );
+ }
+ }
+
+
+ if ( ! empty( $multi_repeated ) ) {
+ $fields_meta = ! empty( $multi_repeated['sub_fields'] ) ? $multi_repeated['sub_fields'] : [];
+ $parent = ! empty( $multi_repeated['parent'] ) ? $multi_repeated['parent'] : '';
+
+ if ( ! empty( $parent ) && ! empty( $fields_meta ) ) {
+ // get how many rows previously saved
+ $row_num = get_post_meta( $post_id, $parent, true );
+
+ // delete previous repeat values
+ foreach ( $fields_meta as $sub_field ) {
+ for ( $i = 0; $i < $row_num; $i++ ) {
+ $tmp_meta = $parent . '_' . $i . '_' . $sub_field;
+ delete_post_meta( $post_id, $tmp_meta );
+ delete_post_meta( $post_id, '_' . $tmp_meta );
+ }
+ }
+
+ $row_number = ! empty( $multi_repeated['row_number'] ) ? $multi_repeated['row_number'] : 0;
+ $sub_fields = ! empty( $multi_repeated['fields'] ) ? $multi_repeated['fields'] : [];
+
+ // save new data
+ for ( $i = 0; $i < $row_number; $i++ ) {
+ foreach ( $sub_fields as $key => $value ) {
+ update_post_meta( $post_id, $key, $value );
+ update_post_meta( $post_id, '_' . $key, uniqid( 'field_' ) );
+ }
+ }
+
+ update_post_meta( $post_id, $parent, $row_number );
+ }
+ }
+
+ // save all custom fields
+ foreach ( $meta_key_value as $meta_key => $meta_value ) {
+ update_post_meta( $post_id, $meta_key, $meta_value );
+ }
+
+ // save any files attached
+ foreach ( $files as $file_input ) {
+ // delete any previous value
+ delete_post_meta( $post_id, $file_input['name'] );
+
+ $image_ids = '';
+
+ if ( count( $file_input['value'] ) > 1 ) {
+ $image_ids = $file_input['value'];
+ }
+
+ if ( count( $file_input['value'] ) === 1 ) {
+ $image_ids = $file_input['value'][0];
+ }
+
+ if ( ! empty( $image_ids ) ) {
+ add_post_meta( $post_id, $file_input['name'], $image_ids );
+ }
+
+ //to track how many files are being uploaded
+ $file_numbers = 0;
+
+ foreach ( $file_input['value'] as $attachment_id ) {
+
+ //if file numbers are greated than allowed number, prevent it from being uploaded
+ if ( $file_numbers >= $file_input['count'] ) {
+ wp_delete_attachment( $attachment_id );
+ continue;
+ }
+
+ wpuf_associate_attachment( $attachment_id, $post_id );
+ //add_post_meta( $post_id, $file_input['name'], $attachment_id );
+
+ // file title, caption, desc update
+
+ // @codingStandardsIgnoreStart
+ $file_data = isset( $_POST['wpuf_files_data'][ $attachment_id ] ) ? wp_unslash( $_POST['wpuf_files_data'][ $attachment_id ] ) : false;
+
+ // @codingStandardsIgnoreEnd
+ if ( $file_data ) {
+ $args = [
+ 'ID' => $attachment_id,
+ 'post_title' => $file_data['title'],
+ 'post_content' => $file_data['desc'],
+ 'post_excerpt' => $file_data['caption'],
+ ];
+ wpuf_update_post( $args );
+
+ update_post_meta( $attachment_id, '_wp_attachment_image_alt', $file_data['title'] );
+ }
+ $file_numbers++;
+ }
+ }
+ }
+
+ public function prepare_mail_body( $content, $user_id, $post_id ) {
+ $user = get_user_by( 'id', $user_id );
+ $post = get_post( $post_id );
+
+ $post_field_search = [
+ '%post_title%',
+ '%post_content%',
+ '%post_excerpt%',
+ '%tags%',
+ '%category%',
+ '%author%',
+ '%author_email%',
+ '%author_bio%',
+ '%sitename%',
+ '%siteurl%',
+ '%permalink%',
+ '%editlink%',
+ ];
+
+ $home_url = sprintf( '%s', home_url(), home_url() );
+ $post_url = sprintf( '%s', get_permalink( $post_id ), get_permalink( $post_id ) );
+ $post_edit_link = sprintf( '%s', admin_url( 'post.php?action=edit&post=' . $post_id ), admin_url( 'post.php?action=edit&post=' . $post_id ) );
+
+ $post_field_replace = [
+ $post->post_title,
+ $post->post_content,
+ $post->post_excerpt,
+ get_the_term_list( $post_id, 'post_tag', '', ', ' ),
+ get_the_term_list( $post_id, 'category', '', ', ' ),
+ $user->display_name,
+ $user->user_email,
+ ( $user->description ) ? $user->description : 'not available',
+ get_bloginfo( 'name' ),
+ $home_url,
+ $post_url,
+ $post_edit_link,
+ ];
+
+ if ( class_exists( 'WooCommerce' ) ) {
+ $post_field_search[] = '%product_cat%';
+ $post_field_replace[] = get_the_term_list( $post_id, 'product_cat', '', ', ' );
+ }
+
+ $content = str_replace( $post_field_search, $post_field_replace, $content );
+
+ // custom fields
+ preg_match_all( '/%custom_([\w-]*)\b%/', $content, $matches );
+ [ $search, $replace ] = $matches;
+
+ if ( $replace ) {
+ foreach ( $replace as $index => $meta_key ) {
+ $value = get_post_meta( $post_id, $meta_key, false );
+
+ if ( isset( $value[0] ) && is_array( $value[0] ) ) {
+ $new_value = implode( '; ', $value[0] );
+ } else {
+ $new_value = implode( '; ', $value );
+ }
+
+ $original_value = '';
+ $meta_val = '';
+
+ if ( count( $value ) > 1 ) {
+ $is_first = true;
+
+ foreach ( $value as $val ) {
+ if ( $is_first ) {
+ if ( get_post_mime_type( (int) $val ) ) {
+ $meta_val = wp_get_attachment_url( $val );
+ } else {
+ $meta_val = $val;
+ }
+ $is_first = false;
+ } else {
+ if ( get_post_mime_type( (int) $val ) ) {
+ $meta_val = $meta_val . ', ' . wp_get_attachment_url( $val );
+ } else {
+ $meta_val = $meta_val . ', ' . $val;
+ }
+ }
+
+ if ( get_post_mime_type( (int) $val ) ) {
+ $meta_val = $meta_val . ',' . wp_get_attachment_url( $val );
+ } else {
+ $meta_val = $meta_val . ',' . $val;
+ }
+ }
+ $original_value = $original_value . $meta_val;
+ } else {
+ if ( 'address_field' === $meta_key ) {
+ $value = get_post_meta( $post_id, $meta_key, true );
+ $new_value = implode( ', ', $value );
+ }
+
+ if ( get_post_mime_type( (int) $new_value ) ) {
+ $original_value = wp_get_attachment_url( $new_value );
+ } else {
+ $original_value = $new_value;
+ }
+ }
+
+ $content = str_replace( $search[ $index ], $original_value, $content );
+ }
+ }
+
+ return $content;
+ }
+
+ public function woo_attribute( $taxonomy ) {
+ check_ajax_referer( 'wpuf_form_add' );
+ $taxonomy_name = isset( $_POST[ $taxonomy['name'] ] ) ? sanitize_text_field( wp_unslash( $_POST[ $taxonomy['name'] ] ) ) : '';
+
+ return [
+ 'name' => $taxonomy['name'],
+ 'value' => $taxonomy_name,
+ 'is_visible' => $taxonomy['woo_attr_vis'] === 'yes' ? 1 : 0,
+ 'is_variation' => 0,
+ 'is_taxonomy' => 1,
+ ];
+ }
+
+ /**
+ * Hook to publish verified guest post with payment
+ *
+ * @since 2.5.8
+ */
+ public function publish_guest_post() {
+ $post_msg = isset( $_GET['post_msg'] ) ? sanitize_text_field( wp_unslash( $_GET['post_msg'] ) ) : '';
+ $pid = isset( $_GET['p_id'] ) ? sanitize_text_field( wp_unslash( $_GET['p_id'] ) ) : '';
+ $fid = isset( $_GET['f_id'] ) ? sanitize_text_field( wp_unslash( $_GET['f_id'] ) ) : '';
+
+ if ( $post_msg === 'verified' ) {
+ $response = [];
+ $post_id = wpuf_decryption( $pid );
+ $form_id = wpuf_decryption( $fid );
+ $form_settings = wpuf_get_form_settings( $form_id );
+ $post_author_id = get_post_field( 'post_author', $post_id );
+ $payment_status = new WPUF_Subscription();
+ $form = new WPUF_Form( $form_id );
+ $pay_per_post = $form->is_enabled_pay_per_post();
+ $force_pack = $form->is_enabled_force_pack();
+
+ if ( $form->is_charging_enabled() && $pay_per_post ) {
+ if ( ( $payment_status->get_payment_status( $post_id ) ) === 'pending' ) {
+ $response['show_message'] = true;
+ $response['redirect_to'] = add_query_arg(
+ [
+ 'action' => 'wpuf_pay',
+ 'type' => 'post',
+ 'post_id' => $post_id,
+ ],
+ get_permalink( wpuf_get_option( 'payment_page', 'wpuf_payment' ) )
+ );
+
+ wp_redirect( $response['redirect_to'] );
+ wpuf_clear_buffer();
+ wp_send_json( $response );
+ }
+ } else {
+ $p_status = get_post_status( $post_id );
+
+ if ( $p_status ) {
+ wp_update_post(
+ [
+ 'ID' => $post_id,
+ 'post_status' => isset( $form_settings['post_status'] ) ? $form_settings['post_status'] : 'publish',
+ ]
+ );
+
+ echo wp_kses_post( "" . __( 'Email successfully verified. Please Login.', 'wp-user-frontend' ) . '
' );
+ }
+ }
+ }
+ }
+
+ public function wpuf_user_subscription_pack( $form_settings, $post_id = null ) {
+
+ // if user has a subscription pack
+ $user_wpuf_subscription_pack = get_user_meta( get_current_user_id(), '_wpuf_subscription_pack', true );
+ $wpuf_user = wpuf_get_user();
+ $user_subscription = new WPUF_User_Subscription( $wpuf_user );
+ if ( ! empty( $user_wpuf_subscription_pack ) && isset( $user_wpuf_subscription_pack['_enable_post_expiration'] )
+ && isset( $user_wpuf_subscription_pack['expire'] ) && strtotime( $user_wpuf_subscription_pack['expire'] ) >= time() ) {
+ $expire_date = gmdate( 'Y-m-d', strtotime( '+' . $user_wpuf_subscription_pack['_post_expiration_time'] ) );
+ update_post_meta( $post_id, $this->post_expiration_date, $expire_date );
+ // save post status after expiration
+ $expired_post_status = $user_wpuf_subscription_pack['_expired_post_status'];
+ update_post_meta( $post_id, $this->expired_post_status, $expired_post_status );
+ // if mail active
+ if ( isset( $user_wpuf_subscription_pack['_enable_mail_after_expired'] ) && $user_wpuf_subscription_pack['_enable_mail_after_expired'] === 'on' ) {
+ $post_expiration_message = $user_subscription->get_subscription_exp_msg( $user_wpuf_subscription_pack['pack_id'] );
+ update_post_meta( $post_id, $this->post_expiration_message, $post_expiration_message );
+ }
+ } elseif ( ! empty( $user_wpuf_subscription_pack ) && isset( $user_wpuf_subscription_pack['expire'] ) && strtotime( $user_wpuf_subscription_pack['expire'] ) <= time() ) {
+ if ( isset( $form_settings['expiration_settings']['enable_post_expiration'] ) ) {
+ $expire_date = gmdate( 'Y-m-d', strtotime( '+' . $form_settings['expiration_settings']['expiration_time_value'] . ' ' . $form_settings['expiration_settings']['expiration_time_type'] . '' ) );
+
+ update_post_meta( $post_id, $this->post_expiration_date, $expire_date );
+ // save post status after expiration
+ $expired_post_status = $form_settings['expiration_settings']['expired_post_status'];
+ update_post_meta( $post_id, $this->expired_post_status, $expired_post_status );
+ // if mail active
+ if ( isset( $form_settings['expiration_settings']['enable_mail_after_expired'] ) && $form_settings['expiration_settings']['enable_mail_after_expired'] === 'on' ) {
+ $post_expiration_message = $form_settings['expiration_settings']['post_expiration_message'];
+ update_post_meta( $post_id, $this->post_expiration_message, $post_expiration_message );
+ }
+ }
+ } elseif ( empty( $user_wpuf_subscription_pack ) || $user_wpuf_subscription_pack === 'Cancel' || $user_wpuf_subscription_pack === 'cancel' ) {
+ if ( isset( $form_settings['expiration_settings']['enable_post_expiration'] ) ) {
+ $expire_date = gmdate( 'Y-m-d', strtotime( '+' . $form_settings['expiration_settings']['expiration_time_value'] . ' ' . $form_settings['expiration_settings']['expiration_time_type'] . '' ) );
+ update_post_meta( $post_id, $this->post_expiration_date, $expire_date );
+ // save post status after expiration
+ $expired_post_status = $form_settings['expiration_settings']['expired_post_status'];
+ update_post_meta( $post_id, $this->expired_post_status, $expired_post_status );
+ // if mail active
+ if ( isset( $form_settings['expiration_settings']['enable_mail_after_expired'] ) && $form_settings['expiration_settings']['enable_mail_after_expired'] === 'on' ) {
+ $post_expiration_message = $form_settings['expiration_settings']['post_expiration_message'];
+ update_post_meta( $post_id, $this->post_expiration_message, $post_expiration_message );
+ }
+ }
+ }
+
+ //Handle featured item when edit
+ $sub_meta = $user_subscription->handle_featured_item( $post_id, $user_wpuf_subscription_pack );
+ $user_subscription->update_meta( $sub_meta );
}
public function send_mail_for_guest( $charging_enabled, $post_id, $form_id, $is_update, $post_author, $meta_vars ) {
diff --git a/includes/Fields/Form_Field_Checkbox.php b/includes/Fields/Form_Field_Checkbox.php
index 948d469a1..9813b9143 100755
--- a/includes/Fields/Form_Field_Checkbox.php
+++ b/includes/Fields/Form_Field_Checkbox.php
@@ -46,6 +46,7 @@ public function render( $field_settings, $form_id, $type = 'post', $post_id = nu
data-required=""
@@ -189,8 +190,10 @@ public function render_field_data( $data, $field ) {
return;
}
+ $data = is_array( $data ) ? array_pop( $data ) : $data;
+ // check again if there is any nested data
$data = is_array( $data ) ? array_pop( $data ) : $data;
- $data = explode( '|' , $data );
+ $data = explode( '|', $data );
$selected = [];
foreach ( $data as $item ) {
diff --git a/includes/Fields/Form_Field_Radio.php b/includes/Fields/Form_Field_Radio.php
index 2a4537510..7e4b9882c 100755
--- a/includes/Fields/Form_Field_Radio.php
+++ b/includes/Fields/Form_Field_Radio.php
@@ -50,6 +50,7 @@ public function render( $field_settings, $form_id, $type = 'post', $post_id = nu