Updating failed message when a wp_insert_post function is hooked to save_post hook
Updating failed message when a wp_insert_post function is hooked to save_post hook
Updating failed message when a wp_insert_post function is hooked to save_post hook
This can happen as you said there are some errors in code or if there is long or duplicate queries. Try to debug it with Query Monitor. Same reason if Safe button takes longer to get active.
See this answer for solution, see comments there about error messages. That should work with Classic editor. It could work with Gutenberg too, but it would need additional effort to get correct error messages. UPDATE: If using classic editor and preventing publishing of invalid records is enough, you can use this code: function my_save_post($post_id) { … Read more
If you have access to the server’s list of PHP processes, you can try killing them or restarting the PHP server. Otherwise, your script might hit a “maximum execution time” limit sometime soon (unless set to inifinite). The setting in question is called max_execution_time and is expressed in seconds if you can access your server’s … Read more
Issue Saving Posts That Contain Shortcode
Filters always return something, they’re not actions, they take something in, modify it, then return it, but your filter does neither. As a result, PHP declares that it returned null, and the next filter along recieves null as the post content. For example, this filter appends the word “Hey!” to the end of the content: … Read more
I found the culprit. I had to change the nonce check in save_custom_post_type() to: if ( !isset( $_POST[‘metabox_nonce’] ) || !wp_verify_nonce( $_POST[‘metabox_nonce’], basename( __FILE__ ) ) ) { return $post_id; }
Finally, I did it! Use the post_updated_messages hook instead. add_filter( ‘post_updated_messages’, function( $messages ) { // Get the permalink $link = esc_url( get_permalink($post_ID) ); // Copy the permalink automatically $autocopy = ‘<script type=”text/javascript”>navigator.clipboard.writeText(“https://wordpress.stackexchange.com/questions/367921/%s”);</script>’; // `6` is for publishing $messages[‘post’][6] = sprintf( __(‘Post published. <a href=”https://wordpress.stackexchange.com/questions/367921/%s”>View post</a>’. $autocopy), $link, $link); // `1` is for updating $messages[‘post’][1] … Read more
It looks like the variable you’re using to set the selected item is not defined in that scope. In your constructor: public function __construct() { if ( is_admin() ) { add_action( ‘load-post.php’, array( $this, ‘init_metabox’ ) ); add_action( ‘load-post-new.php’, array( $this, ‘init_metabox’ ) ); } $this->dropdown_args = [ ‘show_option_none’ => ‘- select a page -‘, … Read more
I believe you should look into status transitions: https://developer.wordpress.org/reference/hooks/transition_post_status/ There are a couple of examples below the explanation on top of the page. Here’s also some example code of mine: add_action( ‘transition_post_status’, ‘nxt_create_news’, 10, 3 ); // Automatically create a news when a wiki post has been published function nxt_create_news($new_status, $old_status, $nxt_wiki_post) { if(‘publish’ === … Read more