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
- Should all plugins be encapsulated in a Class?
- Registering Class methods as hook callbacks
- How do I call wp_get_current_user() in a plugin when plugins are loaded before pluggable.php?
- 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
- Seeking clarification on page request life-cycle
- Saving Plugin settings to the database
- Change destination author link
- Custom Widget outputs the input but doesn’t save anything inside the textarea
- How can i change an image’s author?
- Over write plugin templates
- How to find out what blocks are added by a plugin
- How to Replace Words with Hypertext Link But Ignore Previously Existed Links?
- 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
- Add a plugin before main container
- Prevent a plugin from being automatically activated
- wordpress plugin is not activating from widget
- Override Plugin Script Fucnction in WordPress
- wp_get_post_terms is difference obj model than the one in rest api response
- Replacing a plugin function with a custom renamed function doesn’t work
- How to call WordPress function other files
- Using plugin functions/methods within templates
- Conditional attributes and logic per product category
- What is @Action in WordPress?
- Check if variable is set in filter
- execute function after one completed
- JQuery prepend a function
- wp_enqueue_scripts
- How to get specific string/value from an array? php [closed]
- WordPress Stock Update Programatically
- How can I fetch data from another website to my wordpress website with mysql database
- Save user total active time after login in wordpress [closed]
- Getting a ressource ID, from a WC_Order_Item_Product/Order
- How to translate wordpress error message
- All custom widgets are not showing in widget area at the same time
- Add the_post_thumbnail_url to a shortcode in function.php
- same user role or copy the user role to be same as the other role
- Adding a Tag Parameter / Filter to My Shortcode
- More gentle way to hook WordPress custom url
- How to add custom function to pluggable.php
- 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
- WP Function does not trigger on Webhook API Call
- Cookie value changes back to previous value after changing
- Alternative Hook to the_content for Changing Background Color
- Unpublished Pages Failing To Appear On Custom Path
- Post source link plugin – small modification
- Is there any way to sync Facebook Comments and with comments on WordPress website?
- How to create algorithm for ordering posts in WordPress?
- ACF Fields are not showing up on Homepage
- Hooking into the HTML header container
- Easiest way to load/fire a handful of functions, IF checkbox is checked?
- Block plugin update possibilities (but not by hiding notifications)
- Plugin function in child theme
- post id or permalink auto-incrementing number and reset everyday
- Is admin section completely customizable in terms of styling?
- How to make the first letter of a post title uppercase, in a plugin?
- Soflyy WP All Import Custom File Download Issue
- 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
- WordPress environment not loading properly
- How to echo a plugin’s function into a template?
- How to replace native comment_count with Comments Evolved aggregate count
- It possible to implement an adhoc php web application with wordpress?
- Cannot access variables within a widget
- Is there any wordpress function to update a random post every 10 minutes?
- Autoloading a PHP class – working outside, but not inside WordPress plugin
- Calling an custom field from theme option at the frontend
- WordPress function to add text
- Saving an array to get_options
- Contact Form 7: custom validation [closed]
- functions.php conditional output for a single plugin
- date function not correctly returning date
- Doing action based on input from options menu
- OOP Plugin: Where should I place the action hooks in the class?
- Showing author box on post detail page
- add query string to all pages after user logged in
- How use Dynamic hyperlink on each wordpress post?
- How to prevent page load on form submission
- is_plugin_active() not defined on active plugin, in the thumbnails.php file
- Strict Standards: Non-static method in sidebar generator
- Requires PHP version 5.3.0
- WordPress: code structure
- PHP if url extension action=discussion condition use [closed]
- Can’t use updated variables in handle function
- Make plugin admin page visible to other roles
- How to change all the urls of the WordPress site?
- I want to allow certain file types on dokan upload files
- Read page- or post-content across different builder-plugins
- WordPress : how to create onglet and remove it when only one