PluginProbe
Better Payment – Instant Payments, Donations, Fundraising with Subscriptions & More / 2.4.0
Better Payment – Instant Payments, Donations, Fundraising with Subscriptions & More v2.4.0
2.4.1 2.4.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 All 68 releases
better-payment / includes / Admin.php

Admin.php in Better Payment – Instant Payments, Donations, Fundraising with Subscriptions & More 2.4.0, at includes/Admin.php

234 lines 7.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Better_Payment\Lite;
4
5 use Better_Payment\Lite\Admin\ReactAdmin;
6 use Better_Payment\Lite\Admin\Elementor\Widget;
7 use Better_Payment\Lite\Classes\Helper;
8 use Better_Payment\Lite\Classes\Export;
9 use Better_Payment\Lite\Classes\Import;
10 use PriyoMukul\WPNotice\Notices;
11 use PriyoMukul\WPNotice\Utils\CacheBank;
12 use PriyoMukul\WPNotice\Utils\NoticeRemover;
13
14 /**
15 * Exit if accessed directly
16 */
17 if (!defined('ABSPATH')) {
18 exit;
19 }
20
21 /**
22 * The admin class
23 *
24 * @since 0.0.1
25 */
26 class Admin extends Controller{
27
28 // Check if pro is enabled
29 protected $pro_enabled;
30
31 private static $cache_bank = null;
32
33 /**
34 * Initialize the class
35 *
36 * @since 0.0.1
37 */
38 public function __construct() {
39
40 }
41
42 public function init(){
43 $this->pro_enabled = apply_filters('better_payment/pro_enabled', false);
44
45 new ReactAdmin();
46
47 // Add plugin action links - works with or without Elementor
48 add_filter('plugin_action_links', array($this, 'plugin_actions_links'), 10, 2);
49
50 if ( ! $this->pro_enabled ) {
51 $this->admin_notice();
52 }
53
54 // Usage tracking is NOT registered here any more. It is wired from
55 // Better_Payment::init_plugin() for admin *and* cron requests, because
56 // WP-Cron runs as a non-admin request and this gate hid the tracker's
57 // do_tracking() callback from its own scheduled event. See the note
58 // there. The Pro gate now lives in Helper::start_plugin_tracking().
59
60 add_action('in_admin_header', array( $this, 'hide_admin_notices' ));
61 }
62
63 /**
64 * Add settings page link on plugins page
65 *
66 * @param array $links
67 * @param string $file
68 *
69 * @return array
70 * @since 0.0.1
71 */
72 public function plugin_actions_links($links, $file) {
73 $better_payment_plugin = plugin_basename(BETTER_PAYMENT_FILE);
74
75 if ($file == $better_payment_plugin && current_user_can('manage_options')) {
76 $links[] = sprintf('<a href="%s">%s</a>', admin_url("admin.php?page=better-payment-admin&tab=settings"), __('Settings', 'better-payment'));
77
78 if ( ! $this->pro_enabled ) {
79 $links[] = sprintf('<a href="https://wpdeveloper.com/in/upgrade-better-payment-pro" target="_blank" style="color: #7561F8; font-weight: bold;">' . __('Go Pro', 'better-payment') . '</a>');
80 }
81 }
82
83 return $links;
84 }
85
86 public function admin_notice() {
87 require_once BETTER_PAYMENT_PATH . '/vendor/autoload.php';
88
89 self::$cache_bank = CacheBank::get_instance();
90
91 NoticeRemover::get_instance('1.0.0');
92 NoticeRemover::get_instance('1.0.0', '\WPDeveloper\BetterDocs\Dependencies\PriyoMukul\WPNotice\Notices');
93
94 $notices = new Notices( [
95 'id' => 'better-payment',
96 'storage_key' => 'notices',
97 'lifetime' => 3,
98 'stylesheet_url' => esc_url_raw( BETTER_PAYMENT_URL . '/assets/css/admin.min.css' ),
99 'styles' => esc_url_raw( BETTER_PAYMENT_URL . '/assets/css/admin.min.css' ),
100 'priority' => 9
101 ] );
102
103 $review_notice = 'We hope you\'re enjoying Better Payment! Could you please do us a BIG favor and give it a 5-star rating on WordPress to help us spread the word and boost our motivation?';
104 $_review_notice = [
105 'thumbnail' => plugins_url( 'assets/img/logo.svg', BETTER_PAYMENT_BASENAME ),
106 'html' => '<p>' . $review_notice . '</p>',
107 'links' => [
108 'later' => array(
109 'link' => '//wordpress.org/support/plugin/better-payment/reviews/#new-post',
110 'target' => '_blank',
111 'label' => 'Ok, you deserve it!',
112 'icon_class' => 'dashicons dashicons-external',
113 'attributes' => [
114 'target' => '_blank',
115 ],
116 ),
117 'allready' => array(
118 'label' => 'I already did',
119 'icon_class' => 'dashicons dashicons-smiley',
120 'attributes' => [
121 'data-dismiss' => true
122 ],
123 ),
124 'maybe_later' => array(
125 'label' => 'Maybe Later',
126 'icon_class' => 'dashicons dashicons-calendar-alt',
127 'attributes' => [
128 'data-later' => true
129 ],
130 ),
131 'support' => array(
132 'link' => 'https://wpdeveloper.com/support',
133 'label' => 'I need help',
134 'icon_class' => 'dashicons dashicons-sos',
135 'attributes' => [
136 'target' => '_blank',
137 ],
138 ),
139 'never_show_again' => array(
140 'label' => 'Never show again',
141 'icon_class' => 'dashicons dashicons-dismiss',
142 'attributes' => [
143 'data-dismiss' => true
144 ],
145 )
146 ]
147 ];
148
149 $notices->add(
150 'review',
151 $_review_notice,
152 [
153 'start' => $notices->strtotime( '+7 day' ),
154 'recurrence' => 30,
155 'refresh' => BETTER_PAYMENT_VERSION,
156 'dismissible' => true,
157 ]
158 );
159
160 /**
161 * Summer Offer Notice
162 */
163 $purchase_url = '//betterpayment.co/summer2026-admin-notice';
164 $summer_notice_message = "<p>🏖️ <strong>Summer Savings:</strong> Streamline transactions with fast, optimized payment forms on your WordPress sites – now <strong>up to $150 OFF!</strong> </p><div class='wpsp-notice-action-button' style='display: inline-flex;column-gap:5px;'><a class='button button-primary' href='{$purchase_url}' target='_blank'>Upgrade To Pro Now</a> <button class='wpsp-notice-action-dismiss dismiss-btn' data-dismiss='true' target='_blank'>I Don't Want Any Discount</button></div>";
165
166 $summer_notice = [
167 'thumbnail' => plugins_url( 'assets/img/logo.svg', BETTER_PAYMENT_BASENAME ),
168 'html' => $summer_notice_message,
169 ];
170
171 $notices->add(
172 'bp_summer_notice',
173 $summer_notice,
174 [
175 'start' => $notices->time(),
176 'expire' => strtotime( '11:59:59pm 25th June, 2026' ),
177 'refresh' => BETTER_PAYMENT_VERSION,
178 'dismissible' => true,
179 'screens' => [ 'dashboard' ],
180 ]
181 );
182
183 self::$cache_bank->create_account( $notices );
184 self::$cache_bank->calculate_deposits( $notices );
185 }
186
187 public function hide_admin_notices(){
188 $current_screen = get_current_screen();
189
190 if ($current_screen && (false !== strpos( $current_screen->id, 'better-payment' ) || false !== strpos( $current_screen->id, 'bp-campaign' )) ) {
191 remove_all_actions('user_admin_notices');
192 remove_all_actions('admin_notices');
193 remove_all_actions('all_admin_notices');
194 remove_all_actions('network_admin_notices');
195
196 // To show notice in better payment settings page we have to use 'better_payment_admin_notices' action hook
197 add_action( 'admin_notices', function () {
198 do_action( 'better_payment_admin_notices' );
199 } );
200 }
201 }
202
203 /**
204 * Dispatch and bind actions
205 *
206 * @return void
207 * @since 0.0.1
208 */
209 public static function dispatch_actions( ) {
210 $bpElementorWidgetObj = new Widget();
211
212 $bpImportObj = new Import();
213
214 $bpExportObj = new Export();
215
216 $helperObj = new Helper();
217
218 // Handle select2 ajax search
219 add_action('wp_ajax_better_payment_select2_search_post', [$bpElementorWidgetObj, 'select2_ajax_posts_filter_autocomplete']);
220
221 add_action('wp_ajax_better_payment_select2_get_title', [$bpElementorWidgetObj, 'select2_ajax_get_posts_value_titles']);
222
223 // Elements
224 add_action('elementor/controls/controls_registered',[$bpElementorWidgetObj, 'register_controls']);
225
226 //Page: Transactions
227 add_action('admin_post_better-payment-transactions-import',[$bpImportObj, 'import_transactions']);
228 add_action('wp_ajax_better-payment-transactions-export',[$bpExportObj, 'export_transactions']);
229
230 // Elementor categories
231 add_action('elementor/elements/categories_registered', [$helperObj, 'register_widget_categories']);
232 }
233 }
234