-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfunctions.php
More file actions
472 lines (408 loc) · 15.7 KB
/
functions.php
File metadata and controls
472 lines (408 loc) · 15.7 KB
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
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
<?php
define( 'TANVAS_DOMAIN', 'tanvas');
if(!defined('TANVAS_DEBUG') ){
define( 'TANVAS_DEBUG', 'true');
}
function woo_metaboxes_add($metaboxes){
// if(TANVAS_DEBUG) error_log("TANVAS woo_custom_template:".serialize(get_option('woo_custom_template')));
if(TANVAS_DEBUG) error_log("TANVAS METABOXES:".serialize($metaboxes));
$metaboxes = apply_filters('tanvas_metaboxes', $metaboxes);
return $metaboxes;
}
function woo_options_add($options){
$options[] = array( "name" => __( 'Tanvas Settings'),
"icon" => "styling",
"type" => "heading");
$options[] = array( "name" => __( 'Brand Styling'),
"type" => "subheading");
$options[] = array( "name" => __( 'Brand Color' ),
"desc" => __( 'Pick a custom color for site branding or add a hex color code e.g. #e6e6e6' ),
"id" => "tanvas_style_brand_color",
"std" => "",
"type" => "color");
$options[] = array( "name" => __( 'Brand Color 2' ),
"desc" => __( 'Pick a second color for site branding or add a hex color code e.g. #e6e6e6' ),
"id" => "tanvas_style_brand_color2",
"std" => "",
"type" => "color");
$options[] = array( "name" => __( 'Brand Hover Color' ),
"desc" => __( 'Pick a custom color for site branding or add a hex color code e.g. #e6e6e6' ),
"id" => "tanvas_style_brand_hover_color",
"std" => "",
"type" => "color");
$options[] = array( "name" => __( 'Brouhore Background' ),
"desc" => __( 'Pick a custom color for site branding or add a hex color code e.g. #e6e6e6' ),
"id" => "tanvas_style_brochure_color",
"std" => "",
"type" => "color");
$options[] = array( "name" => __( 'Email Signature' ),
"desc" => __( 'Enter the signature used in emails as html.' ),
'id' => 'email_signature',
'type' => 'textarea');
$options[] = array( "name" => __( 'Footer Image' ),
"desc" => __( 'Specify the image which is used in the footer' ),
'id' => 'tanvas_footer_image',
'type' => 'upload',
"std" => "");
$options[] = array( "name" => __( 'Phone Number HTML' ),
"desc" => __( 'Specify the HTML used to display the phone number in the header (e.g. a href="tel://" link)' ),
'id' => 'tanvas_header_number',
'type' => 'textarea',
"std" => '<a href="tel://61894123000" class="phone"><i class="fa fa-phone"></i> (+61) 08 9412 3000</a>');
$options[] = array( "name" => __( 'Product Background Image' ),
"desc" => __( 'Specify the Image displayed behind the products' ),
'id' => 'tanvas_product_background_image',
'type' => 'upload',
"std" => '/wp-content/themes/tanvas/img/gold-background.jpg');
return $options;
}
/**
* Helper function to return the theme option value.
* If no value has been saved, it returns $default.
* Needed because options are saved as serialized strings.
*
* Not in a class to support backwards compatibility in themes.
*/
if ( ! function_exists( 'of_get_option' ) ) :
function of_get_option( $name, $default = false ) {
$option_name = '';
// Get option settings from database
$options = get_option( 'tanvas' );
// Return specific option
if ( isset( $options[$name] ) ) {
return $options[$name];
}
return $default;
}
endif;
include_once('widgets/doorway-button-widget.php');
include_once('widgets/custom-latest-posts-widget.php');
include_once('widgets/custom-social-media-widget.php');
include_once('widgets/woocommerce-my-account-widget.php');
include_once('includes/warnings.php');
include_once('includes/PNG_Reader.php');
// include_once('includes/flexSlider_Mods.php');
include_once('includes/extras.php');
include_once('includes/shortcodes.php');
include_once('includes/login-customization.php');
include_once('includes/store-customization.php');
// $woo_options = get_option( 'woo_options' );
// TODO: Allow discounts to be specified based on how many liters of solution
/* pretends to be canvas then quits if woocommerce not installed */
function theme_enqueue_styles(){
wp_enqueue_style('parent-style', get_template_directory_uri() . '/style.css' );
wp_enqueue_style('foundation', get_stylesheet_directory_uri() . '/css/foundation.css' );
wp_enqueue_style('design-style', get_stylesheet_directory_uri() . '/css/design-style.css');
wp_enqueue_style('recent-posts', get_stylesheet_directory_uri() . '/css/recent-posts-widget.css');
wp_enqueue_style('flexboxgrid', get_stylesheet_directory_uri() . '/css/flexboxgrid.css');
wp_enqueue_style('tanvas_extra', get_stylesheet_directory_uri() . '/css/extra.css');
wp_enqueue_style('tanvas_menus', get_stylesheet_directory_uri() . '/css/menus.css');
// wp_enqueue_style('this-style', get_stylesheet_uri() );
wp_enqueue_style( 'prefix-font-awesome', '//netdna.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css', array(), '4.4.0' );
wp_enqueue_style( 'font-awesome-5', 'https://use.fontawesome.com/releases/v5.0.6/css/all.css', array(), '5.0.6' );
global $is_IE;
if ( $is_IE ) {
wp_enqueue_style( 'prefix-font-awesome-ie', '//netdna.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome-ie7.min.css', array('prefix-font-awesome'), '4.4.0' );
// Add IE conditional tags for IE 7 and older
global $wp_styles;
$wp_styles->add_data( 'prefix-font-awesome-ie', 'conditional', 'lte IE 7' );
}
}
add_action('wp_enqueue_scripts', 'theme_enqueue_styles');
// /* enqueue font-awesome */
// function theme_enqueue_scripts(){
// wp_enqueue_script( 'font-awesome-5', 'https://use.fontawesome.com/releases/v5.0.6/js/all.js', array(), '5.0.6');
// }
// add_action('wp_enqueue_scripts', 'theme_enqueue_scripts');
function Tanvas_noticeWoocommerceNotInstalled() {
echo
'<div class="updated fade">' .
__('Error: Theme "Tanvas" requires WooCommerce to be installed', 'LaserCommerce') .
'</div>';
}
function Tanvas_WoocommerceCheck() {
if( !in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
add_action('admin_notices', 'Tanvas_noticeWoocommerceNotInstalled');
return false;
}
return true;
}
function Tanvas_noticeLasercommerceNotInstalled() {
echo
'<div class="updated fade">' .
__('Error: Theme "Tanvas" requires LaserCommerce to be installed', 'LaserCommerce') .
'</div>';
}
function Tanvas_LasercommerceCheck() {
if( !in_array( 'lasercommerce/lasercommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
add_action('admin_notices', 'Tanvas_noticeLasercommerceNotInstalled');
return false;
}
return true;
}
if(!Tanvas_WoocommerceCheck() or !Tanvas_WoocommerceCheck()) {
return;
}
/**
* Demo Store Notice Mods
*/
/* Loads script to move site notice to within wrapper */
add_action('wp_enqueue_scripts', function(){
wp_enqueue_script(
'reposition-site-message',
get_stylesheet_directory_uri().'/js/reposition-site-message.js',
array('jquery'),
0.1
);
wp_enqueue_script(
'foundation',
get_stylesheet_directory_uri().'/js/foundation.js',
array('jquery'),
0.1
);
wp_enqueue_script(
'foundation-offcanvas',
get_stylesheet_directory_uri().'/js/foundation.offcanvas.js',
array('jquery'),
0.1
);
}
);
/* Ensure slider js is loaded */
add_filter('woo_load_slider_js', function($load_slider_js){
// if(WP_DEBUG) error_log("woo_load_slider_js filter called wit h" . ($load_slider_js?"T":"F"));
if(is_page_template( 'template-home.php')){
$load_slider_js = true;
}
// if(WP_DEBUG) error_log("woo_load_slider_js returning ". ($load_slider_js?"T":"F"));
return $load_slider_js;
}, 999, 1);
function tanvas_widgets_init() {
register_sidebar( array(
'name' => 'Home Sliders',
'id' => 'tanvas_home_sliders',
'before_widget' => '<div class="slider-container">',
'after_widget' => '</div>',
'before_title' => '<h5 class="slider-title">',
'after_title' => '</h5>'
));
register_sidebar( array(
'name' => 'Home Products',
'id' => 'tanvas_home_products',
'before_widget' => '<div class="product-container">',
'after_widget' => '</div>',
'before_title' => '<h5 class="product-title">',
'after_title' => '</h5>'
));
register_sidebar( array(
'name' => 'Home Doorway Buttons',
'id' => 'tanvas_home_doorway',
'before_widget' => '<div class="doorway-container">',
'after_widget' => '</div>',
'before_title' => '<h5 class="doorway-title">',
'after_title' => '</h5>'
));
register_sidebar( array (
'name' => 'Home Doorway Sidebar',
'id' => 'tanvas_home_doorway_sidebar',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h2>',
'after_title' => '</h2>'
));
register_sidebar( array (
'name' => 'Home Below Doorway Left',
'id' => 'tanvas_home_left',
'before_widget' => '<div class="widget">',
'after_widget' => '</div>',
'before_title' => '<h2>',
'after_title' => '</h2>'
));
register_sidebar( array (
'name' => 'Home Below Doorway Right',
'id' => 'tanvas_home_right',
'before_widget' => '<div class="widget">',
'after_widget' => '</div>',
'before_title' => '<h2>',
'after_title' => '</h2>'
));
register_sidebar( array (
'name' => 'Home Doorway Bottom',
'id' => 'tanvas_home_doorway_bottom',
'before_widget' => '<div class="widget-doorway-bottom">',
'after_widget' => '</div>',
'before_title' => '<h2>',
'after_title' => '</h2>'
));
register_sidebar(array(
'name' => __( 'Footer Widgets One', TANVAS_DOMAIN ),
'id' => 'widget-one',
'before_widget' => '<div class="footer-wigget">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>'
));
register_sidebar(array(
'name' => __( 'Footer Widgets Two', TANVAS_DOMAIN ),
'id' => 'widget-two',
'before_widget' => '<div class="footer-wigget">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>'
));
register_sidebar(array(
'name' => __( 'Footer Widgets Three', TANVAS_DOMAIN ),
'id' => 'widget-three',
'before_widget' => '<div class="footer-wigget">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>'
));
register_sidebar(array(
'name' => __( 'Footer Widgets Four', TANVAS_DOMAIN ),
'id' => 'widget-four',
'before_widget' => '<div class="footer-wigget">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>'
));
register_sidebar(array(
'name' => __( 'Footer Widgets Five', TANVAS_DOMAIN ),
'id' => 'widget-five',
'before_widget' => '<div class="footer-wigget">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>'
));
register_widget( 'lc_doorway_button');
register_widget( 'CUSTOM_SOCIAL_MEDIA_WIDGETS' );
register_widget( 'CUSTOM_LATEST_POSTS_WIDGETS' );
register_widget( 'WooCommerceMyAccountWidgetTanvas');
}
add_action('widgets_init', 'tanvas_widgets_init');
/**
* Adds social media and newsletter icons to nav menu
*/
// function tanvas_add_social_icons () {
// echo "<ul><li class='fr fa-facebook'><i class='facebook-official'></i></lu></ul>";
// }
//add_action( 'woo_nav_inside', 'tanvas_add_social_icons', 20);
// function woo_options_add($options){
// //if(WP_DEBUG) error_log("woo_options_add called with :".serialize($options));
// return $options;
// }
/**
* Clear Attribute Select box if no available Variations
*/
// do_action( 'woocommerce_before_add_to_cart_form' );
function maybe_clear_attribute_select_box( ) {
global $product;
if( isset($product) and $product->is_type('variable')){
$available_variations = $product->get_available_variations();
$any_available = False;
foreach ($available_variations as $variation_data) {
if(isset($variation_data['variation_is_visible']) and $variation_data['variation_is_visible']){
$any_available = True;
//stop output of option box
}
}
if(!$any_available){ ?>
<p><?php echo __('Please', 'tanvas') . " <a href=''>" . __('sign in', 'tanvas') . "</a> " . __('or', 'tanvas') . " <a href=''>". __('register', 'tanvas'). "</a> ". __("to view prices", 'tanvas') ?></p>
<style type="text/css">
form.variations_form.cart{
display:none;
}
</style>
<?php }
}
}
add_action('woocommerce_before_add_to_cart_form', 'maybe_clear_attribute_select_box');
add_action( 'init', 'register_my_menu' );
function register_my_menu() {
register_nav_menu( 'new-menu', __( 'New Menu' ) );
}
/**
* Change In Stock / Out of Stock Text
*/
// Reversed back to original after consideration
// add_filter( 'woocommerce_get_availability', 'wcs_custom_get_availability', 1, 2);
// function wcs_custom_get_availability( $availability, $_product ) {
// // Change Out of Stock Text
// if ( ! $_product->is_in_stock() ) {
// $availability['availability'] = __('Coming Soon', 'woocommerce');
// }
// return $availability;
// }
/**
* Change WooCommerce lost password confirmation message
*/
add_filter('woocommerce_lost_password_message', 'tanvas_custom_lost_password_message', 1, 1);
function tanvas_custom_lost_password_message($message){
return 'A password reset email has been sent to the email address on file for your account, but may take several minutes to show up in your inbox. Please check your junk folder and wait at least 10 minutes before attempting another reset. <br/>Taking too long?<br/>'. do_shortcode('[button link="/contact-us"]CONTACT US[/button]');
}
/**
* Woocommerce cart prices notice
*/
function tanvas_output_cart_price_notice(){
echo do_shortcode(
'[box type="info"]'.
__('Dear customer our new cart has just been launched, while we have endeavored to ensure all pricing is correct we reserve the right to revise all pricing in line with our current listed prices. We thank you for your understanding.', TANVAS_DOMAIN).'<br/>'.
'[/box]'
);
}
add_action( 'woocommerce_before_cart', 'tanvas_output_cart_price_notice');
//custom excerpt length
function excerpt($limit) {
$excerpt = explode(' ', get_the_excerpt(), $limit);
if (count($excerpt)>=$limit) {
array_pop($excerpt);
$excerpt = implode(" ",$excerpt).'...';
} else {
$excerpt = implode(" ",$excerpt);
}
$excerpt = preg_replace('`[[^]]*]`','',$excerpt);
return $excerpt;
}
/**
* Remove deprecated constructor warnings
*/
add_filter('deprecated_constructor_trigger_error', '__return_false');
/**
* Add timestamp to woocommerce order emails
*/
function tanvas_print_timestamp() {
echo "Timestamp: " . date('r');
// echo "<br/>";
}
add_action('woocommerce_email_footer', 'tanvas_print_timestamp', 9, 2 );
/* Remove strict password requirements */
function remove_wc_password_meter() {
wp_dequeue_script( 'wc-password-strength-meter' );
}
add_action( 'wp_print_scripts', 'remove_wc_password_meter', 100 );
/* Just looking for all wp image sizes */
function display_wp_image_sizes() {
global $_wp_additional_image_sizes;
print '<pre>';
print_r( $_wp_additional_image_sizes );
print '</pre>';
}
// add_action( 'the_content', 'display_wp_image_sizes');
/* Stop auto regenerating images */
add_filter( 'woocommerce_background_image_regeneration', '__return_false' );
if ( ! class_exists( 'WC_Regenerate_Images', false ) ) {
global $woocommerce;
if(isset($woocommerce)){
$class_path = $woocommerce->plugin_path() .'/includes/class-wc-regenerate-images.php';
if(file_exists($class_path)){
include_once $class_path;
}
}
}
if ( class_exists('WC_Regenerate_Images', false)){
try {
// WC_Regenerate_Images::$background_process->kill_process();
} catch (Exception $e) {
}
}
?>