You can use wp_localize_script()
to pass JavaScript variables to the editor:
$asset_file = include(get_template_directory() . '/path/to/blocks/index.asset.php');
wp_register_script(
'pb-theme-blocks',
get_template_directory_uri() . '/path/to/blocks/index.js',
$asset_file['dependencies'],
$asset_file['version']
);
wp_localize_script(
'pb-theme-blocks',
'pbThemeBlocksVars',
array(
'classes' => array(), // Your theme classes go here
)
);
Then in your edit
function:
const classes = pbThemeBlocksVars.classes;
Related Posts:
- Gutenberg Blocks doesn’t render correctly when using do_blocks
- Create custom blocks for bootstrap
- Passing the name of selected color from the custom component to `render_callback`
- WordPress – Get Posts with Category data
- register dependency css and js inside a plugin class
- How to remove hardcoded characters from playlists?
- Conditionally loading JavaScript based on the Advanced Custom Fields in the post
- add_meta_boxes action with refresh on save
- How to use copy() function and paste file in /wp-content/themes directory
- Understanding WordPress child theme custom JS loading
- Use different javascript files for each page on website
- do not show web page section when using advanced custom fields pro
- Am I not understanding plugins?
- Using Font Awesome as post thumbnail
- Why WordPress architecture is not pure object oriented and it don’t use MVC pattern? [closed]
- admin-ajax.php responding with 0
- Page Reloads Before AJAX Request Finishes
- custom shortcode will not display the wrapped content
- How to test nonce with AJAX – Plugin development
- Trigger popup in a php if/else statement
- How can i upload images in an admin page?
- How to select the contents in the text view textrea in wp_editor?
- Hide categories that are not used in the post type
- Displaying admin notices inside the block editor from rest_after_insert_{$this->post_type} hook
- How to set up VS Code for WP plugin/theme development in 2021? [closed]
- what is the best practice to add new field to an api route
- I have a problem in the order of enqueues while enqueuing stylesheets and scripts for a specific page in my function.php
- Need Help Fixing My Iframes [closed]
- Improve page speed loading using CDN and async or defer attribute
- How to send Ajax request from my plugin in admin dashboard?
- Menu jumping when calling it via PHP
- AJAX success response is not working but it’s saving my changes
- Redirect to another page using contact form 7? [closed]
- How to obtain the current website URL in my theme?
- What exactly do this function declared into functions.php file of a WP theme?
- Is it save to use eval for a jQuery callback method coming from the database?
- zip unzip attachments in wordpress
- wordpress admin plugin menu custom css
- How to add the sidebar to all the pages except the home page? [closed]
- How to Change CSS Colors from Custom Plugin Settings Page
- wp_nav_menu not working correctly in my underscores theme
- Validate and Sanitize WP REST API Request using WP JSON Schema?
- How can I search all plugins for composer’s vendor/autoload.php?
- Removed jQuery script from header.php , any problems?
- Toolbar Hidden in a Virtual Page
- Ajax URLs without #!, how to prevent falling into single.php on load or reload?
- security concerns if using html data-* attribute for l10n?
- How to use wp_send_json() and output the value with ajax?
- Additional file upload in Gutenberg page options/featured image
- How to populate a Gutenberg select field SelectControl with option value from PHP array
- Settings API form – submit with AJAX
- How to change basename url for wp-admin?
- Post form – AJAX won’t upload featured image – Plugin development
- Gutenberg block don’t save rich text content
- Creating a POP Alert
- How do I disable cache for a certain page?
- Submit remote form to wordpress REST API and save data to custom post type
- Store user form submitted information in post type
- Display attached images of a page or post that are insetred using gallery
- Add a custom link to each image in WordPress gallery
- Collapsible menu on post sidebar only expands and does not collapse
- How to properly escape in ternary operators – Wp Coding Standards?
- How to send Ajax Call from frontend without using wp_localize_script in Theme
- How to use Amazon Elastic Transcoder from WordPress using AWS SDK for PHP?
- Why this plugin is not working?
- WP multisite network plugin fails to see classes loaded with spl autoload
- How to edit the default database of WordPress [closed]
- how can I make content from a plugin hidden when user is logged in? [duplicate]
- How to create post comparison in wordpress
- Import js variables loaded via wp_localize_script() into js module without global scope connection
- Variable ++ in query loop
- Add default block css when the block has been added with php?
- Woocommerce Convert existing order to the cart
- Where to store PHP files created by plugin / themes
- PHP unit testing WordPress?
- Is there a way for a plugin to add an attribute to the tag of a theme?
- How to Add a .js file Only in one specific Page Dynamically to Head
- Looking for callback function after Gutenberg is rendered?
- My shortcode is showing up twice
- Database “Migration” for Plugins?
- using woocommerce_template_single_add_to_cart in shop-loop – javascript issues [closed]
- Can’t load WP function into external function
- Pulling data from custom plugin settings using PHP shortcode and Javascript
- Slider loading issue
- Do I have to worry about useState causing a re-render?
- Compare the old get_theme_mod($name) to the new get_theme_mod($name) return value
- Search form does not work in my website
- Hook called before text widget save
- wpdb prepare insert table doesn’t work
- custom plugin with upload files does not work
- send popup after wp_redirect()
- How do I integrate vanilla Javascript to a wordpress website?
- Looping through dummy posts and showing them in the main index.php
- Update user meta when an external link in admin notice is clicked
- Is there an option to execute javascript file only on plugin activation
- Ajax in a class instantiated via shortcode
- Shortcode Works for Logged in Users but Not Working for Guest
- Permission error on plugin save
- Twig+WordPress how to use array arguments inside a function?
- WordPress Block Editor Gutenberg running code inside ! is_admin()