| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Plugin Name: Better Payment |
| 5 |
* Description: Make instant payment with one click through Better Payment. It offers seamless integrations with Elementor and allows you to get payment through PayPal and Stripe. |
| 6 |
* Plugin URI: https://wpdeveloper.com/ |
| 7 |
* Author: WPDeveloper |
| 8 |
* Version: 0.0.4 |
| 9 |
* Author URI: https://wpdeveloper.com/ |
| 10 |
* Text Domain: better-payment |
| 11 |
* Domain Path: /languages |
| 12 |
*/ |
| 13 |
|
| 14 |
if (!defined('ABSPATH')) { |
| 15 |
exit; |
| 16 |
} // Exit if accessed directly |
| 17 |
|
| 18 |
require_once __DIR__ . '/vendor/autoload.php'; |
| 19 |
|
| 20 |
/** |
| 21 |
* The plugin main class |
| 22 |
* |
| 23 |
* @since 0.0.1 |
| 24 |
*/ |
| 25 |
final class Better_Payment { |
| 26 |
|
| 27 |
/** |
| 28 |
* Plugin version |
| 29 |
* |
| 30 |
* @var string |
| 31 |
* @since 0.0.1 |
| 32 |
*/ |
| 33 |
const version = '0.0.4'; |
| 34 |
|
| 35 |
/** |
| 36 |
* Class construcotr |
| 37 |
* |
| 38 |
* @since 0.0.1 |
| 39 |
*/ |
| 40 |
private function __construct() { |
| 41 |
$this->define_constants(); |
| 42 |
|
| 43 |
register_activation_hook(__FILE__, [$this, 'activate']); |
| 44 |
|
| 45 |
add_action('plugins_loaded', [$this, 'init_plugin']); |
| 46 |
} |
| 47 |
|
| 48 |
/** |
| 49 |
* Initialize a singleton instance |
| 50 |
* |
| 51 |
* @return \Better_Payment |
| 52 |
* @since 0.0.1 |
| 53 |
*/ |
| 54 |
public static function init() { |
| 55 |
static $instance = false; |
| 56 |
|
| 57 |
if (!$instance) { |
| 58 |
$instance = new self(); |
| 59 |
} |
| 60 |
|
| 61 |
return $instance; |
| 62 |
} |
| 63 |
|
| 64 |
/** |
| 65 |
* Define the required plugin constants |
| 66 |
* |
| 67 |
* @return void |
| 68 |
* @since 0.0.1 |
| 69 |
*/ |
| 70 |
public function define_constants() { |
| 71 |
define('BETTER_PAYMENT_VERSION', self::version); |
| 72 |
define('BETTER_PAYMENT_FILE', __FILE__); |
| 73 |
define('BETTER_PAYMENT_PATH', __DIR__); |
| 74 |
define('BETTER_PAYMENT_URL', plugins_url('', BETTER_PAYMENT_FILE)); |
| 75 |
define('BETTER_PAYMENT_ASSETS', BETTER_PAYMENT_URL . '/assets'); |
| 76 |
define('BETTER_PAYMENT_ASSETS_PATH', BETTER_PAYMENT_PATH . '/assets'); |
| 77 |
define('BETTER_PAYMENT_DEV_ASSETS', BETTER_PAYMENT_URL . '/bpbuild'); |
| 78 |
define('BETTER_PAYMENT_DEV_ASSETS_PATH', BETTER_PAYMENT_PATH . '/bpbuild'); |
| 79 |
define('BETTER_PAYMENT_INCLUDES_PATH', BETTER_PAYMENT_PATH . '/includes'); |
| 80 |
define('BETTER_PAYMENT_ADMIN_PATH', BETTER_PAYMENT_INCLUDES_PATH . '/Admin'); |
| 81 |
define('BETTER_PAYMENT_ADMIN_VIEWS_PATH', BETTER_PAYMENT_ADMIN_PATH . '/views'); |
| 82 |
} |
| 83 |
|
| 84 |
/** |
| 85 |
* Do stuff upon plugin activation |
| 86 |
* |
| 87 |
* @return void |
| 88 |
* @since 0.0.1 |
| 89 |
*/ |
| 90 |
public function activate() { |
| 91 |
$installer = new Better_Payment\Lite\Installer(); |
| 92 |
$installer->run(); |
| 93 |
} |
| 94 |
|
| 95 |
/** |
| 96 |
* Initialize the plugin |
| 97 |
* |
| 98 |
* @return void |
| 99 |
* @since 0.0.1 |
| 100 |
*/ |
| 101 |
public function init_plugin() { |
| 102 |
new Better_Payment\Lite\Assets(); |
| 103 |
|
| 104 |
if (defined('DOING_AJAX') && DOING_AJAX) { |
| 105 |
new Better_Payment\Lite\Ajax(); |
| 106 |
} |
| 107 |
|
| 108 |
if (is_admin()) { |
| 109 |
$adminObj = new Better_Payment\Lite\Admin(); |
| 110 |
$adminObj->init(); |
| 111 |
} else { |
| 112 |
new Better_Payment\Lite\Frontend(); |
| 113 |
} |
| 114 |
|
| 115 |
new Better_Payment\Lite\API(); |
| 116 |
|
| 117 |
if (defined('ELEMENTOR_VERSION')) { |
| 118 |
new Better_Payment\Lite\Classes\Better_Payment_Actions(); |
| 119 |
$el_integration = new Better_Payment\Lite\Admin\Elementor\Better_Payment_EL_Integration(); |
| 120 |
$el_integration->init(); |
| 121 |
|
| 122 |
Better_Payment\Lite\Admin\Better_Payment_Settings::save_default_settings(); |
| 123 |
} |
| 124 |
} |
| 125 |
} |
| 126 |
|
| 127 |
/** |
| 128 |
* Initializes the main plugin |
| 129 |
* |
| 130 |
* @return \Better_Payment |
| 131 |
* @since 0.0.1 |
| 132 |
*/ |
| 133 |
|
| 134 |
Better_Payment::init(); |
| 135 |
|
| 136 |
/** |
| 137 |
* Plugin migrator |
| 138 |
* |
| 139 |
* @since 0.0.2 |
| 140 |
*/ |
| 141 |
function better_payment_migrator() { |
| 142 |
Better_Payment\Lite\Classes\Better_Payment_Migrator::migrator(); |
| 143 |
} |
| 144 |
|
| 145 |
|
| 146 |
/** |
| 147 |
* On wp load |
| 148 |
* |
| 149 |
* @return void |
| 150 |
* @since 0.0.1 |
| 151 |
*/ |
| 152 |
add_action('wp_loaded', function () { |
| 153 |
if (get_option('better_payment_version') != BETTER_PAYMENT_VERSION) { |
| 154 |
better_payment_migrator(); |
| 155 |
update_option('better_payment_version', BETTER_PAYMENT_VERSION); |
| 156 |
} |
| 157 |
|
| 158 |
$setup_wizard = get_option('better_payment_setup_wizard'); |
| 159 |
|
| 160 |
if ($setup_wizard == 'redirect') { |
| 161 |
Better_Payment\Lite\Admin\Better_Payment_Setup_Wizard::redirect(); |
| 162 |
} |
| 163 |
|
| 164 |
if ($setup_wizard == 'init') { |
| 165 |
new Better_Payment\Lite\Admin\Better_Payment_Setup_Wizard(); |
| 166 |
} |
| 167 |
}); |
| 168 |
|
| 169 |
/** |
| 170 |
* Dispatch actions |
| 171 |
* |
| 172 |
* @since 0.0.1 |
| 173 |
*/ |
| 174 |
\Better_Payment\Lite\Admin::dispatch_actions(); |
| 175 |
|