-
Notifications
You must be signed in to change notification settings - Fork 0
/
esri-search.php
58 lines (52 loc) · 1.73 KB
/
esri-search.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
/**
* Plugin Name: Esri
* Plugin URI: http://zayo.com
* Description: This is a custom plugin that adds Esri Geocoder functionality.
* Author: Matt Sobieray
* Author URI: http://hyfyn.com
* Version: 0.1.0
*/
/* Place custom code below this line. */
// Locater Shortcode
function services_locater($atts) {
ob_start();
?>
<div id="find-services" class="clearfix">
<h3>Explore Zayo’s Fiber Network</h3>
<div id="search"></div>
</div>
<?php
return ob_get_clean();
}
add_shortcode('locater', 'services_locater');
function check_for_shortcode($posts) {
if ( empty($posts) )
return $posts;
// false because we have to search through the posts first
$found = false;
// search through each post
foreach ($posts as $post) {
// check the post content for the short code
if ( stripos($post->post_content, '[locater]') )
// we have found a post with the short code
$found = true;
// stop the search
break;
}
if ($found){
$url = plugin_dir_url( __FILE__ );
wp_enqueue_style('calro', 'https://js.arcgis.com/3.13/dijit/themes/claro/claro.css', array(), null, false );
wp_enqueue_style('esri-css', 'https://js.arcgis.com/3.13/esri/css/esri.css', array(), null, false );
wp_register_script( 'arcgis', 'https://js.arcgis.com/3.14/init.js', array('jquery'), null, false );
wp_register_script( 'esri-js', $url . 'esri/esri.js', array('jquery'), null, false );
}
return $posts;
}
// perform the check when the_posts() function is called
add_action('the_posts', 'check_for_shortcode');
add_action('wp_footer', function() {
wp_enqueue_script('arcgis');
wp_enqueue_script('esri-js');
});
?>