Jump to content

Detect API vs admin site saves in hooks


guy
 Share

Recommended Posts

Is there a recommended way to detect when a page is saved via the API vs the admin site within a save hook? Such as:

$this->pages->addHookAfter('savedPageOrField', $this, 'someMethod');

within someMethod I'm currently doing the following:

$saveBtn = $input->post('submit_save');

if (!$saveBtn) return;

// only reach the below when passed a submit_save POST param
...

The above seems to work but I wasn't sure if this was a reliable way, or if something more fit for purpose exists?

Link to comment
Share on other sites

@guy You could try this:

if($this->wire()->process == 'ProcessPageEdit') { 
  // save from page editor
}

If you want to capture other types of page editors, like ListerPro, User Profile, etc. you could do this:

if(wireInstanceOf($this->wire()->process, 'WirePageEditor')) {
  // save from any page editing process
}

 

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

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
 Share

  • Recently Browsing   0 members

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