Skip to main content
34 events
when toggle format what by license comment
Feb 8, 2022 at 16:04 comment added Christine Cooper @Welcher Beautiful update to this code. I adapted the new version today to a production site and it is working considerably better than the previous version. Very helpful stream as well.
Nov 24, 2021 at 20:20 comment added Jignesh Bhavani @Welcher It does work for me too. Great work although I didn't get a chance to watch the live stream yet. I'll watch this weekend. Keep up the great work mate :)
Oct 28, 2021 at 17:02 comment added Welcher @JigneshBhavani yes it works for me. I recently did a live stream where I took a different approach. Perhaps it will help. You can see it here - youtube.com/watch?v=ZHmiI1p26Vc
S Oct 28, 2021 at 16:59 history suggested Hashim Aziz CC BY-SA 4.0
Split up old version from newer
Oct 28, 2021 at 16:37 review Suggested edits
S Oct 28, 2021 at 16:59
Oct 28, 2021 at 16:21 comment added Hashim Aziz @JigneshBhavani Does the latest version work for you?
Sep 14, 2021 at 19:44 history edited Welcher CC BY-SA 4.0
Update answer to reflect changes in Gutenberg
Sep 14, 2021 at 18:18 comment added Jignesh Bhavani @Welcher I created work around by using wp.subscribe() method which was allowing me to track new changes on category selector but It doesn't looks convenient as even new post is also showing me Category selection notice which I dispatched along with lockPostSaving(). I'm still trying to fix by Prepublish way. Any head start would be great from you :)
Sep 13, 2021 at 13:54 comment added Welcher @JigneshBhavani thanks for mentioning this! I'll take another look at this today and update the answer if needed.
Sep 13, 2021 at 13:53 comment added Welcher @HashimAziz - yes the naming was intentional however I can see how it could unclear. I was using the build process process provided by the @wordpress/scripts package.
Sep 12, 2021 at 23:11 comment added Jignesh Bhavani Hey @Welcher It does work as expected on first time but after we make changes lets say select few categories but check is not refreshing like inwerpsel mentioned. Any clue if we can make it working using useEffect to recheck after making changes. ? Thanks
Aug 29, 2021 at 20:58 comment added Hashim Aziz I can't seem to get this working. A few clarifications - was it intentional to make the function name/call the same as the hook: enqueue_block_editor_assets? And does this solution require the build process, or should it be working without one?
Apr 26, 2021 at 18:56 comment added Welcher For the benefit of folks coming here and reading the comments, the question requested a solution that renders in the PrePublishPanel and locks publishing at that point. This answer provided that solution - regardless of whether anyone considers this approach an anti-pattern. The approach mentioned by @inwerpsel is a different way of doing this that is not incorrect, but just not what OP requested.
Apr 26, 2021 at 18:44 comment added Welcher Just to follow up here. I just did a copy and paste with no modifications, did a build and not only did it work as expected but it also unlocked the post when hitting cancel. This was how it was intended to work and seems to be still working as expected. This was on WordPress 5.7.1
Mar 21, 2021 at 9:15 comment added inwerpsel Before you go back to your day, maybe you can save other people the time and update your answer to say it doesn't work anymore? ;)
Mar 20, 2021 at 20:13 comment added Welcher Good luck! Looking forward to your approach. I’m going to go back to my day. :)
Mar 20, 2021 at 20:10 comment added inwerpsel "not sure how this is an anti-pattern either, as the only way to introduce functionality to the BlockEditor is done via SlotFill" This is definitely not the only way to customize the block editor. It's the only way to show custom elements in slots in the editor. That doesn't mean it's the only way you can interact with the data in the editor. And even if it was the only way, that doesn't change the fact side effects in render are an anti pattern.
Mar 20, 2021 at 19:28 comment added inwerpsel How would useEffect inside the component solve the problem that the post only gets re-checked when the component gets rendered? As I said, this should not be attached to a component that just happens to be rendered at the right moment. I'm currently trying a subscriber that validates the post whenever it changes, and dispatches the locking/unlocking. I'll post an answer if it works out.
Mar 20, 2021 at 16:07 comment added Welcher This code is a little old now. I would probably add a useEffect hook that that unlocked the post when the component unmounted. I would very much be interested in a alternative solution if you have one.
Mar 20, 2021 at 13:11 comment added inwerpsel It's an anti-pattern because it's not the moment you want this post locking to happen. A component function is only rerun when its props change (or when it uses custom hooks or state). There may be forced re-renders from time to time, but you can't rely on those keeping on happening. I actually tried your solution on WP 5.6, and the post save button stays disabled after making my post valid again. So I can't trigger the panel to render again. I need to close and re-open the whole sidebar using the cog icon to enable the button, because only then it reruns the validation logic and post locking.
Mar 19, 2021 at 16:23 comment added Welcher As this is rendered in the last step before publishing is done, I'd argue this is the best place to do it. I'm not sure how this is an anti-pattern either, as the only way to introduce functionality to the BlockEditor is done via SlotFill - so by your logic, anything rendered anywhere cannot do anything but render static content.
Mar 19, 2021 at 15:54 comment added inwerpsel Locking the post directly in this component is an anti pattern. The PluginPrePublishPanel is exactly what it says it is. It's a panel to render custom things in the sidebar that is shown before publishing. It's not supposed to be the place where you lock/unlock the post saving. Renders should never have this kind of direct effect and doing this will lead to bugs.
Mar 3, 2020 at 12:23 history edited Christine Cooper CC BY-SA 4.0
added 6 characters in body
Jul 12, 2019 at 11:37 comment added Christine Cooper Update: my bug report is successful and they are fixing it!
Jun 17, 2019 at 13:56 comment added Christine Cooper There was a minor issue with the operator for the tags (edited your answer), but works like a charm. I now know how little I know about developing with Gutenberg. Thank you so much for this answer! PS: The reason why it was not displaying originally for me was because users on contributor level can't see the pre-publish panel properly, see this bug report.
Jun 17, 2019 at 13:54 history edited Christine Cooper CC BY-SA 4.0
added 95 characters in body
Jun 11, 2019 at 8:08 history bounty ended Christine Cooper
Jun 11, 2019 at 8:08 vote accept Christine Cooper
Jun 9, 2019 at 17:13 history edited Welcher CC BY-SA 4.0
added 285 characters in body
Jun 7, 2019 at 14:43 history edited Welcher CC BY-SA 4.0
added 440 characters in body
Jun 7, 2019 at 13:11 history edited Christine Cooper CC BY-SA 4.0
deleted 21 characters in body
Jun 6, 2019 at 1:54 history edited Welcher CC BY-SA 4.0
Remove unneeded code in the example
Jun 5, 2019 at 18:09 history edited Welcher CC BY-SA 4.0
Slight change to the code to correctly render the Panel
Jun 5, 2019 at 13:45 history answered Welcher CC BY-SA 4.0