Take a look into this example:
add_filter('some_hook', $callback = function( $arg ) use ( $values ){
//Some calculation here
});
You can set arguments this way, and also use the predefined variables that exist outside the functions scope, by using the use() term.
This way, you can unhook the function wherever you want, by doing this:
remove_filter('some_hook', $callback);
Related Posts:
- Where is the best place to use add_filter
- When can you get current page ID and initialize hooks right after?
- Using the ‘draft_to_publish’ hook (post status transition)
- Enqueue style inside shortcode but its loaded at the bottom of page (before footer scripts)
- How can I limit functionality in one version of a plugin?
- Shortcode display outside the div
- Good tools for locating hooks in a wordpress page/admin interface/blog post?
- Can a plugin add to header/footer/body content?
- Is it possible to add an action to the currently running action?
- How to bulk send emails
- Action on post publish
- How to add inline css/js inside a shortcode
- How to call bind function in wordpress actions or hooks
- How to prevent action in ajax request, when in admin side?
- template_redirect not being called when using ajax
- WordPress plugin for mail subscriptions [closed]
- action-scheduler vs wp-background-processing
- add action wp_head not working
- What are the benefit in adding hook in the init() hook?
- add_action in functions.php, do_action in plugin?
- Check if email address exists front end with AJAX in a plugin
- add action for displaying posts using a shortcode
- ‘wp_login’ action hook not working with wp-login.php file
- Any hook for pre-plugin-update -either bulk or single plugin update
- wordpress plugin is not activating from widget
- When to load auto-login code?
- How to get all of the activate_plugin action parameters?
- How to check current user before all actions and filters?
- Get Time Taken By Each Action Hook in WordPress
- Are functions in main plugin file called before function bound to register_activation_hook runs?
- Custom plugin init action causing general slowness
- Inject HTML meta tag inside wordpress tag using add_shortcode
- Add action to fire when a published post is updated
- Submit Form data to another page via Ajax (WordPress Way)
- Does using `add_action( ‘init’…` cause performance issues?
- Hook for page Request?
- SMTP Error: Could not authenticate [closed]
- sending different email notification while registration based on user role
- Custom CSS not being added by plugin
- How to use add_action for multiple instances of the same class
- How to append new form elements in “Add New” form of Users in WordPress admin panel?
- I cannot include a file in my plugin settings page
- Why do actions with class and public method don’t fire __construct()
- The function called on the wp head hook becomes null
- I want to schedule email (date, time is in database->table) wp_schedule_event() not working
- Nested Actions and Filters
- Passing function into add_action always returns the first argument
- Get post content inside plugin class method
- Remove action added in plugin class from theme
- echo plugin results on pages
- Form tries to download a file on submit
- How to customize ‘recurrance’ of’ wp_schedule_event’?
- Plugin Hook: Get posts
- Is it possible to cancel a post status transition?
- How wordpress plugin hooks works? [duplicate]
- Send email notification when meet the condition
- WordPress isn’t sending welcome email with the password reset
- add_action() not working for admin
- How to create a child/addon plugin
- How to secure the release of WordPress plugins / avoid copying plugins?
- How do I combine a theme with a plugin
- Use wp-config.php constants in all files of plugin
- _prime_post_caches in wordpress
- How do I make a secure API call from a shortcode when a button is clicked?
- WordPress REST API Plugin Development – Add Custom Endpoint
- Hook into the rendering of a WordPress Template
- Save user total active time after login in wordpress [closed]
- WordPress gtag.js with User ID tracking
- how to execute some code after a post is published in WordPress [duplicate]
- wp_loaded with static Singleton
- Calling a save function from a “submit” button
- How to hook into action/filter call
- Select Form Element Not Saving from Plugin Options
- My widget won’t update its values when save is clicked
- Can we give Pending as a Role to wp_insert_user?
- How to automatically activate users after registration without activation email?
- Pass PHP variable to javascript
- Table of contents (TOC) plugin is not showing header tag
- Custom page from wp admin area
- Unexpected add action function in WP plugin
- Avada Live is broken on WP
- Make downloadable ebook read online without download option
- WordPress rewrite rule depend on meta values not ids
- Offering a freemium plugin (a free version + paid version)
- In woocommerce, is there any way to empty wordpress default mini cart when order placed?
- Making a Custom Post Type Plugin – keep getting the white screen of death
- Limit Google Ads to particular blog posts
- Communicating to plugins from webserver
- Buddypress Member list not showing admin and mods
- Hook into install email
- Shortcode in a blog post, footer and related products stop working
- Editing a built plugin: How to activate it only on a single post page
- Autoloading a PHP class – working outside, but not inside WordPress plugin
- Linking Plugin Files to WP
- Remove action plugin
- Send Processing Order Email from custom payment plugin
- How to host a WordPress plugin on my own server and provide updates?
- Inline AJAX script passing variables to PHP
- claim a permalink and all sublinks in plugin
- Vanilla javascript in custom gutenberg block not working