WordPress.org

Ready to get started?Download WordPress

Forums

p2 and categories from the front end? (4 posts)

  1. dwharrington
    Member
    Posted 5 years ago #

    Does anyone know of a good way to get p2 to function so that users can choose categories AND tags from the front end? I can get the category dropdown or checklist to appear no problem, but getting it to register when I hit post is not working.

  2. tjeastmond
    Member
    Posted 5 years ago #

    At a quick glance, they appear to only be checking for:

    • user_id
    • post_title
    • post_content
    • tags
    • and setting the status to post

    You'd have to edit the functions: prologue_new_post() and prologue_new_post_noajax() found in the theme's 'functions.php' file to see your addition in the post.

  3. Woo2k
    Member
    Posted 5 years ago #

    I'm having the same problem.
    Dwarrington: Can you post an update if you find a solution? How did you get the categories dropdown to show?

  4. dwharrington
    Member
    Posted 5 years ago #

    Thanks for the quick reply tjeastmond! This is where I am so far and the category still does not get recorded. I am fairly new at this, so any help is appreciated.

    My post-form.php includes the following:

    <?php
    $user = get_userdata( $current_user->ID );
    $name = isset( $user->first_name ) &amp;&amp; $user->first_name? $user->first_name : $user->display_name;
    ?>
    
    <div id="postbox">
    	<form id="new_post" name="new_post" method="post" action="<?php bloginfo( 'url' ); ?>/">
    		<input type="hidden" name="action" value="post" />
    		<?php wp_nonce_field( 'new-post' ); ?>
    		<div class="avatar"><?php echo prologue_get_avatar( $user->ID, $user->user_email, 48 ); ?></div>
    		<div class="inputarea">
    			<label for="posttext"><?php printf( __('Hi, %s. What's bothering you?', 'p2'), wp_specialchars( $name ) ) ?></label>
    			<div>
    				<?php wp_dropdown_categories('name=post_category&amp;class=post_category'); ?>
    				<textarea name="posttext" id="posttext" tabindex="1" rows="3" cols="60"></textarea>
    			</div>
    			<label class="post-error" for="posttext" id="posttext_error"></label>
    			<div class="postrow">
    				<input type="text" name="tags" id="tags" tabindex="2" autocomplete="on" value="<?php echo attribute_escape(__('Tag it', 'p2')); ?>"
    					onfocus="this.value=(this.value=='<?php echo js_escape(__('Tag it', 'p2')); ?>') ? '' : this.value;"
    					onblur="this.value=(this.value=='') ? '<?php echo js_escape(__('Tag it', 'p2')); ?>' : this.value;" />
    				<input id="submit" type="submit" tabindex="3" value="<?php echo attribute_escape(__('Post it', 'p2')); ?>" />
    			</div>
    			<span class="progress" id="ajaxActivity" style="display:none" ><img src="<?php bloginfo('template_directory'); ?>/i/indicator.gif"
    				alt="<?php echo attribute_escape(__('Loading...', 'p2')); ?>" title='<?php echo attribute_escape(__('Loading...', 'p2')); ?>'/></span>
    		</div>
    		<div class="clear"></div>
    	</form>
    </div> <!-- // postbox -->

    And then in functions.php,

    function prologue_new_post() {
    	if( 'POST' != $_SERVER['REQUEST_METHOD'] || empty( $_POST['action'] ) || $_POST['action'] != 'prologue_new_post' ) {
    	    die();
    	}
    	if ( !is_user_logged_in() ) {
    		die('<p>'.__('Error: not logged in.', 'p2').'</p>');
    	}
    	if( !current_user_can( 'publish_posts' ) ) {
    		die('<p>'.__('Error: not allowed to post.', 'p2').'</p>');
    	}
    	check_ajax_referer( 'ajaxnonce', '_ajax_post' );
    	$user_id		= $current_user->user_id;
    	$post_category  = $_POST['post_category'];
    	$post_content	= $_POST['posttext'];
    	$tags			= trim( $_POST['tags'] );
    	if ( $tags == __('Tag it', 'p2') || $tags == 'Tag it' ) $tags = '';
    
        $post_title = prologue_title_from_content( $post_content );
    
    	$post_id = wp_insert_post( array(
    		'post_author'	=> $user_id,
    		'post_title'	=> $post_title,
    		'post_category' => $post_category,
    		'post_content'	=> $post_content,
    		'tags_input'	=> $tags,
    		'post_status'	=> 'publish'
    	) );
    	echo $post_id? $post_id : '0';
    	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( get_bloginfo( 'url' ) . '/' );
    		exit;
    	}
    
    	check_admin_referer( 'new-post' );
    
    	$user_id		= $current_user->user_id;
    	$post_category  = $_POST['post_category'];
    	$post_content	= $_POST['posttext'];
    	$tags			= $_POST['tags'];
    
    	$title = prologue_title_from_content( $post_content );
    
    	$post_id = wp_insert_post( array(
    		'post_author'	=> $user_id,
    		'post_title'	=> $post_title,
    		'post_category' => $post_category,
    		'post_content'	=> $post_content,
    		'tags_input'	=> $tags,
    		'post_status'	=> 'publish'
    	) );
    
    	wp_redirect( get_bloginfo( 'url' ) . '/' );
    	exit;
    }

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags