Skip to content

How to check and update current post's discussion settings? #64735

Answered by abid76
abid76 asked this question in Q&A
Discussion options

You must be logged in to vote

10 minutes after asking the question I found it out 🙂

You can access current comment status via

wp.data.select('core/editor').getEditedPostAttribute('comment_status')

So the current solution is:

// file my-block-editor-js.js
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) {

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by abid76
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant