Skip to content

📦 NEW: The wp_localize_script functionality#206

Merged
ahmadawais merged 7 commits into
CommandCodeAI:masterfrom
ahmadbilaldev:master
Aug 18, 2019
Merged

📦 NEW: The wp_localize_script functionality#206
ahmadawais merged 7 commits into
CommandCodeAI:masterfrom
ahmadbilaldev:master

Conversation

@ahmadbilaldev
Copy link
Copy Markdown

@ahmadbilaldev ahmadbilaldev commented Aug 18, 2019

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
Copy link
Copy Markdown
Member

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

@ahmadawais ahmadawais changed the title 📦 NEW: Add wp_localize_script functionality 📦 NEW: The wp_localize_script functionality Aug 18, 2019
Copy link
Copy Markdown
Member

@ahmadawais ahmadawais left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read the comments and address the changes.

Comment thread packages/cgb-scripts/config/externals.js Outdated
Comment thread packages/cgb-scripts/config/externals.js Outdated
Comment thread packages/cgb-scripts/config/externals.js Outdated
Comment thread packages/cgb-scripts/config/externals.js Outdated
Comment thread packages/cgb-scripts/config/externals.js Outdated
Comment thread packages/cgb-scripts/config/externals.js Outdated
Comment thread packages/cgb-scripts/config/externals.js Outdated
Comment thread packages/cgb-scripts/template/src/init.php Outdated
Comment thread packages/cgb-scripts/template/src/init.php Outdated
Comment thread packages/cgb-scripts/config/externals.js Outdated
Co-Authored-By: Ahmad Awais ⚡️ <me@AhmadAwais.com>
Copy link
Copy Markdown
Member

@ahmadawais ahmadawais left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! 🔥

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants