WP file traversion and PHP and termination of script

display-pho-version.php →

function dpv_enqueue_script( $hook ) {

	// only run on dashboard page
	if ( 'index.php' != $hook ) {
		return;
	}

	// enqueue script to show PHP version
	wp_enqueue_script( 'dpv_script', plugin_dir_url( __FILE__ ) . 'dpv.js' );

	// pass the PHP version to JavaScript
	wp_localize_script( 'dpv_script', 'dpvObj', array(
		'phpVersion' => phpversion()
	) );

}

add_action( 'admin_en

queue_scripts’, ‘dpv_enqueue_script’ );

dpv.js →

jQuery(document).ready(function ($) {
	$("#wp-version-message").after("<p>Running PHP version: <b style='color:green;'>" + dpvObj.phpVersion + "</b></p>");
});

These two files are part of a small WordPress plugin. Initially, I thought that this is a pure WP question so I posted on here.

I had some good discussions there.

But mostly this is PHP so I am posting here so that I can better insight.

Question:

function dpv_enqueue_script( $hook ) {

// only run on dashboard page
if ( 'index.php' != $hook ) {
	return;
}

$hook is a parameter. How come $hook is automatically getting assigned with PHP pages such as index.php, page.php?

Because this is a binary condition unless you find admin's index.php in WordPress return and terminate the script so that It does not get executed in any front end page.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.