Update agent & agency frontend save

This commit is contained in:
Hoang Huu 2019-10-02 09:45:09 +07:00
parent 600a53371d
commit 5a80db936e
3 changed files with 8 additions and 25 deletions

@ -124,7 +124,6 @@ class Opalestate_Agency_Front {
* *
*/ */
private function update_data_agent_or_agency( $prefix ) { private function update_data_agent_or_agency( $prefix ) {
global $current_user; global $current_user;
$post_id = isset( $_POST['object_id'] ) && absint( $_POST['object_id'] ) ? $_POST['object_id'] : 0; $post_id = isset( $_POST['object_id'] ) && absint( $_POST['object_id'] ) ? $_POST['object_id'] : 0;
@ -154,6 +153,7 @@ class Opalestate_Agency_Front {
unset( $_POST[ $prefix . 'text' ] ); unset( $_POST[ $prefix . 'text' ] );
if ( $data['ID'] > 0 ) { if ( $data['ID'] > 0 ) {
$data['post_status'] = 'publish';
$post_id = wp_update_post( $data, true ); $post_id = wp_update_post( $data, true );
} else { } else {
$data['post_status'] = 'pending'; $data['post_status'] = 'pending';
@ -275,11 +275,8 @@ class Opalestate_Agency_Front {
} }
public function on_save_front_data() { public function on_save_front_data() {
if ( isset( $_POST[ 'nonce_CMB2php' . OPALESTATE_AGENCY_PREFIX . 'front' ] ) ) { if ( isset( $_POST[ 'nonce_CMB2php' . OPALESTATE_AGENCY_PREFIX . 'front' ] ) ) {
$post_id = isset( $_POST['object_id'] ) && $_POST['object_id'] ? absint( $_POST['object_id'] ) : 0; $post_id = isset( $_POST['object_id'] ) && $_POST['object_id'] ? absint( $_POST['object_id'] ) : 0;
$post = get_post( $post_id ); $post = get_post( $post_id );
$post_id = $this->update_data_agent_or_agency( OPALESTATE_AGENCY_PREFIX ); $post_id = $this->update_data_agent_or_agency( OPALESTATE_AGENCY_PREFIX );
@ -368,7 +365,7 @@ class Opalestate_Agency_Front {
$post = get_post( $post_id ); $post = get_post( $post_id );
if ( isset( $post->ID ) && ( $post->post_status != 'publish' || $post->ID == get_the_ID() ) ) { if ( isset( $post->ID ) && ( $post->post_status != 'publish' || $post->ID == get_the_ID() ) ) {
opalestate_add_notice( 'warning', esc_html__( 'You account is under reviewing! It take some time to process.', 'opalestate-pro' ) ); opalestate_add_notice( 'warning', esc_html__( 'You need to enter some required information to publish your account.', 'opalestate-pro' ) );
add_action( 'opalestate_profile_agency_form_before', 'opalestate_print_notices' ); add_action( 'opalestate_profile_agency_form_before', 'opalestate_print_notices' );
} }
@ -516,7 +513,6 @@ class Opalestate_Agency_Front {
'post_author' => $user_id, 'post_author' => $user_id,
], true ); ], true );
do_action( 'opalesate_insert_user_agency', $agency_id ); do_action( 'opalesate_insert_user_agency', $agency_id );
return $agency_id; return $agency_id;

@ -102,7 +102,7 @@ class Opalestate_Agent_Front {
$post = get_post( $post_id ); $post = get_post( $post_id );
if ( isset( $post->ID ) && ( $post->post_status != 'publish' || $post->ID == get_the_ID() ) ) { if ( isset( $post->ID ) && ( $post->post_status != 'publish' || $post->ID == get_the_ID() ) ) {
opalestate_add_notice( 'warning', esc_html__( 'You account is under reviewing! It take some time to process.', 'opalestate-pro' ) ); opalestate_add_notice( 'warning', esc_html__( 'You need to enter some required information to publish your account.', 'opalestate-pro' ) );
add_action( 'opalestate_profile_agent_form_before', 'opalestate_print_notices' ); add_action( 'opalestate_profile_agent_form_before', 'opalestate_print_notices' );
} }
@ -191,9 +191,7 @@ class Opalestate_Agent_Front {
} }
public function on_save_front_data() { public function on_save_front_data() {
if ( isset( $_POST[ 'nonce_CMB2php' . OPALESTATE_AGENT_PREFIX . 'front' ] ) ) { if ( isset( $_POST[ 'nonce_CMB2php' . OPALESTATE_AGENT_PREFIX . 'front' ] ) ) {
$post_id = $this->update_data_agent_or_agency( OPALESTATE_AGENT_PREFIX ); $post_id = $this->update_data_agent_or_agency( OPALESTATE_AGENT_PREFIX );
if ( $post_id ) { if ( $post_id ) {
@ -254,12 +252,11 @@ class Opalestate_Agent_Front {
'post_content' => wp_kses( $_POST[ $prefix . 'text' ], '<b><strong><i><em><h1><h2><h3><h4><h5><h6><pre><code><span><p>' ), 'post_content' => wp_kses( $_POST[ $prefix . 'text' ], '<b><strong><i><em><h1><h2><h3><h4><h5><h6><pre><code><span><p>' ),
]; ];
unset( $_POST[ $prefix . 'title' ] ); unset( $_POST[ $prefix . 'title' ] );
unset( $_POST[ $prefix . 'text' ] ); unset( $_POST[ $prefix . 'text' ] );
if ( $data['ID'] > 0 ) { if ( $data['ID'] > 0 ) {
$data['post_status'] = 'publish';
$post_id = wp_update_post( $data, true ); $post_id = wp_update_post( $data, true );
} else { } else {
$data['post_status'] = 'pending'; $data['post_status'] = 'pending';
@ -307,9 +304,7 @@ class Opalestate_Agent_Front {
} }
public function register_shortcodes() { public function register_shortcodes() {
$this->shortcodes = [ $this->shortcodes = [
'change_agent_profile' => [ 'code' => 'change_agent_profile', 'label' => esc_html__( 'Agent Profile', 'opalestate-pro' ) ], 'change_agent_profile' => [ 'code' => 'change_agent_profile', 'label' => esc_html__( 'Agent Profile', 'opalestate-pro' ) ],
'search_agents' => [ 'code' => 'search_agents', 'label' => esc_html__( 'Search Agents', 'opalestate-pro' ) ], 'search_agents' => [ 'code' => 'search_agents', 'label' => esc_html__( 'Search Agents', 'opalestate-pro' ) ],
'agent_carousel' => [ 'code' => 'agent_carousel', 'label' => esc_html__( 'Agent Carousel', 'opalestate-pro' ) ], 'agent_carousel' => [ 'code' => 'agent_carousel', 'label' => esc_html__( 'Agent Carousel', 'opalestate-pro' ) ],
@ -318,11 +313,9 @@ class Opalestate_Agent_Front {
foreach ( $this->shortcodes as $shortcode ) { foreach ( $this->shortcodes as $shortcode ) {
add_shortcode( 'opalestate_' . $shortcode['code'], [ $this, $shortcode['code'] ] ); add_shortcode( 'opalestate_' . $shortcode['code'], [ $this, $shortcode['code'] ] );
} }
} }
public function agent_carousel( $atts ) { public function agent_carousel( $atts ) {
$atts = is_array( $atts ) ? $atts : []; $atts = is_array( $atts ) ? $atts : [];
$layout = 'search-agency-form'; $layout = 'search-agency-form';
@ -341,9 +334,7 @@ class Opalestate_Agent_Front {
} }
public function archives_query( $query ) { public function archives_query( $query ) {
if ( $query->is_main_query() && is_post_type_archive( 'opalestate_agent' ) ) { if ( $query->is_main_query() && is_post_type_archive( 'opalestate_agent' ) ) {
$args = []; $args = [];
$min = opalestate_options( 'search_agent_min_price', 0 ); $min = opalestate_options( 'search_agent_min_price', 0 );
@ -368,7 +359,6 @@ class Opalestate_Agent_Front {
$tax_query = []; $tax_query = [];
if ( isset( $_GET['location'] ) && $_GET['location'] != -1 ) { if ( isset( $_GET['location'] ) && $_GET['location'] != -1 ) {
$tax_query[] = $tax_query[] =
[ [
@ -411,7 +401,6 @@ class Opalestate_Agent_Front {
] ); ] );
} }
///// search by address and geo location /// ///// search by address and geo location ///
if ( isset( $_GET['geo_long'] ) && isset( $_GET['geo_lat'] ) ) { if ( isset( $_GET['geo_long'] ) && isset( $_GET['geo_lat'] ) ) {

@ -1,7 +1,5 @@
<div class="property-submission-form"> <div class="property-submission-form">
<div class="opalestate-admin-box"> <div class="opalestate-admin-box">
<div class="box-content"> <div class="box-content">
<h3><?php esc_html_e( 'Edit Agent Profile', 'opalestate-pro' ); ?></h3> <h3><?php esc_html_e( 'Edit Agent Profile', 'opalestate-pro' ); ?></h3>
@ -11,7 +9,7 @@
if ( function_exists( 'cmb2_get_metabox_form' ) ) { if ( function_exists( 'cmb2_get_metabox_form' ) ) {
echo cmb2_get_metabox_form( $metaboxes[ OPALESTATE_AGENT_PREFIX . 'front' ], $post_id, [ echo cmb2_get_metabox_form( $metaboxes[ OPALESTATE_AGENT_PREFIX . 'front' ], $post_id, [
'form_format' => '<form action="//' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . '" class="cmb-form" method="post" id="%1$s" enctype="multipart/form-data" encoding="multipart/form-data"><input type="hidden" name="object_id" value="%2$s">%3$s<button type="submit" name="submit-cmb" class="button-primary btn btn-primary">%4$s</button></form>', 'form_format' => '<form action="//' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . '" class="cmb-form" method="post" id="%1$s" enctype="multipart/form-data"><input type="hidden" name="object_id" value="%2$s">%3$s<button type="submit" name="submit-cmb" class="button-primary btn btn-primary">%4$s</button></form>',
'save_button' => esc_html__( 'Save Change', 'opalestate-pro' ), 'save_button' => esc_html__( 'Save Change', 'opalestate-pro' ),
] ); ] );
} }