Opened 13 years ago
Closed 8 years ago
#18266 closed enhancement (wontfix)
WordPress does not signal DB errors when adding/updating post
Reported by: | sirzooro | Owned by: | |
---|---|---|---|
Milestone: | 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 (4)
#1
@
11 years ago
- Keywords reporter-feedback added; needs-patch removed
- Type changed from defect (bug) to enhancement
#2
@
11 years 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 );
Sirzooro,
Could you please elaborate a little. Can you add the code your using for the filter/action attached to
wp_insert_post_data
.