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
- Add 2 links in between the navigation using the Breadcrumb Navxt plugin hook
- Should all plugins be encapsulated in a Class?
- How can I see all the actions attached to an “add_action” hook?
- Registering Class methods as hook callbacks
- How do I call wp_get_current_user() in a plugin when plugins are loaded before pluggable.php?
- Plugin update error message
- Keep one user logged for a year?
- if plugin is active? check if plugin is enabled or not?
- How do I extend one plugin I’m writing with another I’m writing using classes?
- Adding a text domain to every __(), _e() and __n() gettext call without a plan to create own translations
- 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
- Seeking clarification on page request life-cycle
- Saving Plugin settings to the database
- Set a User as Author of all ‘New Posts’ posted
- Post source link plugin – small modification
- Change destination author link
- How to turn off email you receive when registered?
- Custom Widget outputs the input but doesn’t save anything inside the textarea
- Check if a class exists within a method
- Fatal error: Class not found in
- How can i change an image’s author?
- HELP: Integrating WP with raw PHP code once published button is hit
- Over write plugin templates
- How to find out what blocks are added by a plugin
- 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
- How to Replace Words with Hypertext Link But Ignore Previously Existed Links?
- bulk change of image setting “link to” to “link to: image url “
- Placement of Code in Plugin for hooking `save_post`
- Display a text message if the field is not found and not if found
- Reposition Woocommerce Message
- Scope for PHP Variables Assigned in functions.php or a plugin
- How to get post URL in the_content filter?
- Add a plugin before main container
- Build a must-use plugin that tracks when other plugins are activated or deactivated
- Checkbox show / hide output result
- Custom Logo Link WordPress
- Use a hook or filter, or overwrite this Gamipress function?
- 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
- add_rewrite_rule to load different page, without changing URL in browser
- 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
- Allow a particular user to access a particular plugin?
- WP Function does not trigger on Webhook API Call
- Cookie value changes back to previous value after changing
- FPDF for creating pdf diplomas
- Alternative Hook to the_content for Changing Background Color
- Unpublished Pages Failing To Appear On Custom Path
- Creating an array from form inputs before it is posted to the options database
- add a hook of Woocommerce to a plugin but it only shows and doesn’t function properly
- Post source link plugin – small modification
- Is there any way to sync Facebook Comments and with comments on WordPress website?
- Share my WordPress plugin for updating how?
- Custom Plugin: How to Include Install Buttons of other 3rd Party Plugins?
- The function called on the wp head hook becomes null
- adding dynamic/multiple slug values in ‘option_none_value’
- How to create algorithm for ordering posts in WordPress?
- Submitting form to PHP
- ACF Fields are not showing up on Homepage
- Adding discount functionality to the cart
- How to assign a specific service to a specific provider based on location
- Precheck fields when I add a new post
- Hooking into the HTML header container
- Get Shortcode output to database for static post_content
- working code, not working – Plugin Dev
- Easiest way to load/fire a handful of functions, IF checkbox is checked?
- WordPress plugin blog creation
- Block plugin update possibilities (but not by hiding notifications)
- Plugin function in child theme
- post id or permalink auto-incrementing number and reset everyday
- Use action, filter, or hook to append HTML to WordPress plugin function
- Change custom rewrite rule when permalink is updated/changed
- Get post content inside plugin class method
- Is admin section completely customizable in terms of styling?
- Return function results within shortcode
- Configuring default woo commerce login with modal popup
- 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?
- Soflyy WP All Import Custom File Download Issue
- register_activation_hook doesn’t fire at all
- Update (a function) post’s featured image as soon as $image_url changes
- 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
- My ajax request don´t work and return 0
- WordPress environment not loading properly
- plugin not hooking to my custom hook
- Populate select option with JSON file
- Every time I use wp_get_current_user() my plugin breaks