frontend image update code in wordpress

<?php
/*
Template Name: Update Listing

*/
get_header();
?>
<?php
$current_postid='';
$user_id='';
if(isset($_GET['current_postid']))
{
   $current_postid=$_GET['current_postid'];
   $user_id = get_post_field( 'post_author', $_GET['current_postid'] );
}
?>
<?php
 $current_postid=$_GET['current_postid'];
if(isset($_POST['post_update']))
{
 /* image uplaod code start  */
require_once(ABSPATH . "wp-admin" . '/includes/image.php');
require_once(ABSPATH . "wp-admin" . '/includes/file.php');
require_once(ABSPATH . "wp-admin" . '/includes/media.php');


$uploaddir = wp_upload_dir();
$select_attachmentID='';
$select_attachmentID=get_post_meta($_GET['current_postid'],'_thumbnail_id',true);

$featured_attached_path = get_attached_file( $_POST['_thumbnail_id'] );

$post_attachment=$_FILES['post_attachment']['name'];

if(!empty($post_attachment)){
$file = $_FILES['post_attachment'];
$uploadfile = $uploaddir['path'] . '/' . basename( $file['name'] );
move_uploaded_file( $file['tmp_name'] , $uploadfile );
$filename = basename( $uploadfile );
$wp_filetype = wp_check_filetype(basename($filename), null );
$attachment = array(
'post_mime_type' => $wp_filetype['type'],
'post_title' => preg_replace('/\.[^.]+$/', '', $filename),
'post_content' => '',
'post_status' => 'inherit',
'menu_order' => $_i + 1000
);
$attach_id = wp_insert_attachment( $attachment, $uploadfile );
}
else
{
if($select_attachmentID > 0)
{
$select_attachmentID=$_POST['_thumbnail_id'];
}
else
{
  $select_attachmentID='';
}
}


    $post_title=wp_strip_all_tags($_POST['post_title']);
  $post_excerpt=$_POST['post_excerpt'];
$post_term=$_POST['post_term'];

     $post_tag = $_POST['post_tags'];
$userID=$_POST['user_id'];
$business_address=$_POST['business_address'];
$business_phone=$_POST['business_phone'];
$business_email=$_POST['business_email'];
$website_url=$_POST['website_url'];
$video_url=$_POST['video_url'];
$facebook_url=$_POST['facebook_url'];
$twitter_url=$_POST['twitter_url'];
  $whatsapp_number=$_POST['whatsapp_number'];
 
  $director_name=$_POST['director_name'];
  $director_email=$_POST['director_email'];
  $director_phone=$_POST['director_phone'];
  $director_address=$_POST['director_address'];
 
  $address = $business_address;
        $url = 'http://maps.google.com/maps/api/geocode/json?address='.urlencode($address).'&sensor=false&region=England';
       
        $ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_PROXYPORT, 3128);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$response = curl_exec($ch);
curl_close($ch);

$response = json_decode($response);

$lat = $response->results[0]->geometry->location->lat;
$long = $response->results[0]->geometry->location->lng; 

   $post_info = array(
                 'ID' => $current_postid,
'post_title' => $post_title,
'post_content' => $post_excerpt,
'post_status' => 'publish',
'post_type' => 'listing',
'post_author' => $userID,
'tags_input'    =>  array($post_tag)
);
$postID=wp_update_post($post_info);

if($postID){

update_post_meta($postID, 'business_address', $business_address);
update_post_meta($postID, 'business_phone', $business_phone);
update_post_meta($postID, 'business_email', $business_email);
update_post_meta($postID, 'website_url', $website_url);
update_post_meta($postID, 'video_url', $video_url);
update_post_meta($postID, 'facebook_url', $facebook_url);
update_post_meta($postID, 'twitter_url', $twitter_url);
update_post_meta($postID, 'whatsapp_number', $whatsapp_number);
update_post_meta($postID, 'business_address_lat', $lat);
update_post_meta($postID, 'business_address_long', $long);

update_post_meta($postID,'director_photo',$attach_id1);

update_post_meta($postID,'cover_photo',$attach_id2);

update_post_meta($postID,'gallary1',$gallary1_attach_id);
update_post_meta($postID,'gallary2',$gallary2_attach_id);
update_post_meta($postID,'gallary3',$gallary3_attach_id);
update_post_meta($postID,'gallary4',$gallary4_attach_id);
update_post_meta($postID,'gallary5',$gallary5_attach_id);
update_post_meta($postID,'gallary6',$gallary6_attach_id);


update_post_meta($postID, 'director_name',$director_name);
update_post_meta($postID, 'director_email',$director_email);
update_post_meta($postID, 'director_phone',$director_phone);
update_post_meta($postID, 'director_address',$director_address);

update_post_meta($postID, 'facebook_url', $_POST['facebook_url']);
update_post_meta($postID, 'twitter_url', $_POST['twitter_url']);
update_post_meta($postID, 'whatsapp_number', $_POST['whatsapp_number']);
update_post_meta($postID, 'google_plus_url', $_POST['google_plus_url']);
update_post_meta($postID, 'linkedin_url', $_POST['linkedin_url']);
update_post_meta($postID, 'instagram_url', $_POST['instagram_url']);

update_post_meta($postID, 'facebook_url1', $_POST['facebook_url1']);
update_post_meta($postID, 'twitter_url1', $_POST['twitter_url1']);
update_post_meta($postID, 'whatsapp_number1', $_POST['whatsapp_number1']);
update_post_meta($postID, 'google_plus_url1', $_POST['google_plus_url1']);
update_post_meta($postID, 'linkedin_url1', $_POST['linkedin_url1']);
update_post_meta($postID, 'instagram_url1', $_POST['instagram_url1']);

update_post_meta($postID, 'youtube_code', $_POST['youtube_code']);

wp_set_object_terms( $postID, $post_term, 'education_type' );
        wp_set_post_tags($postID, $_POST['post_tags']);

       if(!empty($post_attachment)){
           update_post_meta($postID,'_thumbnail_id',$attach_id);
            set_post_thumbnail( $postID, $attach_id );
}
else
{
    update_post_meta($current_postid,'_thumbnail_id',$select_attachmentID);
        set_post_thumbnail($current_postid, $select_attachmentID );
}


$message= 'Post Successfully Updated';

}
}
?>

Comments

Popular posts from this blog

dynamic create multiple ckeditor onclick event using jquery

get lat and long from city name using jquery

membership registration and login system in php