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; }
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; }
/** * Get post format for current post object. * * The value should be a valid post format or one of the back compat categories. * * @since P2 1.3.4 * @uses p2_get_the_category for back compat category check * @uses p2_get_supported_post_formats for accepted values * * @param object post_id Uses global post if in the loop; required for use outside the loop * @return string */ function p2_get_post_format($post_id = null) { if (is_null($post_id)) { global $post; $post_id = $post->ID; } if (empty($post_id)) { return ''; } // 1- try to get post format, first $post_format = get_post_format($post_id); // 2- try back compat category, next if (false === $post_format) { $post_format = p2_get_the_category($post_id); } // Check against accepted values if (empty($post_format) || !in_array($post_format, p2_get_supported_post_formats())) { $post_format = 'standard'; } return $post_format; }