| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: Better Payment |
| 4 |
* 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. |
| 5 |
* Plugin URI: https://wpdeveloper.net/ |
| 6 |
* Author: WPDeveloper |
| 7 |
* Version: 0.0.2 |
| 8 |
* Author URI: https://wpdeveloper.net/ |
| 9 |
* Text Domain: better-payment |
| 10 |
* Domain Path: /languages |
| 11 |
*/ |
| 12 |
|
| 13 |
if ( !defined( 'ABSPATH' ) ) { |
| 14 |
exit; |
| 15 |
} // Exit if accessed directly |
| 16 |
|
| 17 |
class Better_Payment { |
| 18 |
|
| 19 |
private static $instance; |
| 20 |
|
| 21 |
public static function init() { |
| 22 |
if ( !isset( self::$instance ) && !( self::$instance instanceof Better_Payment ) ) { |
| 23 |
self::$instance = new self(); |
| 24 |
} |
| 25 |
|
| 26 |
return self::$instance; |
| 27 |
} |
| 28 |
|
| 29 |
public function __construct() { |
| 30 |
add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_scripts' ] ); |
| 31 |
$this->define_constants(); |
| 32 |
$this->init_plugin(); |
| 33 |
|
| 34 |
if (is_admin()) { |
| 35 |
if ( defined( 'ELEMENTOR_VERSION' ) ) { |
| 36 |
new Better_Payment_Settings(); |
| 37 |
} |
| 38 |
|
| 39 |
require 'admin/includes/class-better-payment-helper.php'; |
| 40 |
|
| 41 |
if (!did_action('elementor/loaded')) { |
| 42 |
$notice = new Better_Payment_Helper(); |
| 43 |
$notice->elementor_not_loaded(); |
| 44 |
} |
| 45 |
|
| 46 |
if (did_action('elementor/loaded')) { |
| 47 |
add_filter('plugin_action_links', array($this, 'plugin_actions_links'), 10, 2); |
| 48 |
} |
| 49 |
} |
| 50 |
} |
| 51 |
|
| 52 |
public function define_constants() { |
| 53 |
define( 'BETTER_PAYMENT_VERSION', '0.0.2' ); |
| 54 |
define( 'BETTER_PAYMENT_FILE', __FILE__ ); |
| 55 |
define( 'BETTER_PAYMENT_BASENAME', plugin_basename( __FILE__ ) ); |
| 56 |
define( 'BETTER_PAYMENT_PATH', trailingslashit( plugin_dir_path( __FILE__ ) ) ); |
| 57 |
define( 'BETTER_PAYMENT_URL', trailingslashit( plugins_url( '/', __FILE__ ) ) ); |
| 58 |
define( 'BETTER_PAYMENT_ADMIN_PATH', BETTER_PAYMENT_PATH.'admin/'); |
| 59 |
define( 'BETTER_PAYMENT_ADMIN_INCLUDES_PATH', BETTER_PAYMENT_PATH.'admin/includes/'); |
| 60 |
define( 'BETTER_PAYMENT_ADMIN_VIEW_PATH', BETTER_PAYMENT_PATH.'admin/views/'); |
| 61 |
define( 'BETTER_PAYMENT_ADMIN_URL', BETTER_PAYMENT_URL.'admin/'); |
| 62 |
define( 'BETTER_PAYMENT_ADMIN_INCLUDES_URL', BETTER_PAYMENT_URL.'admin/includes/'); |
| 63 |
define( 'BETTER_PAYMENT_ADMIN_VIEW_URL', BETTER_PAYMENT_URL.'admin/views/'); |
| 64 |
define( 'BETTER_PAYMENT_ADMIN_ASSET_URL', BETTER_PAYMENT_URL.'admin/asset/'); |
| 65 |
|
| 66 |
} |
| 67 |
|
| 68 |
public function enqueue_scripts() { |
| 69 |
wp_register_script( 'better-payment-stripe', 'https://js.stripe.com/v3/' ); |
| 70 |
wp_register_script( 'better-payment', BETTER_PAYMENT_URL . 'asset/js/better-payment.min.js', [ |
| 71 |
'jquery', |
| 72 |
'better-payment-stripe' |
| 73 |
], BETTER_PAYMENT_VERSION, true ); |
| 74 |
wp_register_style( 'better-payment-el', BETTER_PAYMENT_URL . 'asset/css/better-payment-el.min.css' ); |
| 75 |
wp_localize_script( 'better-payment', 'betterPayment', array( |
| 76 |
'ajax_url' => admin_url( 'admin-ajax.php' ), |
| 77 |
'nonce' => wp_create_nonce( 'better-payment' ), |
| 78 |
) ); |
| 79 |
|
| 80 |
wp_enqueue_style( 'toastr-css', BETTER_PAYMENT_URL . 'asset/vendor/toastr/css/toastr.min.css' ); |
| 81 |
wp_enqueue_script( 'toastr-js', BETTER_PAYMENT_URL . 'asset/vendor/toastr/js/toastr.min.js', array( 'jquery' ), BETTER_PAYMENT_VERSION, true ); |
| 82 |
|
| 83 |
do_action('better_payment/frontend/after_enqueue_scripts'); |
| 84 |
} |
| 85 |
|
| 86 |
/** |
| 87 |
* Activate plugin. |
| 88 |
* |
| 89 |
* @return void |
| 90 |
* @since 0.0.2 |
| 91 |
*/ |
| 92 |
public function activate_plugin() { |
| 93 |
require 'includes/class-better-payment-installer.php'; |
| 94 |
Better_Payment_Installer::install(); |
| 95 |
} |
| 96 |
|
| 97 |
public function init_plugin() { |
| 98 |
if ( defined( 'ELEMENTOR_VERSION' ) ) { |
| 99 |
require_once 'includes/class-better-payment-handler.php'; |
| 100 |
require_once 'includes/class-better-payment-actions.php'; |
| 101 |
require_once 'includes/elementor/class-better-payment-el-integration.php'; |
| 102 |
|
| 103 |
$better_action = new Better_Payment_Actions(); |
| 104 |
$el_integration = new Better_Payment_EL_integration(); |
| 105 |
$el_integration->init(); |
| 106 |
|
| 107 |
require_once 'admin/includes/class-better-payment-settings.php'; |
| 108 |
require_once 'admin/includes/class-better-payment-db.php'; |
| 109 |
|
| 110 |
Better_Payment_Settings::save_default_settings(); |
| 111 |
} |
| 112 |
} |
| 113 |
|
| 114 |
/** |
| 115 |
* Add settings page link on plugins page |
| 116 |
*/ |
| 117 |
public function plugin_actions_links($links, $file) |
| 118 |
{ |
| 119 |
$better_payment_plugin = plugin_basename(__FILE__); |
| 120 |
|
| 121 |
if ($file == $better_payment_plugin && current_user_can('manage_options')) { |
| 122 |
$links[] = sprintf('<a href="%s">%s</a>', admin_url("admin.php?page=better-payment-settings"), __('Settings', 'better-payment')); |
| 123 |
} |
| 124 |
|
| 125 |
return $links; |
| 126 |
} |
| 127 |
} |
| 128 |
|
| 129 |
register_activation_hook( __FILE__, 'better_payment_activate' ); |
| 130 |
|
| 131 |
function better_payment_activate() { |
| 132 |
require 'includes/class-better-payment-installer.php'; |
| 133 |
Better_Payment_Installer::install(); |
| 134 |
} |
| 135 |
|
| 136 |
add_action( 'plugins_loaded', function () { |
| 137 |
Better_Payment::init(); |
| 138 |
} ); |
| 139 |
|
| 140 |
/** |
| 141 |
* Plugin migrator |
| 142 |
* |
| 143 |
* @since 0.0.2 |
| 144 |
*/ |
| 145 |
function better_payment_migrator() { |
| 146 |
require 'includes/class-better-payment-migrator.php'; |
| 147 |
Better_Payment_Migrator::migrator(); |
| 148 |
} |
| 149 |
|
| 150 |
add_action( 'wp_loaded', function () { |
| 151 |
if (get_option('better_payment_version') != BETTER_PAYMENT_VERSION) { |
| 152 |
better_payment_migrator(); |
| 153 |
update_option('better_payment_version', BETTER_PAYMENT_VERSION); |
| 154 |
} |
| 155 |
|
| 156 |
$setup_wizard = get_option( 'better_payment_setup_wizard' ); |
| 157 |
|
| 158 |
require_once 'admin/includes/class-better-payment-settings.php'; |
| 159 |
require_once 'admin/includes/class-better-payment-db.php'; |
| 160 |
require_once 'admin/includes/class-better-payment-setup-wizard.php'; |
| 161 |
|
| 162 |
if ( $setup_wizard == 'redirect' ) { |
| 163 |
Better_Payment_Setup_Wizard::redirect(); |
| 164 |
} |
| 165 |
|
| 166 |
if ( $setup_wizard == 'init' ) { |
| 167 |
new Better_Payment_Setup_Wizard(); |
| 168 |
} |
| 169 |
} ); |