30, 'user-agent' => 'avada-user-agent', ) ); $response = wp_remote_get( esc_url_raw( $url ), $args ); $body = wp_remote_retrieve_body( $response ); // Try file_get_contents if body is empty. if ( empty( $body ) ) { if ( function_exists( 'ini_get' ) && ini_get( 'allow_url_fopen' ) ) { $body = @file_get_contents( $url ); } } // Initialize the Wordpress filesystem. global $wp_filesystem; if ( empty( $wp_filesystem ) ) { require_once( ABSPATH . '/wp-admin/includes/file.php' ); WP_Filesystem(); } // Attempt to write the file. if ( ! $wp_filesystem->put_contents( $file_path, $body, FS_CHMOD_FILE ) ) { // If the attempt to write to the file failed, then fallback to fwrite. @unlink( $file_path ); $fp = fopen( $file_path, 'w' ); $written = fwrite( $fp, $body ); fclose( $fp ); if ( false === $written ) { return false; } } // If all went well, then return the headers of the request. if ( isset( $response['headers'] ) ) { $response['headers']['response'] = $response['response']['code']; return $response['headers']; } // If all else fails, then return false. return false; } }