Last active
August 25, 2017 14:54
-
-
Save Maden-maxi/37578ab2c731fde012a425d59aa462b8 to your computer and use it in GitHub Desktop.
Download exteranls scripts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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