PluginProbe
Better Payment – Instant Payments, Donations, Fundraising with Subscriptions & More / 2.3.0
Better Payment – Instant Payments, Donations, Fundraising with Subscriptions & More v2.3.0
2.3.4 2.3.3 2.3.2 2.3.1 2.3.0 2.2.2 2.2.1 2.2.0 2.1.2 2.1.1 trunk 0.0.1 0.0.2 0.0.3 0.0.4 0.0.5 0.0.6 0.0.7 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 All 66 releases
better-payment / better-payment.php

better-payment.php in Better Payment – Instant Payments, Donations, Fundraising with Subscriptions & More 2.3.0, at better-payment.php

316 lines 11.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Plugin Name: Better Payment
5 * Description: Better Payment allows you to automate payment transactions to manage donations, make payments, sell products, and more on your Elementor and Gutenberg website.
6 * Plugin URI: https://wpdeveloper.com/
7 * Author: WPDeveloper
8 * Version: 2.3.0
9 * Requires at least: 6.0
10 * Requires PHP: 7.4
11 * Author URI: https://wpdeveloper.com/
12 * Text Domain: better-payment
13 * Domain Path: /languages
14 */
15
16 if (!defined('ABSPATH')) {
17 exit;
18 } // Exit if accessed directly
19
20 require_once __DIR__ . '/vendor/autoload.php';
21
22 /**
23 * The plugin main class
24 *
25 * @since 0.0.1
26 */
27 final class Better_Payment {
28
29 use Better_Payment\Lite\Traits\Helper;
30
31 /**
32 * Plugin version
33 *
34 * @var string
35 * @since 0.0.1
36 */
37 const version = '2.3.0';
38
39 /**
40 * Class construcotr
41 *
42 * @since 0.0.1
43 */
44 private function __construct() {
45 $this->define_constants();
46
47 register_activation_hook(__FILE__, [$this, 'activate']);
48
49 add_action('plugins_loaded', [$this, 'init_plugin']);
50 }
51
52 /**
53 * Initialize a singleton instance
54 *
55 * @return \Better_Payment
56 * @since 0.0.1
57 */
58 public static function init() {
59 static $instance = false;
60
61 if (!$instance) {
62 $instance = new self();
63 }
64
65 return $instance;
66 }
67
68 /**
69 * Define the required plugin constants
70 *
71 * @return void
72 * @since 0.0.1
73 */
74 public function define_constants() {
75 define('BETTER_PAYMENT_VERSION', self::version);
76 // Bump this whenever the campaign CPT rewrite rules change (slug, etc.) to
77 // trigger a one-time flush_rewrite_rules() on the next init for existing installs.
78 define('BETTER_PAYMENT_CAMPAIGN_REWRITE_VERSION', '1');
79 define('BETTER_PAYMENT_FILE', __FILE__);
80 define('BETTER_PAYMENT_BASENAME', plugin_basename(__FILE__));
81 define('BETTER_PAYMENT_PATH', __DIR__);
82 define('BETTER_PAYMENT_URL', plugins_url('', BETTER_PAYMENT_FILE));
83 define('BETTER_PAYMENT_ASSETS', BETTER_PAYMENT_URL . '/assets');
84 define('BETTER_PAYMENT_ASSETS_PATH', BETTER_PAYMENT_PATH . '/assets');
85 define('BETTER_PAYMENT_DEV_ASSETS', BETTER_PAYMENT_URL . '/bpbuild');
86 define('BETTER_PAYMENT_DEV_ASSETS_PATH', BETTER_PAYMENT_PATH . '/bpbuild');
87 define('BETTER_PAYMENT_INCLUDES_PATH', BETTER_PAYMENT_PATH . '/includes');
88 define('BETTER_PAYMENT_ADMIN_PATH', BETTER_PAYMENT_INCLUDES_PATH . '/Admin');
89 define('BETTER_PAYMENT_ADMIN_VIEWS_PATH', BETTER_PAYMENT_ADMIN_PATH . '/views');
90 }
91
92 /**
93 * Do stuff upon plugin activation
94 *
95 * @return void
96 * @since 0.0.1
97 */
98 public function activate() {
99 $installer = new Better_Payment\Lite\Installer();
100 $installer->run();
101
102 // Register the campaign CPT and flush rewrite rules so campaign permalinks
103 // (/bp-campaign/{slug}/) resolve immediately, without needing a manual
104 // Settings → Permalinks re-save. Mark the rewrite version so the init-time
105 // self-heal flush (see init_campaign_module) does not run redundantly.
106 ( new Better_Payment\Lite\Campaign\CPT() )->register();
107 flush_rewrite_rules();
108 update_option( 'better_payment_campaign_rewrite_version', BETTER_PAYMENT_CAMPAIGN_REWRITE_VERSION );
109
110 if (get_option('better_payment_plugin_installed_fresh') !== 'yes' && get_option('better_payment_plugin_installed_time_fresh') === false) {
111 update_option('better_payment_plugin_installed_fresh', 'yes');
112
113 $now = time();
114 update_option('better_payment_plugin_installed_time_fresh', $now);
115 update_option('better_payment_progress_bar_dismissed_expiry_date', $now + 7 * DAY_IN_SECONDS);
116 }
117 }
118
119 /**
120 * Initialize the plugin
121 *
122 * @return void
123 * @since 0.0.1
124 */
125 public function init_plugin() {
126 new Better_Payment\Lite\Assets();
127
128 if (defined('DOING_AJAX') && DOING_AJAX) {
129 new Better_Payment\Lite\Ajax();
130 }
131
132 if (is_admin()) {
133 $adminObj = new Better_Payment\Lite\Admin();
134 $adminObj->init();
135
136 if ( !$this->bp_section_dismissed() ) {
137 add_action('save_post', array($this, 'bp_widget_usage_on_save'), 10, 1);
138 }
139 } else {
140 new Better_Payment\Lite\Frontend();
141 }
142
143 new Better_Payment\Lite\API();
144
145 // Initialize Gutenberg blocks
146 Better_Payment\Lite\Blocks\BlockManager::get_instance();
147 Better_Payment\Lite\Blocks\StyleHandler::init();
148
149 // Initialize Block Actions for payment processing (runs before Elementor Actions)
150 new Better_Payment\Lite\Blocks\BlockActions();
151
152 // Always register PayPal IPN listener + verification poll. These must run even
153 // when Elementor is inactive, because PayPal payments also flow through the
154 // block/campaign path. (Previously registered only inside the Elementor gate
155 // via Classes\Actions, so non-Elementor sites never confirmed PayPal payments.)
156 add_action( 'admin_post_better_payment_paypal_ipn', [ 'Better_Payment\Lite\Classes\Handler', 'handle_paypal_ipn' ] );
157 add_action( 'admin_post_nopriv_better_payment_paypal_ipn', [ 'Better_Payment\Lite\Classes\Handler', 'handle_paypal_ipn' ] );
158 add_action( 'wp_ajax_better_payment_check_paypal_status', [ 'Better_Payment\Lite\Classes\Handler', 'check_paypal_status' ] );
159 add_action( 'wp_ajax_nopriv_better_payment_check_paypal_status', [ 'Better_Payment\Lite\Classes\Handler', 'check_paypal_status' ] );
160
161 if (defined('ELEMENTOR_VERSION')) {
162 new Better_Payment\Lite\Classes\Actions();
163 $el_integration = new Better_Payment\Lite\Admin\Elementor\EL_Integration();
164 $el_integration->init();
165
166 Better_Payment\Lite\Admin\Settings::save_default_settings();
167 }
168
169 // ── Campaign Builder module ────────────────────────────────────
170 $this->init_campaign_module();
171
172 // ── AI module (AI-native Campaign Builder) ─────────────────────
173 $this->init_ai_module();
174 }
175
176 /**
177 * Initialize the AI module (providers, operations, REST endpoints).
178 *
179 * @return void
180 */
181 private function init_ai_module() {
182 // Register providers + resolve settings-driven config.
183 ( new Better_Payment\Lite\AI\AIManager() )->init();
184
185 // REST API for AI (chat/generate/analyze/image/conversations/config).
186 new Better_Payment\Lite\API\AIAPI();
187 }
188
189 /**
190 * Initialize the Campaign Builder module.
191 *
192 * @return void
193 */
194 private function init_campaign_module() {
195 $cpt = new Better_Payment\Lite\Campaign\CPT();
196
197 // CPT registration (runs on init)
198 add_action( 'init', [ $cpt, 'register' ] );
199
200 // Self-heal rewrite rules for installs that updated into this version
201 // (the activation hook does NOT re-run on plugin update). Runs after the
202 // CPT is registered (priority 11 > default 10) so the new rule is present
203 // when we flush, then records the version so it flushes only once.
204 add_action( 'init', static function () {
205 if ( get_option( 'better_payment_campaign_rewrite_version' ) !== BETTER_PAYMENT_CAMPAIGN_REWRITE_VERSION ) {
206 flush_rewrite_rules();
207 update_option( 'better_payment_campaign_rewrite_version', BETTER_PAYMENT_CAMPAIGN_REWRITE_VERSION );
208 }
209 }, 11 );
210
211 // Admin-only: builder page, submenu, asset enqueue
212 if ( is_admin() ) {
213 add_action( 'admin_menu', [ $cpt, 'register_builder_page' ], 20 );
214 add_action( 'admin_enqueue_scripts', [ $cpt, 'enqueue_builder_assets' ] );
215 add_action( 'admin_enqueue_scripts', [ $cpt, 'enqueue_list_assets' ] );
216 add_action( 'load-post-new.php', [ $cpt, 'redirect_new_post' ] );
217 add_action( 'load-post.php', [ $cpt, 'redirect_edit_post' ] );
218 add_filter( 'get_edit_post_link', [ $cpt, 'filter_edit_link' ], 10, 3 );
219 add_action( 'admin_init', [ $cpt, 'redirect_cpt_list' ] );
220
221 // Save post meta when post is saved via standard WP (rare path)
222 add_action( 'save_post_bp_campaign', [ new Better_Payment\Lite\Campaign\MetaBox(), 'save' ] );
223
224 // Custom columns on campaign list table
225 $admin_list = new Better_Payment\Lite\Campaign\CampaignListColumns();
226 add_filter( 'manage_bp_campaign_posts_columns', [ $admin_list, 'add_columns' ] );
227 add_action( 'manage_bp_campaign_posts_custom_column', [ $admin_list, 'render_column' ], 10, 2 );
228 }
229
230 // Serve a custom template for bp_campaign single pages so RendererService renders
231 // the campaign content instead of the theme's empty single.php.
232 add_filter( 'template_include', static function ( $template ) {
233 if ( is_singular( 'bp_campaign' ) ) {
234 $custom = BETTER_PAYMENT_PATH . '/templates/single-bp_campaign.php';
235 return file_exists( $custom ) ? $custom : $template;
236 }
237 return $template;
238 } );
239
240 // Register element types and templates (must run before CPT enqueue_builder_assets).
241 // Deferred to init so __() calls don't trigger translation loading during plugins_loaded.
242 add_action( 'init', [ 'Better_Payment\Lite\Campaign\Elements\CampaignElements', 'register_all' ], 5 );
243
244 // Campaign display block (server-side render)
245 $block = new Better_Payment\Lite\Campaign\CampaignBlock();
246 add_action( 'init', [ $block, 'register' ], 20 );
247
248 // Shortcode [bp_campaign id="42"]
249 $shortcode = new Better_Payment\Lite\Campaign\Shortcode();
250 $shortcode->register();
251
252 // REST API for campaigns
253 new Better_Payment\Lite\API\CampaignAPI();
254
255 // Bust campaign stats cache when a payment is confirmed by any gateway.
256 Better_Payment\Lite\Campaign\CampaignStats::register_hooks();
257 }
258 }
259
260 /**
261 * Initializes the main plugin
262 *
263 * @return \Better_Payment
264 * @since 0.0.1
265 */
266
267 Better_Payment::init();
268
269 /**
270 * Plugin migrator
271 *
272 * @since 0.0.2
273 */
274 function better_payment_migrator() {
275 Better_Payment\Lite\Classes\Migrator::migrator();
276 }
277
278
279 /**
280 * On wp load
281 *
282 * @return void
283 * @since 0.0.1
284 */
285 add_action('wp_loaded', function () {
286 if (get_option('better_payment_version') != BETTER_PAYMENT_VERSION) {
287 better_payment_migrator();
288 update_option('better_payment_version', BETTER_PAYMENT_VERSION);
289 }
290
291 $setup_wizard = get_option('better_payment_setup_wizard');
292
293 if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
294 $is_from_better_payment = (isset( $_POST['form_data'] ) && isset( $_POST['form_data'][0] ) && isset( $_POST['form_data'][0]['name'] ) && strpos( $_POST['form_data'][0]['name'], 'better_payment_' ) !== false) || (isset( $_POST['is_tracking'] ) && $_POST['is_tracking'] === 'true') || (isset( $_POST['action'] ) && $_POST['action'] === 'save_setup_wizard_data');
295
296 if ( ! $is_from_better_payment ) {
297 return;
298 }
299 }
300
301 if ($setup_wizard == 'redirect') {
302 Better_Payment\Lite\Admin\Setup_Wizard::redirect();
303 }
304
305 if ($setup_wizard == 'init') {
306 new Better_Payment\Lite\Admin\Setup_Wizard();
307 }
308 });
309
310 /**
311 * Dispatch actions
312 *
313 * @since 0.0.1
314 */
315 \Better_Payment\Lite\Admin::dispatch_actions();
316