| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: Better Payment |
| 4 |
* Description: Make instant payment with one click through BetterPayment. 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.1 |
| 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 BetterPayment { |
| 18 |
|
| 19 |
private static $instance; |
| 20 |
|
| 21 |
public static function init() { |
| 22 |
if ( !isset( self::$instance ) && !( self::$instance instanceof BetterPayment ) ) { |
| 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 BetterPayment_Settings(); |
| 37 |
} |
| 38 |
|
| 39 |
require 'admin/includes/class-betterpayment-helper.php'; |
| 40 |
|
| 41 |
if (!did_action('elementor/loaded')) { |
| 42 |
$notice = new BetterPayment_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( 'WPBP_PLUGIN_VERSION', '0.0.1' ); |
| 54 |
define( 'WPBP_PLUGIN_FILE', __FILE__ ); |
| 55 |
define( 'WPBP_PLUGIN_BASENAME', plugin_basename( __FILE__ ) ); |
| 56 |
define( 'WPBP_PLUGIN_PATH', trailingslashit( plugin_dir_path( __FILE__ ) ) ); |
| 57 |
define( 'WPBP_PLUGIN_URL', trailingslashit( plugins_url( '/', __FILE__ ) ) ); |
| 58 |
define( 'WPBP_ADMIN_PATH', WPBP_PLUGIN_PATH.'admin/'); |
| 59 |
define( 'WPBP_ADMIN_INCLUDES_PATH', WPBP_PLUGIN_PATH.'admin/includes/'); |
| 60 |
define( 'WPBP_ADMIN_VIEW_PATH', WPBP_PLUGIN_PATH.'admin/views/'); |
| 61 |
define( 'WPBP_ADMIN_URL', WPBP_PLUGIN_URL.'admin/'); |
| 62 |
define( 'WPBP_ADMIN_INCLUDES_URL', WPBP_PLUGIN_URL.'admin/includes/'); |
| 63 |
define( 'WPBP_ADMIN_VIEW_URL', WPBP_PLUGIN_URL.'admin/views/'); |
| 64 |
define( 'WPBP_ADMIN_ASSET_URL', WPBP_PLUGIN_URL.'admin/asset/'); |
| 65 |
|
| 66 |
} |
| 67 |
|
| 68 |
public function enqueue_scripts() { |
| 69 |
wp_register_script( 'betterpayment-stripe', 'https://js.stripe.com/v3/' ); |
| 70 |
wp_register_script( 'betterpayment', WPBP_PLUGIN_URL . 'asset/js/betterpayment.min.js', [ |
| 71 |
'jquery', |
| 72 |
'betterpayment-stripe' |
| 73 |
], WPBP_PLUGIN_VERSION, true ); |
| 74 |
wp_register_style( 'betterpayment-el', WPBP_PLUGIN_URL . 'asset/css/betterpayment-el.min.css' ); |
| 75 |
wp_localize_script( 'betterpayment', 'betterpayment', array( |
| 76 |
'ajax_url' => admin_url( 'admin-ajax.php' ), |
| 77 |
'nonce' => wp_create_nonce( 'betterpayment' ), |
| 78 |
) ); |
| 79 |
|
| 80 |
wp_enqueue_style( 'toastr-css', WPBP_PLUGIN_URL . 'asset/vendor/toastr/css/toastr.min.css' ); |
| 81 |
wp_enqueue_script( 'toastr-js', WPBP_PLUGIN_URL . 'asset/vendor/toastr/js/toastr.min.js', array( 'jquery' ), WPBP_PLUGIN_VERSION, true ); |
| 82 |
|
| 83 |
} |
| 84 |
|
| 85 |
/** |
| 86 |
* Activate plugin. |
| 87 |
* |
| 88 |
* @return void |
| 89 |
* @since 1.0.0 |
| 90 |
*/ |
| 91 |
public function activate_plugin() { |
| 92 |
require 'includes/class-betterpayment-installer.php'; |
| 93 |
BetterPayment_Installer::install(); |
| 94 |
} |
| 95 |
|
| 96 |
public function init_plugin() { |
| 97 |
if ( defined( 'ELEMENTOR_VERSION' ) ) { |
| 98 |
require_once 'includes/class-betterpayment-handler.php'; |
| 99 |
require_once 'includes/class-betterpayment-actions.php'; |
| 100 |
require_once 'includes/elementor/class-betterpayment-el-integration.php'; |
| 101 |
|
| 102 |
$better_action = new BetterPayment_Actions(); |
| 103 |
$el_integration = new BetterPayment_EL_integration(); |
| 104 |
$el_integration->init(); |
| 105 |
|
| 106 |
require_once 'admin/includes/class-betterpayment-settings.php'; |
| 107 |
require_once 'admin/includes/class-betterpayment-db.php'; |
| 108 |
|
| 109 |
BetterPayment_Settings::save_default_settings(); |
| 110 |
} |
| 111 |
} |
| 112 |
|
| 113 |
/** |
| 114 |
* Add settings page link on plugins page |
| 115 |
*/ |
| 116 |
public function plugin_actions_links($links, $file) |
| 117 |
{ |
| 118 |
$betterpayment_plugin = plugin_basename(__FILE__); |
| 119 |
|
| 120 |
if ($file == $betterpayment_plugin && current_user_can('manage_options')) { |
| 121 |
$links[] = sprintf('<a href="%s">%s</a>', admin_url("admin.php?page=betterpayment-settings"), __('Settings', 'better-payment')); |
| 122 |
} |
| 123 |
|
| 124 |
return $links; |
| 125 |
} |
| 126 |
|
| 127 |
} |
| 128 |
|
| 129 |
register_activation_hook( __FILE__, 'wp_better_plugin_activate' ); |
| 130 |
|
| 131 |
function wp_better_plugin_activate() { |
| 132 |
require 'includes/class-betterpayment-installer.php'; |
| 133 |
BetterPayment_Installer::install(); |
| 134 |
} |
| 135 |
|
| 136 |
add_action( 'plugins_loaded', function () { |
| 137 |
BetterPayment::init(); |
| 138 |
} ); |
| 139 |
|
| 140 |
/** |
| 141 |
* Plugin migrator |
| 142 |
* |
| 143 |
* @since 1.0.0 |
| 144 |
*/ |
| 145 |
add_action('wp_loaded', function () { |
| 146 |
// set current version to db |
| 147 |
if (get_option('wpbp_version') != WPBP_PLUGIN_VERSION) { |
| 148 |
// update plugin version |
| 149 |
update_option('wpbp_version', WPBP_PLUGIN_VERSION); |
| 150 |
} |
| 151 |
}); |