Skip to content

Commit

Permalink
adds setting for running shortcode in excerpt; adds helper method for…
Browse files Browse the repository at this point in the history
… settings
  • Loading branch information
Benjamin DeLong committed Mar 26, 2020
1 parent 443a9d4 commit 0e33a94
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
33 changes: 20 additions & 13 deletions class.leaflet-map.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,12 @@ private function init_hooks()

add_action( 'wp_enqueue_scripts', array('Leaflet_Map', 'enqueue_and_register') );

/*
allows maps on excerpts
todo? should be optional somehow (admin setting?)
*/
add_filter('the_excerpt', 'do_shortcode');
$settings = self::settings();

if ($settings->get('shortcode_in_excerpt')) {
// allows maps in excerpts
add_filter('the_excerpt', 'do_shortcode');
}
}

/**
Expand All @@ -147,10 +148,9 @@ private function add_shortcodes()
public static function uninstall()
{
// remove settings in db
// think it needs to be included again (because __construct
// won't need to execute)
include_once LEAFLET_MAP__PLUGIN_DIR . 'class.plugin-settings.php';
$settings = Leaflet_Map_Plugin_Settings::init();
// it needs to be included again because __construct
// won't need to execute
$settings = self::settings();
$settings->reset();

// remove geocoder locations in db
Expand All @@ -172,9 +172,7 @@ public static function load_text_domain()
public static function enqueue_and_register()
{
/* defaults from db */
// Leaflet_Map_Plugin_Settings
include_once LEAFLET_MAP__PLUGIN_DIR . 'class.plugin-settings.php';
$settings = Leaflet_Map_Plugin_Settings::init();
$settings = self::settings();

$js_url = $settings->get('js_url');
$css_url = $settings->get('css_url');
Expand Down Expand Up @@ -240,7 +238,7 @@ function remove_null ($var) {
public function json_sanitize($arr, $args)
{
// remove nulls
$arr = self::filter_null($arr);
$arr = $this->filter_null($arr);

// sanitize output
$args = array_intersect_key($args, $arr);
Expand Down Expand Up @@ -336,4 +334,13 @@ public function add_popup_to_shape($atts, $content, $shape)
echo ";";
}
}

/**
* Get settings from Leaflet_Map_Plugin_Settings
* @return Leaflet_Map_Plugin_Settings
*/
public static function settings () {
include_once LEAFLET_MAP__PLUGIN_DIR . 'class.plugin-settings.php';
return Leaflet_Map_Plugin_Settings::init();
}
}
5 changes: 5 additions & 0 deletions class.plugin-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,11 @@ private function __construct()
'type' => 'text',
'helptext' => __('ToGeoJSON converts KML and GPX files to GeoJSON; if you plan to use [leaflet-kml] or [leaflet-gpx] then this library is loaded. You can change the default if you need.', 'leaflet-map')
),
'shortcode_in_excerpt' => array(
'display_name' => __('Show maps in excerpts', 'leaflet-map'),
'default' => '0',
'type' => 'checkbox',
),
);

foreach ($this->options as $name => $details) {
Expand Down

0 comments on commit 0e33a94

Please sign in to comment.