Skip to content

Changing status to draft #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
palmiak opened this issue Jun 25, 2021 · 0 comments
Open

Changing status to draft #16

palmiak opened this issue Jun 25, 2021 · 0 comments

Comments

@palmiak
Copy link

palmiak commented Jun 25, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant