How to access current discussion settings in gutenberg 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

enqueue_custom_scripts isn’t working

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

useSelect() plus resolver result is serving cached data incorrectly

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

How to re-render Gutenberg component when object instance is available

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

Metabox conditionals depending on post format and template in Gutenberg

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

How to use Javascript to get data from a WordPress form

This approach should work, Modify it for your use case. //JQuery Code jQuery( document ).on( ‘change’, ‘.from-this’, function( e ) { e.preventDefault(); jQuery( ‘.change-this’ ).text( this.value ); } ) HTML Code: <input type=”search” class=”from-this” /> <div class=”change-this”></div>

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)