private static function setFbeBasedAAMSettings()

in core/FacebookWordpressOptions.php [219:253]


  private static function setFbeBasedAAMSettings(){
    $installed_pixel = self::getPixelId();
    $settings_as_array = get_transient(FacebookPluginConfig::AAM_SETTINGS_KEY);
    // If AAM_SETTINGS_KEY is present in the DB and corresponds to the installed
    // pixel, it is converted into an AdsPixelSettings object
    if( $settings_as_array !== false ){
      $aam_settings = new AdsPixelSettings();
      $aam_settings->setPixelId($settings_as_array['pixelId']);
      $aam_settings->setEnableAutomaticMatching($settings_as_array['enableAutomaticMatching']);
      $aam_settings->setEnabledAutomaticMatchingFields($settings_as_array['enabledAutomaticMatchingFields']);
      if($installed_pixel == $aam_settings->getPixelId()){
        self::$aamSettings = $aam_settings;
      }
    }
    // If the settings are not present
    // they are fetched from Meta domain
    // and cached in WP database if they are not null
    if(!self::$aamSettings){
      $refresh_interval =
        self::AAM_SETTINGS_REFRESH_IN_MINUTES*MINUTE_IN_SECONDS;
      $aam_settings = AdsPixelSettings::buildFromPixelId( $installed_pixel );
      if($aam_settings){
        $settings_as_array = array(
          'pixelId' => $aam_settings->getPixelId(),
          'enableAutomaticMatching' =>
            $aam_settings->getEnableAutomaticMatching(),
          'enabledAutomaticMatchingFields' =>
            $aam_settings->getEnabledAutomaticMatchingFields(),
        );
        set_transient(FacebookPluginConfig::AAM_SETTINGS_KEY,
        $settings_as_array, $refresh_interval);
        self::$aamSettings = $aam_settings;
      }
    }
  }