can not serialize and insert data from custom form
can not serialize and insert data from custom form
can not serialize and insert data from custom form
slider i want move 4 images every button click
Custom gutenberg block refuses to load viewScript and I don’t know why
Block style variations not enqueued for blocks inside HTML code dynamically rendered via JS
I finally found it out. You can access current comment settings by using wp.data.select(‘core/editor’).getEditedPostAttribute(‘comment_status’) So the complete solution is: function isCommentsEnabledInBlockEditor() { return wp.data.select(‘core/editor’).getEditedPostAttribute(‘comment_status’) === ‘open’; } function registerPublishBtnHandler() { const publishBtnArray = document.getElementsByClassName(“editor-post-publish-button__button”); if (publishBtnArray && publishBtnArray.length > 0) { const publishBtn = publishBtnArray[0]; if (publishBtn) { publishBtn.addEventListener(“click”, function (e) { if (!isCommentsEnabledInBlockEditor()) { … Read more
Based on the information you’ve provided, there are a few potential reasons why your script might not be enqueued properly in WordPress. Let’s troubleshoot: Try cache busting: It is possible the file is loading but the code is not loading because the file is cached. Try the below code. The $version variable changes every page … Read more
Thanks for MVE, @helgatheviking! It was beneficial. When wp.data caches the resolvers, it also considers arguments. Here’s what happens when following the reproduction steps for the bug: Selecting the first product resolves data, creates a cache for getProduct(1), and sets a value for the product state. Selecting second does the same (cache: getProduct(2)) and sets … Read more
wp_add_inline_script can be used to insert a tiny trigger script that executes after the script specified in script and any instance defined by that script will be available. // When this js executes `Masonry` is sure to be defined wp_add_inline_script( ‘masonry’, ‘if (window.top !== window) doItNow()’); This will end up being executed twice when the … Read more
Something like this should work: const {select, subscribe} = window.wp.data; const cartStoreKey = window.wc.wcBlocksData.CART_STORE_KEY; const unsub = subscribe( onCartChange, cartStoreKey ); function onCartChange() { const cart = select( cartStoreKey ).getCartData(); console.log( ‘¡ cart change !’, cart ); } The block’s frontend script should have the woocommerce script’s handle as a dependency so the window.wc.wcBlocksData will … Read more
Better way is to listen to Gutenberg events. Template change can be observed with something like this: wp.data.subscribe(() => { console.log(wp.data.select( ‘core/editor’ ).getEditedPostAttribute(‘template’)); }); It will fire on many wp.data events, not only for template change. But you can add some checks and do your actions only when it’s needed. Example: const editor = wp.data.select( … Read more