2

I am trying to set a Post's default visibility to 'Private' when a user first creates the post. They should then have the ability to manually select 'published' from the sidebar dropdown once they are ready or the post has been reviewed.

My goal is to ensure posts aren't accidentally published if the user isn't ready or forgot to select 'private'.

I can't find any code that works for Gutenberg. Most I researched are outdated and for the classic editor. I would prefer not to use a plugin if possible.

Any help is much appreciated. Thanks in advance!

8
  • You can also adjust the pre-publish checklist panel instead, or the classic method of using the contributor role so that posts have to be approved to be published. Also note that this means there will be no draft posts, no review approval, and no scheduled publishing available, as well as no way to know the difference between private posts and posts that haven't been published yet
    – Tom J Nowell
    Commented Apr 8, 2021 at 12:38
  • Thanks Tom. Unfortunately Contributors are unable to edit published posts so this wont work for my use case. Having the pre-publish checklist does help, however this still does rely on the user manually changing the status. I would prefer for it to default to 'private' automatically to ensure there is no accidental publishing.
    – Bmillerz
    Commented Apr 8, 2021 at 13:02
  • or having a checkbox that users must check in the pre-publish pane before publishing can happen? Setting the post to private by default isn't an easy thing to do, it's likely you can't find any examples because it has not been done before and requires in depth knowledge that's rare in the WP ecosystem. I can think of a solution but it would make all posts private all the time, even published posts would be turned into private posts, the initial part of the question complicates things greatly. Otherwise the concern you're trying to address is already addressed by lots of other solutions
    – Tom J Nowell
    Commented Apr 8, 2021 at 13:29
  • also have you considered tweaking the capabilities assigned to the author and contributor roles to allow them to edit other authors posts?
    – Tom J Nowell
    Commented Apr 8, 2021 at 13:30
  • I've conducted some research into the problem and the results are not good. It may be easier to replace the publish button with a button that prompts the user asking if they are sure they want to publish
    – Tom J Nowell
    Commented Apr 8, 2021 at 13:46

1 Answer 1

1

At the time of writing, there are no filters on the initial edits array passed from PHP through to javascript and into the editor initialisation function.

If such a filter existed, it would be possible to apply a post_status field, but no PHP or JS hooks exist currently to do this.

The Editor component also provides no opportunities to modify this structure to add/edit values.

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.