-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmailpoet-paid-memberships-pro-addon.php
434 lines (368 loc) · 12.2 KB
/
mailpoet-paid-memberships-pro-addon.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
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
<?php
/*
* Plugin Name: MailPoet Paid Memberships Pro Add-on
* Plugin URI: http://wordpress.org/plugins/mailpoet-paid-memberships-pro-add-on/
* Description: Adds a checkbox on checkout page for your customers to subscribe to your MailPoet newsletters.
* Version: 1.0.0
* Author: Sebs Studio
* Author URI: http://www.sebs-studio.com
* Author Email: sebastien@sebs-studio.com
* Requires at least: 3.7.1
* Tested up to: 3.8.1
*
* Text Domain: mailpoet_paid_memberships_pro_addon
* Domain Path: /languages/
* Network: false
*
* Copyright: (c) 2014 Sebs Studio. (sebastien@sebs-studio.com)
*
* License: GNU General Public License v3.0
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
*
* @package MailPoet_Paid_Memberships_Pro_Addon
* @author Sebs Studio
* @category Core
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! class_exists( 'MailPoet_Paid_Memberships_Pro_Addon' ) ) {
/**
* Main MailPoet Paid Memberships Pro Add-on Class
*
* @class MailPoet_Paid_Memberships_Pro_Addon
* @version 1.0.0
*/
final class MailPoet_Paid_Memberships_Pro_Addon {
/**
* Constants
*/
// Slug
const slug = 'mailpoet-paid-memberships-pro-addon';
// Text Domain
const text_domain = 'mailpoet_paid_memberships_pro_addon';
/**
* Global Variables
*/
/**
* The Plug-in name.
*
* @var string
*/
public $name = "MailPoet Paid Memberships Pro Add-on";
/**
* The Plug-in version.
*
* @var string
*/
public $version = "1.0.0";
/**
* The WordPress version the plugin requires minimum.
*
* @var string
*/
public $wp_version_min = "3.7.1";
/**
* The single instance of the class
*
* @var null
*/
protected static $_instance = null;
/**
* The Plug-in URL.
*
* @var string
*/
public $web_url = "http://www.wordpress.org/plugins/mailpoet-paid-memberships-pro-add-on/";
/**
* The Plug-in documentation URL.
*
* @var string
*/
public $doc_url = "/~https://github.com/seb86/MailPoet-Paid-Memberships-Pro-Add-on/wiki/";
/**
* GitHub Repo URL
*
* @var string
*/
public $github_repo_url = "/~https://github.com/username/MailPoet-Paid-Memberships-Pro-Add-on/";
/**
* Main MailPoet Paid Memberships Pro Add-on Instance
*
* Ensures only one instance of is loaded or can be loaded.
*
* @access public static
* @see MailPoet_Paid_Memberships_Pro_Addon()
* @return MailPoet Paid Memberships Pro Add-on - Main instance
*/
public static function instance() {
if ( is_null( self::$_instance ) ) {
self::$_instance = new self();
}
return self::$_instance;
}
/**
* Constructor
*
* @access public
*/
public function __construct() {
// Define constants
$this->define_constants();
// Check plugin requirements
$this->check_requirements();
// Include required files
$this->includes();
// Hooks
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( &$this, 'action_links' ) );
add_filter( 'plugin_row_meta', array( &$this, 'plugin_row_meta' ), 10, 2 );
add_action( 'init', array( &$this, 'init_mailpoet_paid_memberships_pro_addon' ), 0 );
}
/**
* Plugin action links.
*
* @access public
* @param mixed $links
* @return void
*/
public function action_links( $links ) {
// List your action links
if( current_user_can( 'manage_options' ) ) {
$plugin_links = array(
'<a href="' . admin_url( 'options-general.php?page=pmpro-mailpoet' ) . '">' . __( 'Settings', MAILPOET_PAID_MEMBERSHIPS_PRO_ADDON_TEXT_DOMAIN ) . '</a>',
);
}
return array_merge( $links, $plugin_links );
}
/**
* Plugin row meta links
*
* @access public
* @param array $input already defined meta links
* @param string $file plugin file path and name being processed
* @return array $input
*/
public function plugin_row_meta( $input, $file ) {
if ( plugin_basename( __FILE__ ) !== $file ) {
return $input;
}
$links = array(
'<a href="' . esc_url( $this->doc_url ) . '">' . __( 'Documentation', MAILPOET_PAID_MEMBERSHIPS_PRO_ADDON_TEXT_DOMAIN ) . '</a>',
);
$input = array_merge( $input, $links );
return $input;
}
/**
* Define Constants
*
* @access private
*/
private function define_constants() {
define( 'MAILPOET_PAID_MEMBERSHIPS_PRO_ADDON', $this->name ); // Plugin Name
define( 'MAILPOET_PAID_MEMBERSHIPS_PRO_ADDON_FILE', __FILE__ ); // Plugin file name
define( 'MAILPOET_PAID_MEMBERSHIPS_PRO_ADDON_VERSION', $this->version ); // Plugin version
define( 'MAILPOET_PAID_MEMBERSHIPS_PRO_ADDON_WP_VERSION_REQUIRE', $this->wp_version_min ); // WordPress requires to be...
define( 'MAILPOET_PAID_MEMBERSHIPS_PRO_ADDON_TEXT_DOMAIN', self::text_domain );
define( 'MAILPOET_PAID_MEMBERSHIPS_PRO_ADDON_README_FILE', 'http://plugins.svn.wordpress.org/mailpoet-paid-memberships-pro-add-on/trunk/readme.txt' );
define( 'GITHUB_REPO_URL' , $this->github_repo_url );
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
define( 'MAILPOET_PAID_MEMBERSHIPS_PRO_ADDON_SCRIPT_MODE', $suffix );
}
/**
* Checks that the WordPress setup meets the plugin requirements.
*
* @access private
* @global string $wp_version
* @return boolean
*/
private function check_requirements() {
global $wp_version;
require_once(ABSPATH.'/wp-admin/includes/plugin.php');
if ( !version_compare( $wp_version, MAILPOET_PAID_MEMBERSHIPS_PRO_ADDON_WP_VERSION_REQUIRE, '>=' ) ) {
add_action('admin_notices', array( &$this, 'display_req_notice' ) );
return false;
}
if( function_exists( 'is_plugin_active' ) ) {
if ( !is_plugin_active( 'paid-memberships-pro/paid-memberships-pro.php' ) && !is_plugin_active( 'wysija-newsletters/index.php' ) ) {
add_action('admin_notices', array( &$this, 'display_req_notice_mailpoet' ) );
add_action('admin_notices', array( &$this, 'display_req_notice_paid_memberships_pro' ) );
return false;
}
if ( !is_plugin_active( 'wysija-newsletters/index.php' ) ) {
add_action('admin_notices', array( &$this, 'display_req_notice_mailpoet' ) );
return false;
}
if ( !is_plugin_active( 'paid-memberships-pro/paid-memberships-pro.php' ) ) {
add_action('admin_notices', array( &$this, 'display_req_notice_paid_memberships_pro' ) );
return false;
}
return true;
}
}
/**
* Display the requirement notice for WordPress.
*
* @access static
*/
static function display_req_notice() {
echo '<div id="message" class="error"><p>';
echo sprintf( __('Sorry, <strong>%s</strong> requires WordPress ' . MAILPOET_PAID_MEMBERSHIPS_PRO_ADDON_WP_VERSION_REQUIRE . ' or higher. Please <a href="%s">upgrade</a> your WordPress setup.', MAILPOET_PAID_MEMBERSHIPS_PRO_ADDON_TEXT_DOMAIN), MAILPOET_PAID_MEMBERSHIPS_PRO_ADDON, admin_url( 'update-core.php' ) );
echo '</p></div>';
}
/**
* Display the requirement notice for Paid Memberships Pro.
*
* @access static
*/
static function display_req_notice_paid_memberships_pro() {
echo '<div id="message" class="error"><p>';
echo sprintf( __('Sorry, <strong>%s</strong> requires Paid Memberships Pro for this plugin to work. Please install and activate <strong><a href="%s">Paid Memberships Pro</a></strong> first.', MAILPOET_PAID_MEMBERSHIPS_PRO_ADDON_TEXT_DOMAIN), MAILPOET_PAID_MEMBERSHIPS_PRO_ADDON, admin_url('plugin-install.php?tab=search&type=term&s=Paid+Memberships+Pro') );
echo '</strong></p></div>';
}
/**
* Display the requirement notice for MailPoet.
*
* @access static
*/
static function display_req_notice_mailpoet() {
echo '<div id="message" class="error"><p>';
echo sprintf( __('Sorry, <strong>%s</strong> requires MailPoet Newsletters for this plugin to work. Please install and activate <strong><a href="%s">MailPoet Newsletters</a></strong> first.', MAILPOET_PAID_MEMBERSHIPS_PRO_ADDON_TEXT_DOMAIN), MAILPOET_PAID_MEMBERSHIPS_PRO_ADDON, admin_url('plugin-install.php?tab=search&type=term&s=MailPoet+Newsletters+%28formerly+Wysija%29') );
echo '</p></div>';
}
/**
* Include required core files used in admin and on the frontend.
*
* @access public
* @return void
*/
public function includes() {
include_once( 'includes/mailpoet-paid-memberships-pro-addon-core-functions.php' ); // Contains core functions for the front/back end.
if ( is_admin() ) {
$this->admin_includes();
}
if ( ! is_admin() || defined('DOING_AJAX') ) {
$this->frontend_includes();
}
}
/**
* Include required admin files.
*
* @access public
* @return void
*/
public function admin_includes() {
//include_once( 'includes/admin/mailpoet-paid-memberships-pro-addon-admin-hooks.php' ); // Hooks used in the admin
include_once( 'includes/admin/class-mailpoet-paid-memberships-pro-addon-install.php' ); // Install plugin
include_once( 'includes/admin/class-mailpoet-paid-memberships-pro-addon-admin.php' ); // Admin section
}
/**
* Include required frontend files.
*
* @access public
* @return void
*/
public function frontend_includes() {
include_once( 'includes/mailpoet-paid-memberships-pro-addon-functions.php' ); // Contains functions for various front-end events
include_once( 'includes/mailpoet-paid-memberships-pro-addon-hooks.php' ); // Hooks used in the frontend
}
/**
* Runs when the plugin is initialized.
*
* @access public
*/
public function init_mailpoet_paid_memberships_pro_addon() {
// Set up localisation
$this->load_plugin_textdomain();
// Load JavaScript and stylesheets
$this->register_scripts_and_styles();
// This will run on the frontend and for ajax requests
if ( ! is_admin() || defined('DOING_AJAX') ) {
}
}
/**
* Load Localisation files.
*
* Note: the first-loaded translation file overrides any
* following ones if the same translation is present.
*
* @access public
* @return void
*/
public function load_plugin_textdomain() {
$locale = apply_filters( 'plugin_locale', get_locale(), self::text_domain );
load_textdomain( self::text_domain, WP_LANG_DIR . "/" . self::slug . "/" . $locale . ".mo" );
// Set Plugin Languages Directory
// Plugin translations can be filed in the mailpoet-paid-memberships-pro-addon/languages/ directory
// Wordpress translations can be filed in the wp-content/languages/ directory
load_plugin_textdomain( self::text_domain, false, dirname( plugin_basename( __FILE__ ) ) . "/languages" );
}
/** Helper functions ******************************************************/
/**
* Get the plugin url.
*
* @access public
* @return string
*/
public function plugin_url() {
return untrailingslashit( plugins_url( '/', __FILE__ ) );
}
/**
* Get the plugin path.
*
* @access public
* @return string
*/
public function plugin_path() {
return untrailingslashit( plugin_dir_path( __FILE__ ) );
}
/**
* Registers and enqueues stylesheets and javascripts
* for the administration panel and the front of the site.
*
* @access private
*/
private function register_scripts_and_styles() {
global $wp_locale;
if ( is_admin() ) {
// Stylesheet
$this->load_file( self::slug . '_admin_style', '/assets/css/admin/mailpoet-paid-memberships-pro-addon.css' );
}
else {
// Stylesheet
$this->load_file( self::slug . '-style', '/assets/css/mailpoet-paid-memberships-pro-addon.css' );
} // end if/else
} // end register_scripts_and_styles
/**
* Helper function for registering and enqueueing scripts and styles.
*
* @name The ID to register with WordPress
* @file_path The path to the actual file
* @is_script Optional argument for if the incoming file_path is a JavaScript source file.
*
* @access private
*/
private function load_file( $name, $file_path, $is_script = false, $support = array(), $version = '' ) {
$url = $this->plugin_url() . $file_path;
$file = $this->plugin_path() . $file_path;
if( file_exists( $file ) ) {
if( $is_script ) {
wp_register_script( $name, $url, $support, $version );
wp_enqueue_script( $name );
}
else {
wp_register_style( $name, $url );
wp_enqueue_style( $name );
} // end if
} // end if
} // end load_file
} // end class
} // end if class exists
/**
* Returns the main instance of MailPoet_Paid_Memberships_Pro_Addon to prevent the need to use globals.
*
* @return
*/
function MailPoet_Paid_Memberships_Pro_Addon() {
return MailPoet_Paid_Memberships_Pro_Addon::instance();
}
// Global for backwards compatibility.
$GLOBALS['mailpoet_paid_memberships_pro_addon'] = MailPoet_Paid_Memberships_Pro_Addon();
?>