How do I disable the changing of the permalink for published posts (for non-admin)?

You could do something like the following, this should go in your Child Theme’s functions.php or if not using a Child Theme then add to a custom plugin: function hide_permalink_metabox( $is_post_edit_page ) { if ( !current_user_can(‘update_core’) ) { // allows Admins to edit the permalink echo ‘<style> div#edit-slug-box {display:none!important;} </style>’; } You may need to … Read more

Translating the “Everything” filter menu in Quicksand jquery file

You should be able to pass the language across using wp_localize_script(). So you’re obviously enqueuing your own custom javascript file, lets say that file is called createlist.js. I assume you’re doing it like so: wp_enqueue_script( ‘createlist’, plugins_url( ‘createlist.js’, __DIR__ ), array( ‘jquery’ ), ‘1.0’, true ); (You’ll need to adjust the path for the JS … Read more

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

Update a server-side render Block when woocommerce cart block changed

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

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

Embed dynamic media query in a Gutenberg block

If we stick to your exact example, I would define the value as a custom property in an inline style: <div class=”item” style=”–my-gap: <?php echo esc_attr( $attributes[‘gap’] ); ?>;”> Then in CSS use a media query to use the property as the appropriate margin: .item { margin-bottom: var(–my-gap); } @media ( min-width: 768px ) { … Read more