Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

how can I call a function when time expire

The only way that I know of to perform an action daily (or on another regular interval) is to schedule a cron event. A sustainable way to do that is to write a little plugin that schedules/clear_schedules the cron when activated/deactivated. Here’s a plugin that you could use – I tested to ensure that it was installable and registered the cron event correctly. You will need to either place this in a file (such as custom_cron_event.php) and FTP it to your /plugins folder, or place it in a file and compress (ZIP) the file to upload it to your website through the /wp-admin interface.

Sadly, you can’t rely on a function that fires when user profiles are updated to retrieve user data anymore, because no profiles are being updated. Instead you’ll need to get the users your self and detect if a change is required.

<?php
/*
Plugin Name: Custom Plugin
Plugin URI: 
Description: Adds function on cron
Author: 
Version: 1.0
*/

/*  
 * When this plugin is activated, schedule/clear_schedule cron
 */ 
register_activation_hook(__FILE__, 'activate_custom_cron');
register_deactivation_hook(__FILE__, 'deactivate_custom_cron');

function activate_custom_cron(){
    wp_schedule_event( time(), 'daily', 'do_custom_cron_event');
}

function deactivate_custom_cron(){  
    wp_clear_scheduled_hook('do_custom_cron_event');    
}

add_action( 'do_custom_cron_event', 'custom_cron_event' );

function custom_cron_event() {

/*
 * This is where your function goes
 */

     $current_date = date("Y-m-d");

     $users = get_users();
     foreach( $users as $user){

        $date_to_compare = get_user_meta($user->id, 'year_of_birth');

        if (strtotime($current_date) > strtotime($date_to_compare) ) {

            $user_levels = rua_get_user($user)->get_level_ids(false, false, true);

            foreach ($user_levels as $level) {
                rua_get_user($user)->remove_level($level);
            }
        }
    }
}   

?>

Related Posts:

  1. Query to show average # of months all accounts with specific role have been active
  2. Create a global variable for use in all templates
  3. Add extra field to users
  4. Integrating WordPress to my website, while keeping my own authentication system
  5. Display user’s total comment count outside The Loop
  6. Changing user_nicename
  7. How to auto login user again after change user_login
  8. What is the most efficient way to search users by their display name?
  9. Can i check if user is doing any ajax request?
  10. How do I create a WP user outside of WordPress and auto login?
  11. Network installation giving errors when viewing or adding a user
  12. Showing user ID on user main page from screen options
  13. Getting the Current User
  14. How do I hide specific user profile fields?
  15. Authenticating to WordPress, using my own authentication two-factor system
  16. How to track a users progress through pages by inserting data into WordPress Database?
  17. automated tests as a user?
  18. How can I default to all WordPress roles when parameter is not included in shortcode?
  19. there’s a way to include a minimal WP for check only the current user, its roles (caps?) and then release/free it?
  20. Delete option value from array using update_option()
  21. get_users(…) only returns one user
  22. List User order by ID in Descending order (Backend)
  23. Warning: Use of undefined constant HTTP_USER_AGENT – assumed ‘HTTP_USER_AGENT’ (this will throw an Error in a future version of PHP)
  24. Get all user meta by meta key instead of ID
  25. How to get a list of all possible values of a specific user meta key?
  26. User’s total comment count excluding comments on their own posts
  27. User management system similar to wordpress one?
  28. Show all posts by author
  29. Custom user login page by creating a plugin
  30. Programmatic Login from 3rd Party site
  31. Add New User, extra fields which are required?
  32. user_profile_update_errors hook not executing
  33. Modify user profile data through scripting?
  34. Get users that likes the post
  35. custom user role wordpress – grant guest access to edit.php without insert/update/delete
  36. add_cap not working
  37. Do not execute If User is login as Administrator or any Specific Role
  38. wordpress archive a user
  39. Best practice for show data to one specific user?
  40. Call to undefined function get_userdata() in plugin
  41. get_users meta_query: REGEXP not working for matching new lines
  42. Change CSS based on is_user_logged_in
  43. How to show a users bio on a page
  44. “operation successful” message
  45. php if username is role
  46. How do you create two separate Register pages?
  47. how to prevent wordpress admin from logging in via woocommerce my-account page
  48. Is it possible to create new user from external form using REST API?
  49. Foreach loop inside an array_merge
  50. Shortcode to embed Edit Account form not working
  51. Show current user posts only
  52. One account with multiple logins
  53. Change page password every day (predictable password ;) )
  54. show something only when user comes from specific page at remote host?
  55. Get the users that my following users are following
  56. create front-end users post list by specific category
  57. Show site content based on user role
  58. ‘pre_user_query’ interfering with user export
  59. Edit Account – read and write to MySQL
  60. php return username of currently viewed author profile
  61. How to list users like an archive page 10 users on page and have navigations
  62. How can I call a specific file (via php) by referencing the logged-in username?
  63. Redirect to current user page upon link click
  64. Use of antispambot with $curauth->email
  65. Uses for function: wp_update_user
  66. Display additional user fields
  67. Generate a QR code when creating a new WordPress user
  68. Change wordpress’ database data using ajax – how to get current user id?
  69. Sort new column in Users wp-admin
  70. Sort column in Users admin Tab
  71. Allow a user or role to view drafts and previews, but not other admin privileges?
  72. Woocommerce display orders with products from specific categories to specific admins
  73. Storing huge number of users in wordpress
  74. Billing detail page doesn’t work after I’ve changed the order of the Woocommerce navigation
  75. Admin Panel 404 Error after login
  76. How to block specific user id in custom login form?
  77. Get current user id in function php
  78. How to count active users on a specific page
  79. Hide Approved status for certain users in users list
  80. Call WP Rest-Api to GET /users/me returned NOTHING in console
  81. Uploading/integrating custom user registration page
  82. If user has clicked link add class and store using PHP/WordPress
  83. Store data from JavaScript object to custom table in user account
  84. Export WordPress User Meta to CSV/Excel
  85. Page template not working when logged out
  86. Allow specific user to edit a specific page
  87. How to change the value of a variable using input field?
  88. Display current user metadata on WordPress page
  89. How do I track which user clicked my button?
  90. Help hooking into user_register
  91. Use WP user status (logged_in) to manage access to independent application
  92. Add another role to a user when they click a button?
  93. is_user_logged_in() not working in homepage
  94. wordpress more than one ajax request at the same time issue
  95. (Who to follow) Twitter widget
  96. Can’t get_users info by using json_encode
  97. Editable Student file associated with basic User ID
  98. Adding users to another blog
  99. Changing WordPress author name in database
  100. Matching multi user
Categories PHP Tags account, php, users
WordPress wrong dates bug
How to redirect old permalinks to ones generated by [WP-Hashed-ID] plugin?

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress