Is it possible to bind a function to a filter hook via Ajax?
No, because page requests are self contained.
When you request something from PHP, everything gets loaded from a fresh clean slate. At the end of the request, that slate is discarded.
This is different from say a Node application that is always running.
So, if you make an AJAX request and unhook a filter, it’s only unhooked for that request. A second page load, or AJAX request will not be affected by the unhooking, so it would need to be done on every request.
If you want something to persist across requests, you need to store it somewhere that persists, such as the database of the filesystem. Either way what you want to do won’t work, and there’s no change to WordPress or PHP you could make that would allow it to work the way you proposed.
Related Posts:
- WordPress hooks/filters insert before content or after title
- How do filters and hooks really work in PHP
- Trouble understanding apply_filters()
- How many filter/action hooks are healthy?
- Filter specific shortcode output?
- Earliest hook to reliably get $post/$posts
- How to pass/get data to/from the WooCommerce data-product_variations object?
- Where to hook into post content?
- What does (10, 2) mean when used with add_filter
- Clarification on filters and hooks
- Valid characters for actions, hooks and filters
- How to hook into unregistering a widget instance?
- How to check if a hook is hooked or not?
- Passing Additional Parameters to add_filter Callable
- What hook do I use to edit the post statuses option in admin?
- Filter hook before create order WooCommerce
- Modify WordPress Rest Api Request/Response
- How to add some custom HTML into wordpress admin bar?
- Custom theme hooks / filters – passing arguments
- wp_mail – Remove sitename from email subject
- AJAX filter posts on click based on category
- How to disable all WordPress emails modularly and programatically?
- How to hook wp_list_pages?
- How can I send data to admin-ajax via JS Fetch?
- apply_filters() slices away needed arguments
- WP Rest API – Upload media without saving attachment post
- How to make post and comment count unclickable with dashboard_glance_items hook
- How to use the_excerpt in a filter hook?
- How to add attribute to output with wp_video_shortcode add_filter
- How to change Woocommerce breadcrumbs content?
- Hook into admin post list page
- Anyway to edit the titlebar of WordPress Widgets in the Admin area?
- How to limit the pages displayed for choosing parent page on page attribute’s menu?
- How can I hide all posts that don’t have a thumbnail?
- Change text of Description in Image Library
- Load different template file when condition met?
- Am I using the right hook for removing quicktags on the admin TinyMCE?
- Modify WordPress Page Title ()
- Add an attribute to the root from functions.php with add_filter
- Would like to use hook or filters to customize email templates
- Ajax filter – show all results that contain at least one filter
- Hook to add content after date in post?
- AJAX Post Filter
- Is it possible to assign a css id to a row in plugins list table?
- Right filter for rewriting page statuscode
- Add filter return false not working
- Add Index to Item in WordPress Gallery
- Remove image of srcset
- Re-order search results with posts_orderby filter and post meta value
- Security question – Display a General Custom Login Error Message
- Display post after choice two taxonomy terms
- Ajax Filtering Pagination
- Filter wp_mail based on content type
- Add HTML to the bottom of each post in a post list
- get_the_archive_title hook unwanted changes!
- How to filter wp_get_recent_posts() to only posts that have thumbnails?
- Change add_filter based on Ajax
- Filter posts by categories ajax is showing all the posts
- Hook inside a hook
- Incrementing content with extra text after save/publish
- Code restricted to dashboard, running unexpectedly in the frontend (pre_get_post and admin-ajax.php)
- Adding user filter – Not updating data in URL
- wp_editor customization
- How to check which submission button was clicked?
- Converting restricted html in comments to bbcode
- Why none of xmlrpc filters work
- WP Dashboard -> Posts-> Filter by Category -> Form Method Change : Which Hook
- change attachment custom field onChange event
- How to add a class to Buddypress avatars in the Activity stream? [closed]
- Hide H1 Title using the_title filter
- Add class to all parent elements inside the_content
- Loading a sidebar on an Ajax call
- Which hook should be used in this case?
- Filter dashboard custom post listing by user
- Getting entry ID from frm_email_message filter in formidable
- WooCommerce comments_template Filter Not Firing
- Auto append text after the title?
- Admin New Order: Autofocus on Search a product
- NextGEN Gallery: Adding drop-down menu widget to gallery view without modifying plugin code [closed]
- How to filter part of a variable if it is no array?
- str_replace css meta tag?
- How do you disable the verification process of user email changes?
- How to use apply_filters(‘get_calendar’) to change get_calendar() output?
- Can you call a filter hook by “add_action”?
- Better way to change the default password reset url with the woocommerce one?
- Hooking/Filtering theme name to add theme directory
- How to elect position of new item output in a dropdown when using add_filter
- Replacing text using add_filter
- Passing value from one hook to another
- Change password reqts with NO plugin without breaking resetpass link?
- How to Dynamically Switch WordPress Front Page Without Causing Canonical Redirect?
- hook on the_excerpt
- Why wordpress doesn’t allow to add author filter to media library page in grid mode
- How could I create real-time filtering in this case?
- “Invalid parameter(s): attributes” issue in context of “blocks.registerBlockType” filter
- Load More : Admin Ajax 400 Bad request, returning 0
- Adding custom filter not working
- Core/Image access caption in render_template and in wp.hooks
- Ship block templates or block template parts with plugins
- How to add custom field to top of WordPress Comment Form for both logged in and anon users