• I am building a cron that makes a backup, updates plugins, updates the core, emails me if updates happened or deletes the backups if not. The cron has been scheduled for a weekend at night, giving me a chance to browse the site and see if anything is broken.

    I built and tested the code that the hook/function runs in the cron, on a custom admin page dedicated to dev. It occurred to me before bed that the conditions would not be the same in the cron, it wouldnt have a logged in admin, and it wouldnt have loaded the same files as an admin page.

    Am I wrong, does wp-cron require admin files before a task is run?
    Does a user need to be logged in for plugins, or core to update?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz

    (@bcworkz)

    I assume you are speaking of wp-cron and not server level cron jobs. wp-cron cannot do anything related to the current user because the current wp-cron user has ID == 0. However, wp-cron executes PHP code which generally has very broad authority and can do most operations on the server’s file system, provided the file system has granted write permissions to the user PHP runs as. WP PHP generally has full file system permissions for at least the portion WP is installed in, if not more. Thus wp-cron can update plugins, core files, send emails, etc. This is pretty much how the native update system works. In fact, the native auto-update scheme for minor updates has been extended to plugins and themes. (disabled by default)

    Thread Starter unfinishedcode

    (@unfinishedcode)

    Yes. I am speaking of WP Cron, hence my title.

    My problem with the native automatic update system, is you cannot schedule it. Furthermore, not all plugins can have auto update enabled, a good example of this is Wordfence. It has it’s own auto update system.

    Thank you for answering one of my questions. The other? Does wp cron load/require admin files?

    Moderator bcworkz

    (@bcworkz)

    Sorry, titles sometimes go in one “ear” and out the other. I’m not sure about admin files. I don’t think actual files in /wp-admin/ are loaded unless the cron code does so for itself. However, admin-like functions are available, such as wp_insert_user(), but it’s not declared in /wp-admin/ anyway.

    Thread Starter unfinishedcode

    (@unfinishedcode)

    I guess, I could try running the function on the front end, while not logged in, to be certain. I’m testing for dependant functions, and including files when necessary anyways. Thanks for your insight dude.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘wp cron, admin and updates’ is closed to new replies.