@secretstache/wordpress-gutenberg 0.6.2 → 0.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@secretstache/wordpress-gutenberg",
3
- "version": "0.6.2",
3
+ "version": "0.6.3",
4
4
  "description": "",
5
5
  "author": "Secret Stache",
6
6
  "license": "GPL-2.0-or-later",
@@ -234,7 +234,25 @@ export const getFiltersByNamespace = (namespace) => {
234
234
  };
235
235
 
236
236
  /**
237
- * Unregisters a block type for a specific post type when editor loads.
237
+ * Allow a block for a specific post type
238
+ * @param {string} blockName - Name of the block to unregister
239
+ * @param {string} postType - Post type to check against
240
+ */
241
+ export const setBlockForPostType = (blockName, postType) => {
242
+ const unsubscribe = subscribe(
243
+ () => {
244
+ const currentPostType = select('core/editor').getCurrentPostType();
245
+ if (currentPostType && currentPostType !== postType && getBlockType(blockName)) {
246
+ unregisterBlockType(blockName);
247
+ unsubscribe();
248
+ }
249
+ },
250
+ 'core/editor',
251
+ );
252
+ };
253
+
254
+ /**
255
+ * Disallow a block for a specific post type
238
256
  * @param {string} blockName - Name of the block to unregister
239
257
  * @param {string} postType - Post type to check against
240
258
  */
@@ -242,7 +260,7 @@ export const unsetBlockForPostType = (blockName, postType) => {
242
260
  const unsubscribe = subscribe(
243
261
  () => {
244
262
  const currentPostType = select('core/editor').getCurrentPostType();
245
- if (currentPostType === postType && getBlockType(blockName)) {
263
+ if (currentPostType && currentPostType === postType && getBlockType(blockName)) {
246
264
  unregisterBlockType(blockName);
247
265
  unsubscribe();
248
266
  }