beans_load_fragment_file

Load fragment file.

This function can be short-circuited.

beans_load_fragment_file( string $slug )

Return: (bool) True on success, false on failure.

Parameters

NameTypeRequiredDefaultDescription
$slugstringtrue-The file name to include without extension.

Source

function beans_load_fragment_file( $slug ) {

	/**
	 * Filter whether to load a fragment or not.
	 *
	 * The dynamic portion of the hook name, $slug, refers to the file name without extension. Passing a truthy
	 * value to the filter will short-circuit loading the fragment.
	 *
	 * @since 1.0.0
	 *
	 * @param bool $pre True to short-circuit, False to let the function run.
	 */
	if ( apply_filters( 'beans_pre_load_fragment_' . $slug, false ) ) {
		return false;
	}

	// Stop here if fragment file doesn't exists.
	if ( ! file_exists( BEANS_FRAGMENTS_PATH . $slug . '.php' ) ) {
		return false;
	}

	require_once( BEANS_FRAGMENTS_PATH . $slug . '.php' );

	return true;

}