As a general principal, you shouldn’t do anything that requires an ‘add_action’ after the plugin activation hook. This is because WP loads and runs all plugins and THEN runs the new added one, and then does a re-direct. You have to set a DB option and hook into that. Here is the discussion from the CODEX:
https://codex.wordpress.org/Function_Reference/register_activation_hook
Try doing this outside of the activation hook and see what happens.In other words, PHP runs through the whole WordPress routine on each browser request. When you ‘activate’ a plugin, you actually fire two page requests to the server. This type of activity properly goes in the 2nd page request, which is the re-direct.
Related Posts:
- Do WordPress cron jobs slow down page loading?
- Get frequency of scheduled event
- crontab wp-cron.php on multisite path-based network: one for each path? Or just one for the root?
- Running wp-cron from CLI
- Why?: hundreds of empty files named wp-cron.php?doing_wp_cron.
- Can’t access wp_filesystem in cron function
- WP CRON runs only the first time
- Check if event was scheduled – schedule event only once
- Create function in functions.php with hook name to execute URL
- cron.php being constantly deleted [closed]
- Scheduling posts on wordpress adds wrong seconds as post_date
- wp_schedule_event run in background or not?
- Detect if Cron is Running
- Run function with linux cron job in WordPress
- Schedule cron don’t work
- Cron schedule not updating after run
- Can you register two cron events in a single function?
- When to use wp_schedule_single_event for async / non-blocking processes?
- Issues When Recursively Calling wp_schedule_single_event()
- wp-cron behaviour when there are multiple queued tasks
- System Cron job not firing
- WordPress Cron Job Not working
- WordPress automatic publish: is there a timeout when WordPress won’t publish anymore?
- Cron job not working – Can’t see in the queue attached
- “Missed schedule” posting bug
- How to force ‘cron_schedules’ every minute instead 1 hour?
- Cancel/Stop a currently ongoing scheduled cron event?
- Code does not work in class implementation but works fine in functions.php file
- Use cron to create a non blocking task
- How to create and run cronjob in WP without using the plugin?
- Cron job to run just once per day using external cron service
- Manually running cron from the server
- Cron jobs when running multiple instances on the same DB
- Scheduling WP cron jobs
- WordPress Cron job, 302 response
- How can I prove if wp cron is running my task if I have DISABLE_WP_CRON set to true
- Time limit on long cron job?
- Strange cron job behavior and how to solve it?
- WordPress cron not getting executed when called by external service (but ok from browser)
- Cron and request with wp_remote_post
- How to Set a Condition via Page Template Name in WP Cron Job?
- Real cron killed my cron system. Only define( ‘ALTERNATE_WP_CRON’, true ); works
- Server cron job not working
- Most efficient way to trigger wp-cron through system cron.
- How to make sure WP-CRON job loops through all posts?
- Run external file cron using WordPress Scheduler
- Huge cron option_value into wp_options table
- setting up a wp cron job
- Pages for Cron use Only?
- Cron jobs repeating themselves
- Does DISABLE_WP_CRON prevent plugins from registering new cron tasks?
- Cron event running more than once if triggered from WP Crontrol
- How to know if WP cron is currently running my hook?
- Cronjob function not executed – negative seconds
- WP CRON Fails At 13:00 Every Day
- Update last created post in custom post types with wp_cron()?
- Custom cronjob not executing at all, but manually
- ‘wp_site_health_scheduled_check’ Causes Failure Of Other Scripts
- Having difficulties with WP cron
- Action to create custom field based on shipping class works when manually triggered, but not on cron schedule
- What are scheduled callbacks?
- WP Cron, how to speed it up
- What is the correct way to implement wp-cron server-side in Kubernetes?
- Should I disable WP_CRON and trigger wp-cron.php from the server?
- “Could not open input file: wp-cron.php?import_key=” in shell?
- WP-Cron missing tasks after moving to server job
- WP Cron is not running
- I have a wordpress store with woocomerce and it goes into maintenance every 12 hours
- Is there a quick way to view the wp-cron schedule
- How to test wp_cron?
- Running WP Cron on multisite the right way
- WP Cron Doesn’t Execute When Time Elapses
- Should I disable WP_CRON and instead trigger wp-cron.php from server every few mins?
- PHP Warning on fresh install (Connection timed out)
- Is there a known vulnerability for wp-cron.php?
- Uncaught Error: Call to undefined function wp_generate_attachment_metadata() @ wp-cron
- Using wp_schedule_single_event with arguments to send email
- Running WordPress on the Command Line – Turn off Delayed Output?
- Schedule WordPress Auto-Updates to only run during business hours
- wp_schedule_event is executing but the function related to the hook is not running
- How is WP Cron Locking implemented?
- How to use wp_schedule_event in a class?
- wp_schedule_event won’t accept args
- add_action to wp cron?
- Triggering cron by calling wp-cron.php on the command line rather than with wget?
- Better handling of WP-CRON server load abuse
- When does next Cron Job run (time from now)?
- Run WP Cron Weekly (but on a certain day)
- wp-cron.php is triggered, but scheduled post is not published
- wp_schedule_event() on specific time, daily
- Need to execute a cron job
- wp_next_scheduled returning a past timestamp
- run a cron task without obstructing page load?
- Recurring scheduled task help
- Missed scheduled WordPress
- What happens when wp_cron is deactivated in WordPress?
- How to make wp cron job not fire immediately?
- How Do I Make WordPress Run an Event Every Day?
- get_posts inside cron
- Do wp-cron scheduled tasks run asynchronously?