1

i am attempting to stop a page from being published if certain criteria are not met using the transition_post_status hook. However the WP_DIE does not stop the post from being published.

function check_post_limit( $new_status, $old_status, $post ) {

      if($new_status == 'publish'){

          wp_die();
      }
 }

add_action( 'transition_post_status', 'check_post_limit', 10, 3 );

`

0

1 Answer 1

1

wp_die(); will run AFTER the post is published. You are checking whether the post is published or not, which means the post is already published, what's done is done. You can update to post status from published to draft instead of using wp_die();. The following code will do it:

function check_post_limit( $ID, $post ) {
          $post = array( 'ID' => $ID, 'post_status' => 'draft' );
          wp_update_post($post);
 }
add_action( 'publish_post', 'check_post_limit', 10, 2 );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.