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:
- Earliest hook to reliably get $post/$posts
- How to pass/get data to/from the WooCommerce data-product_variations object?
- What does (10, 2) mean when used with add_filter
- Clarification on filters and hooks
- How to check if a hook is hooked or not?
- Passing Additional Parameters to add_filter Callable
- Modify WordPress Rest Api Request/Response
- How to add some custom HTML into wordpress admin bar?
- Custom theme hooks / filters – passing arguments
- How to hook wp_list_pages?
- How to make post and comment count unclickable with dashboard_glance_items hook
- How to use the_excerpt in a filter hook?
- Hook into admin post list page
- 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?
- About Hooks and Filters
- Shortcodes not resolved in AJAX call response
- Ajax, filters and shortcodes
- Should I use add_action(‘publish_post or add_filter(‘publish_post?
- Multiple Ajax Data Action
- How to get list of all hooks of current theme / plugin?
- What hook/filter can I use to add/edit/show/hide the title under (on hover) links on the table view?
- Change WordPress RSS link with filter?
- Add a header before fields added with the attachment_fields_to_edit() filter
- Hide content editor for posts after approriate date
- Why my admin doesn’t work after adding rest_prepare_post filter?
- add_filter() function misunderstanding
- How to set a custom path, for ajax image upload folder in admin?
- Is it possible to track down Actions and Filters?
- Same Conditionals Not Working on Two Different Hooks
- Filter or Hook to catch pre-rendering of post content
- Can the wp_filter object hold multiple values with the same key
- check to see if hook is available
- apply_filters/do_action tag characters limit
- Insert term when page is published – avoid duplicates after edits
- How to modify core when there is no hook?
- Are there actions or filters I can use for Ajax calls?
- When does a function assigned to the content_filtered_edit_pre filter hook fire?
- Capture post content before page renders
- Remove_action does not work
- How to filter for user registration, be able to throw error message
- How to remove action with slashes and arrows?
- Better extend a class or use add filter/action hooks?
- Add content as soon starts
- Make an array filterable per hook
- Changing WordPress core without hacking core
- Customize title, description and focused keyword [closed]
- Comment search plugin
- Plugin options, presets and filters : can you help me improve my workflow?
- how to customize rss feed tags using hooks?
- Issue understanding and using WordPress filters and actions
- wp_mail works with add_action(‘save_post’, …) but not an ajax action
- Woocommerce “added to cart” message on main(home) page
- How to check if a protected hook is hooked?
- Wrapping my head around add_filter
- Gutenberg Block – Post Featured Image Filter Hook
- Disadvantage of using filters & hooks multiple times
- How To Override A WooCommerce AJAX Function
- Admin post list – adding an option to the date filter dropdown
- Modify message displayed on post save
- Pass debug_backtrace() in WordPress filter
- Remove actions/filters that are set with create_function()
- Get The Caller (Plugin / Theme / Core) For All actions & Hook in WordPress
- comment_for() Custom fields not visible when user is logged in
- How to access page variable inside action hook
- I need to hook and change language of facebook sdk
- Use has_filter on comment_post
- How To Get Search Term and Use in Function
- Renaming wordpress login and get new password button
- Is this hook really deprecated? ( manage_{$taxonomy}_custom_column )
- Hook in a sidebar widget and add some markup
- BuddyPress – A hook available to hide custom born date on public profile view?
- Same URL for portfolio and for a page creates 404 error. Is there any filter that i can use for a child page?
- ‘manage_users_custom_column’ is a filter, but ‘manage_posts_custom_column’ is an action. Why?
- Scanning for custom embed and prefetching
- The gettext hook doesnt work on text with links
- Filter widget_posts_args not working
- Filter the title to only affect the_title() template function
- Remove and replace woocommerce add to cart button [closed]
- How can I filter the comment action links so that I can display the actions links based on user capabilities?
- Hook to change the site URL
- Modify WordPress Page Title ()
- Hook to add content after date in post?
- Is it possible to assign a css id to a row in plugins list table?
- Add Index to Item in WordPress Gallery
- Re-order search results with posts_orderby filter and post meta value
- Code restricted to dashboard, running unexpectedly in the frontend (pre_get_post and admin-ajax.php)
- Converting restricted html in comments to bbcode
- Why none of xmlrpc filters work
- How to add a class to Buddypress avatars in the Activity stream? [closed]
- Which hook should be used in this case?
- WooCommerce comments_template Filter Not Firing
- str_replace css meta tag?
- How to use apply_filters(‘get_calendar’) to change get_calendar() output?
- Can you call a filter hook by “add_action”?
- How to elect position of new item output in a dropdown when using add_filter
- “Invalid parameter(s): attributes” issue in context of “blocks.registerBlockType” filter
- Load More : Admin Ajax 400 Bad request, returning 0