function new_post() { global $user_ID; if (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']); $title = $_POST['post_title']; $post_type = isset($_POST['post_type']) ? $_POST['post_type'] : 'post'; // Strip placeholder text for tags if (__('Tag it', 'p2') == $tags) { $tags = ''; } if (empty($title) || __('Post Title', 'p2') == $title) { // For empty or placeholder text, create a nice title based on content $post_title = p2_title_from_content($post_content); } else { $post_title = $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'] : 'status'; 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_content = p2_list_creator($post_content); $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'; }
function p2_fix_empty_titles($post_ID, $post) { if (!is_object($post) || 'post' !== $post->post_type) { return; } if (empty($post->post_title)) { $post->post_title = p2_title_from_content($post->post_content); $post->post_modified = current_time('mysql'); $post->post_modified_gmt = current_time('mysql', 1); return wp_update_post($post); } }
static function new_post() { global $user_ID; if (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']); $title = $_POST['post_title']; $post_type = isset($_POST['post_type']) ? $_POST['post_type'] : 'post'; // Strip placeholder text for tags if (__('Tag it', 'p2') == $tags) { $tags = ''; } // For empty or placeholder text, create a nice title based on content if (empty($title) || __('Post Title', 'p2') == $title) { $post_title = p2_title_from_content($post_content); } else { $post_title = $title; } $post_format = 'status'; $accepted_post_formats = apply_filters('p2_accepted_post_cats', p2_get_supported_post_formats()); // Keep 'p2_accepted_post_cats' filter for back compat (since P2 1.3.4) if (in_array($_POST['post_format'], $accepted_post_formats)) { $post_format = $_POST['post_format']; } // Add the quote citation to the content if it exists if (!empty($_POST['post_citation']) && 'quote' == $post_format) { $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', 'tags_input' => $tags, 'post_status' => 'publish')); if (empty($post_id)) { echo '0'; } set_post_format($post_id, $post_format); echo $post_id; }
function p2_new_post_noajax() { if ( empty( $_POST['action'] ) || $_POST['action'] != 'post' ) return; if ( !is_user_logged_in() ) auth_redirect(); if ( !current_user_can( 'publish_posts' ) ) { wp_redirect( home_url( '/' ) ); exit; } $current_user = wp_get_current_user(); check_admin_referer( 'new-post' ); $user_id = $current_user->ID; $post_content = $_POST['posttext']; $tags = $_POST['tags']; $post_title = p2_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' ) ); $post_format = 'status'; if ( in_array( $_POST['post_format'], p2_get_supported_post_formats() ) ) $post_format = $_POST['post_format']; set_post_format( $post_id, $post_format ); wp_redirect( home_url( '/' ) ); exit; }
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( home_url( '/' ) ); exit; } global $current_user; check_admin_referer( 'new-post' ); $user_id = $current_user->ID; $post_content = $_POST['posttext']; $tags = $_POST['tags']; $post_title = p2_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( home_url( '/' ) ); exit; }
/** * Given an email object, maybe add a reply or create a new post */ private function process_email($email) { if (empty($email->headers->to)) { return new WP_Error('incorrect-headers', 'Email headers are missing or incorrect.'); } $to_address = array_shift($email->headers->to)->mailbox; $key = array_pop(explode('+', $to_address)); $parsed_key = $this->parse_object_secret($key); if (is_wp_error($parsed_key)) { return $parsed_key; } $user = $this->get_user_from_email($email); if (is_wp_error($user)) { return $user; } $message = $this->get_reply_from_email($email); $message = wp_filter_post_kses($message); switch ($parsed_key['type']) { case 'post': case 'comment': if ('post' == $parsed_key['type']) { $post_id = $parsed_key['id']; $comment_parent = 0; } else { $post_id = get_comment($parsed_key['id'])->comment_post_ID; $comment_parent = $parsed_key['id']; } $comment = array('comment_post_ID' => $post_id, 'comment_author' => $user->display_name, 'comment_author_email' => $user->user_email, 'comment_author_url' => $user->user_url, 'comment_content' => $message, 'comment_parent' => $comment_parent, 'user_id' => $user->ID); $comment_id = wp_insert_comment($comment); // Store the original body just in case update_metadata('comment', $comment_id, $this->orig_body_key, wp_filter_post_kses($email->body)); break; case 'user': $post_format = 'status'; if (!empty($email->headers->subject)) { $post_title = sanitize_text_field($email->headers->subject); $post_format = 'standard'; } else { if (function_exists('p2_title_from_content')) { $post_title = p2_title_from_content($message); } else { $post_title = ''; } } $post = array('post_author' => (int) $parsed_key['id'], 'post_content' => $message, 'post_title' => $post_title, 'post_type' => 'post', 'post_status' => 'publish'); $post_id = wp_insert_post($post); set_post_format($post_id, $post_format); // Store the original body just in case update_metadata('post', $post_id, $this->orig_body_key, wp_filter_post_kses($email->body)); break; } return true; }