The error message you are seeing is normal for that operation. By the time the transition_post_status
hook fires, the HTTP page headers is already sent. By simply echoing an error message inside a hook like transition_post_status
which was never intended to echo any output to the browser, as you did, you are actually trying to insert your error message into this page headers, causing the error message to show up.
transition_post_status
should be used to fire a hooked function on success or to performs a specific task, and not to echo output to the browser. The following is untested, but you can try something like this
add_action( 'transition_post_status', function ( $new_status, $old_status, $post ) {
if( $new_status === 'publish' ) {
add_action( 'admin_head', function () {
echo 'To test if we get this message without headers already sent error message';
}, PHP_INT_MAX );
}, 10, 3 );
Related Posts:
- How to create an API for my plugin?
- How to override existing plugin action with new action
- Which hook should be used to add an action containing a redirect?
- WordPress Update Plugin Hook/Action? Since 3.9
- WordPress Plugin Development – Headers Already Sent Message
- add_action with a class method is causing fatal errors
- Clarity needed on usage of multiple 403 forbidden header() functions at the beginning of the plugin files
- How do you use the plugin boilerplate loader class to hook actions and filters?
- add_filter OO with parameters
- How do I print a notice only on certain admin pages?
- Do I need to call do_action in my plugin?
- How Do I Load My Action Earlier Enough?
- Which to use to execute code during the saving of a plugin settings page?
- Does WP fire delete_post when trashed posts are automatically deleted?
- What’s the earliest point I can get the queried object ID?
- How do I Make a Theme “plugin-ready”?
- Headers already sent error with CSV export plugin
- A Post is saved twice or more during add_action(save_post)
- Get file headers in custom file
- Actions or filters fired when data is saved in a custom table
- Using ob_start() in plugin
- Adding custom code into header.php using a plugin
- How to use filter hook ‘post_updated_messages’ in coherence with action hook ‘save_post’
- What action is called when drafts are saved?
- How can I change HTTP headers only to posts of a specific category from a plugin
- Is it possible to create an action hook using do_action() within add_action()?
- How can I hook into existing WordPress Bulk actions?
- The plugin generated 80 characters of unexpected output!
- When is it too late to call the action wp_enqueue_scripts?
- Odd behaviour with submenu link creation
- What is the Difference between directly call a function and call a function using add_action?
- How to add custom content under plugin row in WordPress admin plugin list?
- Define a function outside a class and call the function using action or filter hook
- Create a plugin to change the action to which a function is hooked
- Cannot modify header information – headers already sent by pluggable.php
- Woocommerce – Hide a Column in Cart Table
- How to redirect to action on custom page within admin section
- Header Button Chance Polylang Elementor
- admin_notices not displaying in plugin
- Which action is triggered when a theme was modified?
- Getting admin notices working for plugin errors
- Which are the hooks run before/after when a category’s deletion?
- Should action callbacks start with a verb?
- Namespaced action and filter tags
- Proper way to pass credentials in a custom login form to avoid “headers already sent”
- Issue plugin commands in admin settings page
- My plugin class doesn’t work! [closed]
- add_action not calling back to function
- Plugin with action ‘save_post’ needs to press publish twice on order to publish
- Adding rewrite rule dynamically
- Prefixing plugin hooks (actions/filters) with a wrapper class or functions
- wp_set_object_terms not updating database without a die()
- Serve text/html from wp-json API via WPEngine, headers not being set properly
- How to filter content for specific content variable
- load_plugin_textdomain doestn’t work with add_action plugins_loaded
- Show error message after exception handled
- I have 2 plugins using the same wp_login action hook and one is not working
- How to give a download link to a .csv file from the custom plugin?
- Valid filenames for add_action’s first parameter
- WordPress class, using add_action to call member function does not work
- Where do I put my add_action(… and add_filter(… and do I need to remove them?
- How dynamic action login_form_{action} is working
- What action hook can I use to add a JavaScript to a page post using a theme template that is not including get_header() nor get_footer()?
- Bug: Post needs to be updated twice when adding action for save_post hook
- Delete data from database using row action
- When does save_post hook fire on post save/update
- Hook add_attachment error
- Call to undefined function is_home() or any conditional tags
- Adding custom stylesheet into header.php using a plugin
- How to find list of all functions bind to a particular hook from my plugin?
- Can I Hook Into the TinyMCE Insert/Edit Link Button to Use Shortlink For Post?
- Include HTML (Bootstrap Modal Box) with a plugin into my header
- wordpress automatic update does not run
- Using init hook for register_taxonomy is causing invalid_taxonomy in wp_insert_term()
- How Can I Add Code To A Preexisting Function Without Editing it
- Adding tables to dashboard pages programmatically?
- Setting post_id for single.php based on URL without a redirect
- Need Help Determining Where Header Error is Happening
- Why does website stretch and white space on load? [duplicate]
- Downloading File via headers doesnt work
- Action / Hook when a new plugin is added
- apply_filters() and call_user_func() to define and call a function outside a class
- WordPress Favicon not Working For Images/Videos/PDFs
- Where do I hook to have the server do something in PHP on block attribute change?
- Post is uncatagorized in publish_post action
- WordPress Plugin Boilerplate – add actions and/or filters based on user’s role
- do_action from within a class does not seem to work
- Two same AJAX calls – one is working, other doesn’t
- wp_ajax add_action fuction won’t fire on custom jQuery action
- remove different admin menu for specific users
- WordPress Reset password Strength set to medium
- Headers already sent on custom plugin (Export function)
- How to force download a plugin generated file?
- add_option_{$option} action hook not being called
- Does WordPress have something like timer hook?
- action callback, for action dispatched as reported by hook sniffer, not called
- How to remove a class [closed]
- Insert plugin html content to a specific spot in the frontpage
- Apply function on all action hooks?
- Ninja Forms: Front-End Forms, Post ID?