Skip to content
This repository has been archived by the owner on Oct 31, 2022. It is now read-only.

Commit

Permalink
Dynamically load admin libraries in cron context
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredcobb committed Jun 14, 2018
1 parent e200eec commit 12db67f
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions includes/class-ccb-core-helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,14 @@ public function send_non_blocking_json_success( $data = [] ) {
*/
public function download_image( $image_url, $filename = '', $post_id = 0 ) {

// When in a WP Cron context these helper functions may not be loaded.
if ( ! function_exists( 'download_url' ) ) {
include_once ABSPATH . 'wp-admin/includes/file.php';
}
if ( ! function_exists( 'media_handle_sideload' ) ) {
include_once ABSPATH . 'wp-admin/includes/media.php';
}

// Fetch the image and store temporarily.
$temp_file = download_url( $image_url );

Expand Down

0 comments on commit 12db67f

Please sign in to comment.