# learnpress/4.4.4/assets/src/apps/js/blocks/utilBlock.js

LearnPress – WordPress LMS Plugin for Create and Sell Online Courses, version 4.4.4. 48 lines.

- Page: https://pluginprobe.com/plugins/learnpress/4.4.4/code/assets/src/apps/js/blocks/utilBlock.js
- Raw: https://pluginprobe.com/plugins/learnpress/4.4.4/raw/assets/src/apps/js/blocks/utilBlock.js
- Modified: 2026-08-03T03:26:42+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/learnpress/4.4.4/code/assets/src/apps/js/blocks/utilBlock.js#L10-L20`.

```javascript
/**
 * Check if the block can be loaded in the current template.
 *
 * @since 4.2.8.4
 * @version 1.0.0
 */
import { unregisterBlockType, getBlockType } from '@wordpress/blocks';
import { subscribe, select } from '@wordpress/data';

let currentPostIdOld = null;
const checkTemplatesCanLoadBlock = ( templates, metadata, callBack ) => {
	subscribe( () => {
		const metaDataNew = { ...metadata };
		const store = select( 'core/editor' ) || null;

		if ( ! store || typeof store.getCurrentPostId !== 'function' || ! store.getCurrentPostId() ) {
			return;
		}

		const currentPostId = store.getCurrentPostId();

		if ( currentPostId === null ) {
			return;
		}

		if ( currentPostIdOld === currentPostId ) {
			return;
		}

		currentPostIdOld = currentPostId;
		if ( getBlockType( metaDataNew.name ) ) {
			unregisterBlockType( metaDataNew.name );

			if ( templates.includes( currentPostId ) ) {
				metaDataNew.ancestor = null;
				callBack( metaDataNew );
			} else {
				if ( ! metaDataNew.ancestor ) {
					metaDataNew.ancestor = [];
				}
				callBack( metaDataNew );
			}
		}
	} );
};

export { checkTemplatesCanLoadBlock };

```
