Support

Account

Home Forums ACF PRO Options Page: First Use Reply To: Options Page: First Use

  • As far as true/false fields go. The value “1” is stored for true and “0” for false. So you’d need to do exact checking:

    
    if ($variable === false) {
      // get_field() returned exactly false, so the value is not set.
      // set the default value
    }
    

    The links above also include the links to the action hooks for when a theme is activated or switched. You’d need to create a function that runs on one or both of these hooks and use the update_field() function to insert all of your default values. You could probably loop through the “fields” sub-array of the export to get the field keys and values to insert. The difficulty of actually inserting the values will depend on the field types involved. I think that repeater fields (and maybe some others) will be problematic.

    Really, there are only 2 choices, value checking in the theme when the value is loaded or building a function to insert the data when your theme is activated, and of course seeing if it was already inserted by a previous activation of your theme or removing the data when your theme is deactivated.

    This isn’t really a problem is the options page addon. The insertion of data does not happen until someone edits the options page. You’re suggesting that instead, when a field group is created that all the default values are auto inserted. There is no way to tell where that data needs to be inserted because you can attach the same field group to many places (posts, pages, options pages, users, custom post types, etc) many of which will not even exist when when the field group is created. Doing this would by pretty much impossible to detect when to do it and where to insert the data.