is_customize_preview() like function to check if Customizer “Live Preview” in JavaScript

you can just check for the customize object, but if you absolutely need a conditional statement to determine whatever it is you need, you can do something like this: jQuery( function( $ ) { // set var var in_customizer = false; // check for wp.customize return boolean if ( typeof wp !== ‘undefined’ ) { … Read more

How to make a local cache of mshots images

I think this should work. function upload_image_from_url($url) { /** Require dependencies */ require_once( ABSPATH . ‘wp-admin/includes/image.php’ ); require_once( ABSPATH . ‘wp-admin/includes/file.php’ ); require_once( ABSPATH . ‘wp-admin/includes/media.php’ ); // Save as a temporary file $tmp = download_url( $url ); // Check for download errors if ( is_wp_error( $tmp ) ) { @unlink( $file_array[ ‘tmp_name’ ] ); … Read more