-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
326 lines (312 loc) · 11.6 KB
/
functions.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
<?php
/**
* Bootstrap the Theme Options Framework
* and initialize options
*/
require get_template_directory() . '/lib/theme-options-setup.php';
require get_template_directory() . '/lib/conure-theme-setup.php';
require get_template_directory() . '/lib/conure-theme-addons.php';
require get_template_directory() . '/lib/theme-helper-functions.php';
/**
* Set up Theme Options and Support
*/
add_action( 'after_setup_theme', 'conure_setup' );
function conure_setup()
{
#Not currently using language support
#load_theme_textdomain( 'conure', get_template_directory() . '/languages' );
/**
* Register global options from theme options "up_options"
*/
add_action( 'init', 'register_global_up_options_variable' );
add_action( 'wp_enqueue_scripts', 'conure_load_scripts' );
add_action( 'widgets_init', 'conure_widgets_init' );
add_action( 'login_enqueue_scripts', 'custom_login_logo' );
add_filter( 'login_headerurl', 'my_login_logo_url' );
add_action( 'wp_before_admin_bar_render', 'remove_wp_logo' );
#add_action( 'admin_init', 'my_remove_menu_pages' );
add_theme_support( 'automatic-feed-links' );
add_theme_support( 'post-thumbnails' );
register_nav_menus( array(
'main-menu' => __( 'Main Menu', 'conure' )
)
);
add_filter( 'wp_title', 'conure_filter_wp_title' );
add_filter( 'the_title', 'conure_title' );
}
function google_map( $atts, $content = null ) {
extract(
shortcode_atts(
array(
'address' => false,
'width' => '100%',
'height' => '400px',
),
$atts)
);
global $up_options;
$address = $up_options->office_location;
if( $address ) :
wp_print_scripts( 'google-maps-api' );
$coordinates = google_map_get_coordinates( $address );
// var_dump($coordinates);
if( !is_array( $coordinates ) )
return;
$map_id = uniqid( 'google_map_' );
ob_start(); ?>
<div class="google_map_canvas" id="<?php echo esc_attr( $map_id ); ?>" style="height: <?php echo esc_attr( $atts['height'] ); ?>; width: <?php echo esc_attr( $atts['width'] ); ?>"></div>
<script type="text/javascript">
var map_<?php echo $map_id; ?>;
function ale_run_map_<?php echo $map_id ; ?>(){
// var location = new google.maps.LatLng("30.25459", "-81.58827");
var location = new google.maps.LatLng("<?php echo $coordinates['lat']; ?>", "<?php echo $coordinates['lng']; ?>");
var map_options = {
zoom: 15,
center: location,
scrollwheel: false,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map_<?php echo $map_id ; ?> = new google.maps.Map(document.getElementById("<?php echo $map_id ; ?>"), map_options);
var marker = new google.maps.Marker({
position: location,
map: map_<?php echo $map_id ; ?>
});
}
ale_run_map_<?php echo $map_id ; ?>();
</script>
<?php
endif;
return ob_get_clean();
}
add_shortcode('google_map', 'google_map');
//Loads Google Map API
function google_map_load_scripts(){
wp_register_script( 'google-maps-api', 'http://maps.google.com/maps/api/js?sensor=false' );
}
add_action( 'wp_enqueue_scripts', 'google_map_load_scripts' );
//Retrieve coordinates for an address
function google_map_get_coordinates( $address, $force_refresh = false ) {
$address_hash = md5( $address );
$coordinates = get_transient( $address_hash );
if ($force_refresh || $coordinates === false) {
$args = array( 'address' => urlencode( $address ), 'sensor' => 'false', 'key' => 'AIzaSyA4-ZxE3QqrSWpnwsjSke4Bs5DDN1LeFB0' );
$url = add_query_arg( $args, 'https://maps.googleapis.com/maps/api/geocode/json' );
// var_dump($url);
$response = wp_remote_get( $url );
if( is_wp_error( $response ) )
return;
$data = wp_remote_retrieve_body( $response );
if( is_wp_error( $data ) )
return;
if ( $response['response']['code'] == 200 ) {
// var_dump($data);
$data = json_decode( $data );
if ( $data->status === 'OK' ) {
$coordinates = $data->results[0]->geometry->location;
$cache_value['lat'] = $coordinates->lat;
$cache_value['lng'] = $coordinates->lng;
$cache_value['address'] = (string) $data->results[0]->formatted_address;
// // cache coordinates for 3 months
// set_transient($address_hash, $cache_value, 3600*24*30*3);
// $data = $cache_value;
// var_dump($data->status);
} elseif ( $data->status === 'ZERO_RESULTS' ) {
return __( 'No location for the address.', 'aletheme' );
} elseif( $data->status === 'INVALID_REQUEST' ) {
return __( 'Bad request. Did you enter an address name?', 'aletheme' );
} else {
return ($data->status);
// return __( 'Error, please check if you have entered the shortcode correctly.', 'aletheme' );
}
} else {
return __( 'Can\'t connect Google API.', 'aletheme' );
}
} else {
// return cached results
$data = $coordinates;
}
// return (array) $data;
$coords = array();
// var_dump($data);
// print("<pre>".print_r($data,true)."</pre>");
// var_dump($data->results[0]->geometry->location->lat);
$coords['lat'] = $data->results[0]->geometry->location->lat;
$coords['lng'] = $data->results[0]->geometry->location->lng;
// var_dump($data->results[0]->geometry->location->lng);
return $coords;
}
//Fix bug with responsive
function google_map_css() {
echo '<style type="text/css">
.google_map_canvas img {
max-width: none;
}</style>';
}
add_action( 'wp_head', 'google_map_css' );
add_filter( 'wp_title', 'blankslate_filter_wp_title' );
function blankslate_filter_wp_title( $title ){
return $title . esc_attr( get_bloginfo( 'name' ) );
}
//Custom Widgets
class QuoteWidget extends WP_Widget {
function QuoteWidget() {
// Instantiate the parent object
parent::__construct( false, 'Online Quote Button' );
}
function widget( $args, $instance ) {
?>
<div class="widget-container quote">
<a href="/online-quote">
<h3 class="widget-title">Online Quote</h3>
<div class="textwidget">
<p>> > > GET YOURS HERE</p>
</div>
</a>
</div>
<?php
}
}
class ShopNowWidget extends WP_Widget {
function ShopNowWidget() {
// Instantiate the parent object
parent::__construct( false, 'Shop Now Widget' );
}
function widget( $args, $instance ) {
?>
<div class="widget-container shop-now">
<div class="textwidget">
<div><img src="/wp-content/themes/paintBoothMan/assets/images/filters.jpg"></div>
<div><p>Our Exhaust Filters meet or exceed 98% efficiency as required by EPA!</p></div>
<div><a href="/filters"><button>Shop Filters Now</button></a></div>
</div>
</div>
<?php
}
}
class ProductMenuWidget extends WP_Widget {
function ProductMenuWidget() {
// Instantiate the parent object
parent::__construct( false, 'Product Menu Widget' );
}
function widget( $args, $instance ) {
?>
<div class="widget-container product-menu">
<ul class="menu">
<li id="filters"><a>Filters</a></li>
<li id="paint-booths"><a>Paint Booths</a></li>
<li id="amu"><a>Air Make Up Units</a></li>
<li id="curtain-walls"><a>Curtain Walls</a></li>
<li id="accessories"><a>Accessories</a></li>
</ul>
</div>
<?php
}
}
function myplugin_register_widgets() {
register_widget( 'QuoteWidget' );
register_widget( 'ShopNowWidget' );
register_widget( 'ProductMenuWidget' );
}
add_action( 'widgets_init', 'myplugin_register_widgets' );
add_shortcode('productFilter', 'showFilter');
function showFilter($atts){
$text = '
<div class="search-wrapper">
<div class="wrap">
<ul>
<li class="search-label">
<span>SEARCH:</span>
</li>
<li class="filter-by-wrapper">
<select class="filter-by">
<option value="default" selected="selected">Filter By:</option>
<option value="type">By Type</option>
<option value="manufacturer">By Manufacturer</option>
</select>
</li>
<li class="category">
<select class="type" disabled>
<option value="please-select">Select Type</option>
<optgroup label="Ceiling Filters">
<option value="afr-1-premium">AFR-1 Premium</option>
<option value="ff-560-gx">FF-560 GX</option>
<option value="intake-rolls">Intake Rolls</option>
<option value="tacky-intake-panels">Tacky Intake Panels</option>
</optgroup>
<option value="crossdraft-intake-filters">Crossdraft Intake Filters</option>
<optgroup label="Exhaust Filters">
<option value="exhaust-bags">Bags</option>
<option value="exhaust-cubes">Cubes</option>
<option value="carbon-panels">Carbon Panels</option>
<option value="exhaust-metal">Metal</option>
<option value="exhaust-metal-pleated">Metal Pleated</option>
<option value="exhaust-pads">Pads</option>
<option value="panels">Panels</option>
<option value="pleated">Pleated</option>
<optgroup label=" Rolls">
<option value="andreae-rolls"> Andreae Rolls</option>
<option value="fiberglass-rolls"> Fiberglass Rolls</option>
<option value="paper-rolls"> Paper Rolls</option>
<option value="paint-pocket-rolls"> Paint Pocket Rolls</option>
<option value="polyester-rolls"> Polyester Rolls</option>
</optgroup>
</optgroup>
<optgroup label="Prefilters / Pocket Filters">
<option value="prefilter-bags">Bags</option>
<option value="prefilter-cubes">Cubes</option>
<option value="prefilter-metal">Metal</option>
<option value="prefilter-metal-pleated">Metal Pleated</option>
<option value="prefilter-pads">Pads</option>
<option value="panels-links">Panels & Links</option>
<option value="pleated">Pleated</option>
<option value="prefilter-rolls">Rolls</option>
</optgroup>
</select>
<div class="man-wrapper">
<select class="manufacturer" style="display:none" disabled>
<option value="">Select Manufacturer</option>
</select>
</div>
</li>
<li class="size-wrapper">
<select class="sizes" "style=display:none" disabled>
<option value="please-select">Select Size</option>
</select>
</li>
<!--<li class="keyword-search-wrapper">
<input class="search-keyword" placeholder="Keyword" disabled>
</li>-->
<li class="loader"><div><img src="/wp-content/themes/paintBoothMan/assets/images/loading.gif"></div></li>
</ul>
</div>
</div>';
return $text;
}
add_filter( 'woocommerce_add_to_cart_fragments', 'woocommerce_header_add_to_cart_fragment' );
function woocommerce_header_add_to_cart_fragment( $fragments ) {
ob_start();
?>
<a class="cart-contents" href="<?php echo WC()->cart->get_cart_url(); ?>" title="<?php _e( 'View your shopping cart' ); ?>">
<?php echo sprintf (_n( '(%d) Item', '(%d) Items' , WC()->cart->cart_contents_count ), WC()->cart->cart_contents_count ); ?> In Your Shopping Cart<?php #echo WC()->cart->get_cart_total(); ?>
<!-- <img src="/wp-content/themes/paintBoothMan/assets/images/cart.png"> -->
<i class="icon-shopping-cart"></i>
</a>
<?php
$fragments['a.cart-contents'] = ob_get_clean();
return $fragments;
}
//woocommerce edits
// remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10);
// remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10);
// add_action('woocommerce_before_main_content', 'my_theme_wrapper_start', 10);
// function my_theme_wrapper_start() {
// echo '<section id="main">';
// }
// add_action('woocommerce_after_main_content', 'my_theme_wrapper_end', 10);
// function my_theme_wrapper_end() {
// echo '</section>';
// }
// add_action( 'after_setup_theme', 'woocommerce_support' );
// function woocommerce_support() {
// add_theme_support( 'woocommerce' );
// }