ahmadawais / create-guten-block

📦 A zero-configuration #0CJS developer toolkit for building WordPress Gutenberg block plugins.
https://Awais.dev/cgb-post
MIT License
3.16k stars 329 forks source link

📦 NEW: The wp_localize_script functionality #206

Closed ahmadbilaldev closed 5 years ago

ahmadbilaldev commented 5 years ago

This PR adds wp_localize_script in the CGB template.

Problem You can not determine the path or URL of the plugin programatically inside the blocks. This is usually done by PHP functions plugin_dir_path() and plugin_dir_url(). However, they are not accessible inside the blocks (say if one wants to include an image locally and link to it in the src tag).

Solution In this PR, I have added an array CGB_GLOBAL containing dynamic data for a JS Global. The globals can now be imported inside the block JS file. More useful globals can be added in the future.

ahmadawais commented 5 years ago

Thanks for the PR. @ahmadbilaldev learn Emoji log better. Using both NEW and ADD are redundant.