Update functions.
This commit is contained in:
parent
b57e76d12f
commit
f8b6371ee5
@ -52,7 +52,6 @@ class Opalestate_Agent_Front {
|
||||
* Auto update meta information to post from user data updated or created
|
||||
*/
|
||||
public function init() {
|
||||
|
||||
add_action( 'opalestate_on_set_role_agent', [ $this, 'on_set_role' ], 1, 9 );
|
||||
add_filter( 'opalestate_before_render_profile_agent_form', [ $this, 'render_front_form' ], 2, 2 );
|
||||
add_filter( 'pre_get_posts', [ $this, 'archives_query' ], 1 );
|
||||
@ -66,7 +65,10 @@ class Opalestate_Agent_Front {
|
||||
|
||||
|
||||
/**
|
||||
* render_extra_profile_link.
|
||||
* Render extra profile link.
|
||||
*
|
||||
* @param $menu
|
||||
* @return mixed
|
||||
*/
|
||||
public function render_extra_profile_link( $menu ) {
|
||||
global $current_user;
|
||||
@ -133,12 +135,14 @@ class Opalestate_Agent_Front {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process upload files.
|
||||
*
|
||||
* @param int $post_id Post ID.
|
||||
*/
|
||||
private function process_upload_files( $post_id ) {
|
||||
|
||||
//upload images for featured and gallery images
|
||||
// Upload images for featured and gallery images.
|
||||
if ( isset( $_FILES ) && ! empty( $_FILES ) ) {
|
||||
|
||||
///
|
||||
$fields = [
|
||||
$this->get_field_name( 'gallery' ),
|
||||
$this->get_field_name( 'avatar_id' ),
|
||||
@ -146,11 +150,11 @@ class Opalestate_Agent_Front {
|
||||
];
|
||||
|
||||
foreach ( $_FILES as $key => $value ) {
|
||||
// allow processing in fixed collection
|
||||
// Allow processing in fixed collection.
|
||||
if ( in_array( $key, $fields ) ) {
|
||||
$ufile = $_FILES[ $key ];
|
||||
|
||||
/// /////
|
||||
|
||||
if ( isset( $ufile['name'] ) && is_array( $ufile['name'] ) ) {
|
||||
$output = [];
|
||||
|
||||
@ -180,16 +184,20 @@ class Opalestate_Agent_Front {
|
||||
$_key = str_replace( "_id", "", $key );
|
||||
$_POST[ $_key ] = $new_atm['url'];
|
||||
}
|
||||
|
||||
$this->new_attachmenet_ids[ $new_atm['attachment_id'] ] = $new_atm['attachment_id'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* On save front data.
|
||||
*
|
||||
* @return false|mixed|string|void
|
||||
*/
|
||||
public function on_save_front_data() {
|
||||
if ( isset( $_POST[ 'nonce_CMB2php' . OPALESTATE_AGENT_PREFIX . 'front' ] ) ) {
|
||||
$post_id = $this->update_data_agent_or_agency( OPALESTATE_AGENT_PREFIX );
|
||||
@ -217,14 +225,14 @@ class Opalestate_Agent_Front {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Get field name.
|
||||
*/
|
||||
private function get_field_name( $field ) {
|
||||
return OPALESTATE_AGENT_PREFIX . $field;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Update data for agent or agency.
|
||||
*/
|
||||
private function update_data_agent_or_agency( $prefix ) {
|
||||
global $current_user;
|
||||
@ -270,7 +278,7 @@ class Opalestate_Agent_Front {
|
||||
/*
|
||||
* Processing upload files
|
||||
*/
|
||||
$this->process_upload_files( $post_id, $_POST );
|
||||
$this->process_upload_files( $post_id );
|
||||
|
||||
cmb2_get_metabox_form( $metaboxes[ $prefix . 'front' ], $post_id );
|
||||
$cmb = cmb2_get_metabox( $prefix . 'front', $post_id );
|
||||
@ -333,22 +341,21 @@ class Opalestate_Agent_Front {
|
||||
return opalestate_load_template_path( 'shortcodes/agent-carousel', $atts );
|
||||
}
|
||||
|
||||
/**
|
||||
* Archive query.
|
||||
*
|
||||
* @param $query
|
||||
* @return mixed
|
||||
*/
|
||||
public function archives_query( $query ) {
|
||||
if ( $query->is_main_query() && is_post_type_archive( 'opalestate_agent' ) ) {
|
||||
$args = [];
|
||||
|
||||
$min = opalestate_options( 'search_agent_min_price', 0 );
|
||||
$max = opalestate_options( 'search_agent_max_price', 10000000 );
|
||||
|
||||
|
||||
$min = opalestate_options( 'search_agent_min_price', 0 );
|
||||
$max = opalestate_options( 'search_agent_max_price', 10000000 );
|
||||
$search_min_price = isset( $_GET['min_price'] ) ? sanitize_text_field( $_GET['min_price'] ) : '';
|
||||
$search_max_price = isset( $_GET['max_price'] ) ? sanitize_text_field( $_GET['max_price'] ) : '';
|
||||
|
||||
$search_min_area = isset( $_GET['min_area'] ) ? sanitize_text_field( $_GET['min_area'] ) : '';
|
||||
$search_max_area = isset( $_GET['max_area'] ) ? sanitize_text_field( $_GET['max_area'] ) : '';
|
||||
$s = isset( $_GET['search_text'] ) ? sanitize_text_field( $_GET['search_text'] ) : null;
|
||||
|
||||
|
||||
$paged = ( get_query_var( 'paged' ) == 0 ) ? 1 : get_query_var( 'paged' );
|
||||
$default = [
|
||||
'post_type' => 'opalestate_agent',
|
||||
@ -436,9 +443,10 @@ class Opalestate_Agent_Front {
|
||||
return $query;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Search agents.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function search_agents() {
|
||||
return opalestate_load_template_path( 'shortcodes/search-agents' );
|
||||
@ -470,6 +478,13 @@ class Opalestate_Agent_Front {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create agent.
|
||||
*
|
||||
* @param array $args
|
||||
* @param $user_id
|
||||
* @return int|\WP_Error
|
||||
*/
|
||||
public function create_agent( $args = [], $user_id ) {
|
||||
$data = get_user_by( 'id', $user_id );
|
||||
|
||||
@ -515,7 +530,11 @@ class Opalestate_Agent_Front {
|
||||
}
|
||||
|
||||
/**
|
||||
* Render front form.
|
||||
*
|
||||
* @param $metaboxes
|
||||
* @param int $post_id
|
||||
* @return mixed
|
||||
*/
|
||||
public function render_front_form( $metaboxes, $post_id = 0 ) {
|
||||
$metabox = new Opalestate_Agent_MetaBox();
|
||||
|
@ -40,15 +40,13 @@ function opalestate_output_msg_json( $result = false, $message = '', $args = [],
|
||||
* Process upload images for properties
|
||||
*/
|
||||
function opalesate_upload_image( $submitted_file, $parent_id = 0 ) {
|
||||
|
||||
// do_action( 'opalestate_before_process_ajax_upload_file' );
|
||||
|
||||
require_once ABSPATH . 'wp-admin/includes/image.php';
|
||||
require_once ABSPATH . 'wp-admin/includes/image.php';
|
||||
require_once ABSPATH . 'wp-admin/includes/file.php';
|
||||
require_once ABSPATH . 'wp-admin/includes/media.php';
|
||||
|
||||
$uploaded_image = wp_handle_upload( $submitted_file,
|
||||
[ 'test_form' => false ] ); //Handle PHP uploads in WordPress, sanitizing file names, checking extensions for mime type, and moving the file to the appropriate directory within the uploads directory.
|
||||
// Handle PHP uploads in WordPress, sanitizing file names, checking extensions for mime type, and moving the
|
||||
// file to the appropriate directory within the uploads directory.
|
||||
$uploaded_image = wp_handle_upload( $submitted_file, [ 'test_form' => false ] );
|
||||
|
||||
if ( isset( $uploaded_image['file'] ) ) {
|
||||
$file_name = basename( $submitted_file['name'] );
|
||||
@ -63,10 +61,15 @@ function opalesate_upload_image( $submitted_file, $parent_id = 0 ) {
|
||||
'post_status' => 'inherit',
|
||||
];
|
||||
|
||||
$attach_id = wp_insert_attachment( $attachment_details, $uploaded_image['file'], $parent_id ); // This function inserts an attachment into the media library
|
||||
$attach_data = wp_generate_attachment_metadata( $attach_id,
|
||||
$uploaded_image['file'] ); // This function generates metadata for an image attachment. It also creates a thumbnail and other intermediate sizes of the image attachment based on the sizes defined
|
||||
wp_update_attachment_metadata( $attach_id, $attach_data ); // Update metadata for an attachment.
|
||||
// This function inserts an attachment into the media library.
|
||||
$attach_id = wp_insert_attachment( $attachment_details, $uploaded_image['file'], $parent_id );
|
||||
|
||||
// This function generates metadata for an image attachment.
|
||||
// It also creates a thumbnail and other intermediate sizes of the image attachment based on the sizes defined
|
||||
$attach_data = wp_generate_attachment_metadata( $attach_id, $uploaded_image['file'] );
|
||||
|
||||
// Update metadata for an attachment.
|
||||
wp_update_attachment_metadata( $attach_id, $attach_data );
|
||||
|
||||
$thumbnail_url = opalestate_get_upload_image_url( $attach_data );
|
||||
|
||||
@ -79,7 +82,6 @@ function opalesate_upload_image( $submitted_file, $parent_id = 0 ) {
|
||||
update_post_meta( $attach_id, '_pending_to_use_', 1 );
|
||||
|
||||
return $ajax_response;
|
||||
|
||||
}
|
||||
|
||||
return [];
|
||||
|
Loading…
Reference in New Issue
Block a user