You can use an anonymous function with PHP’s use
statement like so:
function mycars($mycarsclass){
$args = array(
'car1' => 'Volvo',
'car2' => 'Toyota'
);
$mycarsclass->add_node($args);
}
add_action('mycarsaction', function () use ($mycarsclass) {
mycars($mycarsclass);
});
do_action('mycarsaction');
or declare a separate function and pass that:
function mycars($mycarsclass){
$args = array(
'car1' => 'Volvo',
'car2' => 'Toyota'
);
$mycarsclass->add_node($args);
}
function mycars_mycarsclass() {
$mycarsclass = new mycarsclass();
mycars($mycarsclass);
}
add_action('mycarsaction', 'mycars_mycarsclass');
do_action('mycarsaction');
Related Posts:
- Customizing subject in comment notification e-mails
- WP showing “warning: call_user_func_array()”, What to do?
- Are there action hooks for comments?
- front end editor creation for Restropress plug in – displaying information from a WP admin area, on a different URL
- How can I see all the actions attached to an “add_action” hook?
- How do I call wp_get_current_user() in a plugin when plugins are loaded before pluggable.php?
- Plugin update error message
- How to Loop Plugin Option Field Set?
- Can we completely remove the WordPress Sitemaps (WordPress 5.5)?
- WordPress Hook that will run when media file deleted
- Set a User as Author of all ‘New Posts’ posted
- Post source link plugin – small modification
- Check if a class exists within a method
- HELP: Integrating WP with raw PHP code once published button is hit
- How to redirect Old Post URL to new Post and keep Old post Comments?
- Modifying Footnote Plugin for Descriptive Title Attributes
- I would like to use create a function in my custom plugin to tell WP to use a different header
- New Plugin: Post update pushes a copy as a revision
- bulk change of image setting “link to” to “link to: image url “
- Placement of Code in Plugin for hooking `save_post`
- How to get post URL in the_content filter?
- How to initialize something in unit test before the init hook being called?
- Pass info from functions.php to plugin
- add_query_arg not working
- Executing my function once on a specific time
- How to stop or remove an action being called inside a function of an extended class
- Theme my Login plugin, how to update fields
- Date calculations from 2 custom fields
- How to enable specific plugin only based around shop manager role?
- get current date + 90 days and checking every day
- Adding a new field to the address field type in gravity forms
- Calculate price and display on woocommerce product single page under price (simple price, variable price) [closed]
- Nested shortcode functions accessing variable
- Customize permalink wordpress category id
- WP Query. Is there a maximum size?
- Redirect to another page using contact form 7? [closed]
- Load Javascript from Plugin in One Page Only?
- Why is my custom post type not being activated on plug-in activation?
- Checking the count within a foreach loop
- Create a post builder skin in a plugin
- Plugin Development – Functions or Hooks?
- wp_dequeue_script for a Plugin
- Need to replace Currency Shortforms
- How do I add $_SESSION[”] to my wordpress page?
- Built a second plugin but it overwrote the first one
- WordPress: Add custom add_filter for custom functions
- How to remove a class function from a plugin by using remove_action()?
- How to translate wordpress error message
- Api external with wordpress
- profile_update hook doesn’t works inside a class
- All custom widgets are not showing in widget area at the same time
- Plugin: Hooking up classes that have their own hooks
- Hook for altering the content of all wp mails
- More gentle way to hook WordPress custom url
- Can you echo PHP code from a variable?
- Build a must-use plugin that tracks when other plugins are activated or deactivated
- Checkbox show / hide output result
- Custom Logo Link WordPress
- How to convert Currency from USD to other IP Based currency in Php function
- how to validate input field in wordpress generated with wpform plugin
- implement custom roles in custom plugin
- How to get current cart values using WC_Shortcodes?
- Attempting to list all product categories and the price range of all products within them
- FPDF for creating pdf diplomas
- Creating an array from form inputs before it is posted to the options database
- Custom Plugin: How to Include Install Buttons of other 3rd Party Plugins?
- adding dynamic/multiple slug values in ‘option_none_value’
- How to assign a specific service to a specific provider based on location
- Get post content inside plugin class method
- Is admin section completely customizable in terms of styling?
- How to make the first letter of a post title uppercase, in a plugin?
- Compare Ajax Data Results
- How can I make the search bar in my wordpress site search all of the pages rather than just the blog posts?
- Migrating custom php we wrote from functions.php into a site-specific plugin
- What is the correct entry point for capturing coverage data
- Nested DIV’s across functions in PHP, do not seem to work
- Every time I use wp_get_current_user() my plugin breaks
- Cannot access variables within a widget
- Posting code inside the post instead of in the template file using shortcode
- WordPress function to add text
- Saving plugin data returns “You do not have sufficient permissions to access this page.”
- Metabox Data not saving
- How to add a handler for a button in plugin?
- Can anyone tell me why I can’t edit a plugin when it is installed without having to re-install?
- private functions in plugins
- Doing action based on input from options menu
- Including a PHP file via a function that is part of a plugin?
- Move related products after product summary? [closed]
- How to tweak a plugin without preventing it from updating
- Adminimize Plugin — Is there an alternative to limiting Editor to ‘Appearance > Widgets’ only?
- Integrate Razorpay quick payments plugin with contact form7 plugin
- Woocommerce disable checkout on specific day
- Strict Standards: Non-static method in sidebar generator
- How to Add Extra Text In WordPress Title Before Post Publish
- Function not being called on form submit, only blank admin-post.php page
- How can I save the selected page in the dropdown after anyone clicks on Save Changes?
- How can I save the selected page in the dropdown after anyone clicks on Save Changes?
- WordPress Convert queries to slashes using function.php
- How to change all the urls of the WordPress site?
- I want to allow certain file types on dokan upload files