Skip to content

Commit 20f249d

Browse files
committed
v2.0.2 - Dynamic Plugin Directory Fix
The plugin now works correctly no matter what the directory it is located inside is named.
1 parent 4fb11a1 commit 20f249d

File tree

6 files changed

+51
-73
lines changed

6 files changed

+51
-73
lines changed

inreach-mapshare.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Plugin Name: inReach MapShare
55
Plugin URI: https://github.com/morehawes/inreach-mapshare
66
Description: Display inReach MapShare data on your WordPress site. Visit the <a href="options-general.php?page=inreach-mapshare-settings">Settings</a> page to create and customise Shortcodes.
7-
Version: 2.0.1
7+
Version: 2.0.2
88
Text Domain: inreach-mapshare
99
Author: Joe Hawes
1010
Author URI: https://www.morehawes.ca/
@@ -28,15 +28,15 @@
2828
$plugin_name = 'inReach MapShare';
2929

3030
//Icon URLs
31-
$message_icon = InMap_Helper::asset_url('img/message.svg', $plugin_slug);
32-
$tracking_icon = InMap_Helper::asset_url('img/location-gps.svg', $plugin_slug);
31+
$message_icon = InMap_Helper::asset_url('img/message.svg');
32+
$tracking_icon = InMap_Helper::asset_url('img/location-gps.svg');
3333

