Skip to content

Instantly share code, notes, and snippets.

@Maden-maxi
Last active August 25, 2017 14:54
Show Gist options
  • Save Maden-maxi/37578ab2c731fde012a425d59aa462b8 to your computer and use it in GitHub Desktop.
Save Maden-maxi/37578ab2c731fde012a425d59aa462b8 to your computer and use it in GitHub Desktop.
Download exteranls scripts
<?php
function download_file( $file_url, $save_to ) {
$content = file_get_contents( $file_url );
file_put_contents( $save_to, $content );
}
if ( ! wp_next_scheduled( 'download_external_scripts_cron_hook' ) ) {
wp_schedule_event( time(), 'daily', 'download_external_scripts_cron_hook' );
}
add_action( 'download_external_scripts_cron_hook', 'download_external_scripts_cron_exec' );
function download_external_scripts_cron_exec() {
$extranals = array(
'devicepx' => 'https://s0.wp.com/wp-content/js/devicepx-jetpack.js',
'googleanalytics-platform-sharethis' => 'https://platform-api.sharethis.com/js/sharethis.js',
'grofiles-cards' => 'https://secure.gravatar.com/js/gprofiles.js'
);
$local_exterbals = [];
foreach ($extranals as $name => $url) {
$local_exterbals[$key] = pathinfo($url, PATHINFO_BASENAME);
}
$save_to_path = __DIR__ . '/scripts';
if( !is_dir($save_to_path) ) mkdir($save_to_path);
foreach ($extranals as $name => $url) {
$filename = pathinfo($url, PATHINFO_BASENAME);
download_file( $url, __DIR__ . '/scripts/' . $filename );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment