| @@ -1,14 +1,16 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace Better_Payment\Lite; |
| 4 | 4 | |
| 5 | -use Better_Payment\Lite\Admin\Better_Payment_Settings; | |
| 6 | -use Better_Payment\Lite\Admin\Elementor\Better_Payment_Widget; | |
| 5 | +use Better_Payment\Lite\Admin\ReactAdmin; | |
| 7 | 6 | use Better_Payment\Lite\Admin\Elementor\Widget; |
| 8 | -use Better_Payment\Lite\Admin\Menu; | |
| 9 | -use Better_Payment\Lite\Classes\Better_Payment_Helper; | |
| 7 | +use Better_Payment\Lite\Classes\Helper; | |
| 10 | 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; | |
| 11 | 13 | |
| 12 | 14 | /** |
| 13 | 15 | * Exit if accessed directly |
| 14 | 16 | */ |
| @@ -17,9 +19,9 @@ | ||
| 17 | 19 | } |
| 18 | 20 | |
| 19 | 21 | /** |
| 20 | 22 | * The admin class |
| 21 | - * | |
| 23 | + * | |
| 22 | 24 | * @since 0.0.1 |
| 23 | 25 | */ |
| 24 | 26 | class Admin extends Controller{ |
| 25 | 27 | |
| @@ -25,11 +27,13 @@ | ||
| 25 | 27 | |
| 26 | 28 | // Check if pro is enabled |
| 27 | 29 | protected $pro_enabled; |
| 28 | 30 | |
| 31 | + private static $cache_bank = null; | |
| 32 | + | |
| 29 | 33 | /** |
| 30 | 34 | * Initialize the class |
| 31 | - * | |
| 35 | + * | |
| 32 | 36 | * @since 0.0.1 |
| 33 | 37 | */ |
| 34 | 38 | public function __construct() { |
| 35 | 39 | |
| @@ -37,28 +41,32 @@ | ||
| 37 | 41 | |
| 38 | 42 | public function init(){ |
| 39 | 43 | $this->pro_enabled = apply_filters('better_payment/pro_enabled', false); |
| 40 | 44 | |
| 41 | - if ( defined( 'ELEMENTOR_VERSION' ) ) { | |
| 42 | - new Better_Payment_Settings(); | |
| 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(); | |
| 43 | 52 | } |
| 44 | 53 | |
| 45 | - if (!did_action('elementor/loaded')) { | |
| 46 | - $notice = new Better_Payment_Helper(); | |
| 47 | - $notice->elementor_not_loaded(); | |
| 48 | - } | |
| 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(). | |
| 49 | 59 | |
| 50 | - if (did_action('elementor/loaded')) { | |
| 51 | - add_filter('plugin_action_links', array($this, 'plugin_actions_links'), 10, 2); | |
| 52 | - } | |
| 60 | + add_action('in_admin_header', array( $this, 'hide_admin_notices' )); | |
| 53 | 61 | } |
| 54 | 62 | |
| 55 | 63 | /** |
| 56 | 64 | * Add settings page link on plugins page |
| 57 | - * | |
| 65 | + * | |
| 58 | 66 | * @param array $links |
| 59 | 67 | * @param string $file |
| 60 | - * | |
| 68 | + * | |
| 61 | 69 | * @return array |
| 62 | 70 | * @since 0.0.1 |
| 63 | 71 | */ |
| 64 | 72 | public function plugin_actions_links($links, $file) { |
| @@ -64,9 +72,9 @@ | ||
| 64 | 72 | public function plugin_actions_links($links, $file) { |
| 65 | 73 | $better_payment_plugin = plugin_basename(BETTER_PAYMENT_FILE); |
| 66 | 74 | |
| 67 | 75 | if ($file == $better_payment_plugin && current_user_can('manage_options')) { |
| 68 | - $links[] = sprintf('<a href="%s">%s</a>', admin_url("admin.php?page=better-payment-settings"), __('Settings', 'better-payment')); | |
| 76 | + $links[] = sprintf('<a href="%s">%s</a>', admin_url("admin.php?page=better-payment-admin&tab=settings"), __('Settings', 'better-payment')); | |
| 69 | 77 | |
| 70 | 78 | if ( ! $this->pro_enabled ) { |
| 71 | 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>'); |
| 72 | 80 | } |
| @@ -74,8 +82,125 @@ | ||
| 74 | 82 | |
| 75 | 83 | return $links; |
| 76 | 84 | } |
| 77 | 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 | + | |
| 78 | 203 | /** |
| 79 | 204 | * Dispatch and bind actions |
| 80 | 205 | * |
| 81 | 206 | * @return void |
| @@ -81,25 +206,28 @@ | ||
| 81 | 206 | * @return void |
| 82 | 207 | * @since 0.0.1 |
| 83 | 208 | */ |
| 84 | 209 | public static function dispatch_actions( ) { |
| 85 | - $menuObj = new Menu(); | |
| 86 | - $menuObj->init(); | |
| 87 | - | |
| 88 | 210 | $bpElementorWidgetObj = new Widget(); |
| 89 | 211 | |
| 212 | + $bpImportObj = new Import(); | |
| 213 | + | |
| 90 | 214 | $bpExportObj = new Export(); |
| 91 | 215 | |
| 216 | + $helperObj = new Helper(); | |
| 217 | + | |
| 92 | 218 | // Handle select2 ajax search |
| 93 | 219 | add_action('wp_ajax_better_payment_select2_search_post', [$bpElementorWidgetObj, 'select2_ajax_posts_filter_autocomplete']); |
| 94 | - add_action('wp_ajax_nopriv_better_payment_select2_search_post', [$bpElementorWidgetObj, 'select2_ajax_posts_filter_autocomplete']); | |
| 95 | 220 | |
| 96 | 221 | add_action('wp_ajax_better_payment_select2_get_title', [$bpElementorWidgetObj, 'select2_ajax_get_posts_value_titles']); |
| 97 | - add_action('wp_ajax_nopriv_better_payment_select2_get_title', [$bpElementorWidgetObj, 'select2_ajax_get_posts_value_titles']); | |
| 98 | 222 | |
| 99 | 223 | // Elements |
| 100 | 224 | add_action('elementor/controls/controls_registered',[$bpElementorWidgetObj, 'register_controls']); |
| 101 | 225 | |
| 102 | 226 | //Page: Transactions |
| 227 | + add_action('admin_post_better-payment-transactions-import',[$bpImportObj, 'import_transactions']); | |
| 103 | 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']); | |
| 104 | 232 | } |
| 105 | 233 | } |