bh_az_listing_init()

Initialises the plugin’s functions, partials, javascript and css.


Description


Source

File: a-z-listing.php

function bh_az_listing_init() {
	$dir = dirname( __FILE__ ) . '/';

	// Common functions.
	foreach ( glob( $dir . 'functions/common/*.php' ) as $filename ) {
		/** @noinspection PhpIncludeInspection */
		require_once( $filename );
	}

	// Functions: always present.
	foreach ( glob( $dir . 'functions/*.php' ) as $filename ) {
		/** @noinspection PhpIncludeInspection */
		require_once( $filename );
	}

	// Partials: only visible outside of admin.
	if ( ! is_admin() && 'wp-login.php' !== $GLOBALS['pagenow'] ) {
		foreach ( glob( $dir . 'partials/*.php' ) as $filename ) {
			/** @noinspection PhpIncludeInspection */
			require_once( $filename );
		}
	}

	// Locale.
	// $locale = get_locale();
	// $lang = substr( $locale, 0, 2 );
	// $country = substr( $locale, 3, 2 );
	//
	// if ( is_readable( $dir . 'languages/' . $lang . '-' . $country . '.php' ) ) {
	// 	require_once( $dir . 'languages/' . $lang . '-' . $country . '.php' );
	// } elseif ( is_readable( $dir . 'languages/' . $lang . '.php' ) ) {
	// 	require_once( $dir . 'languages/' . $lang . '.php' );
	// }

	// Javascripts: autoload.
	if ( is_admin() ) {
		$glob = glob( $dir . 'scripts/admin/*.js' );
		$admin = 'admin/';
	} else {
		$glob = glob( $dir . 'scripts/*.js' );
		$admin = '';
	}

	foreach ( $glob as $filename ) {
		$matches = array();
		preg_match( '!([^/]+).js$!', $filename, $matches );
		$code = 'bh-' . $matches[1];
		$url = plugins_url( 'scripts/' . $admin . $matches[1] . '.js', __FILE__ );
		wp_enqueue_script( $code, $url, array( 'jquery' ), null, true );
	}

	// CSS: autoload.
	$glob = glob( $dir . '*.css' );

	foreach ( $glob as $filename ) {
		$matches = array();
		preg_match( '!([^/]+).css!', $filename, $matches );
		$code = 'functionality-css-' . $matches[1];
		$url = plugins_url( $matches[1] . '.css', __FILE__ );

		if ( 'admin' !== $matches[1] || is_admin() ) {
			wp_enqueue_style( $code, $url );
		}
	}
}

Changelog

Changelog
Version Description
0.1 Introduced.


User Contributed Notes

You must log in before being able to contribute a note or feedback.