It looks like you are adding the hook just inside the body of the class. Try adding it into an init()
method and calling it after it is instantiated or at the very least in the constructor.
I think the issues is that the hook is being registered before the class has been fully read by PHP?
Try this:
final class My_Class_Name {
function init() {
add_action('after_switch_theme', array( $this, 'activate' ));
}
function activate() {
}
}
$class = new My_Class_Name();
$class->init();
Hope this helps!
Related Posts:
- WordPress and event-driven programming – what is it about?
- Custom plugin: Trying to show saved data on frontend
- Receiving Stripe Webhooks on a wordpress website
- Check php version before theme activation
- Change the footer text on the login page
- How to remove a metabox from menu editor page?
- Multiple wp_schedule_event cron jobs in plugin cause multi-execution
- How to remove “out of stock” variation options from size dropdown in woocommerce?
- Audio Player not loading when the content is loaded through Ajax, MediaElement.js no applied
- Hooking new functions to actions + passing parameters
- Find variables available at a given hook
- Passing data between two hooks in separate HTML requests
- Replace existing content from specific WooCommerce admin orders list column
- enqueue hover function
- WooCommerce: Add Payment Gateway Field to Webhooks [closed]
- action hook wp_head higher priority as all other plugins/hooks
- using add_action for a header hook that has an additional parameter
- When using the_author hook, how can I determine the PHP file that generates each call to `the_author()`?
- How to call function at the bottom of post using plugin?
- Randomise upload filenames (or another solution to hide the original image URL from theft?)
- Setting up 2 SMTP accounts: 1 for wordpress and 1 for woocommerce
- How to load a template-part based on a url wildcard?
- Remove an action hook within a Class
- How to pass arguments to add_action() or retrieve return value of called function?
- ajax, right way to do it and make it works?
- Sending data from custom inputs in WordPress comment form in the admin notification email
- Edit incorrect password message WordPress
- Reload part of checkout on changed shipping method
- Contact Fom 7 – how to add custom HTML inside span.wpcf7-form-control-wrap AND IMMEDIATELY AFTER input.wpcf7-form-control?
- Woocommerce: hook action/filter I could use to add variation id and price with each attribute opt on WooCommerce Rest api
- Remove metabox from WordPress menu editor page?
- Remove a div from RSS feed
- Set meta field to publish date + 2 weeks
- How to add an arrow to menu items has submenus
- WordPress Gravatar filter is removing my custom attributes
- Error in custom php function doesn’t exist
- Generating an nonce for Content Security Policy and all scripts – How to make it match/persist for each page load?
- Don’t insert if permalink is the same?
- Adding widgets to my plugin page instead of WordPress dashboard
- Modify custom field input data before creating a new post
- how to make custom ajax handler?
- Are all hooks/functions tied to Kses meant for sanitization?
- Why does wp_head hook my functions to the beginning of my source code?
- Pass argument to event hook
- How to remove woocommerce_breadcrumb() from do_action( ‘woocommerce_before_main_content’ ); [closed]
- Should `wp_login` be used since it’s deprecated?
- Omit custom post type from wp-sitemap.xml based on meta key using wp_sitemaps_posts_query_args
- How to use a custom hook
- Theme not calling Jquery properly
- How to remove the message ‘We could not find any results for your search’ without changing template files and without adding posts/pages?
- Get access to variable from previous pageview, excluding ajax-calls
- WordPress redirect redirecting too many times or not at all
- Why does the post_type_link hook everything twice?
- How to have different site identity logos on each page on Astra Theme [closed]
- Get user custom field value on function.php
- Send notification email to admin for every new post published
- Adding function to child theme’s function.php
- Comapare get_user_meta value
- Add a custom class to the body tag using custom fields
- Must filter functions receive all arguments passed to them?
- Why doesn’t global $wp_query not get hooked?
- Creating customized php files in theme folder
- Dynamically Generate Functions and Hooks
- save_post trigerred twice
- How to sort WooCommerce products page by latest in-stock items first?
- Replace a single variable with add_filter
- Variation prices breakdown only for single product page
- Removing “There is no account with that username or email address.” error message in “/wp-login.php?action=lostpassword”
- How do I add a function to parent theme
- Prevent header and footer from loading on specific pages with template or plugin
- Add custom field on admin dashboard comments / reviews
- Contain multiple page templates in one PHP custom template file in WordPress?
- Show full post instead of excerpt
- Wp_Schedule_Event every few minutes doesn’t work
- Trouble Accessing Gravity Forms API (GFAPI)
- Enqueue assets from multiple directories using add_action/do_action
- Adding new divs with custom classes to products on WooCommerce shop page [closed]
- Fatal error: Uncaught Error: Class ‘WP_Block_Styles_Registry’
- Custom meta box is not displaying value showing tag as empty
- using filter and hook inside class
- Register/enqueue scripts only on certain admin pages
- How do I get the value of a current user’s custom field?
- Need to forward Data from WooCommerce Webhook sent to same site WordPress REST API custom endpoint
- add_filter() inside another add_filter()
- Getting page / post URL on publish and / or update
- Add class to all meta boxes for a custom post type
- Fatal error when using array_diff() function inside of wp_update_nav_menu hook?
- How can I move the posted-on date above the post and below the entry-header?
- Post formating on Home page
- calling a function from a class in your template
- Cannot modify header information – headers already sent
- Send a custom notification to customer on WooCommerce cancelled order status
- Assign new post author IF another user in custom field on post transition
- Create and publish a new post every Monday, listing the post titles and links to the posts published during the previous week
- understanding wp_next_scheduled
- transition_post_status hook, works – but not if the post is new
- php was updated – critical error [closed]
- Guests comment form – prevent duplicate email addresses
- Woocommerce – add tracking code to another email template
- Is there a hook that I can use when a fatal error occurs?