Completed
Push — master ( 55c935...d6f625 )
by Sébastien
01:59
created

WCSATT_STT::plugin_url()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/*
3
 * Plugin Name: WooCommerce Subscribe All the Things: Sign-up and Trial Add-on
4
 * Plugin URI:  https://github.com/seb86/woocommerce-subscribe-to-all-the-things-signup-trial-add-on
5
 * Version:     1.0.1
6
 * Description: Adds a sign-up fee and free trial option for each subscription scheme. Requires WooCommerce Subscribe All the Things extension v1.1.0+.
7
 * Author:      Sébastien Dumont
8
 * Author URI:  https://sebastiendumont.com
9
 *
10
 * Text Domain: wc-satt-stt
11
 * Domain Path: /languages/
12
 *
13
 * Requires at least: 4.1
14
 * Tested up to: 4.5.3
15
 *
16
 * Copyright: © 2016 Sébastien Dumont
17
 * License: GNU General Public License v3.0
18
 * License URI: http://www.gnu.org/licenses/gpl-3.0.html
19
 */
20
if ( ! defined('ABSPATH') ) exit; // Exit if accessed directly.
21
22
if ( ! class_exists( 'WCSATT_STT' ) ) {
23
	class WCSATT_STT {
24
25
		/* Plugin version. */
26
		const VERSION = '1.0.1';
27
28
		/* Required WC version. */
29
		const REQ_WC_VERSION = '2.3.0';
30
31
		/* Required WCSATT version */
32
		const REQ_WCSATT_VERSION = '1.1.0';
33
34
		/* Text domain. */
35
		const TEXT_DOMAIN = 'wc-satt-stt';
36
37
		/**
38
		 * @var WCSATT_STT - the single instance of the class.
39
		 *
40
		 * @since 1.0.0
41
		 */
42
		protected static $_instance = null;
43
44
		/**
45
		 * Main WCSATT_STT Instance.
46
		 *
47
		 * Ensures only one instance of WCSATT_STT is loaded or can be loaded.
48
		 *
49
		 * @static
50
		 * @see WCSATT_STT()
51
		 * @return WCSATT_STT - Main instance
52
		 * @since 1.0.0
53
		 */
54
		public static function instance() {
55
			if ( is_null( self::$_instance ) ) {
56
				self::$_instance = new self();
57
			}
58
			return self::$_instance;
59
		}
60
61
		/**
62
		 * Cloning is forbidden.
63
		 *
64
		 * @since 1.0.0
65
		 */
66
		public function __clone() {
67
			_doing_it_wrong( __FUNCTION__, __( 'Foul!' ), '1.0.0' );
68
		}
69
70
		/**
71
		 * Unserializing instances of this class is forbidden.
72
		 *
73
		 * @since 1.0.0
74
		 */
75
		public function __wakeup() {
76
			_doing_it_wrong( __FUNCTION__, __( 'Foul!' ), '1.0.0' );
77
		}
78
79
		/**
80
		 * Load the plugin.
81
		 */
82
		public function __construct() {
83
			add_action( 'plugins_loaded', array( $this, 'load_plugin' ), 11 );
84
			add_action( 'init', array( $this, 'init_plugin' ) );
85
			add_filter( 'plugin_row_meta', array( $this, 'plugin_meta_links' ), 10, 4 );
86
		}
87
88
		public static function plugin_url() {
89
			return plugins_url( basename( plugin_dir_path(__FILE__) ), basename( __FILE__ ) );
90
		} // END plugin_url()
91
92
		public static function plugin_path() {
93
			return untrailingslashit( plugin_dir_path( __FILE__ ) );
94
		} // END plugin_path()
95
96
		/*
97
		 * Check requirements on activation.
98
		 *
99
		 * @global $woocommerce
100
		 */
101
		public function load_plugin() {
102
			global $woocommerce;
103
104
			// Check that the required WooCommerce is running.
105
			if ( version_compare( $woocommerce->version, self::REQ_WC_VERSION, '<' ) ) {
106
				add_action( 'admin_notices', array( $this, 'wcsatt_stt_wc_admin_notice' ) );
107
				return false;
108
			}
109
110
			// Checks that WooCommerce Subscribe All the Things is running or is less than the required version.
111
			if ( ! class_exists( 'WCS_ATT' ) || version_compare( WCS_ATT::VERSION, self::REQ_WCSATT_VERSION, '<' ) ) {
112
				add_action( 'admin_notices', array( $this, 'wcsatt_stt_admin_notice' ) );
113
				return false;
114
			}
115
116
			require_once( 'includes/class-wcsatt-stt-cart.php' );
117
			require_once( 'includes/class-wcsatt-stt-display.php' );
118
119
			// Admin includes
120
			if ( is_admin() ) {
121
				require_once( 'includes/admin/class-wcsatt-stt-admin.php' );
122
			}
123
124
		} // END load_plugin()
125
126
		/**
127
		 * Display a warning message if minimum version of WooCommerce check fails.
128
		 *
129
		 * @return void
130
		 */
131
		public function wcsatt_stt_wc_admin_notice() {
132
			echo '<div class="error"><p>' . sprintf( __( '%1$s requires at least %2$s v%3$s in order to function. Please upgrade %2$s.', 'wc-satt-stt' ), 'WooCommerce Subscribe All the Things: Sign-up and Trial Add-on', 'WooCommerce', self::REQ_WC_VERSION ) . '</p></div>';
133
		} // END wcsatt_stt_wc_admin_notice()
134
135
		/**
136
		 * Display a warning message if minimum version of WooCommerce Subscribe All the Things check fails.
137
		 *
138
		 * @return void
139
		 */
140
		public function wcsatt_stt_admin_notice() {
141
			echo '<div class="error"><p>' . sprintf( __( '%1$s requires at least %2$s v%3$s in order to function. Please upgrade %2$s.', 'wc-satt-stt' ), 'WooCommerce Subscribe All the Things: Sign-up and Trial Add-on', 'WooCommerce Subscribe All the Things', self::REQ_WCSATT_VERSION ) . '</p></div>';
142
		} // END wcsatt_stt_admin_notice()
143
144
		/**
145
		 * Initialize the plugin if ready.
146
		 *
147
		 * @return void
148
		 */
149
		public function init_plugin() {
150
			// Load text domain.
151
			load_plugin_textdomain( 'wc-satt-stt', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
152
		} // END init_plugin()
153
154
		/**
155
		 * Show row meta on the plugin screen.
156
		 *
157
		 * @param  mixed $links Plugin Row Meta
158
		 * @param  mixed $file  Plugin Base file
159
		 * @param  array $data  Plugin Data
160
		 * @return array
161
		 */
162
		public function plugin_meta_links( $links, $file, $data, $status ) {
163
			if ( $file == plugin_basename( __FILE__ ) ) {
164
				$author1 = '<a href="' . $data[ 'AuthorURI' ] . '">' . $data[ 'Author' ] . '</a>';
165
				$author2 = '<a href="http://www.subscriptiongroup.co.uk/">Subscription Group Limited</a>';
166
				$links[ 1 ] = sprintf( __( 'By %s', self::TEXT_DOMAIN ), sprintf( __( '%s and %s', self::TEXT_DOMAIN ), $author1, $author2 ) );
167
			}
168
169
			return $links;
170
		} // END plugin_meta_links()
171
172
	} // END class
173
174
} // END if class exists
175
176
return WCSATT_STT::instance();