-
Notifications
You must be signed in to change notification settings - Fork 0
/
The-fairy-light-shop-site-plugin.php
154 lines (114 loc) · 3.73 KB
/
The-fairy-light-shop-site-plugin.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
<?php
/*
Plugin Name: The Fairy Light Shop Site Plugin
Plugin URI: http://voice.co.nz/
Description: Our take on WooCommerce Product Price Based on Countries (https://github.com/wp-plugins/woocommerce-product-price-based-on-countries) for TFLS
Version: 1.0
Author: Nicholas Byfleet
Author URI: http://nbyfleet.com/
License: A http://www.binpress.com/license/view/l/a59b50bad876cc0b780d0d2652b39ca4
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) :
if ( ! class_exists( 'WC_Fairy_Light_Shop' ) ) : // Make sure that we're not stepping on anyone's toes
/**
* Main WC Fairy Light Shop Class
*
* @class WC_Fairy_Light_Shop
* @version 1.0.0
*/
class WC_Fairy_Light_Shop {
/**
* @var The single instance of the class
*/
protected static $_instance = null;
/**
* @var $regions
*/
protected $regions = null;
/**
* Main WC_Fairy_Light_Shop Instance
*
* @static
* @see TFLS()
*/
public static function instance() {
if ( is_null( self::$_instance ) ) {
self::$_instance = new self();
}
return self::$_instance;
}
public function __construct() {
$upload_dir = wp_upload_dir();
define( 'TFLS_FILE', __FILE__ );
define( 'TFLS_UPLOAD_DIR', $upload_dir['basedir'] . '/the_fairy_light_shop_site_plugin' );
define( 'TFLS_GEOIP_DB', TFLS_UPLOAD_DIR . '/GeoLite2-Country.mmdb' );
include_once 'includes/tfls-functions.php';
if ( $this->is_request( 'admin' ) ) {
include_once 'includes/class-tfls-admin.php';
} elseif ( $this->is_request( 'frontend' ) ) {
require_once 'includes/class-tfls-frontend.php';
}
}
/**
* Get regions
* @return array
*/
public function get_regions() {
if ( is_null( $this->regions ) ) {
$regions = get_option( '_oga_tfls_countries_groups' );
if ( ! $regions ) {
$regions = array();
}
$this->regions = $regions;
}
return $this->regions;
}
/**
* What type of request is this?
*
* @param string $type frontend or admin
*
* @return bool
*/
private function is_request( $type ) {
$is_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX;
switch ( $type ) {
case 'admin' :
$ajax_allow_actions = array( 'woocommerce_add_variation' );
return ( is_admin() && ! $is_ajax ) || ( is_admin() && $is_ajax && isset( $_POST['action'] ) && in_array( $_POST['action'], $ajax_allow_actions ) );
case 'frontend' :
return ! $this->is_request( 'bot' ) && file_exists( TFLS_GEOIP_DB ) && ( ! is_admin() || ( is_admin() && $is_ajax ) ) && ! defined( 'DOING_CRON' );
case 'bot':
$user_agent = strtolower( $_SERVER['HTTP_USER_AGENT'] );
return preg_match( "/googlebot|adsbot|yahooseeker|yahoobot|msnbot|watchmouse|pingdom\.com|feedfetcher-google/", $user_agent );
}
}
} // End class
/**
* Returns the main instance of WC_Fairy_Light_Shop so as to avoid the need to use globals.
*
* @return WC_Fairy_Light_Shop
*/
function TFLS() {
return WC_Fairy_Light_Shop::instance();
}
$wc_the_fairy_light_shop = TFLS();
endif; // ! class_exists ( 'WC_The_Fairy_Light_Shop' )
else :
add_action( 'admin_init', 'oga_tfls_deactivate' );
function oga_tfls_deactivate() {
deactivate_plugins( plugin_basename( __FILE__ ) );
}
add_action( 'admin_notices', 'oga_tfls_no_woocommerce_admin_notice' );
function oga_tfls_no_woocommerce_admin_notice() {
?>
<div class="updated">
<p><strong>The Fairy Light Shop Site Plugin </strong>has been deactivated because <a
href="http://woothemes.com/">Woocommerce plugin</a> is required</p>
</div>
<?php
}
endif;