Cronjob as admin

Hi Elgg'ers,

I was wondering if it is possible to set up a cronjob that runs a script that you can normally only run as admin
I use the plugin SNA4elgg, which on the admin page, has it's own section and a download button. I have already figured out how to save that file onto my filesystem on the server. But now i would like to run this script periodically, so i don't have to do this every day manually. I would really appreciate some hints into doing this. Thank you 

  • Normally you would run this on the backend via control panel from your hosting. Cron isn't an Elgg thing, it's a server thing.

  • You can disable the access level handling within the callback function you register for the cron plugin hook. Then you can access entities during the cronjob execution that would require an admin to be logged in otherwise.

    Register in the init function of your plugin:

    elgg_register_plugin_hook_handler('cron', 'daily', 'my_cronjob');

    and then add the callback function to be executed during the daily cronjob:

    function my_cronjob($event, $object_type, $object) {

        $access = elgg_set_ignore_access(true);
        $access_status = access_get_show_hidden_status();

        <now the code that you want to be executed>


  • Just exactly what I needed! Many thanks.

Beginning Developers

Beginning Developers

This space is for newcomers, who wish to build a new plugin or to customize an existing one to their liking