1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Call function if Admin Option Changes?

Discussion in 'XenForo Development Discussions' started by alexp999, Mar 7, 2014.

  1. alexp999

    alexp999 Active Member


    I am working on an add-on and would like to clear out a cache directory if a setting changes.

    I have seen that you can run a validation callback, is it possible to use this to determine if the value has changed?

    i.e. I don't want to clear the cache directory everytime someone presses save in the ACP settings, only if this specific settings value has changed.
  2. Brogan

    Brogan XenForo Moderator Staff Member

    Yes, that's exactly how you do it.
    I do it for my FT add-on when the max value is changed:
    alexp999 and Chris D like this.
  3. alexp999

    alexp999 Active Member

    How do you compare the old and new value within that function?
  4. Chris D

    Chris D XenForo Developer Staff Member

    You have access to the $dw object, see XenForo_Option_TemplateFiles for an example.

    You can do: $dw->getExisting('option_value') and compare that to $option or simply, $dw->isChanged('option_value');
    Last edited: Mar 7, 2014
    alexp999 likes this.
  5. alexp999

    alexp999 Active Member

    isChanged didn't seem to work, but getExisting did, so I have been able to create an if statement which does what I want.

    Thanks for the help. :)

Share This Page