Managed to find the solution.
My finished code is:
register_activation_hook ( __FILE__, 'cron_job' );
function cron_job()
{
wp_schedule_event( time(), 'hourly', 'hourly_job' );
}
add_action( 'hourly_job', 'cron_job_task' );
function cron_job_task ()
{
$users = get_users(
array(
'fields' => array( 'ID', 'user_registered' ),
'role' => 'coaching',
)
);
foreach ( $users as $user ) {
$time = $user->user_registered;
if(strtotime($time) < strtotime('-3 months')) {
$u = new WP_User( $user->ID );
$u->remove_role( 'coaching' );
$u->add_role( 'platinum' );
}
}
}
?>
With a cPanel cron job set hourly.
Related Posts:
- Uncaught Error: Call to undefined function wp_generate_attachment_metadata() @ wp-cron
- Updating WooCommerce variable product stock issue
- WordPress Console Application (ability to excecute a custom function via crontab only)
- Switch from wp-cron to a server cron job
- WP Import All Multiple Dynamic Link Imports
- my hook or my function wont run in the cronjob
- Cron job shedules replace?
- How to get the active theme’s slug?
- Preserve custom URL parameter on more pages
- if plugin is active? check if plugin is enabled or not?
- Making plugin unique to not conflict with plugins with the same name
- How to store ACF custom fields data in a custom table
- Trying to disable plugins doens’t work
- Errors while using ajax from external wordpress page
- shortcode doesn’t work
- Setting up widgets in wordpress with a unique ID for the after_title argument
- post expire after x days
- How to get all events from ‘All in one Events calender’ plugin in JSON format?
- cURL error 60: SSL certificate problem: unable to get local issuer certificate
- How to Replace Words with Hypertext Link But Ignore Previously Existed Links?
- Custom form action to handle data inside a plugin
- WP Post Template – Templates in own folder
- Apple push notification doesn’t work
- Override Plugin Script Fucnction in WordPress
- Image upload and download from front-end
- Conditional attributes and logic per product category
- Using Wishlist Member and I need to access a user’s status
- Why namespaces are rarely used in WordPress plugins?
- Subdomains with almost the same content
- How can integrate zend module with wordpress admin dashbord [closed]
- Setup wp_schedule_event within a custom plugin
- WordPress custom taxonomy not showing
- My WordPress site when down after installing a plugin and now all I get is a simple white screen [closed]
- WHy custom plugin slows down the loading of the pages?
- Adding media upload button to User Profile page (following a tutorial)
- Pass user role to javascript code inside body
- Integrating boxtal PHP library into a custom WordPress Plugin
- WordPress Stock Update Programatically
- UTF-32be error WordPress
- Getting a ressource ID, from a WC_Order_Item_Product/Order
- Customize Menu | Styling LESS/SCSS code formats
- ACF – How to set the menu order for the relationship field
- Custom search search does not work?
- same user role or copy the user role to be same as the other role
- Passing PHP Variables to AJAX Loaded Pages
- Social share buttons text shows up on post excerpts
- How to displaying Custom image, text and default image logo from Redux Framework option panel
- Plugin Admin panel checkbox unchecked after submit
- Getting URL GET parameter with Code snippets and storing it in database?
- Send Array from JS to php file then insert it in wp database through a plugin
- Offer Download Links for Product Images
- save_post_product action not firing
- How to get the custom field value using SQL query
- WordPress fatal error from php protocol codes
- Possible way of having multiple Gutenberg instances for a page?
- Woocommerce add products to cart
- How to hide an option from dropdown in filter module
- Changing wordpress/woocommerce notices default message to other languages (text)
- Why does my custom plugin only function correctly once per page?
- How to change “Read More” text?
- Using id to show item
- I can’t view the orders on the woocomerce dashboard with the brainblocks plugin
- WP Migrate DB Pro plugin cannot transfer Media files to remote server
- Woocommerce – Change variations output
- Is admin section completely customizable in terms of styling?
- Change (replace) word in metabox
- Limiting buddy press features based on membership level (PMPro)
- WordPress environment not loading properly
- How to remove a css class for any wordpress page
- Creating wordpress admin page panel [Theme Option]
- How to replace native comment_count with Comments Evolved aggregate count
- export high ress images to pdf
- Autoloading a PHP class – working outside, but not inside WordPress plugin
- Calling an custom field from theme option at the frontend
- custom url with custom post
- Saving an array to get_options
- Variable passed to each() is not an array
- MySql Query for WordPress
- Some of my php is rendered only when logged as admin
- Shrinktheweb plugin problem
- Pulling sub-site content into specific pages
- Issue with custom plugin
- Help me with my first very basic plugin
- Getting Post Permalink Outside of Loop Not Working
- is_plugin_active() not defined on active plugin, in the thumbnails.php file
- Undefined constant error in pluggable.php
- How to create post comparison in wordpress
- How to insert current “login” page to certain page?
- Requires PHP version 5.3.0
- True or False: Is an Apache error or PHP error the same as a WordPress error?
- Need help with wordpress audio preload
- Allow direct access to files/folders within WordPress to replace wp-admin
- How to trigger plugin migration code when plugin updates?
- How to Save Category and Delete Category in same Function
- is_singular() in mu-plugins not working
- Error 400 Invalid “products[1].productId” Kinguin [closed]
- I want to move the one click accesbility button on bottom of my website screen,
- WordPress : how to create onglet and remove it when only one
- How to customize WP_Error (REST JWT authentication plugin) [closed]
- Which approach for managing automatic updates would be more robust?