PATH:
home
/
letacommog
/
laindinois
/
OLD
/
wp-content
/
plugins
/
dwt-listing-rest-api
/
classes
/
profile
<?php add_action( 'rest_api_init', 'dwt_listing_profile_events_hooks_get', 0 ); function dwt_listing_profile_events_hooks_get() { register_rest_route( 'downtown/app', '/my-events/', array( 'methods' => WP_REST_Server::READABLE, 'callback' => 'dwt_listing_get_my_events', 'permission_callback' => function () { return dwt_listing_basic_auth(); }, ) ); register_rest_route( 'downtown/app', '/my-events/', array( 'methods' => WP_REST_Server::EDITABLE, 'callback' => 'dwt_listing_get_my_events', 'permission_callback' => function () { return dwt_listing_basic_auth(); }, ) ); } // Get My Personal Events if (!function_exists('dwt_listing_get_my_events')) { function dwt_listing_get_my_events($request) { global $dwt_listing_api; global $dwt_listing_options; $user = wp_get_current_user(); $user_id = $user->ID; $user_events = $event_arr = array(); $event_arr['e_publish'] = esc_html__("Published Events", "dwt-listing-api"); $event_arr['e_pending'] = esc_html__("Pending Events", "dwt-listing-api"); $event_arr['e_expired'] = esc_html__("Expired Events", "dwt-listing-api"); $event_arr['admin_approval'] = esc_html__("Waiting for admin approval.", "dwt-listing-api"); $event_arr['from'] = esc_html__('From ','dwt-listing-api'); $event_arr['to'] = esc_html__('To ','dwt-listing-api'); $event_arr['venue'] = esc_html__('Venue ','dwt-listing-api'); $event_arr['e_edit'] = esc_html__("Edit", "dwt-listing-api"); $event_arr['e_delete'] = esc_html__("Delete", "dwt-listing-api"); $event_arr['e_expire'] = esc_html__("Expired", "dwt-listing-api"); $event_arr['create'] = esc_html__("Create Event", "dwt-listing-api"); $event_arr['update_event'] = esc_html__("Update Event", "dwt-listing-api"); $event_arr['delete_msg'] = esc_html__("Are you sure you want to do this?", "dwt-listing-api"); $event_arr['gallery_limit'] = $dwt_listing_options['dwt_listing_event_upload_limit']; $event_arr['gallery_limit_mgs'] = sprintf( esc_html__('Sorry you cant upload more than %s images.', 'dwt-listing-api' ), $dwt_listing_options['dwt_listing_event_upload_limit'] ); $event_arr['required_msg'] = esc_html__("You are required to fill out all fields.", "dwt-listing-api"); $limit = 10; if(isset($dwt_listing_api['app_dashboard_user_events']) && $dwt_listing_api['app_dashboard_user_events'] !="") { $limit = $dwt_listing_api['app_dashboard_user_events']; } //publish events $user_events['active_events'] = dwt_listing_get_my_personal_reviews('publish',$limit,$user_id); //pending events $user_events['pending_events'] = dwt_listing_get_my_personal_reviews('pending',$limit,$user_id); //pending events $user_events['expired_events'] = dwt_listing_get_my_personal_reviews('expired',$limit,$user_id); $event_arr['my_events'] = $user_events; //create event //get user listings $parent_listing = ''; $my_listings = dwt_listing_fetch_my_listings_inapp($user_id); //Categories $event_cats = dwt_listing_categories_fetch('l_event_cat' , 0 ); $event_categories = array(); if(!empty($event_cats) && is_array($event_cats) && count($event_cats) > 0) { foreach($event_cats as $eventz) { $event_categories[] = array("category_id" =>$eventz->term_id,"category_name" => dwt_listing_convert_uniText($eventz->name)); } } $event_creatz['title'] = array("main_title" => __("Event Title", "dwt-listing-api"), "placeholder" =>__("Food festival in lahore", "dwt-listing-api"),"is_required" => true,"value" => ''); $event_creatz['category'] = array("main_title" => __("Select Category", "dwt-listing-api"), "placeholder" =>__("Select Event Category", "dwt-listing-api"),"is_required" => true,"value" => '',"dropdown" => $event_categories); $event_creatz['phone'] = array("main_title" => __("Phone Number", "dwt-listing-api"), "placeholder" =>__("+99 3331 234567", "dwt-listing-api"),"is_required" => false,"value" => ''); $event_creatz['email'] = array("main_title" => __("Contact Email", "dwt-listing-api"), "placeholder" =>__("abc@xyz.com", "dwt-listing-api"),"is_required" => true,"value" => ''); $event_creatz['desc'] = array("main_title" => __("Description", "dwt-listing-api"), "placeholder" =>__("Event detials here...", "dwt-listing-api"),"is_required" => true,"value" => ''); $event_creatz['date_start'] = array("main_title" => __("Event Start Date", "dwt-listing-api"), "placeholder" =>__("Event starting date", "dwt-listing-api"),"is_required" => true,"value" => ''); $event_creatz['date_end'] = array("main_title" => __("Event Start Date", "dwt-listing-api"), "placeholder" =>__("Event ending date", "dwt-listing-api"),"is_required" => true,"value" => ''); $event_creatz['gallery'] = array("main_title" => __("Event Gallery", "dwt-listing-api"), "placeholder" =>__("Select Pics", "dwt-listing-api"),"is_required" => true,"has_gallery" =>false, "dropdown" => ''); $event_creatz['location'] = array("main_title" => __("Event Location", "dwt-listing-api"), "placeholder" =>__("Deluxe Diner Division No. 18, Canada", "dwt-listing-api"),"is_required" => true,"value" => ''); $event_creatz['latt'] = array("main_title" => __("Latitude", "dwt-listing-api"), "placeholder" =>dwt_listing_text('dwt_listing_list_lati_place'),"is_required" => true,"value" => ''); $event_creatz['long'] = array("main_title" => __("Longitude", "dwt-listing-api"), "placeholder" =>dwt_listing_text('dwt_listing_list_longi_place'),"is_required" => true,"value" => ''); $event_creatz['related'] = array("main_title" => __("Related Listing (Optional)", "dwt-listing-api"), "placeholder" =>__("Select Your Listing", "dwt-listing-api"),"is_required" => true,"value" => '',"dropdown" => $my_listings); $event_arr['create_event'] =$event_creatz; $event_arr['profile_data'] = dwt_listing_basic_profile_data(); $response = array( 'success' => true, 'data' => $event_arr, "message" => ""); return $response; } } // Get My More Events add_action( 'rest_api_init', 'dwt_listing_profile_events_hooks_get_more', 0 ); function dwt_listing_profile_events_hooks_get_more() { register_rest_route( 'downtown/app', '/load-my-events/', array( 'methods' => WP_REST_Server::EDITABLE, 'callback' => 'dwt_listing_load_my_events', 'permission_callback' => function () { return dwt_listing_basic_auth(); }, ) ); } if (!function_exists('dwt_listing_load_my_events')) { function dwt_listing_load_my_events($request) { global $dwt_listing_api; $param = $request->get_json_params(); if(isset($param['event_type']) && $param['event_type'] !="" ) { $user = wp_get_current_user(); $user_id = $user->ID; $limit = 10; if(isset($dwt_listing_api['app_dashboard_user_events']) && $dwt_listing_api['app_dashboard_user_events'] !="") { $limit = $dwt_listing_api['app_dashboard_user_events']; } $my_count = $original_status = $response = ''; $meta_query_args = $listingz = array(); $meta_key = ''; $meta_value = ''; $meta_compare = '='; $original_status = $param['event_type']; if($param['event_type'] == 'publish') { $event_status = 'publish'; $meta_query_args = array(array('key'=>'dwt_listing_event_status','value' => 1,'compare' => '=')); } else if($param['event_type'] == 'pending') { $event_status = 'pending'; $meta_query_args = array(array('key'=>'dwt_listing_event_status','value' => 1,'compare' => '=')); } else if($param['event_type'] == 'expired') { $event_status = 'publish'; $meta_key = 'dwt_listing_event_status'; $meta_value = '0'; } else { $event_status = 'publish'; $meta_query_args = array(array('key'=>'dwt_listing_event_status','value' => 1,'compare' => '=')); } if(!empty($param['next_page'])) { $page = $param['next_page']; } else { $page = 1; } $args = array ( 'post_type' => 'events', 'author' => $user_id, 'post_status' => $event_status, 'posts_per_page' => $limit, 'paged' => $page, 'order'=> 'DESC', 'orderby' => 'date', 'meta_key' => $meta_key , 'meta_value' =>$meta_value, 'meta_query' => $meta_query_args ); $my_events = new WP_Query($args); if ($my_events->have_posts()) { $lists = array(); $pieces = $category_name = $categor_id = $listing_cats = $total_leads = $contact_leads = $web_leads = $total_views = $status_type = $b_status = $is_featured = ''; while ( $my_events->have_posts() ) { $my_events->the_post(); $event_id = get_the_ID(); $media = dwt_listing_fetch_event_gallery($event_id); $event_start_date = get_post_meta($event_id, 'dwt_listing_event_start_date', true ); $event_end_date = get_post_meta($event_id, 'dwt_listing_event_end_date', true ); $event_venue = get_post_meta($event_id, 'dwt_listing_event_venue', true); $term_list = wp_get_post_terms($event_id, 'l_event_cat', array("fields" => "all")); if(!empty($term_list)) { $link = get_term_link($term_list[0]->term_id); $category_name = $term_list[0]->name; } if($event_start_date !="" && $event_end_date !="") { $event_start = date_i18n( get_option( 'date_format'), strtotime( $event_start_date ) ); $event_end = date_i18n( get_option( 'date_format'), strtotime( $event_end_date ) ); } $final_title = $limited_title = ''; if(isset($dwt_listing_api['app_title_limit']) && $dwt_listing_api['app_title_limit'] !="") { $limited_title = dwt_listing_words_count(get_the_title($event_id), $dwt_listing_api['app_title_limit']); $final_title = stripslashes_deep(wp_strip_all_tags(str_replace("|"," ",$limited_title))); } else { $final_title = get_the_title($event_id); } $limited_title_venue = $e_vanue; if(isset($dwt_listing_api['app_title_event_venue']) && $dwt_listing_api['app_title_event_venue'] !="") { $limited_title_venue = dwt_listing_words_count($event_venue, $dwt_listing_api['app_title_event_venue']); $e_vanue = stripslashes_deep(wp_strip_all_tags(str_replace("|"," ",$limited_title_venue))); } $eventz[] = array( "event_id" => $event_id, "event_category_name" => dwt_listing_convert_uniText($category_name), "event_title" => dwt_listing_convert_uniText($final_title), "image" => dwt_listing_return_event_idz_app($media,'dwt_listing_locations-thumb'), "event_loc" => $e_vanue, "event_start_date" => $event_start, "event_end_date" => $event_end, ); } wp_reset_postdata(); } $lists['has_events'] = (count((array) $eventz) > 0) ? true : false; $lists['event_count'] = esc_html__("Total Events : ", "dwt-listing-api") . $my_events->found_posts; if(count((array) $eventz) > 0) { $lists['events'] = $eventz; } else { $lists['message'] = esc_html__("You dont have any event yet!", "dwt-listing-api"); } $has_next_page = $lastpage = $next = ''; //pagination $next = $page + 1; $lastpage = ceil($my_events->found_posts/$limit); $has_next_page = ($next <= (int)$lastpage) ? true : false; $lists[$original_status.'_'.'pagination'] = array("total_events" => $my_events->found_posts, "current_page" => (int)$page, "next_page" => (int)$next, "has_next_page" => $has_next_page ); return $lists; } } } // Edit My Event add_action( 'rest_api_init', 'dwt_listing_profile_events_hooks_get_update', 0 ); function dwt_listing_profile_events_hooks_get_update() { register_rest_route( 'downtown/app', '/edit-event/', array( 'methods' => WP_REST_Server::EDITABLE, 'callback' => 'dwt_listing_edit_my_events', 'permission_callback' => function () { return dwt_listing_basic_auth(); }, ) ); } if (!function_exists('dwt_listing_edit_my_events')) { function dwt_listing_edit_my_events($request) { global $dwt_listing_api; global $dwt_listing_options; $user = wp_get_current_user(); $user_id = $user->ID; $media = $event_cat = $term_list = $post = $event_desc = $event_title = $event_catz = $term_listz = $parent_listing = $listing_longitide = $listing_lattitude = $event_venue =$event_end_date =$event_start_date = $event_email =$event_contact = $event_id = ''; $json_data = $request->get_json_params(); $is_update = isset($json_data['is_update']) ? sanitize_text_field($json_data['is_update']) : ''; $update_id = ''; //check if there is event in progess $listing_lattitude = dwt_listing_text('dwt_listing_default_lat'); $listing_longitide = dwt_listing_text('dwt_listing_default_long'); //Categories $event_cats = dwt_listing_categories_fetch('l_event_cat' , 0 ); $event_categories = array(); if(!empty($event_cats) && is_array($event_cats) && count($event_cats) > 0) { foreach($event_cats as $eventz) { $event_categories[] = array("category_id" =>$eventz->term_id,"category_name" =>dwt_listing_convert_uniText($eventz->name)); } } $my_listings = dwt_listing_fetch_my_listings_inapp($user_id); $has_gallery = false; if($is_update !="") { $event_id = $is_update; $update_id = $is_update; $post = get_post($event_id); $event_title = dwt_listing_convert_uniText($post->post_title); $event_desc = dwt_listing_convert_uniText($post->post_content); $event_contact = get_post_meta($event_id, 'dwt_listing_event_contact', true); $event_email = get_post_meta($event_id, 'dwt_listing_event_email', true); $event_start_date = get_post_meta($event_id, 'dwt_listing_event_start_date', true); $event_end_date = get_post_meta($event_id, 'dwt_listing_event_end_date', true); $event_venue = get_post_meta($event_id, 'dwt_listing_event_venue', true); $listing_lattitude = get_post_meta($event_id, 'dwt_listing_event_lat', true); $listing_longitide = get_post_meta($event_id, 'dwt_listing_event_long', true); $parent_listing = get_post_meta($event_id, 'dwt_listing_event_listing_id', true); //event term $term_list = wp_get_post_terms($event_id, 'l_event_cat', array("fields" => "ids")); if(!empty($term_list)) { $event_cat = $term_list[0]; } //gallery $media = dwt_listing_fetch_event_gallery($event_id); if( count((array) $media ) > 0 ) { $has_gallery = true; foreach( $media as $m ) { $mid = ''; if ( isset( $m->ID ) ) { $mid = $m->ID; } else { $mid = $m; } $full_img = $thumb_imgs = ''; $full_img = wp_get_attachment_image_src($mid, 'dwt_listing_locations-thumb'); $gallery[] = array( "url" => esc_url($full_img[0]), "image_id" => esc_attr($mid), ); } } } $event_arr['gallery_limit'] = $dwt_listing_options['dwt_listing_event_upload_limit']; $event_arr['gallery_limit_mgs'] = sprintf( esc_html__('Sorry you cant upload more than %s images.', 'dwt-listing-api' ), $dwt_listing_options['dwt_listing_event_upload_limit'] ); $event_arr['required_msg'] = esc_html__("You are required to fillout all fields.", "dwt-listing-api"); $event_creatz['title'] = array("main_title" => __("Event Title", "dwt-listing-api"), "placeholder" =>__("Food festival in lahore", "dwt-listing-api"),"is_required" => true,"value" => $event_title); $event_creatz['category'] = array("main_title" => __("Select Category", "dwt-listing-api"), "placeholder" =>__("Select Event Category", "dwt-listing-api"),"is_required" => true,"value" => $event_cat,"dropdown" => $event_categories); $event_creatz['phone'] = array("main_title" => __("Phone Number", "dwt-listing-api"), "placeholder" =>__("+99 3331 234567", "dwt-listing-api"),"is_required" => false,"value" => $event_contact); $event_creatz['email'] = array("main_title" => __("Contact Email", "dwt-listing-api"), "placeholder" =>__("abc@xyz.com", "dwt-listing-api"),"is_required" => true,"value" => $event_email); $event_creatz['desc'] = array("main_title" => __("Description", "dwt-listing-api"), "placeholder" =>__("Event detials here...", "dwt-listing-api"),"is_required" => true,"value" => $event_desc); $event_creatz['date_start'] = array("main_title" => __("Event Start Date", "dwt-listing-api"), "placeholder" =>__("Event starting date", "dwt-listing-api"),"is_required" => true,"value" => $event_start_date); $event_creatz['date_end'] = array("main_title" => __("Event Start Date", "dwt-listing-api"), "placeholder" =>__("Event ending date", "dwt-listing-api"),"is_required" => true,"value" => $event_end_date); $event_creatz['gallery'] = array("main_title" => __("Event Gallery", "dwt-listing-api"), "placeholder" =>__("Select Pics", "dwt-listing-api"),"is_required" => true,"has_gallery" => $has_gallery,"dropdown" => $gallery); $event_creatz['location'] = array("main_title" => __("Event Location", "dwt-listing-api"), "placeholder" =>__("Deluxe Diner Division No. 18, Canada", "dwt-listing-api"),"is_required" => true,"value" => $event_venue); $event_creatz['latt'] = array("main_title" => __("Latitude", "dwt-listing-api"), "placeholder" =>dwt_listing_text('dwt_listing_list_lati_place'),"is_required" => true,"value" => $listing_lattitude); $event_creatz['long'] = array("main_title" => __("Longitude", "dwt-listing-api"), "placeholder" =>dwt_listing_text('dwt_listing_list_longi_place'),"is_required" => true,"value" => $listing_longitide); $event_creatz['related'] = array("main_title" => __("Related Listing (Optional)", "dwt-listing-api"), "placeholder" =>__("Select Your Listing", "dwt-listing-api"),"is_required" => true,"value" => $parent_listing,"dropdown" => $my_listings); $event_arr['create_event'] =$event_creatz; $response = array('success' => true, 'data' => $event_arr, "message" => ""); return $response; } } // Event Submission add_action( 'rest_api_init', 'dwt_listing_submission_event_hook', 0 ); function dwt_listing_submission_event_hook() { register_rest_route( 'downtown/app', '/event-submission/', array( 'methods' => WP_REST_Server::EDITABLE, 'callback' => 'dwt_listing_eventz_submission', 'permission_callback' => function () { return dwt_listing_basic_auth(); }, ) ); } if (!function_exists('dwt_listing_eventz_submission')) { function dwt_listing_eventz_submission($request) { global $dwt_listing_options; $user = wp_get_current_user(); $user_id = $user->ID; $json_data = $request->get_body_params(); $event_title = isset($json_data['title']) ? sanitize_text_field($json_data['title']) : ''; $event_cat = isset($json_data['category']) ? sanitize_text_field($json_data['category']) : ''; $event_number = isset($json_data['number']) ? sanitize_text_field($json_data['number']) : ''; $event_email = isset($json_data['email']) ? sanitize_text_field($json_data['email']) : ''; $event_desc = isset($json_data['desc']) ? sanitize_text_field($json_data['desc']) : ''; $event_start_date = isset($json_data['start_date']) ? sanitize_text_field($json_data['start_date']) : ''; $event_end_date = isset($json_data['end_date']) ? sanitize_text_field($json_data['end_date']) : ''; $event_venue = isset($json_data['venue']) ? sanitize_text_field($json_data['venue']) : ''; $event_lat = isset($json_data['lat']) ? sanitize_text_field($json_data['lat']) : ''; $event_long = isset($json_data['long']) ? sanitize_text_field($json_data['long']) : ''; $event_parent_listing = isset($json_data['parent_listing']) ? sanitize_text_field($json_data['parent_listing']) : ''; $is_update = isset($json_data['is_update']) ? sanitize_text_field($json_data['is_update']) : ''; if ( $_SERVER['REQUEST_METHOD'] == 'POST' && empty($_POST) && $_SERVER['CONTENT_LENGTH'] > 0) { $displayMaxSize = ini_get('post_max_size'); switch ( substr($displayMaxSize,-1) ) { case 'G': $displayMaxSize = (int)$displayMaxSize * 1024; case 'M': $displayMaxSize = (int)$displayMaxSize * 1024; case 'K': $displayMaxSize = (int) $displayMaxSize * 1024; } return rest_ensure_response(array( 'success' => false, 'data' => '', 'message' => sprintf( __( 'Posted data is too large %s bytes exceeds the maximum size of %d bytes.', 'dwt-listing-api' ), $_SERVER['CONTENT_LENGTH'], $displayMaxSize))); } if($event_title == '' || $event_cat == '' ||$event_number == '' ||$event_email == '' ||$event_desc == '' ||$event_start_date == '' ||$event_end_date == '' ||$event_venue == '' || $event_lat == '' || $event_long == '') { return array( 'success' => false, 'data' => '', 'message' => __( "Please fill out all fields", 'dwt-listing-api' )); } //$final_srat_date = date('mm/dd/yyyy h:i:s a', strtotime($date)); if(empty($is_update)) { if(get_user_meta($user_id, 'event_in_progress', true ) !="") { $event_id = get_user_meta ($user_id, 'event_in_progress', true ); if( get_post_status ( $event_id ) && $event_id != "" && get_post_status( $event_id ) == 'pending') { $event_id = $event_id; update_post_meta($event_id, 'dwt_listing_event_status', '' ); } else { update_user_meta($user_id, 'event_in_progress',''); $my_post = array( 'post_title' => '', 'post_status' => 'pending', 'post_author' => $user_id, 'post_type' => 'events' ); $id = wp_insert_post( $my_post ); if( $id ) { update_user_meta($user_id, 'event_in_progress', $id ); $event_id = $id; update_post_meta($event_id, 'dwt_listing_event_status', '' ); } } } else { $my_post = array( 'post_title' => '', 'post_status' => 'pending', 'post_author' => $user_id, 'post_type' => 'events' ); $id = wp_insert_post( $my_post ); if($id) { update_user_meta($user_id, 'event_in_progress', $id ); $event_id = $id; update_post_meta($event_id, 'dwt_listing_event_status', '' ); } } } $event_status = 'publish'; if( $is_update != "" ) { $event_id = $is_update; if( $dwt_listing_options['dwt_listing_event_up_approval'] == 'manual' ) { $event_status = 'pending'; } else if( $dwt_listing_options['dwt_listing_event_up_approval'] == 'auto' ) { $event_status = 'publish'; } else if( get_post_status( $event_id ) == 'pending' ) { $event_status = 'pending'; } else { $event_status = 'publish'; } } else { if( $dwt_listing_options['dwt_listing_event_approval'] == '0' ) { $event_status = 'pending'; } else { $event_status = 'publish'; } if(get_user_meta($user_id, 'event_in_progress', true) != "") { // Now user can post new ad //send email on event creation delete_user_meta($user_id, 'event_in_progress'); dwt_listing_notify_on_new_event($event_id); } } $uploaded_file_size = $actual_size = $display_size = $size_arr = $allowed_file_types = $uploaded_file_type = ''; $size_arr = explode( '-', $dwt_listing_options['dwt_listing_event_images_size'] ); $display_size = $size_arr[1]; $actual_size = $size_arr[0]; if ($_FILES) { $files = $_FILES["event_multiple_attachments"]; foreach ($files['name'] as $key => $value) { if ($files['name'][$key]) { $file = array( 'name' => $files['name'][$key], 'type' => $files['type'][$key], 'tmp_name' => $files['tmp_name'][$key], 'error' => $files['error'][$key], 'size' => $files['size'][$key] ); $uploaded_file_type = $files['type'][$key]; $uploaded_file_size = $files['size'][$key]; $allowed_file_types = array('image/jpg', 'image/jpeg', 'image/png'); if(!in_array($uploaded_file_type, $allowed_file_types)) { return rest_ensure_response(array( 'success' => false, 'data' => '', 'message' => __( "Sorry, only JPG, JPEG, and PNG files are allowed.",'dwt-listing-api' ))); } if ($uploaded_file_size > $actual_size){ return rest_ensure_response(array( 'success' => false, 'data' => '', 'message' => esc_html__( "Max allowed image size is", 'dwt-listing-api' ) . " " . $display_size)); } // Check max image limit $media = ''; $media = get_attached_media('image',$event_id); if(count( $media ) >= $dwt_listing_options['dwt_listing_event_upload_limit'] ) { $msg = esc_html__("Sorry you cant upload more than ",'dwt-listing-api'); $images_l = esc_html__(" images ",'dwt-listing-api'); return array( 'success' => false, 'data' => '', 'message' => $msg . $dwt_listing_options['dwt_listing_event_upload_limit'] . $images_l); } $_FILES = array ("event_multiple_attachments" => $file); foreach ($_FILES as $file => $array) { dwt_listing_events_images_up($file,$event_id); } } } } $my_eventz = array( 'ID' => $event_id, 'post_title' => $event_title, 'post_status' => $event_status, 'post_content' => $event_desc, 'post_name' =>$event_title ); wp_update_post($my_eventz); update_post_meta($event_id, 'dwt_listing_event_status', '1' ); update_post_meta($event_id, 'dwt_listing_event_contact', $event_number); update_post_meta($event_id, 'dwt_listing_event_email', $event_email); update_post_meta($event_id, 'dwt_listing_event_start_date', $event_start_date); update_post_meta($event_id, 'dwt_listing_event_end_date', $event_end_date); update_post_meta($event_id, 'dwt_listing_event_venue', $event_venue); update_post_meta($event_id, 'dwt_listing_event_lat', $event_lat); update_post_meta($event_id, 'dwt_listing_event_long', $event_long); update_post_meta($event_id, 'dwt_listing_event_listing_id', $event_parent_listing); wp_set_post_terms( $event_id, $event_cat, 'l_event_cat' ); //fetch data gainst event id $final_data = array(); $final_data['status'] = $event_status; $final_data['events'] = dwt_listing_get_single_event($event_id); if( $is_update != "" ) { return rest_ensure_response(array( 'success' => true, 'data' => $final_data, 'message' => __( "Event updated successfully", 'dwt-listing-api') , 'event_id' => $event_id)); } else { return rest_ensure_response(array( 'success' => true, 'data' => $final_data, 'message' => __( "Event Created Successfully", 'dwt-listing-api') , 'event_id' => $event_id)); } } } if (!function_exists('dwt_listing_events_images_up')) { function dwt_listing_events_images_up($file_handler,$event_id) { // check to make sure its a successful upload if ($_FILES[$file_handler]['error'] !== UPLOAD_ERR_OK) { return rest_ensure_response(array( 'success' => false, 'data' => '', 'message' => $_FILES[$file_handler]['error'] )); } if ($_FILES[$file_handler]['error'] == UPLOAD_ERR_INI_SIZE) { return rest_ensure_response(array( 'success' => false, 'data' => '', 'message' => $_FILES[$file_handler]['error'] )); } if ($_FILES[$file_handler]['error'] == UPLOAD_ERR_FORM_SIZE) { return rest_ensure_response(array( 'success' => false, 'data' => '', 'message' => $_FILES[$file_handler]['error'] )); } require_once(ABSPATH . "wp-admin" . '/includes/image.php'); require_once(ABSPATH . "wp-admin" . '/includes/file.php'); require_once(ABSPATH . "wp-admin" . '/includes/media.php'); $attach_id = media_handle_upload( $file_handler, $event_id ); if ( is_wp_error( $attach_id ) ) { return rest_ensure_response(array( 'success' => false, 'data' => '', 'message' => __( "Something went wrong there was an error uploading the image.", 'dwt-listing-api'))); } else { if(get_post_meta( $event_id, 'downotown_event_arrangement_', true ) !="") { $imgaes = ''; $imgaes = get_post_meta($event_id, 'downotown_event_arrangement_', true ); $imgaes = $imgaes .',' . $attach_id; update_post_meta( $event_id, 'downotown_event_arrangement_', $imgaes ); } else { update_post_meta( $event_id, 'downotown_event_arrangement_', $attach_id ); } } } } //Delete Uploaded Image add_action( 'rest_api_init', 'dwt_listing_submission_gallerydelete_hook', 0 ); function dwt_listing_submission_gallerydelete_hook() { register_rest_route( 'downtown/app', '/delete-event-img/', array( 'methods' => WP_REST_Server::EDITABLE, 'callback' => 'dwt_listing_eventz_gallery_detete', 'permission_callback' => function () { return dwt_listing_basic_auth(); }, ) ); } if (!function_exists('dwt_listing_eventz_gallery_detete')) { function dwt_listing_eventz_gallery_detete($request) { global $dwt_listing_options; $user = wp_get_current_user(); $user_id = $user->ID; $json_data = $request->get_json_params(); $attachmentid = isset($json_data['image_id']) ? sanitize_text_field($json_data['image_id']) : ''; $event_id = isset($json_data['event_id']) ? sanitize_text_field($json_data['event_id']) : ''; if(!empty($event_id) && !empty($attachmentid)) { if( dwt_listing_text('dwt_listing_disable_edit') == '1' && !is_super_admin( get_current_user_id())) { return array( 'success' => false, 'data' => '', 'message' => __( "Disable for Demo.", 'dwt-listing-api')); } wp_delete_attachment( $attachmentid, true ); if( get_post_meta( $event_id, 'downotown_event_arrangement_', true ) != "" ) { $ids = get_post_meta( $event_id, 'downotown_event_arrangement_', true ); $res = str_replace($attachmentid, "", $ids); $res = str_replace(',,', ",", $res); $img_ids= trim($res,','); update_post_meta( $event_id, 'downotown_event_arrangement_', $img_ids ); } //gallery $has_gallery = false; $media = dwt_listing_fetch_event_gallery($event_id); if( count((array) $media ) > 0 ) { $has_gallery = true; foreach( $media as $m ) { $mid = ''; if ( isset( $m->ID ) ) { $mid = $m->ID; } else { $mid = $m; } $full_img = $thumb_imgs = ''; $full_img = wp_get_attachment_image_src($mid, 'dwt_listing_locations-thumb'); $gallery[] = array( "url" => esc_url($full_img[0]), "image_id" => esc_attr($mid), ); } } $event_creatz = array(); $event_creatz['gallery'] = array("main_title" => __("Event Gallery", "dwt-listing-api"), "placeholder" =>__("Select Pics", "dwt-listing-api"),"is_required" => true,"has_gallery" => $has_gallery,"dropdown" => $gallery); return array( 'success' => true, 'data' => $event_creatz, 'message' => ''); } } } //Delete Uploaded Image add_action( 'rest_api_init', 'dwt_listing_event_delete', 0 ); function dwt_listing_event_delete() { register_rest_route( 'downtown/app', '/delete-event/', array( 'methods' => WP_REST_Server::EDITABLE, 'callback' => 'dwt_listing_eventz_del', 'permission_callback' => function () { return dwt_listing_basic_auth(); }, ) ); } if (!function_exists('dwt_listing_eventz_del')) { function dwt_listing_eventz_del($request) { global $dwt_listing_options; $user = wp_get_current_user(); $user_id = $user->ID; $json_data = $request->get_json_params(); $event_id = isset($json_data['event_id']) ? sanitize_text_field($json_data['event_id']) : ''; if(!empty($event_id)) { if( dwt_listing_text('dwt_listing_disable_edit') == '1' && !is_super_admin( get_current_user_id())) { return array( 'success' => false, 'data' => '', 'message' => __( "Disable for Demo.", 'dwt-listing-api')); } if( wp_trash_post( $event_id ) ) { return array( 'success' => true, 'data' => '', 'message' => __("Event removed successfully.", 'dwt-listing-api')); } else { return array( 'success' => false, 'data' => '', 'message' => __("An error occurred, please try again later.", 'dwt-listing-api')); } } else { return array( 'success' => false, 'data' => '', 'message' => __("Something went wrong please try later.", 'dwt-listing-api')); } } } //Expire My Event add_action( 'rest_api_init', 'dwt_listing_event_expire', 0 ); function dwt_listing_event_expire() { register_rest_route( 'downtown/app', '/expire-event/', array( 'methods' => WP_REST_Server::EDITABLE, 'callback' => 'dwt_listing_eventz_exp', 'permission_callback' => function () { return dwt_listing_basic_auth(); }, ) ); } if (!function_exists('dwt_listing_eventz_exp')) { function dwt_listing_eventz_exp($request) { global $dwt_listing_options; $user = wp_get_current_user(); $user_id = $user->ID; $json_data = $request->get_json_params(); $event_id = isset($json_data['event_id']) ? sanitize_text_field($json_data['event_id']) : ''; if(!empty($event_id)) { if( dwt_listing_text('dwt_listing_disable_edit') == '1' && !is_super_admin( get_current_user_id())) { return array( 'success' => false, 'data' => '', 'message' => __( "Disable for Demo.", 'dwt-listing-api')); } update_post_meta($event_id, 'dwt_listing_event_status', '0' ); return array( 'success' => true, 'data' => '', 'message' => __("Event Expired Successfully.", 'dwt-listing-api')); } else { return array( 'success' => false, 'data' => '', 'message' => __("Something went wrong please try later.", 'dwt-listing-api')); } } } //Re-Active Expired Events add_action( 'rest_api_init', 'dwt_listing_event_expire_reactive', 0 ); function dwt_listing_event_expire_reactive() { register_rest_route( 'downtown/app', '/reactive-event/', array( 'methods' => WP_REST_Server::EDITABLE, 'callback' => 'dwt_listing_eventz_reactive', 'permission_callback' => function () { return dwt_listing_basic_auth(); }, ) ); } if (!function_exists('dwt_listing_eventz_reactive')) { function dwt_listing_eventz_reactive($request) { $user = wp_get_current_user(); $user_id = $user->ID; $json_data = $request->get_json_params(); $event_id = isset($json_data['event_id']) ? sanitize_text_field($json_data['event_id']) : ''; if(!empty($event_id)) { if( dwt_listing_text('dwt_listing_disable_edit') == '1' && !is_super_admin( get_current_user_id())) { return array( 'success' => false, 'data' => '', 'message' => __( "Disable for Demo.", 'dwt-listing-api')); } update_post_meta($event_id, 'dwt_listing_event_status', '1' ); return array( 'success' => true, 'data' => '', 'message' => __("Event activated successfully.", 'dwt-listing-api')); } else { return array( 'success' => false, 'data' => '', 'message' => __("Something went wrong please try later.", 'dwt-listing-api')); } } }
[+]
..
[-] personal-events.php
[edit]