Home Forums Event Espresso Premium Message Queue System: AHEE__EE_Messages_Scheduler__cleanup

Message Queue System: AHEE__EE_Messages_Scheduler__cleanup

Posted: February 12, 2024 at 12:55 pm


February 12, 2024 at 12:55 pm

I have EE Version 5.0.11.p and would like to use the new “Cleanup of old messages” feature so I set Message Retention settings to 12 months. Your instructions on indicate that “set the retention settings to 12 months, the next time the AHEE__EE_Messages_Scheduler__cleanup cron job ran on your WordPress website, it would remove any messages that were older than 12 months”

However old messages are not being removed. Is there something I need to add to get this functionality to work? Do I need to add the cron for clearing emails? Can you tell me the hook name?

Thanks for your help!


February 12, 2024 at 2:40 pm

Can you also let me know whats the action name of the cron that we need to look into?


  • Support Staff

February 13, 2024 at 5:07 am

Hi there,

You shouldn’t need to add this cron job manually, EE4 automatically adds the above cron for you so lets check if its listed first.

Install a plugin you can use to view the WP Cron tasks on the site, something like this:

Then go to Tools -> Cron Events.

Search for AHEE__EE_Messages_Scheduler__cleanup there.

This is what I see:

What shows up on your site?


February 13, 2024 at 10:15 am

I installed the plugin and I see a similar event for AHEE__EE_Messages_Scheduler__cleanup with run once daily and next at 2024-02-14 02:06:56 14 hours 53 minutes

However, looking at my message log, I still see messages from 2022.

What am I missing from the setup?


  • Support Staff

February 13, 2024 at 2:41 pm

What am I missing from the setup?

Hmmm, nothing by the sounds of it.

High volume site? How many messages are on the site?

Are you comfortable with PHP?

I can give you some code to run and view the output of…

Infact, I can give you the code the cleanup job runs to find our exactly what that is returning.


February 13, 2024 at 2:57 pm

This reply has been marked as private.


  • Support Staff

February 13, 2024 at 3:28 pm

The delete function runs on 2000 rows at a time, so within a single day, that’s 4000 rows deleted.

If you go to EE -> Messages, then on the pagination at the top/bottom of the table click on the >> icon to go to the last page… take note of the last row ID.

Then in another tab go to Tools -> Cron Events again and find the ‘AHEE__EE_Messages_Scheduler__cleanup’, click run now.

Now go back to the Message table and refresh page, find the ‘last’ entry in the table, is it the same as before?


  • Support Staff

February 13, 2024 at 3:36 pm

This reply has been marked as private.


February 13, 2024 at 3:38 pm

I ran the ‘AHEE__EE_Messages_Scheduler__cleanup’, click run now and that seemed to work. How can I automate this?


  • Support Staff

February 13, 2024 at 3:57 pm

So it sounds like it already is automated, you made the change to the retention settings yesterday, right? So it will have run 2-4 times so far removing 8k rows.

We keep the limit relatively low to prevent timeouts on various hosting types, what type of hosting are you using? The cron removes 2k rows each time it’s processed so for your ~100k and assuming 80% of those are ‘old’ messages that’s roughly 20 days to delete those 80k messages.

How long did it take to process the request when you clicked run now above?

If it was quick you could set the limit higher and manually run that cron a few times, that’s the ‘safest’ and likely quickest option:

add_filter('EEM_Message__delete_old_messages__limit', 'tw_ee_increase_delete_old_messages__limit', 10);
function tw_ee_increase_delete_old_messages__limit($limit) {
    return 5000;

Add something like the above to increase the limit to 5000, you may get away with higher values depending on your server. It depends how long it took to process the above request, if it was pretty much instant you have a lot of wiggle room and can go higher. At that value your looking at 8days if you leave it as is, or just manually run the cron like you did above until your happy with the number of messages (16 times would clear 80k).

Once you have the message count down the cron job should then keep on top of your messages as new ones are created so this is just to get your current backlog cleared.

You must be logged in to reply to this support post. Sign In or Register for an Account

Event Espresso