• I have looked at all the documentation available, but I cannot figure out if this is possible. Here is my situation:

    1. I have an existing plugin that adds several features to the gallery shortcode. It does so by adding a few attributes to the gallery shortcode and, while processing the shortcode it checks for those attributes. If present it runs my branch of code, and if not, it runs the core WP code. I am in the process of converting this plugin to Gutenberg.
    2. When it comes to creating new instances of the shortcode, I am able to neatly do so using blocks with the Block API.
    3. However, there are over 10,000 users of the plugin, and several of them have existing instances of the gallery shortcode with the additional attributes required by the plugin.
    4. Now, when I activate Gutenberg, open a post, and click on “Convert to Blocks”, all of the existing instances get converted to the core/gallery block.
    5. To let the transformation happen to my plugin, I have added the following code in the block registration section:
      transforms: {
      	from: [
      		{
      			type: 'shortcode',
      			tag: 'gallery',
      			attributes: {
      				myattr: {
      					type: 'string',
      					shortcode: function(named) {
      						return JSON.stringify(named.named);
      					}
      				}
      			}
      		}
      	]
      },
    6. But with the code above, whenever I click on “Convert to Blocks” the shortcodes all get converted to blocks for my plugin! If I add a priority to the code and assign a higher number for priority, the code switches back to showing the core gallery.

    My question is: in the code I pasted above, is there any way to specifically target shortcodes with tag gallery that have a certain attribute defined? I have looked at extending blocks, as well as the transforms documentation, in addition to going through the pre-compilation code on Github to figure this out, but I haven’t had any luck.

  • The topic ‘Target specific blocks / shortcodes for “Transform”’ is closed to new replies.