1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* Plugin Name: WooCommerce Subscription Shortcodes |
4
|
|
|
* Plugin URI: https://github.com/seb86/WooCommerce-Subscription-Shortcodes |
5
|
|
|
* Description: Experimental extension providing a few shortcodes that you can use to add details about the subscription product where you want them to be. |
6
|
|
|
* Version: 1.0.0 Beta |
7
|
|
|
* Author: Sébastien Dumont |
8
|
|
|
* Author URI: https://sebastiendumont.com |
9
|
|
|
* |
10
|
|
|
* Text Domain: woocommerce-subscription-shortcodes |
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( 'WCSS' ) ) { |
23
|
|
|
|
24
|
|
|
class WCSS { |
25
|
|
|
|
26
|
|
|
/* Plugin version. */ |
27
|
|
|
const VERSION = '1.0.0'; |
28
|
|
|
|
29
|
|
|
/* Required WC version. */ |
30
|
|
|
const REQ_WC_VERSION = '2.3.0'; |
31
|
|
|
|
32
|
|
|
/* Text domain. */ |
33
|
|
|
const TEXT_DOMAIN = 'woocommerce-subscription-shortcodes'; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var WCSS - the single instance of the class. |
37
|
|
|
* |
38
|
|
|
* @since 1.0.0 |
39
|
|
|
*/ |
40
|
|
|
protected static $_instance = null; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Main WCSS Instance. |
44
|
|
|
* |
45
|
|
|
* Ensures only one instance of WCSS is loaded or can be loaded. |
46
|
|
|
* |
47
|
|
|
* @static |
48
|
|
|
* @see WCSS() |
49
|
|
|
* @return WCSS - Main instance |
50
|
|
|
* @since 1.0.0 |
51
|
|
|
*/ |
52
|
|
|
public static function instance() { |
53
|
|
|
if ( is_null( self::$_instance ) ) { |
54
|
|
|
self::$_instance = new self(); |
55
|
|
|
} |
56
|
|
|
return self::$_instance; |
57
|
|
|
} // END instance() |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Cloning is forbidden. |
61
|
|
|
* |
62
|
|
|
* @since 1.0.0 |
63
|
|
|
*/ |
64
|
|
|
public function __clone() { |
65
|
|
|
_doing_it_wrong( __FUNCTION__, __( 'Foul!' ), '1.0.0' ); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Unserializing instances of this class is forbidden. |
70
|
|
|
* |
71
|
|
|
* @since 1.0.0 |
72
|
|
|
*/ |
73
|
|
|
public function __wakeup() { |
74
|
|
|
_doing_it_wrong( __FUNCTION__, __( 'Foul!' ), '1.0.0' ); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Do some work. |
79
|
|
|
*/ |
80
|
|
|
public function __construct() { |
81
|
|
|
add_action( 'plugins_loaded', array( $this, 'plugins_loaded' ) ); |
82
|
|
|
add_action( 'init', array( $this, 'init_textdomain' ) ); |
83
|
|
|
add_filter( 'plugin_row_meta', array( $this, 'plugin_meta_links' ), 10, 4 ); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function plugin_url() { |
87
|
|
|
return plugins_url( basename( plugin_dir_path(__FILE__) ), basename( __FILE__ ) ); |
88
|
|
|
} // END plugin_url() |
89
|
|
|
|
90
|
|
|
public function plugin_path() { |
91
|
|
|
return untrailingslashit( plugin_dir_path( __FILE__ ) ); |
92
|
|
|
} // END plugin_path() |
93
|
|
|
|
94
|
|
|
public function plugins_loaded() { |
95
|
|
|
global $woocommerce; |
96
|
|
|
|
97
|
|
|
// Subs 2 check |
98
|
|
|
if ( ! function_exists( 'wcs_is_subscription' ) ) { |
99
|
|
|
add_action( 'admin_notices', array( $this, 'wcs_admin_notice' ) ); |
100
|
|
|
return false; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
// WC 2 check |
104
|
|
|
if ( version_compare( $woocommerce->version, self::REQ_WC_VERSION ) < 0 ) { |
105
|
|
|
add_action( 'admin_notices', array( $this, 'wc_admin_notice' ) ); |
106
|
|
|
return false; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
require_once( 'includes/class-wcs-shortcodes.php' ); |
110
|
|
|
} // END plugins_loaded() |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Display a warning message if Subs version check fails. |
114
|
|
|
* |
115
|
|
|
* @return void |
116
|
|
|
*/ |
117
|
|
|
public function wc_admin_notice() { |
118
|
|
|
echo '<div class="error"><p>' . sprintf( __( 'WooCommerce Subscription Shortcodes requires at least WooCommerce %s in order to function. Please upgrade WooCommerce.', self::TEXT_DOMAIN ), self::REQ_WC_VERSION ) . '</p></div>'; |
119
|
|
|
} // END wc_admin_notice() |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Display a warning message if WC version check fails. |
123
|
|
|
* |
124
|
|
|
* @return void |
125
|
|
|
*/ |
126
|
|
|
public function wcs_admin_notice() { |
127
|
|
|
echo '<div class="error"><p>' . sprintf( __( 'WooCommerce Subscription Shortcodes requires WooCommerce Subscriptions version 2.0+.', self::TEXT_DOMAIN ), self::REQ_WC_VERSION ) . '</p></div>'; |
128
|
|
|
} // END wcs_admin_notice() |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Load textdomain. |
132
|
|
|
* |
133
|
|
|
* @return void |
134
|
|
|
*/ |
135
|
|
|
public function init_textdomain() { |
136
|
|
|
load_plugin_textdomain( 'woocommerce-subscription-shortcodes', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); |
137
|
|
|
} // END init_text_domain() |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* Show row meta on the plugin screen. |
141
|
|
|
* |
142
|
|
|
* @param mixed $links Plugin Row Meta |
143
|
|
|
* @param mixed $file Plugin Base file |
144
|
|
|
* @return array |
145
|
|
|
*/ |
146
|
|
|
public function plugin_meta_links( $links, $file, $data, $status ) { |
|
|
|
|
147
|
|
|
if ( $file == plugin_basename( __FILE__ ) ) { |
148
|
|
|
$author1 = '<a href="' . $data[ 'AuthorURI' ] . '">' . $data[ 'Author' ] . '</a>'; |
149
|
|
|
$author2 = '<a href="http://www.subscriptiongroup.co.uk/">Subscription Group Limited</a>'; |
150
|
|
|
$links[ 1 ] = sprintf( __( 'By %s', self::TEXT_DOMAIN ), sprintf( __( '%s and %s', self::TEXT_DOMAIN ), $author1, $author2 ) ); |
151
|
|
|
|
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
return $links; |
155
|
|
|
} // END plugin_meta_links() |
156
|
|
|
|
157
|
|
|
} // END class |
158
|
|
|
|
159
|
|
|
} // END if class exists |
160
|
|
|
|
161
|
|
|
return WCSS::instance(); |
162
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.