-
Notifications
You must be signed in to change notification settings - Fork 1
/
buddyforms-pods.php
executable file
·329 lines (290 loc) · 9.33 KB
/
buddyforms-pods.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
<?php
/**
* Plugin Name: BuddyForms Pods
* Plugin URI: https://themekraft.com/products/buddyforms-pods/
* Description: Use BuddyForms with Pods
* Version: 1.0.5
* Author: ThemeKraft
* Author URI: https://themekraft.com/
* License: GPLv2 or later
* Network: false
* Text Domain: buddyforms-pods
*
*****************************************************************************
*
* This script is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
****************************************************************************
*/
class BuddyFormsPODS {
/**
* @var string
*/
public static $version = '1.0.5';
public static $include_assets = false;
public static $slug = 'buddyforms-pods';
/**
* Instance of this class
*
* @var $instance BuddyFormsPODS
*/
protected static $instance = null;
/**
* Initiate the class
*
* @package buddyforms pods
* @since 0.1
*/
public function __construct() {
add_action( 'init', array( $this, 'includes' ) );
add_action( 'plugins_loaded', array( $this, 'load_plugin_textdomain' ) );
$this->load_constants();
}
/**
* Defines constants needed throughout the plugin.
*
* These constants can be overridden in bp-custom.php or wp-config.php.
*
* @package buddyforms_pods
* @since 1.0
*/
public function load_constants() {
if ( ! defined( 'BUDDYFORMS_PODS_PLUGIN_URL' ) ) {
define( 'BUDDYFORMS_PODS_PLUGIN_URL', plugins_url( '/', __FILE__ ) );
}
if ( ! defined( 'BUDDYFORMS_PODS_INSTALL_PATH' ) ) {
define( 'BUDDYFORMS_PODS_INSTALL_PATH', dirname( __FILE__ ) . '/' );
}
if ( ! defined( 'BUDDYFORMS_PODS_INCLUDES_PATH' ) ) {
define( 'BUDDYFORMS_PODS_INCLUDES_PATH', BUDDYFORMS_PODS_INSTALL_PATH . 'includes/' );
}
if ( ! defined( 'BUDDYFORMS_PODS_ASSETS_URL' ) ) {
define( 'BUDDYFORMS_PODS_ASSETS_URL', BUDDYFORMS_PODS_PLUGIN_URL . 'assets/' );
}
}
public static function error_log( $message ) {
if ( ! empty( $message ) ) {
error_log( self::getSlug() . ' -- ' . $message );
}
}
/**
* @return string
*/
public static function getNeedAssets() {
return self::$include_assets;
}
/**
* @param string $include_assets
*/
public static function setNeedAssets( $include_assets ) {
self::$include_assets = $include_assets;
}
/**
* Include files needed by BuddyForms
*
* @package buddyforms_pods
* @since 1.0
*/
public function includes() {
if ( self::is_buddy_form_active() ) {
if ( defined( 'PODS_VERSION' ) ) {
require_once BUDDYFORMS_PODS_INCLUDES_PATH . 'form-elements.php';
require_once BUDDYFORMS_PODS_INCLUDES_PATH . 'bfPodsAPI.php';
require_once BUDDYFORMS_PODS_INCLUDES_PATH . 'functions.php';
} else {
add_action( 'admin_notices', array( $this, 'need_pods' ) );
}
} else {
add_action( 'admin_notices', array( $this, 'need_buddyforms' ) );
}
}
public static function load_plugins_dependency() {
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
}
public static function is_buddy_form_active() {
self::load_plugins_dependency();
return is_plugin_active('buddyforms-premium/BuddyForms.php') || is_plugin_active('buddyforms/BuddyForms.php');
}
public function need_buddyforms() {
BuddyFormsPODS::admin_notice( '<p>Need <strong>BuddyForms Professional</strong> activated. Minimum version <i>2.5.10</i> required.</p>' );
}
public function need_pods() {
BuddyFormsPODS::admin_notice( '<p>Need <strong>Pods</strong> activated. Minimum version <i>2.7.16</i> required.</p>' );
}
/**
* Load the textdomain for the plugin
*
* @package buddyforms_pods
* @since 1.0
*/
public function load_plugin_textdomain() {
load_plugin_textdomain( 'buddyforms-pods', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
}
/**
* Get plugin version
*
* @return string
*/
static function getVersion() {
return self::$version;
}
/**
* Get plugins slug
*
* @return string
*/
static function getSlug() {
return self::$slug;
}
public static function admin_notice( $html = '' ) {
if ( empty( $html ) ) {
$html = '<b>Oops...</b> BuddyForms Pods cannot run without <a target="_blank" href="https://themekraft.com/buddyforms/">BuddyForms</a>.';
}
?>
<style>
.buddyforms-notice label.buddyforms-title {
background: rgba(0, 0, 0, 0.3);
color: #fff;
padding: 2px 10px;
position: absolute;
top: 100%;
bottom: auto;
right: auto;
-moz-border-radius: 0 0 3px 3px;
-webkit-border-radius: 0 0 3px 3px;
border-radius: 0 0 3px 3px;
left: 10px;
font-size: 12px;
font-weight: bold;
cursor: auto;
}
.buddyforms-notice .buddyforms-notice-body {
margin: .5em 0;
padding: 2px;
}
.buddyforms-notice.buddyforms-title {
margin-bottom: 30px !important;
}
.buddyforms-notice {
position: relative;
}
</style>
<div class="error buddyforms-notice buddyforms-title">
<label class="buddyforms-title">BuddyForms Pods</label>
<div class="buddyforms-notice-body">
<?php echo $html; ?>
</div>
</div>
<?php
}
/**
* Return an instance of this class.
*
* @return object A single instance of this class.
*/
public static function get_instance() {
// If the single instance hasn't been set, set it now.
if ( null == self::$instance ) {
self::$instance = new self;
}
return self::$instance;
}
}
// Create a helper function for easy SDK access.
function buddyforms_pods_freemius() {
global $buddyforms_pods_fs;
if ( ! isset( $buddyforms_pods_fs ) ) {
// Include Freemius SDK.
if ( file_exists( dirname( dirname( __FILE__ ) ) . '/buddyforms/includes/resources/freemius/start.php' ) ) {
// Try to load SDK from parent plugin folder.
require_once dirname( dirname( __FILE__ ) ) . '/buddyforms/includes/resources/freemius/start.php';
} elseif ( file_exists( dirname( dirname( __FILE__ ) ) . '/buddyforms-premium/includes/resources/freemius/start.php' ) ) {
// Try to load SDK from premium parent plugin folder.
require_once dirname( dirname( __FILE__ ) ) . '/buddyforms-premium/includes/resources/freemius/start.php';
}
try {
$buddyforms_pods_fs = fs_dynamic_init( array(
'id' => '4706',
'slug' => 'bf-pods',
'type' => 'plugin',
'public_key' => 'pk_5ffd22ecf0de8130b49fc380bf260',
'is_premium' => true,
'is_premium_only' => true,
'has_paid_plans' => true,
'is_org_compliant' => false,
'trial' => array(
'days' => 14,
'is_require_payment' => true,
),
'parent' => array(
'id' => '391',
'slug' => 'buddyforms',
'public_key' => 'pk_dea3d8c1c831caf06cfea10c7114c',
'name' => 'BuddyForms',
),
'menu' => array(
'first-path' => 'plugins.php',
'support' => false,
),
) );
} catch ( Freemius_Exception $e ) {
return false;
}
}
return $buddyforms_pods_fs;
}
function buddyforms_pods_fs_is_parent_active_and_loaded() {
// Check if the parent's init SDK method exists.
return function_exists( 'buddyforms_core_fs' );
}
function buddyforms_pods_fs_is_parent_active() {
$active_plugins = get_option( 'active_plugins', array() );
if ( is_multisite() ) {
$network_active_plugins = get_site_option( 'active_sitewide_plugins', array() );
$active_plugins = array_merge( $active_plugins, array_keys( $network_active_plugins ) );
}
foreach ( $active_plugins as $basename ) {
if ( 0 === strpos( $basename, 'buddyforms/' ) ||
0 === strpos( $basename, 'buddyforms-premium/' )
) {
return true;
}
}
return false;
}
function buddyforms_pods_need_buddyforms() {
BuddyFormsPODS::admin_notice();
}
function buddyforms_pods_fs_init() {
if ( buddyforms_pods_fs_is_parent_active_and_loaded() ) {
// Init Freemius.
buddyforms_pods_freemius();
// Signal that the add-on's SDK was initiated.
do_action( 'buddyforms_pods_fs_loaded' );
$GLOBALS['BuddyFormsPODS'] = BuddyFormsPODS::get_instance();
} else {
add_action( 'admin_notices', 'buddyforms_pods_need_buddyforms' );
}
}
if ( buddyforms_pods_fs_is_parent_active_and_loaded() ) {
// If parent already included, init add-on.
buddyforms_pods_fs_init();
} elseif ( buddyforms_pods_fs_is_parent_active() ) {
// Init add-on only after the parent is loaded.
add_action( 'buddyforms_core_fs_loaded', 'buddyforms_pods_fs_init' );
} else {
// Even though the parent is not activated, execute add-on for activation / uninstall hooks.
buddyforms_pods_fs_init();
}