Search code examples
phpwordpresscronhook

Wordpress core function in custom hook


I developed a plugin that sends a report by email with plugins to update. For this I use the function Wordpress get_core_updates(). Everything works with the hook admin_post_ when I do a manual sending.

My problem is that I want to send automatically with a CRON. When the event is triggered, I have an error:

  • PHP Fatal error: Uncaught Error: Call to undefined function get_core_updates()

The function is therefore not available when I go through a CRON event.

Do you have a solution?

Thanks in advance


Solution

  • This method belongs to /wp-admin/includes/update.php file, I guess this file won't be loaded in CRON mode since it's a part of the admin domain.

    You can add this piece of code in your CRON function:

    if (false === function_exists('get_core_updates')) {
        require_once(ABSPATH . 'wp-admin/includes/update.php');
    }
    

    It will include the file with the function. I would think this access can lead to some security issues.