0
0
Wordpressframework~10 mins

Automated backup strategies in Wordpress - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to schedule a daily backup using WordPress cron.

Wordpress
if ( ! wp_next_scheduled( '[1]' ) ) {
    wp_schedule_event( time(), 'daily', 'my_backup_event' );
}
Drag options to blanks, or click blank then click option'
Amy_backup_event
Bdaily_backup
Cbackup_daily
Dbackup_event
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different event name in wp_next_scheduled than in wp_schedule_event.
Forgetting to check if the event is already scheduled.
2fill in blank
medium

Complete the code to hook the backup function to the scheduled event.

Wordpress
add_action( '[1]', 'perform_backup' );
Drag options to blanks, or click blank then click option'
Amy_backup_event
Bbackup_daily
Cdaily_backup
Dbackup_event
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different event name in add_action than the scheduled event.
Misspelling the event name.
3fill in blank
hard

Fix the error in the backup function to properly save the backup file.

Wordpress
function perform_backup() {
    $backup_file = WP_CONTENT_DIR . '/backups/backup-' . date('Y-m-d') . '.zip';
    $result = [1]( $backup_file );
}
Drag options to blanks, or click blank then click option'
Acopy
Bzip_backup
Cwp_mkdir_p
Dfile_put_contents
Attempts:
3 left
💡 Hint
Common Mistakes
Using copy or file_put_contents which do not create backups.
Using wp_mkdir_p which only creates directories.
4fill in blank
hard

Fill both blanks to register a custom cron schedule and use it for backups.

Wordpress
add_filter( 'cron_schedules', function( $schedules ) {
    $schedules['[1]'] = [
        'interval' => [2],
        'display'  => 'Every 6 hours'
    ];
    return $schedules;
});
Drag options to blanks, or click blank then click option'
Asix_hours
B21600
C3600
Dhourly
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'hourly' which is a default schedule, not custom.
Using incorrect interval values.
5fill in blank
hard

Fill all three blanks to unschedule the backup event correctly.

Wordpress
$timestamp = wp_next_scheduled( '[1]' );
if ( $timestamp ) {
    wp_unschedule_event( $timestamp, '[2]' );
    wp_clear_scheduled_hook( '[3]' );
}
Drag options to blanks, or click blank then click option'
Amy_backup_event
Bbackup_event
Ddaily_backup
Attempts:
3 left
💡 Hint
Common Mistakes
Using different event names in unscheduling functions.
Forgetting to clear the scheduled hook.