Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

// https://kinsta.com/blog/defer-parsing-of-javascript/ function defer_parsing_of_js( $..

Decoded Output download

<?   
// https://kinsta.com/blog/defer-parsing-of-javascript/ 
function defer_parsing_of_js( $url ) { 
    if ( is_user_logged_in() ) return $url; //don't break WP Admin 
    if ( FALSE === strpos( $url, '.js' ) ) return $url; 
    if ( strpos( $url, 'jquery.js' ) ) return $url; 
    return str_replace( ' src', ' defer src', $url ); 
} 
add_filter( 'script_loader_tag', 'defer_parsing_of_js', 10 ); 
//************************************************************************** 
// https://macarthur.me/posts/build-your-own-simple-lazy-loading-functionality-in-wordpress 
add_action('wp_enqueue_scripts', function () { 
        wp_register_style('os24-speedup', false); 
    wp_enqueue_style('os24-speedup'); 
    wp_add_inline_style('BP-speedup', '.lazy-load {transition: opacity .15s;opacity: 0;}.lazy-load.is-loaded {opacity: 1;}'); 
    //wp_enqueue_script( 'intersection-observer-polyfill', 'path-to-intersection-observer.js', [], null, true ); 
    wp_enqueue_script( 'lozad', 'https://cdn.jsdelivr.net/npm/[email protected]/dist/lozad.min.js', ['intersection-observer-polyfill'], null, true ); 
    wp_add_inline_script( 'lozad', ' 
    	var myElements = document.querySelectorAll("#main img"); 
    	lozad(myElements).observe(); 
    '); 
 
    wp_add_inline_script( 'lozad', ' 
        lozad(".lazy-load").observe(); 
    '); 
    wp_add_inline_script( 'lozad', ' 
    	lozad(".lazy-load", { 
    		rootMargin: "300px 0px" 
    	}).observe(); 
    '); 
     
    wp_add_inline_script( 'lozad', ' 
    	lozad(".lazy-load", { 
    		rootMargin: "300px 0px", 
    		loaded: function (el) { 
    			el.classList.add("is-loaded"); 
    		} 
    	}).observe(); 
    '); 
}); 
 
 
add_filter('the_content', function ($content) { 
	//-- Change src to data attributes. 
	$content = preg_replace("/<img(.*?)(src=)(.*?)>/i", '<img$1data-$2$3>', $content); 
    //-- Change srcset to data attributes. 
    $content = preg_replace("/<img(.*?)(srcset=)(.*?)>/i", '<img$1data-$2$3>', $content); 
	//-- Add .lazy-load class to each image that already has a class. 
	$content = preg_replace('/<img(.*?)class=\"(.*?)\"(.*?)>/i', '<img$1class="$2 lazy-load"$3>', $content); 
	//-- Add .lazy-load class to each image that doesn't already have a class. 
	$content = preg_replace('/<img((.(?!class=))*)\/?>/i', '<img class="lazy-load"$1>', $content); 
	return $content; 
}); 
 
add_filter('wp_generate_attachment_metadata', 'replace_uploaded_image'); 
function replace_uploaded_image($image_data) { 
    // if there is no large image : return 
    if (!isset($image_data['sizes']['large'])) return $image_data; 
 
    // paths to the uploaded image and the large image 
    $upload_dir = wp_upload_dir(); 
    $uploaded_image_location = $upload_dir['basedir'] . '/' .$image_data['file']; 
    // $large_image_location = $upload_dir['path'] . '/'.$image_data['sizes']['large']['file']; // ** This only works for new image uploads - fixed for older images below. 
    $current_subdir = substr($image_data['file'], 0, strrpos($image_data['file'], "/")); 
    $large_image_location = $upload_dir['basedir'] . '/'.$current_subdir.'/'.$image_data['sizes']['large']['file']; 
 
    // delete the uploaded image 
    unlink($uploaded_image_location); 
 
    // rename the large image 
    rename($large_image_location, $uploaded_image_location); 
 
    // update image metadata and return them 
    $image_data['width'] = $image_data['sizes']['large']['width']; 
    $image_data['height'] = $image_data['sizes']['large']['height']; 
    unset($image_data['sizes']['large']); 
 
    return $image_data; 
} 
 
//************************************************************************** 
 
/* 
add_action( 'wp_footer', function () { 
?> 
<script> 
 
function init() { 
var vidDefer = document.getElementsByTagName('iframe'); 
for (var i=0; i<vidDefer.length; i++) { 
if(vidDefer[i].getAttribute('data-src')) { 
vidDefer[i].setAttribute('src',vidDefer[i].getAttribute('data-src')); 
} } } 
window.onload = init; 
 
</script> 
<?php } ); 
 
 */ 
 
 
/** 
Defer parsing of JavaScript with code snippet from Varvy 
*/ 
 
/* 
add_action( 'wp_footer', 'my_footer_scripts' ); 
function my_footer_scripts(){ 
?> 
<script type="text/javascript"> 
function downloadJSAtOnload() { 
var element = document.createElement("script"); 
element.src = "defer.js"; 
document.body.appendChild(element); 
} 
if (window.addEventListener) 
window.addEventListener("load", downloadJSAtOnload, false); 
else if (window.attachEvent) 
window.attachEvent("onload", downloadJSAtOnload); 
else window.onload = downloadJSAtOnload; 
</script> 
<?php 
} 
 
*/ 
 
 
 ?>

Did this file decode correctly?

Original Code


// https://kinsta.com/blog/defer-parsing-of-javascript/
function defer_parsing_of_js( $url ) {
    if ( is_user_logged_in() ) return $url; //don't break WP Admin
    if ( FALSE === strpos( $url, '.js' ) ) return $url;
    if ( strpos( $url, 'jquery.js' ) ) return $url;
    return str_replace( ' src', ' defer src', $url );
}
add_filter( 'script_loader_tag', 'defer_parsing_of_js', 10 );
//**************************************************************************
// https://macarthur.me/posts/build-your-own-simple-lazy-loading-functionality-in-wordpress
add_action('wp_enqueue_scripts', function () {
        wp_register_style('os24-speedup', false);
    wp_enqueue_style('os24-speedup');
    wp_add_inline_style('BP-speedup', '.lazy-load {transition: opacity .15s;opacity: 0;}.lazy-load.is-loaded {opacity: 1;}');
    //wp_enqueue_script( 'intersection-observer-polyfill', 'path-to-intersection-observer.js', [], null, true );
    wp_enqueue_script( 'lozad', 'https://cdn.jsdelivr.net/npm/[email protected]/dist/lozad.min.js', ['intersection-observer-polyfill'], null, true );
    wp_add_inline_script( 'lozad', '
    	var myElements = document.querySelectorAll("#main img");
    	lozad(myElements).observe();
    ');

    wp_add_inline_script( 'lozad', '
        lozad(".lazy-load").observe();
    ');
    wp_add_inline_script( 'lozad', '
    	lozad(".lazy-load", {
    		rootMargin: "300px 0px"
    	}).observe();
    ');
    
    wp_add_inline_script( 'lozad', '
    	lozad(".lazy-load", {
    		rootMargin: "300px 0px",
    		loaded: function (el) {
    			el.classList.add("is-loaded");
    		}
    	}).observe();
    ');
});


add_filter('the_content', function ($content) {
	//-- Change src to data attributes.
	$content = preg_replace("/<img(.*?)(src=)(.*?)>/i", '<img$1data-$2$3>', $content);
    //-- Change srcset to data attributes.
    $content = preg_replace("/<img(.*?)(srcset=)(.*?)>/i", '<img$1data-$2$3>', $content);
	//-- Add .lazy-load class to each image that already has a class.
	$content = preg_replace('/<img(.*?)class=\"(.*?)\"(.*?)>/i', '<img$1class="$2 lazy-load"$3>', $content);
	//-- Add .lazy-load class to each image that doesn't already have a class.
	$content = preg_replace('/<img((.(?!class=))*)\/?>/i', '<img class="lazy-load"$1>', $content);
	return $content;
});

add_filter('wp_generate_attachment_metadata', 'replace_uploaded_image');
function replace_uploaded_image($image_data) {
    // if there is no large image : return
    if (!isset($image_data['sizes']['large'])) return $image_data;

    // paths to the uploaded image and the large image
    $upload_dir = wp_upload_dir();
    $uploaded_image_location = $upload_dir['basedir'] . '/' .$image_data['file'];
    // $large_image_location = $upload_dir['path'] . '/'.$image_data['sizes']['large']['file']; // ** This only works for new image uploads - fixed for older images below.
    $current_subdir = substr($image_data['file'], 0, strrpos($image_data['file'], "/"));
    $large_image_location = $upload_dir['basedir'] . '/'.$current_subdir.'/'.$image_data['sizes']['large']['file'];

    // delete the uploaded image
    unlink($uploaded_image_location);

    // rename the large image
    rename($large_image_location, $uploaded_image_location);

    // update image metadata and return them
    $image_data['width'] = $image_data['sizes']['large']['width'];
    $image_data['height'] = $image_data['sizes']['large']['height'];
    unset($image_data['sizes']['large']);

    return $image_data;
}

//**************************************************************************

/*
add_action( 'wp_footer', function () {
?>
<script>

function init() {
var vidDefer = document.getElementsByTagName('iframe');
for (var i=0; i<vidDefer.length; i++) {
if(vidDefer[i].getAttribute('data-src')) {
vidDefer[i].setAttribute('src',vidDefer[i].getAttribute('data-src'));
} } }
window.onload = init;

</script>
<?php } );

 */


/**
Defer parsing of JavaScript with code snippet from Varvy
*/

/*
add_action( 'wp_footer', 'my_footer_scripts' );
function my_footer_scripts(){
?>
<script type="text/javascript">
function downloadJSAtOnload() {
var element = document.createElement("script");
element.src = "defer.js";
document.body.appendChild(element);
}
if (window.addEventListener)
window.addEventListener("load", downloadJSAtOnload, false);
else if (window.attachEvent)
window.attachEvent("onload", downloadJSAtOnload);
else window.onload = downloadJSAtOnload;
</script>
<?php
}

*/


Function Calls

None

Variables

None

Stats

MD5 cd6fcc98604f23eca7f0dd8855b928d5
Eval Count 0
Decode Time 39 ms