Jump to content

[SOLVED] make locked pages editable for superusers


Recommended Posts

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

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)

    //if the page isn’t locked -> don’t care
    if (!$page->isLocked())

    //if it’s locked and we’re a superuser, unlock
    if (user()->isSuperuser()) {
        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.

  • Like 2
  • Thanks 1
Link to comment
Share on other sites

  • jploch changed the title to [SOLVED] make locked pages editable for superusers

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...