Skip to content

Changing status to draft #16

@palmiak

Description

@palmiak

Hi @nfmohit

While working on a similar plugin, but for Buddy.works integration I was trying to tackle the problem related to auto-deployment and while looking at your code I saw one bug.

if ( 'auto-draft' == get_post_status( $post_id ) || 'draft' == get_post_status( $post_id ) || wp_is_post_revision( $post_id ) ) {
    return;
}

So if we will unpublish the post/page it won't run and I think it should as unpublishing changes the content of the page.

I used a bit different approach. First of all I used transition_post_status action and then I went for something like this:

function check_post_status( $new_status, $old_status, $post ) {
  if ( 'auto-draft' === $post->post_status || wp_is_post_revision( $post->ID ) ) {
	  return false;
  }
  
  // publishing or updating something
  if ( 'publish' === $new_status ) {
	  return true;
  }
  
  // unpublishing
  if ( 'publish' !== $new_status && 'publish' === $old_status ) {
	  return true;
  }
  
  return false;
  
}

Of course your functionality is a bit different, but I hope you get the point.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions