• Resolved matthewbaynham

    (@matthewbaynham)


    I’m currently writing my first WordPress plugin (React, JS) and I’m wondering how my plugin could enable the save button.

    Let me explain what I mean.

    Think about someone creating a new page or post in WordPress, then they add my plugin to their page or post and they publish it.

    Then they have the page or post open and they adjust what text they have typed into my plugin. The problem is my plugin isn’t attached the save button for the page or post, so when they type away in a <input> box on my plugin, they want to save the page or post. But save button on the page or post hasn’t enabled.

    An ugly work around is, if they change something on the page or post that is not my plugin then the save button enables. But I don’t want to use this ugly work round, I want my plugin to enable to save button itself so that everything looks seamless to the user.

    So how do I get my plugin to connect programmatically with the save button on the page or post?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    The answer may depend upon which editor the user is using. AFAIK, the Save button is always enabled in the block editor, at least it is on my test site. The new post Publish button is initially disabled until one enters a title. After publishing the button then reads “Save”. Both versions of the button do have a aria-disabled attribute whose value can be changed from true to false via JS. There may or may not be more to enabling the button than that, but it’s the first thing to try since it’s obviously part of the solution if not the entire solution.

    Thread Starter matthewbaynham

    (@matthewbaynham)

    I fixed it in the end.

    I was setting the attributes wrong. I was doing this props.attributes.X = 7; which is wrong.

    What I should have been doing is using the setAttributes method props.setAttributes({ X: 7 });

    If you use the set setAttributes method then it’ll enable the save button.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.