WordPress.org

Ready to get started?Download WordPress

Forums

P2
Suggested Enhancement (2 posts)

  1. mattyrob
    Member
    Posted 7 months ago #

    I write the Subscribe2 plugin for WordPress. It can handle post formats and can be configured to not send for specified formats. This code works when using the P2 theme if the post is made from admin but Subscribe2 still generates emails if posts for excluded post formats are made from the front end of the P2 site.

    This is because a placeholder post is not created when posting from the front end of the site. This can be remedied with a patch to use the get_default_post_to_edit() function so that the post format for a post can be set before the call to wp_insert_post() which triggers the transition hooks that Subscribe2 links to.

    I cannot find a way to open a new ticket for the P2 theme so have had to paste the diff patch below. If there is a better place please let me know.

    Index: functions.php
    ===================================================================
    --- functions.php	(revision 31036)
    +++ functions.php	(working copy)
    @@ -506,7 +506,15 @@
    
     	$post_title = p2_title_from_content( $post_content );
    
    +	$post_format = 'status';
    +	if ( in_array( $_POST['post_format'], p2_get_supported_post_formats() ) )
    +		$post_format = $_POST['post_format'];
    +
    +	$post = get_default_post_to_edit( 'post', true );
    +	set_post_format( $post_id, $post_format );
    +
     	$post_id = wp_insert_post( array(
    +		'ID'			=> $post->ID,
     		'post_author'   => $user_id,
     		'post_title'    => $post_title,
     		'post_content'  => $post_content,
    @@ -514,12 +522,6 @@
     		'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;
    Index: inc/ajax.php
    ===================================================================
    --- inc/ajax.php	(revision 31036)
    +++ inc/ajax.php	(working copy)
    @@ -226,7 +226,11 @@
     		if ( ! empty( $_POST['post_citation'] ) && 'quote' == $post_format )
     			$post_content = '<p>' . $post_content . '</p><cite>' . $_POST['post_citation'] . '</cite>';
    
    +		$post = get_default_post_to_edit( 'post', true );
    +		set_post_format( $post , $post_format);
    +
     		$post_id = wp_insert_post( array(
    +			'ID'			=> $post->ID,
     			'post_author'   => $user_id,
     			'post_title'    => $post_title,
     			'post_content'  => $post_content,
    @@ -238,7 +242,6 @@
     		if ( empty( $post_id ) )
     			echo '0';
    
    -		set_post_format( $post_id, $post_format );
     		echo $post_id;
     	}
     }
  2. Hi mattyrob - thanks a lot for the patch, I'll pass it along to the developers.

Reply

You must log in to post.

About this Theme

About this Topic