$current_user = wp_get_current_user(); $user_id = $current_user->ID; } else { $user_id = 1; } $post = array('comment_status' => 'open', 'ping_status' => 'open', 'post_author' => $user_id, 'post_content' => $description, 'post_status' => 'pending', 'post_title' => $title, 'post_type' => 'coupons'); $post_id = wp_insert_post($post); if ($post_id == 0) { $errors[] = __("The listing couldn't be added to the database, try again.", "Teo"); } else { $cat = (array) $cat; wp_set_post_terms($post_id, $cat, 'category'); //setting the correct category $tmp = new MediaUpload(); if ($_FILES['coupon_image']['error'] == 0) { $featured_image = $tmp->saveUpload('coupon_image'); add_post_meta($post_id, '_thumbnail_id', $featured_image['attachment_id']); } //setting custom fields info if ($discount != '') { add_post_meta($post_id, '_single_discount', $discount); } if ($code != '') { add_post_meta($post_id, '_single_code', $code); } if ($date != '') { add_post_meta($post_id, '_single_date', strtotime($date)); } if ($url != '') { add_post_meta($post_id, '_single_url', $url); }
public function wp_roni_photo_contest_shortcode($attr, $content = null) { global $post; $data = []; // Checks if there was a POST request if ($_POST) { if (empty($_POST['author-name'])) { $this->errors[] = 'Pozabili ste vnesti svoje ime!'; } if (empty($_POST['author-email'])) { $this->errors[] = 'Pozabili ste vnesti svoj e-mail!'; } /* * TODO: Email already exists * This check is implemented bot not used */ /*if( emailExists( filter_var( $_POST['author_email'], FILTER_SANITIZE_EMAIL ) ) ) { $this->errors[] = 'Ta email je že obstaja'; }*/ if ($_FILES['file-upload']['error'] == 4) { $this->errors[] = 'Pozabili ste vstaviti sliko!'; } if ($_FILES['file-upload']['size'] > 1000000) { $this->errors[] = 'Slike je prevelika!. Naložite manjšo sliko! Maksimalno 1MB.'; } $image_type = strtolower(substr(strrchr($_FILES['file-upload']['type'], '/'), 1)); if ($image_type != 'jpg' && $image_type != 'jpeg' && $image_type != 'png' && $image_type != 'gif' && $image_type != '') { $this->errors[] = 'Format ' . '.' . $image_type . ' ni podprt. Podprti so samo .jpg, .jpeg, .png in .gif!'; } if (!empty($this->errors)) { $_SESSION['errors'] = $this->errors; } else { $name = $_POST['author-name']; $email = $_POST['author-email']; $title = $_POST['image-title']; $description = $_POST['image-description']; $upload = new MediaUpload(); $file = $upload->saveUpload($field_name = 'file-upload'); $original_path = $this->upload_dir['baseurl'] . '/' . _wp_relative_upload_path($file['file']); $resize_image = new ResizeImage($original_path); $resize_image->resizeImage(350, 350, 'crop'); $crop_path = 'wp-content/uploads/tekmovanje' . $this->upload_dir['subdir'] . '/' . $file['file_info']['filename'] . '-350x350' . '.' . $file['file_info']['extension']; $resize_image->saveImage($crop_path, 100); $data['attachment_id'] = $file['attachment_id']; $data['title'] = $title; $data['description'] = $description; $data['attachment_id'] = $file['attachment_id']; $data['image_path'] = $original_path; $data['image_thumb_path'] = $this->upload_dir['baseurl'] . '/' . _wp_relative_upload_path($file['file_info']['dirname']) . '/' . $file['file_info']['filename'] . '-350x350' . '.' . $file['file_info']['extension']; $data['author_name'] = $name; $data['author_email'] = $email; $data['number_of_votes'] = 0; $data['created'] = date('d.m.Y G:i:s'); $save_data = $this->saveToDatabse($data); # TODO: Database error handler not implemented yet $_SESSION['success'] = 'Slika je bila uspešno naložena!'; # TOO: Create post for every image upload $my_post = array('post_title' => 'Nov vnos', 'post_content' => 'This is my post.', 'post_status' => 'publish', 'post_author' => 1); //wp_insert_post( $my_post ); } } $images_data = $this->getImages(); $contest_subtitle = get_option('wp_roni_photo_contest_subtitle'); $contest_description = get_option('wp_roni_photo_contest_description'); // Get the front end ( form, and images grid ) ob_start(); require 'inc/front-end.php'; $content = ob_get_clean(); session_destroy(); return $content; }