jploch Posted August 14, 2022 Share Posted August 14, 2022 Is ist possible to make locked pages editable for superusers? If a page ist locked I want to prevent the client to edit it, but would like to make changes myselft without unlocking and then locking the page again. Link to comment Share on other sites More sharing options...
Jan Romero Posted August 14, 2022 Share Posted August 14, 2022 Haven’t thoroughly tested it or anything, but this hook seems to work: wire()->addHookBefore('ProcessPageEdit::execute', function(HookEvent $event) { /** @var Page $page */ $page = $event->object->getPage(); //ProcessPageEdit does roughly this to figure out if it’s dealing with a save request. if it isn’t, we don’t care if (!count($_POST) || (int)input()->post('id') !== $page->id) return; //if the page isn’t locked -> don’t care if (!$page->isLocked()) return; //if it’s locked and we’re a superuser, unlock if (user()->isSuperuser()) { $page->removeStatus(Page::statusLocked); wire()->message('leet hax, you just edited a locked page.'); //You don’t need to re-lock the page here, because the Locked checkbox is //sent with the page edit form, so saving will set it to the desired value } }); I would have hooked processSave directly, but it’s not hookable. Bonus tip: You can change the warning that says “This page is locked for edits” if you put this in the hook: if (user()->isSuperuser()) $event->object->noticeLocked .= ', but I’ll make an exception for you because you’re such a pleasure to be around'; Btw, you can always edit locked pages from the API as a superuser. 2 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now