function prologue_new_post_noajax() { if ('POST' != $_SERVER['REQUEST_METHOD'] || empty($_POST['action']) || $_POST['action'] != 'post') { return; } if (!is_user_logged_in()) { auth_redirect(); } if (!current_user_can('publish_posts')) { wp_redirect(get_bloginfo('url') . '/'); exit; } global $current_user; check_admin_referer('new-post'); $user_id = $current_user->ID; $post_content = $_POST['posttext']; $tags = $_POST['tags']; $post_title = prologue_title_from_content($post_content); $post_id = wp_insert_post(array('post_author' => $user_id, 'post_title' => $post_title, 'post_content' => $post_content, 'tags_input' => $tags, 'post_status' => 'publish')); wp_redirect(get_bloginfo('url') . '/'); exit; }
function new_post() { global $user_ID; if ('POST' != $_SERVER['REQUEST_METHOD'] || empty($_POST['action']) || $_POST['action'] != 'new_post') { die('-1'); } if (!is_user_logged_in()) { die('<p>' . __('Error: not logged in.', 'p2') . '</p>'); } if (!(current_user_can('publish_posts') || get_option('p2_allow_users_publish') && $user_ID)) { die('<p>' . __('Error: not allowed to post.', 'p2') . '</p>'); } check_ajax_referer('ajaxnonce', '_ajax_post'); $user = wp_get_current_user(); $user_id = $user->ID; $post_content = $_POST['posttext']; $tags = trim($_POST['tags']); if ($tags == __('Tag it', 'p2') || $tags == 'Tag it') { $tags = ''; } if (empty($_POST['post_title'])) { $post_title = prologue_title_from_content($post_content); } else { $post_title = $_POST['post_title']; } require_once ABSPATH . '/wp-admin/includes/taxonomy.php'; require_once ABSPATH . WPINC . '/category.php'; $accepted_post_cats = apply_filters('p2_accepted_post_cats', array('post', 'quote', 'status', 'link')); $post_cat = in_array($_POST['post_cat'], $accepted_post_cats) ? $_POST['post_cat'] : 'post'; if (!category_exists($post_cat)) { wp_insert_category(array('cat_name' => $post_cat)); } $post_cat = get_category_by_slug($post_cat); /* Add the quote citation to the content if it exists */ if (!empty($_POST['post_citation']) && 'quote' == $post_cat->slug) { $post_content = '<p>' . $post_content . '</p><cite>' . $_POST['post_citation'] . '</cite>'; } $post_id = wp_insert_post(array('post_author' => $user_id, 'post_title' => $post_title, 'post_content' => $post_content, 'post_type' => $post_type, 'post_category' => array($post_cat->cat_ID), 'tags_input' => $tags, 'post_status' => 'publish')); echo $post_id ? $post_id : '0'; }