3434
$config = [
3535
'plugin_slug' => $plugin_slug,
3636
'plugin_text_domain' => $plugin_slug,
3737
'plugin_name' => $plugin_name,
3838
'plugin_name_short' => $plugin_name,
39-
'plugin_version' => '2.0.1',
39+
'plugin_version' => '2.0.2',
4040
'settings_id' => 'inmap_settings',
4141
'settings_default_tab' => 'inmap-settings-tab-mapshare',
4242
'site_url' => 'https://github.com/morehawes/inreach-mapshare/',

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "inreach-mapshare",
33
"private": true,
4-
"version": "2.0.1",
4+
"version": "2.0.2",
55
"type": "module",
66
"scripts": {
77
"build": "vite build --watch"

readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ Please report issues or make suggestions by creating a <a href="https://github.c
6363
6464
## Installation
6565

66-
1. [Download the plugin (.zip)](https://github.com/OpenGIS/inreach-mapshare/archive/refs/tags/2.0.1.zip).
66+
1. [Download the plugin (.zip)](https://github.com/OpenGIS/inreach-mapshare/archive/refs/heads/master.zip).
6767
2. In your WordPress Admin, go to Plugins > Add New Plugin.
6868
3. Click the "Upload Plugin" button.
69-
4. Upload the `inreach-mapshare.zip` file.
69+
4. Upload the `inreach-mapshare.zip` file downloaded.
7070
5. Activate the plugin.
7171
6. Configure the plugin in WP Admin > Settings > inReach MapShare.
7272

src/php/Admin.php

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,26 @@ class InMap_Admin {
66

77
function __construct() {
88
//Admin only
9-
if (!is_admin()) {
9+
if (! is_admin()) {
1010
return;
1111
}
1212

13-
add_action('admin_init', array($this, 'load_assets'));
14-
add_action('current_screen', array($this, 'get_current_screen'));
15-
add_action('admin_head', array($this, 'admin_head'));
13+
add_action('admin_init', [$this, 'load_assets']);
14+
add_action('current_screen', [$this, 'get_current_screen']);
15+
add_action('admin_head', [$this, 'admin_head']);
1616

1717
new InMap_Shortcode;
1818
new InMap_Settings;
1919

20-
//Actions
21-
add_action('admin_init', array($this, 'load_assets'));
22-
add_filter('plugin_action_links_' . InMap_Helper::plugin_file_path(), array($this, 'add_action_links'));
20+
// add_filter('plugin_action_links_' . InMap_Helper::plugin_file_path(), array($this, 'add_action_links'));
2321
}
2422

2523
function add_action_links($links) {
26-
$links_before = array();
24+
$links_before = [];
2725

28-
$links_after = array(
26+
$links_after = [
2927
'<a href="' . admin_url('options-general.php?page=' . InMap_Helper::slug_prefix('settings', '-')) . '">' . esc_html__('Settings', InMap_Config::get_item('plugin_text_domain')) . '</a>',
30-
);
28+
];
3129

3230
return array_merge($links_before, $links, $links_after);
3331
}
@@ -37,12 +35,12 @@ function load_assets() {
3735

3836
//Enqueue
3937
InMap_Assets::css_enqueue([
40-
'url' => InMap_Helper::plugin_url('dist/inreach-mapshare.css'),
38+
'url' => InMap_Helper::asset_url('inreach-mapshare.css'),
4139
]);
4240

4341
InMap_Assets::js_enqueue([
4442
'id' => 'inmap_admin_js',
45-
'url' => InMap_Helper::plugin_url('dist/inreach-mapshare.js'),
43+
'url' => InMap_Helper::asset_url('inreach-mapshare.js'),
4644

4745
'deps' => [
4846
'jquery',

src/php/Helper.php

Lines changed: 27 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
class InMap_Helper {
44

55
static public function make_hash($data, $length = 6) {
6-
if (!is_string($data)) {
6+
if (! is_string($data)) {
77
$data = json_encode($data);
88
}
99

@@ -18,40 +18,20 @@ static public function site_url($url_path = '') {
1818
return InMap_Config::get_item('site_url') . $url_path;
1919
}
2020

21-
static public function http_url($data = array()) {
22-
return trim(add_query_arg(array_merge(array('inmap_http' => '1'), $data), home_url('/')), '/');
21+
static public function http_url($data = []) {
22+
return trim(add_query_arg(array_merge(['inmap_http' => '1'], $data), home_url('/')), '/');
2323
}
2424

25-
static public function plugin_url($file_path = '', $plugin_slug = '') {
26-
if (!$plugin_slug) {
27-
$plugin_slug = InMap_Config::get_item('plugin_slug');
28-
}
29-
30-
return plugin_dir_url('') . $plugin_slug . '/' . $file_path;
31-
}
32-
33-
static public function plugin_file_path($file_path = '', $plugin_slug = '') {
34-
if (!$file_path) {
35-
$file_path = InMap_Config::get_item('plugin_slug') . '.php';
36-
}
37-
38-
if (!$plugin_slug) {
39-
$plugin_slug = InMap_Config::get_item('plugin_slug');
40-
}
41-
42-
return $plugin_slug . '/' . $file_path;
25+
static public function plugin_url($file_path = '') {
26+
return dirname(plugin_dir_url(__DIR__)) . '/' . $file_path;
4327
}
4428

45-
static public function asset_url($file_path = '', $plugin_slug = '') {
46-
if (!$plugin_slug) {
47-
$plugin_slug = InMap_Config::get_item('plugin_slug');
48-
}
49-
50-
return plugin_dir_url('') . $plugin_slug . '/dist/' . $file_path;
29+
static public function asset_url($file_path = '') {
30+
return self::plugin_url('dist/' . $file_path);
5131
}
5232

5333
static public function plugin_name($short = false) {
54-
if (!$short) {
34+
if (! $short) {
5535
return InMap_Config::get_item('plugin_name');
5636
} else {
5737
return InMap_Config::get_item('plugin_name_short');
@@ -79,14 +59,14 @@ static public function plugin_about() {
7959

8060
//WP.org Directory Link
8161
if (InMap_Config::get_item('directory_url') && $directory_url = parse_url(InMap_Config::get_item('directory_url'))) {
82-
if (isset($directory_url['host']) && !empty($directory_url['host'])) {
62+
if (isset($directory_url['host']) && ! empty($directory_url['host'])) {
8363
$out .= ' <li><a href="' . InMap_Config::get_item('directory_url') . '">' . $directory_url['host'] . '</a></li>' . "\n";
8464
}
8565
}
8666

8767
//GitHub Repo Link
8868
if ($github_url = parse_url(InMap_Config::get_item('github_url'))) {
89-
if (isset($github_url['host']) && !empty($github_url['host'])) {
69+
if (isset($github_url['host']) && ! empty($github_url['host'])) {
9070
$out .= ' <li><a href="' . InMap_Config::get_item('github_url') . '">' . $github_url['host'] . '</a></li>' . "\n";
9171
}
9272
}
@@ -110,17 +90,17 @@ static public function do_debug() {
11090
}
11191

11292
static public function debug($thing, $die = false) {
113-
if (!self::do_debug()) {
93+
if (! self::do_debug()) {
11494
return;
11595
}
11696

117-
if (!$die) {
97+
if (! $die) {
11898
echo '<textarea onclick="jQuery(this).hide()" style="background:rgba(255,255,255,.8);position:absolute;top:30px;right:0;width:400px;height:400px;padding:15px;z-index:+10000000"><pre>';
11999
}
120100

121101
print_r($thing);
122102

123-
if (!$die) {
103+
if (! $die) {
124104
echo '</pre></textarea>';
125105
} else {
126106
die;
@@ -135,7 +115,7 @@ static public function make_key($str, $prefix = '', $use_underscores = true) {
135115
}
136116

137117
//Like in JS
138-
if (!$use_underscores) {
118+
if (! $use_underscores) {
139119
$str = str_replace('_', '', $str);
140120
}
141121

@@ -151,15 +131,15 @@ static public function anchor_urls(string $text) {
151131
}
152132

153133
public static function convert_values_to_single_value($array_in) {
154-
$array_out = array();
134+
$array_out = [];
155135

156-
if (!is_array($array_in)) {
136+
if (! is_array($array_in)) {
157137
return $array_out;
158138
}
159139

160140
foreach ($array_in as $key => $value) {
161141
//Single value
162-
if (!is_array($value)) {
142+
if (! is_array($value)) {
163143
//Use that
164144
$array_out[$key] = $value;
165145
//Multiple values
@@ -175,7 +155,7 @@ public static function convert_values_to_single_value($array_in) {
175155
public static function convert_single_value_to_array($value_in) {
176156
//Array
177157
if (is_array($value_in)) {
178-
$array_out = array();
158+
$array_out = [];
179159

180160
foreach ($value_in as $key => $value) {
181161
$multi = explode(InMap_Config::get_item('multi_value_seperator'), $value);
@@ -212,23 +192,23 @@ public static function css_prefix($text = '') {
212192
public static function slug_prefix($text = '', $sep = '_', $hyphen = true) {
213193
$out = InMap_Config::get_item('plugin_slug') . $sep . $text;
214194

215-
if (!$hyphen) {
195+
if (! $hyphen) {
216196
$out = str_replace('-', '_', $out);
217197
}
218198

219199
return $out;
220200
}
221201

222202
public static function array_string_to_array($string) {
223-
$string = str_replace(array('[', ']', '"', '"'), array('', '', '', ''), $string);
203+
$string = str_replace(['[', ']', '"', '"'], ['', '', '', ''], $string);
224204

225205
return self::comma_string_to_array($string);
226206
}
227207

228208
public static function comma_string_to_array($string) {
229209
//Process options
230210
$options_exploded = explode(',', $string);
231-
$options_array = array();
211+
$options_array = [];
232212
foreach ($options_exploded as $option) {
233213
$value = trim($option);
234214
$key = self::make_key($value);
@@ -240,7 +220,7 @@ public static function comma_string_to_array($string) {
240220
}
241221

242222
public static function multi_use_as_key($array_in, $as_key = false) {
243-
$array_out = array();
223+
$array_out = [];
244224

245225
$count = 0;
246226
foreach ($array_in as $data) {
@@ -259,7 +239,7 @@ public static function multi_use_as_key($array_in, $as_key = false) {
259239
}
260240

261241
static public function flatten_meta($data_in) {
262-
$data_out = array();
242+
$data_out = [];
263243

264244
if (is_array($data_in)) {
265245
foreach ($data_in as $data_key => $data_value) {
@@ -271,10 +251,10 @@ static public function flatten_meta($data_in) {
271251
}
272252

273253
static public function repeatable_setting_option_array($tab, $section, $key) {
274-
$options_array = array();
254+
$options_array = [];
275255
$values = InMap_Config::get_item($tab, $section, true);
276256

277-
if (!is_array($values)) {
257+
if (! is_array($values)) {
278258
return null;
279259
}
280260

@@ -290,7 +270,7 @@ static public function repeatable_setting_option_array($tab, $section, $key) {
290270
}
291271

292272
public static function assoc_array_table($assoc_array) {
293-
if (!is_array($assoc_array) || !sizeof($assoc_array)) {
273+
if (! is_array($assoc_array) || ! sizeof($assoc_array)) {
294274
return false;
295275
}
296276

@@ -329,7 +309,7 @@ static function time_ago($time = '0', $comparison = false) {
329309
__('Years', InMap_Config::get_item('plugin_text_domain')),
330310
];
331311

332-
$lengths = array("60", "60", "24", "7", "4.35", "12", "365");
312+
$lengths = ["60", "60", "24", "7", "4.35", "12", "365"];
333313

334314
$now = time();
335315
if ($comparison && ($now >= $comparison)) {

src/php/Shortcode.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function __construct() {
1212

1313
function load_assets() {
1414
//InMap CSS
15-
InMap_Assets::css_enqueue(InMap_Helper::plugin_url('dist/inreach-mapshare.css'));
15+
InMap_Assets::css_enqueue(InMap_Helper::asset_url('inreach-mapshare.css'));
1616

1717
//Message Icon
1818
if ($message_icon = InMap_Config::get_setting('appearance', 'icons', 'message_icon')) {
@@ -75,7 +75,7 @@ function load_assets() {
7575
jQuery("head")
7676
.append(
7777
jQuery("<link />").attr({
78-
"href" : "' . InMap_Helper::plugin_url('dist/css/leaflet.css') . '",
78+
"href" : "' . InMap_Helper::asset_url('css/leaflet.css') . '",
7979
8080
"rel" : "stylesheet",
8181
"id" : "inmap_leaflet_css",
@@ -86,7 +86,7 @@ function load_assets() {
8686
.append(
8787
jQuery("<script />").attr({
8888
"id" : "inmap_leaflet_js",
89-
"src" : "' . InMap_Helper::plugin_url('dist/js/leaflet.js') . '",
89+
"src" : "' . InMap_Helper::asset_url('js/leaflet.js') . '",
9090
"type" : "text/javascript"
9191
})
9292
)
@@ -99,7 +99,7 @@ function load_assets() {
9999
//InMap JS
100100
InMap_Assets::js_enqueue([
101101
'id' => 'inmap_shortcode_js',
102-
'url' => InMap_Helper::plugin_url('dist/inreach-mapshare.js'),
102+
'url' => InMap_Helper::asset_url('inreach-mapshare.js'),
103103
'deps' => ['jquery'],
104104
'data' => [
105105
'basemap_url' => InMap_Config::get_setting('appearance', 'map', 'basemap_url'),
@@ -116,13 +116,13 @@ public function handle_shortcode($shortcode_data, $content = null) {
116116
$out = "\n" . '<!-- START ' . InMap_Config::get_name() . ' Shortcode -->' . "\n";
117117
$out .= '<div class="inmap-wrap">';
118118

119-
$shortcode_data = shortcode_atts(array(
119+
$shortcode_data = shortcode_atts([
120120
'mapshare_identifier' => 'demo',
121121
'mapshare_password' => false,
122122
'mapshare_date_start' => false,
123123
'mapshare_date_end' => false,
124124
'mapshare_route_url' => false,
125-
), $shortcode_data, InMap_Config::get_item('plugin_shortcode'));
125+
], $shortcode_data, InMap_Config::get_item('plugin_shortcode'));
126126

127127
if ($shortcode_data['mapshare_identifier']) {
128128

@@ -148,7 +148,7 @@ public function handle_shortcode($shortcode_data, $content = null) {
148148

149149
$geojson = $Inreach_Mapshare->get_geojson();
150150

151-
if (is_string($geojson) && !empty($geojson)) {
151+
if (is_string($geojson) && ! empty($geojson)) {
152152
$point_count = $Inreach_Mapshare->point_count;
153153
$point_text = ($point_count == 1) ? __('Point', InMap_Config::get_item('plugin_text_domain')) : __('Points', InMap_Config::get_item('plugin_text_domain'));
154154

0 commit comments

Comments
 (0)