• Resolved mateusvitor

    (@mateusvitor)


    Greetings from Aveiro!
    I’m using this plugin to highlight countries where my users are.
    I’m using ACF for users to set their country.

    Can I intercept a loading function and inject a country list/array?
    Or if I export map data, is there a field I can just refill with more countries and re-import to populate my map?

    Thank you.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Carlos Moreira

    (@carlosmoreirapt)

    Hi @mateusvitor
    If you’re able to create custom PHP code, you can use the igm_add_meta filter.

    Example of a custom plugin that extends this one to manipulate data using that filter among other things: https://github.com/carmoreira/igm-charities-integration/blob/master/igm-charities.php

    You’ll need to manipulate the $meta[‘regions] value.

    I haven’t documented all filters yet, but you can find some info here:
    https://interactivegeomaps.com/docs/available-filters-to-manipulate-data/

    The Pro version will probably have an integration with ACF soon.

    Hope it helps.
    Greetings, Carlos

    Thread Starter mateusvitor

    (@mateusvitor)

    Thank you, it really helped.
    I completely override the $meta[‘regions’], because I know there is nothing there of value in my case. I echoed all the stuff just to see what was there. I copied the list of countries in the map settings page, pasted in a sheet, sorted, re-concactenated the countries’ shortcode with their names as PT : Portugal, so it fits the advanced custom field(acf) select options, and it was all smooth sailing. Just had to re-associate the countries in each user for the acf because it was returning the old values so label and value were coming out the same.
    Sharing this in case someone else needs.
    Cheers!

    
    function vmg_igm_meta( $meta ) {
      /*
      // get option values.
        $opts      = get_option( 'interactive-maps' );
        $tax       = isset( $opts['igmc_taxonomy'] )       ? $opts['igmc_taxonomy'] : '';
        $metaf     = isset( $opts['igmc_meta'] )           ? $opts['igmc_meta'] : '';
        $acf       = isset( $opts['igmc_meta_is_acf'] )    ? $opts['igmc_meta_is_acf'] : false;
        $action    = isset( $opts['igmc_action_content'] ) ? $opts['igmc_action_content'] : 'open_url';
        $empty     = isset( $opts['igmc_hide_empty'] )     ? $opts['igmc_hide_empty'] : false;
        $cache     = isset( $opts['igmc_cache'] )          ? $opts['igmc_cache'] : false;
        $post_type = isset( $opts['igmc_cpt'] )            ? $opts['igmc_cpt'] : 'any';
        $regions   = isset( $meta['regions'] )             ? $meta['regions'] : [];
    
        //$regions = isset( $meta['regions'] ) && is_array( $meta['regions'] ) ? $meta['regions'] : [];
      echo '<div style="display:none">';
        echo '<h5 class="d-none">$opts </h5>';
        echo '<pre class="d-none">';
        var_dump($opts);
        echo ' </pre>';
        //
        echo '<h5 class="d-none">$tax</h5>';
        echo '<pre class="d-none">';
        var_dump($tax);
        echo ' </pre>';
        //
        echo '<h5 class="d-none">$metaf</h5>';
        echo '<pre class="d-none">';
        var_dump($metaf);
        echo ' </pre>';
        //
        echo '<h5 class="d-none">$acf</h5>';
        echo '<pre class="d-none">';
        var_dump($acf);
        echo ' </pre>';
        //
        echo '<h5 class="d-none">$action</h5>';
        echo '<pre class="d-none">';
        var_dump($action);
        echo ' </pre>';
        //
        echo '<h5 class="d-none">$empty</h5>';
        echo '<pre class="d-none">';
        var_dump($empty);
        echo ' </pre>';
        //
        echo '<h5 class="d-none">$cache</h5>';
        echo '<pre class="d-none">';
        var_dump($cache);
        echo ' </pre>';
        //
        echo '<h5 class="d-none">$post_type</h5>';
        echo '<pre class="d-none">';
        var_dump($post_type);
        echo ' </pre>';
        //
        echo '<h5 class="d-none">$regions</h5>';
        echo '<pre class="d-none">';
        var_dump($regions);
        echo ' </pre>';
      echo '</div>';
      */
      /*
      array(1) {
        [0]=>
        array(5) {
          ["name"]=>
          string(8) "Portugal"
          ["id"]=>
          string(2) "PT"
          ["tooltipContent"]=>
          string(17) "Portugal is nice."
          ["content"]=>
          string(0) ""
          ["useDefaults"]=>
          string(1) "1"
        }
      }
     */
    
      $all_users = get_users();
      $participant_countries_array_by_key = array();
      $participant_countries_array = array();
      if(!empty($all_users)):
        foreach ($all_users as $user) :
          $u_uID = 'user_'.$user -> ID;
          if(get_field('is_a_participant', $u_uID)):
            $participant_country = get_field('country', $u_uID); // [ 'value', 'label' ]
            echo '<h5 class="d-none">$participant_country </h5>';
            echo '<pre class="d-none">';
            var_dump($participant_country);
            echo ' </pre>';
    
            $p_first_name = $user -> user_firstname;
            $p_last_name = $user -> user_lastname;
            $p_append = get_field('user_append', $u_uID);
            $participant_proper_name = $p_last_name.', '.$p_first_name;
            $participant_proper_name = $p_append ? $participant_proper_name.', '.$p_append : $participant_proper_name;
    
            if( array_key_exists( $participant_country['value'], $participant_countries_array_by_key ) ){
              $participant_countries_array_by_key[$participant_country['value']]["tooltipContent"] .= '<br>'.$participant_proper_name;
            }else{
              $participant_countries_array_by_key[$participant_country['value']] = array(
                "name"           => $participant_country['label'],
                "id"             => $participant_country['value'],
                "tooltipContent" => '<br>'.$participant_proper_name,
                "content"        => "",
                "useDefaults"    => "1",
              );
            }
          endif; // is a participant
        endforeach; // all users
      endif; // users not empty
      ksort( $participant_countries_array_by_key );
      foreach ($participant_countries_array_by_key as $pc) {
        array_push( $participant_countries_array, $pc);
      }
      /*
      echo '<div style="display:none">';
        echo '<h5 class="d-none">$participant_countries_array_by_key </h5>';
        echo '<pre class="d-none">';
        var_dump($participant_countries_array_by_key);
        echo ' </pre>';
        echo '<h5 class="d-none">$participant_countries_array </h5>';
        echo '<pre class="d-none">';
        var_dump($participant_countries_array);
        echo ' </pre>';
        echo ' </div>';
      */
      $meta['regions'] = $participant_countries_array;
      return $meta;
    }
    
    add_filter( 'igm_add_meta', 'vmg_igm_meta', 1 );
    
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Importing list of countries’ is closed to new replies.