Skip to content

Commit 13b9c1f

Browse files
author
Benjamin Pick
committed
subdivisions
1 parent 4080bdb commit 13b9c1f

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

shortcode.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,9 @@ function geoip_detect2_shortcode($attr)
8787
try {
8888
if (count($properties) == 1) {
8989
$return = $userInfo->{$properties[0]};
90-
} else if (count($properties) == 2) {
91-
$return = $userInfo->{$properties[0]};
92-
if (!is_object($return))
93-
throw new \RuntimeException('Invalid property name.');
94-
$return = $return->{$properties[1]};
9590
} else if ($properties[0] == 'subdivisions' && (count($properties) == 2 || count($properties) == 3)) {
9691
$return = $userInfo->{$properties[0]};
97-
if (!is_object($return))
92+
if (!is_array($return))
9893
throw new \RuntimeException('Invalid property name.');
9994
if (!is_numeric($properties[1]))
10095
throw new \RuntimeException('Invalid property name (must be numeric, e.g. "subdivisions.0").');
@@ -105,6 +100,11 @@ function geoip_detect2_shortcode($attr)
105100
throw new \RuntimeException('Invalid property name.');
106101
$return = $return->{$properties[2]};
107102
}
103+
} else if (count($properties) == 2) {
104+
$return = $userInfo->{$properties[0]};
105+
if (!is_object($return))
106+
throw new \RuntimeException('Invalid property name.');
107+
$return = $return->{$properties[1]};
108108
} else {
109109
throw new \RuntimeException('Only 1 dot supported. Please send a bug report to show me the shortcode you used if you need it ...');
110110
}

tests/test-shortcode.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ function testShortcodeProperties() {
4040
}
4141
function testSubdivisionProperties() {
4242
$this->assertEquals('HE', do_shortcode('[geoip_detect2 property="subdivisions.0.isoCode"]'));
43-
$this->assertEquals('Hesse', do_shortcode('[geoip_detect2 property="subdivisions.0"]'));
43+
$this->assertEquals('Hesse', do_shortcode('[geoip_detect2 property="subdivisions.0"]'));
44+
$this->assertContains('<!--',do_shortcode('[geoip_detect2 property="subdivisions.1"]'));
45+
$this->assertContains('<!--',do_shortcode('[geoip_detect2 property="subdivisions.wrong"]'));
4446
}
4547
function testNonStringProperties() {
4648
$this->assertEquals('2929134', do_shortcode('[geoip_detect2 property="city.geonameId"]'));

0 commit comments

Comments
 (0)