| 1 |
<?php |
| 2 |
|
| 3 |
namespace Better_Payment\Lite; |
| 4 |
|
| 5 |
use Better_Payment\Lite\Admin\Better_Payment_Settings; |
| 6 |
use Better_Payment\Lite\Admin\Elementor\Better_Payment_Widget; |
| 7 |
use Better_Payment\Lite\Admin\Elementor\Widget; |
| 8 |
use Better_Payment\Lite\Admin\Menu; |
| 9 |
use Better_Payment\Lite\Classes\Better_Payment_Helper; |
| 10 |
use Better_Payment\Lite\Classes\Export; |
| 11 |
use PriyoMukul\WPNotice\Notices; |
| 12 |
use PriyoMukul\WPNotice\Utils\CacheBank; |
| 13 |
use PriyoMukul\WPNotice\Utils\NoticeRemover; |
| 14 |
|
| 15 |
/** |
| 16 |
* Exit if accessed directly |
| 17 |
*/ |
| 18 |
if (!defined('ABSPATH')) { |
| 19 |
exit; |
| 20 |
} |
| 21 |
|
| 22 |
/** |
| 23 |
* The admin class |
| 24 |
* |
| 25 |
* @since 0.0.1 |
| 26 |
*/ |
| 27 |
class Admin extends Controller{ |
| 28 |
|
| 29 |
// Check if pro is enabled |
| 30 |
protected $pro_enabled; |
| 31 |
|
| 32 |
private static $cache_bank = null; |
| 33 |
|
| 34 |
/** |
| 35 |
* Initialize the class |
| 36 |
* |
| 37 |
* @since 0.0.1 |
| 38 |
*/ |
| 39 |
public function __construct() { |
| 40 |
|
| 41 |
} |
| 42 |
|
| 43 |
public function init(){ |
| 44 |
$this->pro_enabled = apply_filters('better_payment/pro_enabled', false); |
| 45 |
|
| 46 |
if ( defined( 'ELEMENTOR_VERSION' ) ) { |
| 47 |
new Better_Payment_Settings(); |
| 48 |
} |
| 49 |
|
| 50 |
if (!did_action('elementor/loaded')) { |
| 51 |
$notice = new Better_Payment_Helper(); |
| 52 |
$notice->elementor_not_loaded(); |
| 53 |
} |
| 54 |
|
| 55 |
if (did_action('elementor/loaded')) { |
| 56 |
add_filter('plugin_action_links', array($this, 'plugin_actions_links'), 10, 2); |
| 57 |
} |
| 58 |
|
| 59 |
if ( ! $this->pro_enabled ) { |
| 60 |
$this->admin_notice(); |
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
/** |
| 65 |
* Add settings page link on plugins page |
| 66 |
* |
| 67 |
* @param array $links |
| 68 |
* @param string $file |
| 69 |
* |
| 70 |
* @return array |
| 71 |
* @since 0.0.1 |
| 72 |
*/ |
| 73 |
public function plugin_actions_links($links, $file) { |
| 74 |
$better_payment_plugin = plugin_basename(BETTER_PAYMENT_FILE); |
| 75 |
|
| 76 |
if ($file == $better_payment_plugin && current_user_can('manage_options')) { |
| 77 |
$links[] = sprintf('<a href="%s">%s</a>', admin_url("admin.php?page=better-payment-settings"), __('Settings', 'better-payment')); |
| 78 |
|
| 79 |
if ( ! $this->pro_enabled ) { |
| 80 |
$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>'); |
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
return $links; |
| 85 |
} |
| 86 |
|
| 87 |
public function admin_notice() { |
| 88 |
require_once BETTER_PAYMENT_PATH . '/vendor/autoload.php'; |
| 89 |
|
| 90 |
self::$cache_bank = CacheBank::get_instance(); |
| 91 |
|
| 92 |
NoticeRemover::get_instance('1.0.0'); |
| 93 |
NoticeRemover::get_instance('1.0.0', '\WPDeveloper\BetterDocs\Dependencies\PriyoMukul\WPNotice\Notices'); |
| 94 |
|
| 95 |
$notices = new Notices( [ |
| 96 |
'id' => 'better-payment', |
| 97 |
'storage_key' => 'notices', |
| 98 |
'lifetime' => 3, |
| 99 |
'stylesheet_url' => esc_url_raw( BETTER_PAYMENT_URL . '/assets/css/admin.min.css' ), |
| 100 |
'styles' => esc_url_raw( BETTER_PAYMENT_URL . '/assets/css/admin.min.css' ), |
| 101 |
'priority' => 9 |
| 102 |
] ); |
| 103 |
|
| 104 |
$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?', 'better-payment' ); |
| 105 |
$_review_notice = [ |
| 106 |
'thumbnail' => plugins_url( 'assets/img/logo.svg', BETTER_PAYMENT_BASENAME ), |
| 107 |
'html' => '<p>' . $review_notice . '</p>', |
| 108 |
'links' => [ |
| 109 |
'later' => array( |
| 110 |
'link' => '//wordpress.org/support/plugin/better-payment/reviews/#new-post', |
| 111 |
'target' => '_blank', |
| 112 |
'label' => __( 'Ok, you deserve it!', 'better-payment' ), |
| 113 |
'icon_class' => 'dashicons dashicons-external', |
| 114 |
'attributes' => [ |
| 115 |
'target' => '_blank', |
| 116 |
], |
| 117 |
), |
| 118 |
'allready' => array( |
| 119 |
'label' => __( 'I already did', 'better-payment' ), |
| 120 |
'icon_class' => 'dashicons dashicons-smiley', |
| 121 |
'attributes' => [ |
| 122 |
'data-dismiss' => true |
| 123 |
], |
| 124 |
), |
| 125 |
'maybe_later' => array( |
| 126 |
'label' => __( 'Maybe Later', 'better-payment' ), |
| 127 |
'icon_class' => 'dashicons dashicons-calendar-alt', |
| 128 |
'attributes' => [ |
| 129 |
'data-later' => true |
| 130 |
], |
| 131 |
), |
| 132 |
'support' => array( |
| 133 |
'link' => 'https://wpdeveloper.com/support', |
| 134 |
'label' => __( 'I need help', 'better-payment' ), |
| 135 |
'icon_class' => 'dashicons dashicons-sos', |
| 136 |
'attributes' => [ |
| 137 |
'target' => '_blank', |
| 138 |
], |
| 139 |
), |
| 140 |
'never_show_again' => array( |
| 141 |
'label' => __( 'Never show again', 'better-payment' ), |
| 142 |
'icon_class' => 'dashicons dashicons-dismiss', |
| 143 |
'attributes' => [ |
| 144 |
'data-dismiss' => true |
| 145 |
], |
| 146 |
) |
| 147 |
] |
| 148 |
]; |
| 149 |
|
| 150 |
$notices->add( |
| 151 |
'review', |
| 152 |
$_review_notice, |
| 153 |
[ |
| 154 |
'start' => $notices->strtotime( '+7 day' ), |
| 155 |
'recurrence' => 30, |
| 156 |
'refresh' => BETTER_PAYMENT_VERSION, |
| 157 |
'dismissible' => true, |
| 158 |
] |
| 159 |
); |
| 160 |
|
| 161 |
self::$cache_bank->create_account( $notices ); |
| 162 |
self::$cache_bank->calculate_deposits( $notices ); |
| 163 |
} |
| 164 |
|
| 165 |
/** |
| 166 |
* Dispatch and bind actions |
| 167 |
* |
| 168 |
* @return void |
| 169 |
* @since 0.0.1 |
| 170 |
*/ |
| 171 |
public static function dispatch_actions( ) { |
| 172 |
$menuObj = new Menu(); |
| 173 |
$menuObj->init(); |
| 174 |
|
| 175 |
$bpElementorWidgetObj = new Widget(); |
| 176 |
|
| 177 |
$bpExportObj = new Export(); |
| 178 |
|
| 179 |
// Handle select2 ajax search |
| 180 |
add_action('wp_ajax_better_payment_select2_search_post', [$bpElementorWidgetObj, 'select2_ajax_posts_filter_autocomplete']); |
| 181 |
|
| 182 |
add_action('wp_ajax_better_payment_select2_get_title', [$bpElementorWidgetObj, 'select2_ajax_get_posts_value_titles']); |
| 183 |
|
| 184 |
// Elements |
| 185 |
add_action('elementor/controls/controls_registered',[$bpElementorWidgetObj, 'register_controls']); |
| 186 |
|
| 187 |
//Page: Transactions |
| 188 |
add_action('wp_ajax_better-payment-transactions-export',[$bpExportObj, 'export_transactions']); |
| 189 |
} |
| 190 |
} |
| 191 |
|