function add_org_post($data, $future = false) { global $wpdb; if (is_user_logged_in()) { if (isset($data['author_email']) && filter_var($data['author_email'], FILTER_VALIDATE_EMAIL)) { $author_email = $data['author_email']; } else { echo '<div class="error">Не (корректно) заполнено поле "Ваш email"</div>'; return; } if (isset($data['title']) && !empty($data['title'])) { $title = $data['title']; } else { echo '<div class="error">Не заполнено поле "Название организации"</div>'; return; } if (isset($data['description']) && !empty($data['description'])) { $content = $data['description']; } else { echo '<div class="error">Не заполнено поле "Описание"</div>'; return; } if (!check_attachment_files() && !$future) { echo '<div class="error">Загружаемый вами тип файла не поддерживается</div>'; return; } $contacts = isset($data['contacts']) ? strip_tags($wpdb->escape(nl2br($data['contacts']), '<p><br><br/>')) : ''; $type = strip_tags($wpdb->escape($data['p_type'])); $post_name = sanitize_title_with_translit($wpdb->escape($title)); $post_date = current_time('mysql'); //date('Y-m-d H:i:s'); /* создаем массив и собираем все данные вместе */ $the_post = array(); $the_post['post_author'] = get_current_user_id(); $the_post['post_date'] = $post_date; $the_post['post_date_gmt'] = $post_date; $the_post['post_content'] = str_replace(array("\r\n", "\n", "\r"), "<br>", strip_tags($wpdb->escape(str_replace('"', '"', $content)), '<p><br><br/>')); $the_post['post_title'] = htmlspecialchars(strip_tags($wpdb->escape($title))); $the_post['post_excerpt'] = ''; $the_post['post_status'] = 'pending'; $the_post['comments_status'] = 'open'; $the_post['ping_status'] = 'closed'; $the_post['post_password'] = ''; $the_post['post_name'] = $post_name; $the_post['to_ping'] = ''; $the_post['pinged'] = ''; $the_post['post_content_filtered'] = ''; $the_post['guid'] = ''; $the_post['post_type'] = $type; $the_post['post_mime_type'] = ''; $the_post['comment_count'] = 0; $the_post['filter'] = true; // говорим вордпресс "все ок, не надо что-то проверять и удалять из моего поста" $post_ID = 0; if (!empty($data['org_id'])) { $org = get_post($data['org_id']); $the_post["ID"] = $org->ID; if ($org->post_author == $the_post['post_author']) { $post_ID = wp_update_post($the_post); } } else { $post_ID = wp_insert_post($the_post); } if ($post_ID > 0) { require_once ABSPATH . WPINC . '/registration.php'; wp_update_user(array('ID' => $the_post['post_author'], 'user_email' => $author_email)); wp_set_post_terms($post_ID, $data['location'], 'nlocation'); wp_set_post_terms($post_ID, $data['category'], 'catcategory'); if (!empty($data['org_id'])) { update_post_meta($post_ID, 'catalog_contacts', $contacts); } else { add_post_meta($post_ID, 'catalog_contacts', $contacts, true); } if (!$future) { $featuredImage = true; foreach ($_FILES as $file_id => $array) { if ($featuredImage) { $attachment_id = insert_attachment($file_id, $post_ID, $featuredImage); $featuredImage = false; } else { $attachment_id = insert_attachment($file_id, $post_ID, $featuredImage); } } } if (isset($_POST['images']) && is_array($_POST['images'])) { $images = $_POST['images']; $first = true; foreach ($images as $imgID) { wp_update_post(array('ID' => $imgID, 'post_parent' => $post_ID)); if ($first) { set_post_thumbnail($post_ID, $imgID); $first = false; } } } echo '<div class="succes">Ваша запись поставлена в очередь на модерацию.</div>'; } else { echo '<div class="error">произошла ошибка</div>'; } } }
function save_company() { if (!empty($_POST['hidden_action_register']) && $_POST['hidden_action_register'] == "register_cfs") { global $wpdb; $msg = ""; if ($_POST['companyname'] == "") { $msg .= "Enter value for Company name.<br>"; } if ($_POST['noofemployee'] == "") { $msg .= "Enter value for Number of Employees.<br>"; } if ($_POST['companygoal'] == "") { $msg .= "Enter value for Company Goal.<br>"; } if ($_POST['email'] == "") { $msg .= "Enter value for email.<br>"; } else { if (!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) { $msg .= "Enter correct value for email.<br>"; } } if ($_POST['contactnumber'] == "") { $msg .= "Enter value for Contact Number.<br>"; } if ($_FILES['logoimg']['name'] == "") { $msg .= "Upload Logo Image.<br>"; } if ($msg == "") { $pwd = '123456'; $userdata = array('user_login' => $_POST['email'], 'user_pass' => $pwd, 'user_email' => $_POST['email'], 'role' => 'donator'); $user_id = wp_insert_user($userdata); if (!is_wp_error($user_id)) { $new_post = array('post_title' => sanitize_text_field($_POST['companyname']), 'post_type' => 'company', 'post_status' => 'publish', 'post_author' => $user_id); $pid = wp_insert_post($new_post); if ($_FILES['logoimg']['name']) { $exts = array("jpeg", "jpg", "png"); $temp1 = explode(".", $_FILES['logoimg']['name']); $file_ext1 = strtolower(end($temp1)); if (in_array($file_ext1, $exts)) { $pupload = insert_attachment('logoimg', $pid, true); } } update_post_meta($pid, '_no_of_employees', sanitize_text_field($_POST['noofemployee'])); update_post_meta($pid, '_company_goal', sanitize_text_field($_POST['companygoal'])); update_post_meta($pid, '_contact_email', sanitize_text_field($_POST['email'])); update_post_meta($pid, '_contact_number', sanitize_text_field($_POST['contactnumber'])); if ($_POST['team']) { for ($i = 0; $i < sizeof($_POST['team']); $i++) { if ($_POST['team'][$i] != "") { $sSQL = "insert into " . $wpdb->prefix . "cfs_team (team_name,company_id) values('" . $_POST['team'][$i] . "','" . $pid . "')"; $wpdb->query($sSQL); } } } echo '<div class="msg success">Company is registered successfully</div>'; } else { echo '<div class="msg error">' . ($msg = $user_id->get_error_message() . '</div>'); } } else { echo '<div class="msg error">' . $msg . '</div>'; } } }
if (!$is_active) { $call = 0; } } } if (isset($_POST['post_nonce_field']) && wp_verify_nonce($_POST['post_nonce_field'], 'post_nonce')) { $title = sanitize_text_field($_POST['title']); $description = $_POST['description']; $idea = array('post_title' => $title, 'post_content' => $description, 'post_status' => 'draft', 'post_type' => 'idea'); $idea_id = wp_insert_post($idea); if ($idea_id) { wp_set_object_terms($idea_id, array(intval($_POST['idea_cat'])), 'idea_cat'); if ($_FILES) { foreach ($_FILES as $file => $array) { if (!empty($file)) { insert_attachment($file, $idea_id, 'idea_file'); } } } update_post_meta($idea_id, 'user_name', sanitize_text_field($_POST['uname'])); update_post_meta($idea_id, 'user_surname', sanitize_text_field($_POST['usurname'])); //update_post_meta( $idea_id, 'user_tel', sanitize_text_field( $_POST['utel'] ) ); update_post_meta($idea_id, 'user_email', sanitize_text_field($_POST['uemail'])); $cp_message = '<div class="alert alert-success" role="alert"><p>H καταχώρησή σας ήταν επιτυχής. Σύντομα η ιδέα σας θα δημοσιευθεί απο έναν διαχειριστή!</p></div>'; $success = true; } else { $cp_message = '<div class="alert alert-danger" role="alert"><p>Παρουσιάστηκε πρόβλημα και η καταχώρησή Δεν ήταν επιτυχής.</p></div>'; } } get_header(); $submit_link = get_the_permalink();
<?php if (!defined('WW_SESS')) { exit; } // page title - if undefined the site title is displayed by default $page_title = 'Attachments'; // upload attachment if (isset($_POST['upload_attachment']) && $_POST['upload_attachment'] == 'upload') { $upload_status = insert_attachment(); if (is_int($upload_status)) { header('Location: ' . $_SERVER["PHP_SELF"] . '?page_name=attachments&attachment_id=' . $upload_status); } else { $error = $upload_status; } } // update attachment details if (isset($_POST['update']) && $_POST['update'] == 'update details') { $attachment_id = (int) $_POST['attachment_id']; if (!empty($attachment_id)) { $update_status = update_attachment($attachment_id); if ($update_status == true) { header('Location: ' . $url); } else { $error = $update_status; } } } // insert attachment details - for rogue attachments if (isset($_POST['insert']) && $_POST['insert'] == 'insert details') { $insert_status = insert_attachment_details($_POST);
} if ($_POST['action'] == 'edit_attachment') { edit_attachment($_POST['sample_id'], $_POST['attachment_id']); } if ($_POST['action'] == 'add_attachment') { add_attachment($_POST['sample_id']); } if ($_POST['action'] == 'save_attachment') { if (isset($_FILES)) { save_attachment($_POST, $_FILES); } list_attachment($_POST['sample_id']); } if ($_POST['action'] == 'insert_attachment') { if (isset($_FILES)) { insert_attachment($_POST, $_FILES); } update_cross_reference($_POST['sample_id']); list_attachment($_POST['sample_id']); } if ($_POST['action'] == 'delete_attachment') { if (isset($_FILES)) { delete_attachment($_POST['sample_id'], $_POST['attachment_id']); } update_cross_reference($_POST['sample_id']); list_attachment($_POST['sample_id']); } if ($_POST['action'] == 'print_attachment') { echo '<h2 style="page-break-before: always;"></h2>'; print_attachment($_POST['sample_id']); }
function submit_post_function() { if (isset($_POST['capf']) && $_POST['capf'] == "on" && (isset($_POST['capr']) && $_POST['capr'] == "on")) { $valid = false; if (isset($_COOKIE['Captcha'])) { list($hash, $time) = explode('.', $_COOKIE['Captcha']); // The code under the md5 first section needs to match the code // entered in easycaptcha.php if (md5('HDBHAYYEJKPWIKJHDD' . $_REQUEST['ttgps_captcha'] . $_SERVER['REMOTE_ADDR'] . $time) != $hash) { $abortmessage = __('Captcha code is wrong. Go back and try to get it right or reload to get a new captcha code.', 'ttgps_text_domain'); wp_die($abortmessage); exit; } elseif (time() - 5 * 60 > $time) { $abortmessage = __('Captcha timed out. Please go back, reload the page and submit again.', 'ttgps_text_domain'); wp_die($abortmessage); exit; } else { // Set flag to accept and store user input $valid = true; } } else { $abortmessage = __('No captcha cookie given. Make sure cookies are enabled.', 'ttgps_text_domain'); wp_die($abortmessage); exit; } // End of if (isset($_COOKIE['Captcha'])) } else { $valid = true; } //Checking Filtered Key words// if (isset($_POST['enable_filter']) && $_POST['enable_filter'] == "on") { $filter_array = explode(',', $_POST['filter_items']); $filtered_words_found = array_filter($filter_array, 'filtered_word_check'); if (count($filtered_words_found) > 0) { $abortmessage = __('Following Filtered Messeged are found in your Post. Please go back and Edit your Post before submit'); $abortmessage .= "<br><br> <strong>"; $abortmessage .= __('Filtered Words List: '); $abortmessage .= implode(', ', $filtered_words_found) . "</strong>"; wp_die($abortmessage); } } //====================================// if ($valid) { $title = isset($_POST["title"]) ? $_POST["title"] : ""; $content = isset($_POST["content"]) ? $_POST["content"] : ""; $tags = isset($_POST["tags"]) ? $_POST["tags"] : ""; $author = isset($_POST["author"]) ? $_POST["author"] : ""; $email = isset($_POST["email"]) ? $_POST["email"] : ""; $site = isset($_POST["site"]) ? $_POST["site"] : ""; $authorid = isset($_POST["authorid"]) ? $_POST["authorid"] : ""; if (isset($_POST['catdrp'])) { $category = $_POST['catdrp'] == -1 ? array(1) : array($_POST['catdrp']); } else { $category = ""; } $redirect_location = isset($_POST["redirect_url"]) ? $_POST["redirect_url"] : ""; $to_email = isset($_POST["to_email"]) ? $_POST["to_email"] : ""; //$nonce=$_POST["_wpnonce"]; $poststatus = $_POST["post_status"]; if (isset($_POST['submit'])) { $new_post = array('post_title' => $title, 'post_content' => $content, 'post_category' => $category, 'tags_input' => $tags, 'post_status' => $poststatus, 'post_type' => 'post', 'post_author' => $authorid); $pid = wp_insert_post($new_post); add_post_meta($pid, 'author', $author, true); add_post_meta($pid, 'author-email', $email, true); add_post_meta($pid, 'author-website', $site, true); if (!function_exists('wp_handle_upload')) { require_once ABSPATH . 'wp-admin/includes/file.php'; } if ($_FILES) { $files = $_FILES['featured-img']; 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]); $_FILES = array("featured-img" => $file); $counter = 1; foreach ($_FILES as $file => $array) { if ($counter == 1) { $newupload = insert_attachment($file, $pid, true); } else { $newupload = insert_attachment($file, $pid, false); } ++$counter; } // End of inner foreach } // End of if } // End of outer foreach } // End of if($_FILES) } // End of if (isset($_POST['submit'])) if ($_POST['notify_flag'] == "on") { ttgps_send_confirmation_email($to_email); } // Redirect browser to review submission page //$redirectaddress = ( empty( $_POST['_wp_http_referer'] ) ? site_url() : $_POST['_wp_http_referer'] ); $redirectaddress = !empty($redirect_location) ? $redirect_location : $_POST['_wp_http_referer']; wp_redirect(add_query_arg(__('submission_success', 'ttgps_text_domain'), '1', $redirectaddress)); exit; } // End of if ($valid) }
} if (function_exists('get_video_thumbnail')) { get_video_thumbnail($postID); } } // Loop through submitted images and save the first one as featured image if (isset($_FILES['image']) && $_FILES['image']['size'] > 0) { array_reverse($_FILES); $i = 0; foreach ($_FILES as $file => $array) { if ($i == 0) { $set_feature = 1; } else { $set_feature = 0; } $newUpload = insert_attachment($file, $postID, $set_feature); } } //$return_url = add_query_arg('status', 'pending', $_POST['return']); wp_redirect(get_permalink($postID)); exit; } else { $return_url = add_query_arg('status', 'error', $_POST['return']); wp_redirect($return_url); exit; } } else { $return_url = add_query_arg('status', 'error', $_POST['return']); wp_redirect($return_url); exit; }
/* Upload Images */ if ($_FILES) { foreach ($_FILES as $submitted_file => $file_array) { if (is_valid_image($_FILES[$submitted_file]['name'])) { $size = intval($_FILES[$submitted_file]['size']); if ($size > 0) { if ($submitted_file == 'featured_image') { /* Featured Image */ $uploaded_file_id = insert_attachment($submitted_file, $property_id, true); /* Virtual Tour Image */ if (empty($tour_video_image) && !empty($_POST['video-url'])) { update_post_meta($property_id, 'REAL_HOMES_tour_video_image', $uploaded_file_id); } } else { /* Gallery Images */ $uploaded_file_id = insert_attachment($submitted_file, $property_id); add_post_meta($property_id, 'REAL_HOMES_property_images', $uploaded_file_id); } } } else { /* Skip the image upload if image do not has a valid file extension */ } } } /* Send Email Notice on Property Submit */ $action = $_POST['action']; if ($action == "add_property") { $submit_notice_email = get_option('theme_submit_notice_email'); if (!empty($submit_notice_email)) { $current_user = wp_get_current_user(); $submitter_name = $current_user->display_name;
function chow_post_submission() { if ('POST' == $_SERVER['REQUEST_METHOD'] && !empty($_POST['action']) && $_POST['action'] == "new_post" && isset($_POST['post_nonce_field']) && wp_verify_nonce($_POST['post_nonce_field'], 'post_nonce')) { global $postAdded; global $submit_errors; $hasError = false; $submit_errors = array(); if (empty($_POST['title'])) { $hasError = true; $submit_errors[] = 'title'; } $title = sanitize_text_field($_POST['title']); if (empty($title)) { $title = 'User Submitted Post'; } $category = intval($_POST['cat']); $summary = stripslashes($_POST['summary']); $ingredients = array(); foreach ($_POST['ingredient_name'] as $k => $v) { $ingredients[] = array('name' => $v, 'note' => sanitize_text_field($_POST['ingredient_note'][$k])); } $instructions = stripslashes($_POST['instructions']); if (empty($_POST['instructions']) || $_POST['instructions'] == ' ') { $hasError = true; $submit_errors[] = 'instructions'; } $recipeoptions = array(sanitize_text_field($_POST['preptime']), sanitize_text_field($_POST['cooktime']), sanitize_text_field($_POST['yield'])); $ntfacts = $_POST['cookingpressntfacts']; if (isset($_POST['serving'])) { $serving = mysql_real_escape_string($_POST['serving']); } else { $serving = ''; } $level = mysql_real_escape_string($_POST['level']); if (isset($_POST['allergen'])) { $allergens = $_POST['allergen']; } else { $allergens = ''; } if (isset($_POST['timeneeded'])) { $timeneeded = sanitize_text_field($_POST['timeneeded']); } else { $timeneeded = ''; } // ADD THE FORM INPUT TO $new_post ARRAY $new_post = array('post_title' => $title, 'post_content' => '', 'post_category' => array($_POST['cat']), 'post_status' => 'draft', 'post_type' => 'post'); //SAVE THE POST if ($hasError == false) { $pid = wp_insert_post($new_post); if ($_FILES) { foreach ($_FILES as $file => $array) { $newupload = insert_attachment($file, $pid); set_post_thumbnail($pid, $newupload); } } // END THE add_post_meta($pid, 'cookingpressingridients', $ingredients, true); add_post_meta($pid, 'cookingpressinstructions', $instructions, true); add_post_meta($pid, 'cookingpressrecipeoptions', $recipeoptions, true); add_post_meta($pid, 'cookingpressntfacts', $ntfacts, true); add_post_meta($pid, 'cookingpresssummary', $summary, true); //SET OUR TAGS UP PROPERLY wp_set_object_terms($pid, $level, 'level'); wp_set_object_terms($pid, $serving, 'serving'); wp_set_object_terms($pid, $timeneeded, 'timeneeded'); if (isset($allergens)) { wp_set_object_terms($pid, $allergens, 'allergen'); } do_action('wp_insert_post', 'wp_insert_post'); $postAdded = true; } } //edit if ('POST' == $_SERVER['REQUEST_METHOD'] && !empty($_POST['action']) && !empty($_POST['edit_post_id']) && $_POST['action'] == "update_post" && isset($_POST['post_nonce_field']) && wp_verify_nonce($_POST['post_nonce_field'], 'post_nonce')) { global $postUpdated; global $submit_errors; $edited_post_id = $_POST['edit_post_id']; $hasError = false; $submit_errors = array(); if (empty($_POST['title'])) { $hasError = true; $submit_errors[] = 'title'; } $title = sanitize_text_field($_POST['title']); if (empty($title)) { $title = 'User Submitted Post'; } $category = intval($_POST['cat']); $summary = stripslashes($_POST['summary']); $ingredients = array(); foreach ($_POST['ingredient_name'] as $k => $v) { $ingredients[] = array('name' => $v, 'note' => sanitize_text_field($_POST['ingredient_note'][$k])); } $instructions = stripslashes($_POST['instructions']); if (empty($_POST['instructions']) || $_POST['instructions'] == ' ') { $hasError = true; $submit_errors[] = 'instructions'; } $recipeoptions = array(sanitize_text_field($_POST['preptime']), sanitize_text_field($_POST['cooktime']), sanitize_text_field($_POST['yield'])); $ntfacts = $_POST['cookingpressntfacts']; if (isset($_POST['serving'])) { $serving = mysql_real_escape_string($_POST['serving']); } else { $serving = ''; } $level = mysql_real_escape_string($_POST['level']); if (isset($_POST['allergen'])) { $allergens = $_POST['allergen']; } else { $allergens = ''; } if (isset($_POST['timeneeded'])) { $timeneeded = sanitize_text_field($_POST['timeneeded']); } else { $timeneeded = ''; } // ADD THE FORM INPUT TO $new_post ARRAY $new_post = array('post_title' => $title, 'ID' => $edited_post_id, 'post_content' => '', 'post_category' => array($_POST['cat']), 'post_status' => 'pending', 'post_type' => 'post'); //SAVE THE POST if ($hasError == false) { if ($_FILES) { foreach ($_FILES as $file => $array) { if (!empty($array['name'])) { $newupload = insert_attachment($file, $edited_post_id); set_post_thumbnail($edited_post_id, $newupload); } } } $update = wp_update_post($new_post); if ($update) { // END THE update_post_meta($edited_post_id, 'cookingpressingridients', $ingredients); update_post_meta($edited_post_id, 'cookingpressinstructions', $instructions); update_post_meta($edited_post_id, 'cookingpressrecipeoptions', $recipeoptions); update_post_meta($edited_post_id, 'cookingpressntfacts', $ntfacts); update_post_meta($edited_post_id, 'cookingpresssummary', $summary); //SET OUR TAGS UP PROPERLY wp_set_object_terms($edited_post_id, $level, 'level'); wp_set_object_terms($edited_post_id, $serving, 'serving'); wp_set_object_terms($edited_post_id, $timeneeded, 'timeneeded'); if (isset($allergens)) { wp_set_object_terms($edited_post_id, $allergens, 'allergen'); } //do_action('wp_insert_post', 'wp_insert_post'); $postUpdated = true; } } } }
/** * Подгрузка изображения * @param $url * @param $postId * @todo добавить обходной вариант на тот случай, если загрузка не удалась — просто запоминать урл на картинку * @todo Вынести наконец всё в красивый класс и закончить рефакторинг — запланировано на 7.06.2012 */ function download_image($url, $postId) { if (!GS_Config::init()->get('ps_download_images')) { $currentValue = get_post_meta($postId, 'image', TRUE); update_post_meta($postId, 'image', $url, $currentValue); return; } if (!GdeSlonImport::checkCurl()) { $opts = array('http' => array('method' => "GET", 'header' => "Accept-language: en\r\n")); $context = stream_context_create($opts); $fileContents = file_get_contents($url, false, $context); } else { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $fileContents = curl_redirect_exec($ch); curl_close($ch); } if (!$fileContents) { echo 'При попытке загрузить файл ' . $url . ' возникла ошибка: ' . "Содержимое файла не получено. Файл был присоединён старым способом\n\r"; $currentValue = get_post_meta($postId, 'image', TRUE); update_post_meta($postId, 'image', $url, $currentValue); return; } $localFilepath = dirname(__FILE__) . '/downloads/' . basename($url); $f = fopen($localFilepath, 'w'); fwrite($f, $fileContents); fclose($f); /** * Удаление не пользовательских аттачментов */ foreach (get_children(array('post_parent' => $postId, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'numberposts' => -1)) as $attachment) { if (get_post_meta($attachment->ID, 'is_image_from_gdeslon', TRUE)) { wp_delete_attachment($attachment->ID, TRUE); } } $state = insert_attachment($localFilepath, $postId, true); if (is_wp_error($state)) { echo 'При попытке загрузить файл ' . $url . ' возникла ошибка: ' . $state->get_error_message() . ". Файл был присоединён старым способом\n\r"; $currentValue = get_post_meta($postId, 'image', TRUE); update_post_meta($postId, 'image', $url, $currentValue); } else { add_post_meta($state, 'is_image_from_gdeslon', TRUE); } if (is_file($localFilepath)) { unlink($localFilepath); } }
} else { $post_category = 1; } if (isset($_POST['post_tags'])) { $post_tags = $_POST['post_tags']; } $post = array('post_title' => $post_title, 'post_content' => $post_content, 'post_category' => array($post_category), 'tags_input' => $post_tags, 'post_status' => 'publish', 'post_type' => $_POST['post_type']); $post_id = wp_insert_post($post); if (!empty($_FILES['file_0']['name'])) { foreach ($_FILES as $file_id => $array) { if ($file_id == "file_0") { $featuredImage = true; $attachment_id = insert_attachment($file_id, $post_id, $featuredImage); } else { $featuredImage = false; $attachment_id = insert_attachment($file_id, $post_id, $featuredImage); } } } unset($_POST); echo "<meta http-equiv='refresh' content='0;url={$location}' />"; } ?> <?php wp_head(); ?> </head> <body <?php
# Agregar elementos a nuevo post $new_post = array('post_title' => $title, 'post_content' => $description, 'post_category' => array($_POST['cat']), 'tags_input' => array($tags), 'post_status' => 'draft', 'post_type' => 'post'); # Guardar Publicacion $pid = wp_insert_post($new_post); # Agregando custom field add_post_meta($pid, 'Checkbx2', $imdb, true); ##################### # Insertando etiquetas wp_set_post_tags($pid, $_POST['post_tags']); # Redireccionar wp_redirect(home_url()); } # Agregando Imagen if ($_FILES) { array_reverse($_FILES); $i = 0; foreach ($_FILES as $file => $array) { if ($i == 0) { $set_feature = 1; } else { $set_feature = 0; } $newupload = insert_attachment($file, $pid, $set_feature); $i++; } } # Insertando publicacion a la base de datos. do_action('wp_insert_post', 'wp_insert_post'); # Fin de funcion. ?> </div>
function save_images($image_url, $post_id, $i) { //set_time_limit(180); //每个图片最长允许下载时间,秒 $file = file_get_contents($image_url); $fileext = substr(strrchr($image_url, '.'), 1); $fileext = strtolower($fileext); if ($fileext == "" || strlen($fileext) > 4) { $fileext = "jpg"; } $savefiletype = array('jpg', 'gif', 'png', 'bmp'); if (!in_array($fileext, $savefiletype)) { $fileext = "jpg"; } $im_name = date('YmdHis', time()) . $i . mt_rand(10, 20) . '.' . $fileext; $res = wp_upload_bits($im_name, '', $file); if (isset($res['file'])) { $attach_id = insert_attachment($res['file'], $post_id); } else { return; } if (ot_get_option('auto_save_image_thumb') == 'on' && $i == 1) { set_post_thumbnail($post_id, $attach_id); } return $res; }