WordPress.org

Make WordPress Core

Opened 3 years ago

Last modified 3 months ago

#18266 new enhancement

WordPress does not signal DB errors when adding/updating post

Reported by: sirzooro Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 3.2.1
Component: Posts, Post Types Keywords:
Focuses: Cc:

Description

WordPress does not signal DB errors when adding/updating post. As I checked, edit_post() (defined in wp-admin/includes/post.php) calls wp_update_post() but does not check if it returned error. Therefore end user never gets any error message.

I found this when I tried to replace valid SQL query with some invalid one, in order to stop insert operation when custom validation done in wp_insert_post_data hook failed.

Change History (3)

comment:1 c3mdigital8 months ago

  • Keywords reporter-feedback added; needs-patch removed
  • Type changed from defect (bug) to enhancement

Sirzooro,

Could you please elaborate a little. Can you add the code your using for the filter/action attached to wp_insert_post_data.

comment:2 sirzooro8 months ago

  • Keywords reporter-feedback removed

The main issue is that WP does not check if wp_insert_post_data hook returned error, and stop operation (see #18692). Because of this I looked for some way to force this using some other method, and found that I should be able to do this by triggering SQL error. While playing with (I had to check how to mask this error from user) I found that real (not artificially introduced) SQL error may not be shown, so I logged this ticked.

Here is my code:

function kill_sql_query( $query ) {
	if ( preg_match( '/^\s*(insert|update:?)\s/i', $query ) ) {
		return 'xxx';
	} else {
		return $query;
	}
}

function my_wp_insert_post_data( $data, $post_arr )
{
	if ( post_is_invalid( $data ) )
	{
		// Do not want to execute any extra SQL queries - just proceeded to INSERT/UPDATE query for current post
		remove_all_actions( 'pre_post_update' );

		// Now we can add the filter
		add_filter( 'query', 'kill_sql_query' );
	}
	return $data;
}

add_filter( 'wp_insert_post_data', 'my_wp_insert_post_data', 100, 2 );

comment:3 nacin3 months ago

  • Component changed from General to Post Types
Note: See TracTickets for help on using tickets.