Fix submission bug.

This commit is contained in:
Hoang Huu 2019-10-31 15:21:48 +07:00
parent 8d86aa767d
commit 57f4284fb9
5 changed files with 318 additions and 303 deletions

View File

@ -93,8 +93,6 @@ class Opalestate_Install {
$options['currency_position'] = 'before';
$options['measurement_unit'] = 'sqft';
$options['google_map_api_keys'] = 'AIzaSyCfMVNIa7khIqYHCw6VBn8ShUWWm4tjbG8';
$options['admin_approve'] = 'on';
$options['require_input_price'] = 'on';
$options['from_name'] = get_bloginfo( 'name' );
$options['from_email'] = get_bloginfo( 'admin_email' );
$options['message_log'] = 1;
@ -129,6 +127,7 @@ class Opalestate_Install {
$options['enable_agency_reviews'] = 'on';
$options['enable_agent_reviews'] = 'on';
$options['admin_approve'] = 'on';
$options['enable_submission_tab_media'] = 'on';
$options['enable_submission_tab_location'] = 'on';
$options['enable_submission_tab_amenities'] = 'on';

View File

@ -240,7 +240,7 @@ class Opalestate_Property_MetaBox {
'name' => esc_html__( 'Regular Price', 'opalestate-pro' ) . $currency,
'type' => 'text',
'description' => esc_html__( 'Enter amount without currency', 'opalestate-pro' ),
'attributes' => opalestate_get_option( 'require_input_price' ) ? [ 'required' => 'required' ] : '',
'attributes' => [ 'required' => 'required' ],
'before_row' => '<div class="row-group-features group-has-three group-price clearfix"><h3>' . ( is_admin() ? "" : esc_html__( 'Price', 'opalestate-pro' ) ) . '</h3>', // callback
],
[

View File

@ -59,14 +59,13 @@ class Opalestate_Property_MetaBox_Submission {
public function get_fields_groups() {
return [
'general' => [ 'status' => true, 'title' => esc_html__( 'General', 'opalestate-pro' ) ],
'media' => [ 'status' => $this->is_enabled_tab( 'media' ), 'title' => esc_html__( 'Media', 'opalestate-pro' ) ],
'location' => [ 'status' => $this->is_enabled_tab( 'location' ), 'title' => esc_html__( 'Location', 'opalestate-pro' ) ],
'information' => [ 'status' => $this->is_enabled_tab( 'information' ), 'title' => esc_html__( 'Information', 'opalestate-pro' ) ],
'amenities' => [ 'status' => $this->is_enabled_tab( 'amenities' ), 'title' => esc_html__( 'Amenities', 'opalestate-pro' ) ],
'facilities' => [ 'status' => $this->is_enabled_tab( 'facilities' ), 'title' => esc_html__( 'Facilities', 'opalestate-pro' ) ],
'apartments' => [ 'status' => $this->is_enabled_tab( 'apartments' ), 'title' => esc_html__( 'Apartments', 'opalestate-pro' ) ],
'floor_plans' => [ 'status' => $this->is_enabled_tab( 'floor_plans' ), 'title' => esc_html__( 'Floor plans', 'opalestate-pro' ) ]
'floor_plans' => [ 'status' => $this->is_enabled_tab( 'floor_plans' ), 'title' => esc_html__( 'Floor plans', 'opalestate-pro' ) ],
];
}
@ -95,7 +94,6 @@ class Opalestate_Property_MetaBox_Submission {
'default' => $post_id,
],
[
'name' => esc_html__( 'Title', 'opalestate-pro' ) . '<span class="required"> *</span>',
'id' => $prefix . 'title',
@ -113,14 +111,13 @@ class Opalestate_Property_MetaBox_Submission {
'default' => ! empty( $post ) ? $post->post_content : '',
'before_row' => '<hr>',
],
[
'id' => $prefix . 'price',
'name' => esc_html__( 'Regular Price', 'opalestate-pro' ) . $currency . '<span class="required"> *</span>',
'type' => 'text',
'description' => esc_html__( 'Enter amount without currency', 'opalestate-pro' ),
'attributes' => opalestate_get_option( 'require_input_price' ) ? [ 'required' => 'required' ] : '',
'before_row' => '<hr><div class="field-row-2">', // callback
'attributes' => [ 'required' => 'required' ],
'before_row' => '<hr><div class="field-row-2">',
],
[
'id' => $prefix . 'saleprice',
@ -168,7 +165,6 @@ class Opalestate_Property_MetaBox_Submission {
}
public function metaboxes_media_fields() {
$id = 0;
if ( isset( $_GET['id'] ) ) {
@ -210,7 +206,7 @@ class Opalestate_Property_MetaBox_Submission {
'name' => esc_html__( '360° Virtual Tour', 'opalestate-pro' ),
'type' => 'textarea_small',
'description' => esc_html__( 'Input iframe to show 360° Virtual Tour.', 'opalestate-pro' ),
'before_row' => '<hr>'
'before_row' => '<hr>',
],
[
'id' => "{$prefix}attachments",
@ -247,10 +243,10 @@ class Opalestate_Property_MetaBox_Submission {
'name' => esc_html__( 'Parking', 'opalestate-pro' ),
'id' => $prefix . 'parking',
'type' => 'text',
'attributes' => array(
'attributes' => [
'type' => 'number',
'pattern' => '\d*',
),
],
'sanitization_cb' => 'absint',
'escape_cb' => 'absint',
'description' => esc_html__( 'Enter number of Parking', 'opalestate-pro' ),
@ -259,10 +255,10 @@ class Opalestate_Property_MetaBox_Submission {
'name' => esc_html__( 'Bedrooms', 'opalestate-pro' ),
'id' => $prefix . 'bedrooms',
'type' => 'text',
'attributes' => array(
'attributes' => [
'type' => 'number',
'pattern' => '\d*',
),
],
'sanitization_cb' => 'absint',
'escape_cb' => 'absint',
'description' => esc_html__( 'Enter number of bedrooms', 'opalestate-pro' ),
@ -271,10 +267,10 @@ class Opalestate_Property_MetaBox_Submission {
'name' => esc_html__( 'Bathrooms', 'opalestate-pro' ),
'id' => $prefix . 'bathrooms',
'type' => 'text',
'attributes' => array(
'attributes' => [
'type' => 'number',
'pattern' => '\d*',
),
],
'sanitization_cb' => 'absint',
'escape_cb' => 'absint',
'description' => esc_html__( 'Enter number of bathrooms', 'opalestate-pro' ),
@ -289,10 +285,10 @@ class Opalestate_Property_MetaBox_Submission {
'name' => esc_html__( 'Area Size', 'opalestate-pro' ),
'id' => $prefix . 'areasize',
'type' => 'text',
'attributes' => array(
'attributes' => [
'type' => 'number',
'pattern' => '\d*',
),
],
'sanitization_cb' => 'absint',
'escape_cb' => 'absint',
'description' => esc_html__( 'Enter size of area in sqft', 'opalestate-pro' ),
@ -307,10 +303,10 @@ class Opalestate_Property_MetaBox_Submission {
'name' => esc_html__( 'Living Rooms', 'opalestate-pro' ),
'id' => "{$prefix}livingrooms",
'type' => 'text',
'attributes' => array(
'attributes' => [
'type' => 'number',
'pattern' => '\d*',
),
],
'sanitization_cb' => 'absint',
'escape_cb' => 'absint',
'description' => esc_html__( 'Enter Number of Living Rooms', 'opalestate-pro' ),
@ -320,10 +316,10 @@ class Opalestate_Property_MetaBox_Submission {
'name' => esc_html__( 'Kitchens', 'opalestate-pro' ),
'id' => "{$prefix}kitchens",
'type' => 'text',
'attributes' => array(
'attributes' => [
'type' => 'number',
'pattern' => '\d*',
),
],
'sanitization_cb' => 'absint',
'escape_cb' => 'absint',
'description' => esc_html__( 'Enter Number of Kitchens', 'opalestate-pro' ),
@ -333,10 +329,10 @@ class Opalestate_Property_MetaBox_Submission {
'name' => esc_html__( 'Rooms', 'opalestate-pro' ),
'id' => "{$prefix}amountrooms",
'type' => 'text',
'attributes' => array(
'attributes' => [
'type' => 'number',
'pattern' => '\d*',
),
],
'sanitization_cb' => 'absint',
'escape_cb' => 'absint',
'description' => esc_html__( 'Enter Number of Amount Rooms', 'opalestate-pro' ),
@ -375,7 +371,7 @@ class Opalestate_Property_MetaBox_Submission {
'name' => esc_html__( 'Postal Code / Zip', 'opalestate-pro' ),
'id' => $prefix . 'zipcode',
'type' => 'text',
'after_row'=> '</div><hr>'
'after_row' => '</div><hr>',
],
[

View File

@ -36,7 +36,7 @@ class OpalEstate_Submission {
*
*
*/
public $new_attachmenet_ids = array();
public $new_attachmenet_ids = [];
/**
* Constructor
@ -95,7 +95,7 @@ class OpalEstate_Submission {
'submission_list' => [
'code' => 'submission_list',
'label' => esc_html__( 'My Properties', 'opalestate-pro' ),
]
],
];
foreach ( $shortcodes as $shortcode ) {
@ -107,7 +107,7 @@ class OpalEstate_Submission {
* Is submission page. 'submission_page' option in General Setting
*/
public function setting_content_tab( $tabs ) {
$tabs['submission_page'] = esc_html__( 'Submission Page', 'opalestate-pro' );
$tabs['submission_page'] = esc_html__( 'Submission', 'opalestate-pro' );
return $tabs;
}
@ -152,16 +152,13 @@ class OpalEstate_Submission {
[
'name' => esc_html__( 'Enable Admin Approve', 'opalestate-pro' ),
'desc' => esc_html__( 'the Property will be auto approve when user submit, if you do not enable it.', 'opalestate-pro' ),
'desc' => esc_html__( 'Admin must review and approve before properties are published.', 'opalestate-pro' ),
'id' => 'admin_approve',
'type' => 'checkbox',
'type' => 'switch',
'options' => [
'on' => esc_html__( 'Enable', 'opalestate-pro' ),
'off' => esc_html__( 'Disable', 'opalestate-pro' ),
],
[
'name' => esc_html__( 'Enable Require Price', 'opalestate-pro' ),
'desc' => esc_html__( 'Enable or Disable require user enter price and price label.', 'opalestate-pro' ),
'id' => 'require_input_price',
'type' => 'checkbox',
],
[
'name' => esc_html__( 'Submission Tab Settings', 'opalestate-pro' ),
@ -240,6 +237,30 @@ class OpalEstate_Submission {
'off' => esc_html__( 'Disable', 'opalestate-pro' ),
],
],
[
'name' => esc_html__( 'Submission Settings', 'opalestate-pro' ),
'id' => 'opalestate_title_submission_settings',
'type' => 'title',
'before_row' => '<hr>',
'after_row' => '<hr>',
],
[
'name' => esc_html__( 'Generate property SKU', 'opalestate-pro' ),
'desc' => esc_html__( 'Enable automatic generate property SKU.', 'opalestate-pro' ),
'id' => 'enable_submission_generate_sku',
'type' => 'switch',
'options' => [
'on' => esc_html__( 'Enable', 'opalestate-pro' ),
'off' => esc_html__( 'Disable', 'opalestate-pro' ),
],
],
[
'name' => esc_html__( 'Property SKU prefix', 'opalestate-pro' ),
'desc' => esc_html__( 'Prefix for property SKU.', 'opalestate-pro' ),
'id' => 'submission_sku_prefix',
'type' => 'text',
'default' => 'SKU',
],
]
),
];
@ -258,8 +279,8 @@ class OpalEstate_Submission {
* Is submission page. 'submission_page' option in General Setting
*/
public function render_button_edit() {
global $post, $current_user;
wp_get_current_user();
if ( $current_user->ID == $post->post_author ) {
@ -281,13 +302,12 @@ class OpalEstate_Submission {
return opalestate_get_option( 'submission_page' ) == $post->ID;
}
/**
* Register metabox.
*
*
* @return \Opalestate_Property_MetaBox_Submission
*/
public function register_metabox() {
$metabox = new Opalestate_Property_MetaBox_Submission();
add_filter( 'cmb2_meta_boxes', [ $metabox, 'register_form' ], 9999 );
@ -299,7 +319,6 @@ class OpalEstate_Submission {
* FrontEnd Submission
*/
public function submission() {
global $current_user;
if ( ! is_user_logged_in() ) {
@ -310,10 +329,10 @@ class OpalEstate_Submission {
}
if ( isset( $_GET['do'] ) && $_GET['do'] == 'completed' ) {
OpalEstate()->session->set( 'submission', 'addnew' );
echo opalestate_load_template_path( 'submission/completed' );
return;
}
@ -324,7 +343,6 @@ class OpalEstate_Submission {
wp_enqueue_style( 'opalesate-submission' );
wp_enqueue_style( 'opalesate-cmb2-front' );
$metabox = $this->register_metabox();
$metaboxes = apply_filters( 'cmb2_meta_boxes', [] );
@ -355,6 +373,7 @@ class OpalEstate_Submission {
return;
}
}
return opalestate_load_template_path( 'submission/submission-form',
[
'post_id' => $post_id,
@ -369,6 +388,7 @@ class OpalEstate_Submission {
*/
public function cmb2_get_metabox() {
$object_id = 'fake-oject-id';
return cmb2_get_metabox( OPALESTATE_PROPERTY_PREFIX . 'front', $object_id );
}
@ -388,13 +408,9 @@ class OpalEstate_Submission {
// Setup and sanitize data
if ( isset( $_POST[ $prefix . 'title' ] ) && ! $blocked && $user_id ) {
$metabox = $this->register_metabox();
$metaboxes = apply_filters( 'cmb2_meta_boxes', [] );
$post_id = ! empty( $_POST['post_id'] ) ? absint( $_POST['post_id'] ) : false;
if ( $post_id ) {
@ -403,12 +419,9 @@ class OpalEstate_Submission {
do_action( 'opalestate_process_submission_before' );
}
$review_before = opalestate_get_option( 'admin_approve' );
$post_status = 'pending';
if ( ! $review_before ) {
if ( 'on' != opalestate_get_option( 'admin_approve', 'on' ) ) {
$post_status = 'publish';
}
@ -424,7 +437,6 @@ class OpalEstate_Submission {
$post_content = isset( $_POST[ $prefix . 'text' ] ) ? wp_kses( $_POST[ $prefix . 'text' ],
'<b><strong><i><em><h1><h2><h3><h4><h5><h6><pre><code><span><p>' ) : '';
$data = [
'post_title' => sanitize_text_field( $_POST[ $prefix . 'title' ] ),
'post_author' => $user_id,
@ -458,9 +470,9 @@ class OpalEstate_Submission {
if ( empty( $data['post_title'] ) || empty( $data['post_author'] ) ) {
return opalestate_output_msg_json( false,
__( 'Please enter data for all require fields before submitting', 'opalestate-pro' ),
array(
'heading' => esc_html__('Submission Information' ,'opalestate-pro')
)) ;
[
'heading' => esc_html__( 'Submission Information', 'opalestate-pro' ),
] );
}
$post_id = wp_insert_post( $data, true );
@ -495,8 +507,15 @@ class OpalEstate_Submission {
delete_post_thumbnail( $post_id );
}
// remove meta field;
// Remove meta field.
update_post_meta( $post_id, $prefix . 'featured_image', null );
// Update SKU.
if ( 'on' == opalestate_get_option( 'enable_submission_generate_sku', 'off' ) ) {
$sku_generated = apply_filters( 'opalestate_submission_sku_generated', sanitize_text_field( opalestate_options( 'submission_sku_prefix', 'SKU' ) . $post_id ) );
update_post_meta( $post_id, $prefix . 'sku', $sku_generated );
}
//redirect
$_SESSION['messages'][] = [ 'success', esc_html__( 'Property has been successfully updated.', 'opalestate-pro' ) ];
@ -519,26 +538,24 @@ class OpalEstate_Submission {
}
}
//
return opalestate_output_msg_json( true,
$message,
array(
[
'heading' => esc_html__( 'Submission Information', 'opalestate-pro' ),
'redirect' => opalestate_submssion_page( $post_id, array('do' => 'completed') )
)) ;
'redirect' => opalestate_submssion_page( $post_id, [ 'do' => 'completed' ] ),
] );
}
} else {
return opalestate_output_msg_json( fales,
__( 'Currently, your account was blocked, please keep contact admin to resolve this!.', 'opalestate-pro' ),
array('heading' => esc_html__('Submission Information' ,'opalestate-pro') )
[ 'heading' => esc_html__( 'Submission Information', 'opalestate-pro' ) ]
);
}
}
return opalestate_output_msg_json( fales,
__( 'Sorry! Your submitted datcould not save a at this time', 'opalestate-pro' ),
array('heading' => esc_html__('Submission Information', 'opalestate-pro') )
[ 'heading' => esc_html__( 'Submission Information', 'opalestate-pro' ) ]
);
}
}
@ -552,8 +569,9 @@ class OpalEstate_Submission {
}
/**
* Process upload files.
*
*
* @param int $post_id Post ID.
*/
private function process_upload_files( $post_id ) {
@ -561,10 +579,10 @@ class OpalEstate_Submission {
if ( isset( $_FILES ) && ! empty( $_FILES ) ) {
///
$fields = array(
$fields = [
$this->get_field_name( 'gallery' ),
$this->get_field_name( 'featured_image' ),
);
];
foreach ( $_FILES as $key => $value ) {
// allow processing in fixed collection
@ -573,26 +591,25 @@ class OpalEstate_Submission {
/// /////
if ( isset( $ufile['name'] ) && is_array( $ufile['name'] ) ) {
$output = array();
$output = [];
foreach ( $ufile['name'] as $f_key => $f_value ) {
$loop_file = array(
$loop_file = [
'name' => $ufile['name'][ $f_key ],
'type' => $ufile['type'][ $f_key ],
'tmp_name' => $ufile['tmp_name'][ $f_key ],
'error' => $ufile['error'][ $f_key ],
'size' => $ufile['size'][$f_key]
);
'size' => $ufile['size'][ $f_key ],
];
$new_atm = $this->upload_image( $loop_file, $post_id );
if ( $new_atm ) {
$_POST[$key] = isset($_POST[$key]) ? $_POST[$key] : array();
$_POST[ $key ] = isset( $_POST[ $key ] ) ? $_POST[ $key ] : [];
$_POST[ $key ][ $new_atm['attachment_id'] ] = $new_atm['url'];
$this->new_attachmenet_ids[ $new_atm['attachment_id'] ] = $new_atm['attachment_id'];
}
}
}
///
} ///
elseif ( isset( $ufile['name'] ) ) {
$new_atm = $this->upload_image( $ufile, $post_id );
if ( $new_atm ) {
@ -605,28 +622,26 @@ class OpalEstate_Submission {
}
// for group files
$fields = array(
$this->get_field_name('public_floor_group')
);
$fields = [
$this->get_field_name( 'public_floor_group' ),
];
foreach ( $_FILES as $key => $value ) {
if ( in_array( $key, $fields ) ) {
$ufile = $_FILES[ $key ];
if ( isset( $ufile['name'] ) && is_array( $ufile['name'] ) ) {
$output = array();
$output = [];
foreach ( $ufile['name'] as $f_key => $f_value ) {
foreach ( $f_value as $u_key => $u_v ) {
$loop_file = array(
$loop_file = [
'name' => $ufile['name'][ $f_key ][ $u_key ],
'type' => $ufile['type'][ $f_key ][ $u_key ],
'tmp_name' => $ufile['tmp_name'][ $f_key ][ $u_key ],
'error' => $ufile['error'][ $f_key ][ $u_key ],
'size' => $ufile['size'][$f_key][$u_key]
);
'size' => $ufile['size'][ $f_key ][ $u_key ],
];
$new_atm = $this->upload_image( $loop_file, $post_id );
if ( $new_atm ) {
@ -642,7 +657,6 @@ class OpalEstate_Submission {
}
}
/**
* Process upload images for properties
*/

View File

@ -7,7 +7,12 @@ $type = OpalEstate()->session->get( 'submission' );
<div class="inner">
<?php if ( $type == 'addnew' ): ?>
<div class="addnew-msg">
<h5><?php echo esc_html__('Thanks for your submission, it takes some time to review the property.'); ?></h5>
<?php if ( 'on' != opalestate_get_option( 'admin_approve', 'on' ) ) : ?>
<h5><?php esc_html_e( 'Thanks for your submission, your property is published.', 'opalestate-pro' ); ?></h5>
<?php else : ?>
<h5><?php esc_html_e( 'Thanks for your submission, it takes some time to review the property.', 'opalestate-pro' ); ?></h5>
<?php endif; ?>
<?php echo sprintf( esc_html__( 'Click to %s here %s to back to your listing or %s edit %s this.', 'opalestate-pro' ),
'<a href="' . opalestate_submssion_list_page() . '">', '</a>',
'<a href="' . opalestate_submssion_page( $post_id ) . '">', '</a>'
@ -15,7 +20,7 @@ $type = OpalEstate()->session->get( 'submission' );
</div>
<?php else : ?>
<div class="edit-msg">
<?php echo esc_html__('Your property is completed success.'); ?>
<?php esc_html_e( 'Your property is completed success.', 'opalestate-pro' ); ?>
<?php echo sprintf( esc_html__( 'Click to %s here %s to back to your listing or %s edit %s this.', 'opalestate-pro' ),
'<a href="' . opalestate_submssion_list_page() . '">', '</a>',
'<a href="' . opalestate_submssion_page( $post_id ) . '">', '</a>'
@ -24,4 +29,5 @@ $type = OpalEstate()->session->get( 'submission' );
<?php endif; ?>
</div>
</div>
<?php OpalEstate()->session->set( 'submission', null ); ?>