Skip to main content
Sorry to edit again, fixed Question title
Link

How can I hook into creating a new post and execute wp_die does not work as intended(), before the post is inserted into the database?

added 158 characters in body
Source Link

Info about wp_die from codex: Kill WordPress execution and display HTML message with error message. A call to this function complements the die() PHP function. The difference is that HTML will be displayed to the user. It is recommended to use this function only when the execution should not continue any further.

I have code:

function myHook( $post_ID, $post )
{
     wp_die('Error', 'Error',  array( 'response' => 500, 'back_link' => true ));
}
add_action( 'save_post', 'myHook', 0, 2 );

Problem is that error page appears, but post is still inserted. Shouldn't saving be interrupted by this hook? If I misunderstood description, how can I break execution so post will not be saved?

EDIT: I just found that save_post is called after instert to database not before. Does there exist any function called before insert that i can hook into?

Thanks in advance

Info about wp_die from codex: Kill WordPress execution and display HTML message with error message. A call to this function complements the die() PHP function. The difference is that HTML will be displayed to the user. It is recommended to use this function only when the execution should not continue any further.

I have code:

function myHook( $post_ID, $post )
{
     wp_die('Error', 'Error',  array( 'response' => 500, 'back_link' => true ));
}
add_action( 'save_post', 'myHook', 0, 2 );

Problem is that error page appears, but post is still inserted. Shouldn't saving be interrupted by this hook? If I misunderstood description, how can I break execution so post will not be saved?

Thanks in advance

Info about wp_die from codex: Kill WordPress execution and display HTML message with error message. A call to this function complements the die() PHP function. The difference is that HTML will be displayed to the user. It is recommended to use this function only when the execution should not continue any further.

I have code:

function myHook( $post_ID, $post )
{
     wp_die('Error', 'Error',  array( 'response' => 500, 'back_link' => true ));
}
add_action( 'save_post', 'myHook', 0, 2 );

Problem is that error page appears, but post is still inserted. Shouldn't saving be interrupted by this hook? If I misunderstood description, how can I break execution so post will not be saved?

EDIT: I just found that save_post is called after instert to database not before. Does there exist any function called before insert that i can hook into?

Thanks in advance

Source Link

wp_die does not work as intended?

Info about wp_die from codex: Kill WordPress execution and display HTML message with error message. A call to this function complements the die() PHP function. The difference is that HTML will be displayed to the user. It is recommended to use this function only when the execution should not continue any further.

I have code:

function myHook( $post_ID, $post )
{
     wp_die('Error', 'Error',  array( 'response' => 500, 'back_link' => true ));
}
add_action( 'save_post', 'myHook', 0, 2 );

Problem is that error page appears, but post is still inserted. Shouldn't saving be interrupted by this hook? If I misunderstood description, how can I break execution so post will not be saved?

Thanks in advance