After a bit more slogging through code and Googling, I found the answer. It’s contained in this thread (see Otto42’s post), but for the record, adding the following to your plugin will override the 404 handling for the conditions you specify:
add_filter('template_redirect', 'my_404_override' );
function my_404_override() {
global $wp_query;
if (<some condition is met>) {
status_header( 200 );
$wp_query->is_404=false;
}
}
Note that you need to set “is_404” to false before PHP outputs headers, which is why hooking it in the template_redirect logic is a good idea.
~ Patch
Related Posts:
- How to intercept a 404 error
- Adding onload to body
- How to use a WooCommerce action hook?
- Where can I find a list of WordPress hooks?
- How can I edit post data before it is saved?
- Difference between do_action and add_action
- Difference between after_setup_theme and init action hooks?
- get $post in init filter or action?
- Move excerpt meta box to above content editor
- Trigger custom action when setting button pressed
- Add subtitle to Woocommerce product title
- How to add a new product type on woocommerce product types? [closed]
- Which hook if user profile information is updated?
- Why does wp_enqueue_style() in plugin not load stylesheet?
- Are hooks called synchronously?
- Disable block from editor based on post type
- Difference between hooks Plugin_loaded and admin_int?
- Woocommerce Product Category Widget – hide categories that have no products in stock [closed]
- Make W3 Total Cache “Empty All Caches” function purge varnish [closed]
- Modify featured image URL at runtime
- How to inject content after
- How to debug removal of rewrite rule flushing?
- Some plugins adding full server path after url (with custom wp-content folder)
- Why am I sometimes getting a 404 error when I try to update a page with Elementor?
- How can I add a default description to uploaded files?
- Hook Widget to Woo Theme in functions.php
- Security around save_post hook
- How to use the post_updated hook before and after arguments
- How to add rewrite rules and pagination to retrieve attachments files?
- What are ideal hooks to call register_sidebars?
- AddFilter option_active_plugins is executed 6 times. Why?
- I don’t understand why I shoud use lostpassword_url hook?
- How to get session token of current user in wp_login hook?
- Hook any php file into the wordpress api
- WP CLI Get all Enqueued Scripts and Styles
- Error 404 using wpml plugin
- Delay an action until current action is completed
- Custom Post Type Plugin not loading category template and loading 404 instead
- Help to change the text for new website notification (wpmu_welcome_notification)
- How to pull code snippet from functionality plugin?
- How to remove query string from current page URL?
- Plugins rewrite rules the right way
- Strange behaviour with add_{$meta_type}_metadata | add_post_metadata filter
- Add nofollow to custom widget posts
- Change Password Confirmed Email Text
- Register form: add custom field BEFORE default fields
- Custom Front End Registration – How Does the Key work in the Password Set Request?
- Howto check version of another plugin and then add a submenu page to it
- Lock user information once fields have been filled in
- save_post hook to add terms getting deleted when using bulk edit
- Add Different Actions To Different Page’s wp_footer
- Turning on output buffering in a wordpress plugin
- How to use template_include hook with form submission?
- Getting the post ID in parse_query
- Remove genesis_404 hook from genesis_loop [closed]
- wp_trash_post hook – problem with page updating if using wp_die
- What hooks do I need to hook into to capture ever wp_user creation/change?
- is it possible to hook every page style?
- Add action to custom Function
- Neccessary to call add_submenu_page and add_menu_page from admin_menu hook?
- Plugin Hook When New Author Added
- How to call do_action() to pass arguments to hooked functions that take different number of args?
- Fail on admin_enqueue_scripts when I try it to upload a CSS file to my WordPress Plugin
- Alternative Hook to the_content for Changing Background Color
- Unpublished Pages Failing To Appear On Custom Path
- Hooking into the HTML header container
- Hide WordPress Site URL from Source Code
- Error later wordpress 5.3.2 update. Please help
- Plugin function in child theme
- How to abort a save operation with a WordPress hook?
- is_page not triggering
- {status}_{post_type} does not run correctly?
- Check if front page within function passed to action
- Hook after creating a post and retrieve infos from this post immediatly
- Identify if the_post hook is being called from the admin post list
- $new_pass always returns null – password_reset hook
- Why can’t I shove an instance of a class into a variable from a do_action hook?
- Passing a parameter to filter and action functions
- How to resolve 500 error in post listing page?
- WordPress hook source
- Object oriented programming, add_action in constructor not firing
- How to `remove_action` from plugin
- Get new (not old) post inside transition_post_status hook
- Transition Post status not working
- Cannot override hooks.php
- Removing action from template class
- Remove “enqueued” script from array
- functions.php conditional output for a single plugin
- Function is Missing an Action Hook
- How to access variables in the function where apply_filters() is called?
- OOP Plugin: Where should I place the action hooks in the class?
- 404 Page when emptying spam or deleting a plugin
- getSaveContent.extraProps hook for core/post-title doesn’t add new attributes on to the frontend
- How can I modify the code generated for a PDF by the Add Media button in Classic Editor?
- Do New_to_publish hooks work for custom post types
- Plugin Icon does not work correctly
- Creating my own “recent blog posts” static Gutenberg block, can’t use react hooks in the frontend
- Change social icon in twenty twenty three theme
- How do I set a custom post type Category after import using wp_set_post_terms
- Why does before_delete_post run when opening a post in the backend?