# National Flags

**URL:** https://meta.discourse.org/t/national-flags/55969
**Category:** Plugin
**Tags:** broken
**Created:** [January 18, 2017, 3:13pm UTC](https://meta.discourse.org/t/national-flags/55969 "2017-01-18T15:13:40Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![Ebs](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ebs/32/119612_2.png) [@Ebs](https://meta.discourse.org/u/Ebs)
#### Post date: [January 18, 2017, 3:13pm UTC](https://meta.discourse.org/t/national-flags/55969/1 "2017-01-18T15:13:40Z")

</div>

## ⚠ This plugin is broken, use the fork instead [National Flags (fork)](https://meta.discourse.org/t/national-flags-fork/384423) ⚠

Inspired by [the phpBB Plugin](https://www.phpbb.com/customise/db/extension/phpbb_3.1_national_flags/), I’ve put together a similar plugin for Discourse.

 ![](https://global.discourse-cdn.com/meta/original/3X/e/2/e25761a3415fee4376d64ff6a79282bea430f1ec.PNG)

After installing and enabling in Admin/Plugins, users will have a new custom setting called ‘National Flag’. After selecting a country code from the dropdown, the flag image will be displayed alongside their name in topics and also displayed on their user profile.

 ![](https://global.discourse-cdn.com/meta/original/3X/b/3/b3814066dd2ddc6d638467805e1f0dddf42037ee.PNG)

In its current state, it’s fairly ‘hacky’ and there’s _plenty_ of room for improvement. I’d appreciate some help with the code if anyone is willing to offer their assistance!

Thoughts and ideas are welcome, I plan to update and improve this in the future!

> **[GitHub - Ebsy/discourse-nationalflags: National Flags plugin for Discourse](https://github.com/Ebsy/discourse-nationalflags)**
>
> National Flags plugin for Discourse

---

<div class="post-metadata">

### Author: ![JagWaugh](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jagwaugh/32/69335_2.png) [@JagWaugh](https://meta.discourse.org/u/JagWaugh)
#### Post date: [January 18, 2017, 3:39pm UTC](https://meta.discourse.org/t/national-flags/55969/2 "2017-01-18T15:39:05Z")

</div>

It’ll take me a while until I’ve written a melody for the “wish concert”, but the chorus goes something like “great, can you make it do a whole lot more?”.

On a more serious note…

What we wanted was to autopropagate the nationality based on the ip the user registered from (chances are that is where the user is actually from). Allowing the users to override that, would be a second wish.

---

<div class="post-metadata">

### Author: ![Ebs](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ebs/32/119612_2.png) [@Ebs](https://meta.discourse.org/u/Ebs)
#### Post date: [January 18, 2017, 4:46pm UTC](https://meta.discourse.org/t/national-flags/55969/3 "2017-01-18T16:46:37Z")

</div>

a similar thing was discussed in the other thread. So, basically an IP Lookup when the user registers. the ‘nationalflag\_iso’ would then be autofilled?

For me, personally, my forum is based around expats. So the country where the user lives is rarely the country they’re originally from.

I’d like to make the plugin more effecient first, but I’ll certainly keep this request in mind.

---

<div class="post-metadata">

### Author: ![JagWaugh](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jagwaugh/32/69335_2.png) [@JagWaugh](https://meta.discourse.org/u/JagWaugh)
#### Post date: [January 18, 2017, 5:05pm UTC](https://meta.discourse.org/t/national-flags/55969/4 "2017-01-18T17:05:45Z")

</div>

Yes, that was what we were looking for.

What we wanted was a reliable location/timezone indication (our forum is worldwide, so the ability to see if someone is in your timezone, near a car you wanted someone to go and have a look at was what we were initially looking for).

Users being what they are, they’ll want to be adding all kinds of alternative truth hoods to their profiles - “I live in Arizona, but I was born in Scotland.” kind of thing. Sweet, in a meatbag kind of a way, but not all that reliable (in a meatbag kind of a way).

With our forum, I wouldn’t want to show any information which would indicate that a user was away from home. By that I mean a difference between the “registered” flag, and the “last login” could be construed as an invitation to come and steal my classic car, if I had been so silly as to give enough information to allow someone to figure out where I lived.

> [@Ebs](#):
>
> a similar thing was discussed in the other thread. So, basically an IP Lookup when the user registers. the ‘nationalflag\_iso’ would then be autofilled?

---

<div class="post-metadata">

### Author: ![Vikas\_Dangi](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vikas_dangi/32/131628_2.png) [@Vikas\_Dangi](https://meta.discourse.org/u/Vikas_Dangi)
#### Post date: [February 10, 2017, 12:05pm UTC](https://meta.discourse.org/t/national-flags/55969/5 "2017-02-10T12:05:17Z")

</div>

That’s what I am looking for. But why you uses countries prefix instead of using full country names. Short country names may confuse users.

---

<div class="post-metadata">

### Author: ![Ebs](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ebs/32/119612_2.png) [@Ebs](https://meta.discourse.org/u/Ebs)
#### Post date: [February 10, 2017, 12:31pm UTC](https://meta.discourse.org/t/national-flags/55969/6 "2017-02-10T12:31:30Z")

</div>

Hi, thanks for the reply!

I chose to use the ISO Country Codes for a few reasons, the main one being laziness! 😉 the original files were already named with their country code. I realise it could potentially cause problems for users, but a quick [Google search](https://www.iso.org/obp/ui/#search) will get you your answer. (and using the codes ~~avoids~~ solves the translation issue ;))

I do hope to make some changes to the plugin in the near future and I’ll definitely look into displaying the countries in a more user-friendly manner.

---

<div class="post-metadata">

### Author: ![JagWaugh](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jagwaugh/32/69335_2.png) [@JagWaugh](https://meta.discourse.org/u/JagWaugh)
#### Post date: [February 24, 2017, 10:40am UTC](https://meta.discourse.org/t/national-flags/55969/7 "2017-02-24T10:40:56Z")

</div>

Since adding the plugin we seem to be getting a lot of warning messages in /logs, including:

TypeError: e.attrs.userCustomFields is null  
Unable to get property ‘nationalflag\_iso’ of undefined or null reference  
TypeError: null is not an object (evaluating ‘e.attrs.userCustomFields.nationalflag\_iso’)  
Uncaught TypeError: Cannot read property ‘nationalflag\_iso’ of null

Is anyone else seeing this?

If the cause of these log events is merely that a user hasn’t chosen a flag, then shouldn’t they just be Info messages, rather than Warnings?

---

<div class="post-metadata">

### Author: ![Ebs](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ebs/32/119612_2.png) [@Ebs](https://meta.discourse.org/u/Ebs)
#### Post date: [February 24, 2017, 10:54am UTC](https://meta.discourse.org/t/national-flags/55969/8 "2017-02-24T10:54:45Z")

</div>

thanks for the feedback!  
Yes, it looks like I’m not setting the default value for the custom field. This means all users who don’t have a national flag, don’t have a default value and its returning null.

I’ll have a look at it when I get a chance. It’s an unsightly warning message, but nevertheless just a warning message. 🙂

---

<div class="post-metadata">

### Author: ![Ebs](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ebs/32/119612_2.png) [@Ebs](https://meta.discourse.org/u/Ebs)
#### Post date: [February 26, 2017, 8:30pm UTC](https://meta.discourse.org/t/national-flags/55969/9 "2017-02-26T20:30:55Z")

</div>

This is fixed now. Just pushed the update to Github.  
(I just added a conditional to the show-user-card connector, now you shouldn’t be getting any more warnings)

---

<div class="post-metadata">

### Author: ![ezworldwide](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ezworldwide/32/49134_2.png) [@ezworldwide](https://meta.discourse.org/u/ezworldwide)
#### Post date: [February 27, 2017, 12:51am UTC](https://meta.discourse.org/t/national-flags/55969/10 "2017-02-27T00:51:04Z")

</div>

I was waiting for this fix before putting on my site. I just loaded the plugin on my site and I’m getting the errors. I’m also getting this weird bug when a user posts the dialogue box disappears and the post only shows if you refresh the page.

---

<div class="post-metadata">

### Author: ![JagWaugh](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jagwaugh/32/69335_2.png) [@JagWaugh](https://meta.discourse.org/u/JagWaugh)
#### Post date: [February 27, 2017, 4:16am UTC](https://meta.discourse.org/t/national-flags/55969/11 "2017-02-27T04:16:43Z")

</div>

We saw something [similar](https://meta.discourse.org/t/occasional-page-loads-with-no-post-content-due-to-plugins/57793/6) to your refresh issue after going to v1.8.0.beta5, it went away on it’s own.

---

<div class="post-metadata">

### Author: ![ezworldwide](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ezworldwide/32/49134_2.png) [@ezworldwide](https://meta.discourse.org/u/ezworldwide)
#### Post date: [February 27, 2017, 4:21am UTC](https://meta.discourse.org/t/national-flags/55969/12 "2017-02-27T04:21:31Z")

</div>

That’s good to know. It wasn’t happening consistently, just intermittently for a few users…but enough for them to start complaining about it. Have your warning messages gone away? As soon as I loaded the plugin, I started getting them.

---

<div class="post-metadata">

### Author: ![JagWaugh](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jagwaugh/32/69335_2.png) [@JagWaugh](https://meta.discourse.org/u/JagWaugh)
#### Post date: [February 27, 2017, 4:24am UTC](https://meta.discourse.org/t/national-flags/55969/13 "2017-02-27T04:24:00Z")

</div>

Can’t say yet, just updating my sandbox site now.

---

<div class="post-metadata">

### Author: ![JagWaugh](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jagwaugh/32/69335_2.png) [@JagWaugh](https://meta.discourse.org/u/JagWaugh)
#### Post date: [February 28, 2017, 10:35am UTC](https://meta.discourse.org/t/national-flags/55969/14 "2017-02-28T10:35:38Z")

</div>

The error messages stopped with the next update. (Thanks @Ebs )

---

<div class="post-metadata">

### Author: ![JagWaugh](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jagwaugh/32/69335_2.png) [@JagWaugh](https://meta.discourse.org/u/JagWaugh)
#### Post date: [February 28, 2017, 11:28am UTC](https://meta.discourse.org/t/national-flags/55969/15 "2017-02-28T11:28:07Z")

</div>

Ups, spoke too soon. I just updated the live site to latest, first user post after the update gives:

```
TypeError: null is not an object (evaluating 'e.attrs.userCustomFields.nationalflag_iso')

```

---

<div class="post-metadata">

### Author: ![Ebs](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ebs/32/119612_2.png) [@Ebs](https://meta.discourse.org/u/Ebs)
#### Post date: [February 28, 2017, 12:15pm UTC](https://meta.discourse.org/t/national-flags/55969/16 "2017-02-28T12:15:07Z")

</div>

Alright, that’s on the post decorator. Easy fix. I’ll do it tonight (and properly test it this time ;))

---

<div class="post-metadata">

### Author: ![ezworldwide](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ezworldwide/32/49134_2.png) [@ezworldwide](https://meta.discourse.org/u/ezworldwide)
#### Post date: [February 28, 2017, 4:07pm UTC](https://meta.discourse.org/t/national-flags/55969/17 "2017-02-28T16:07:03Z")

</div>

Thanks for your attention to this. In the few moments I had it up and running it was a big hit with my users. I run a political forum (don’t ever do that) and my users were quite excited to display the flags of the countries the post from, identify with, or just to pick flags based on countries that have policies that align with their political views. Great plugin and should be a part of core in my view (at least as an option).

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [February 28, 2017, 8:20pm UTC](https://meta.discourse.org/t/national-flags/55969/18 "2017-02-28T20:20:09Z")

</div>

> [@ezworldwide](#):
>
> I run a political forum (don’t ever do that)

😆 words to live by

---

<div class="post-metadata">

### Author: ![tophee](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tophee/32/73406_2.png) [@tophee](https://meta.discourse.org/u/tophee)
#### Post date: [March 2, 2017, 11:25am UTC](https://meta.discourse.org/t/national-flags/55969/19 "2017-03-02T11:25:10Z")

</div>

I just upgradet to the latest version (720206f) but I still don’t get the National Flag option in my user preferences. 😧 Might there be a conflict with another plugin? Or where should I start fixing this?

---

<div class="post-metadata">

### Author: ![JagWaugh](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jagwaugh/32/69335_2.png) [@JagWaugh](https://meta.discourse.org/u/JagWaugh)
#### Post date: [March 2, 2017, 11:46am UTC](https://meta.discourse.org/t/national-flags/55969/20 "2017-03-02T11:46:03Z")

</div>

Have you enabled it in /admin/site\_settings/category/plugins?filter=nationalflag?

 ![](https://global.discourse-cdn.com/meta/original/3X/b/6/b697d56cb07bc3a958721a260cea7c46accb03f1.png)

[Next page](https://meta.discourse.org/t/national-flags/55969.md?page=2)
