define_constants(); $this->init_plugin(); if (is_admin()) { if ( defined( 'ELEMENTOR_VERSION' ) ) { new BetterPayment_Settings(); } require 'admin/includes/class-betterpayment-helper.php'; if (!did_action('elementor/loaded')) { $notice = new BetterPayment_Helper(); $notice->elementor_not_loaded(); } if (did_action('elementor/loaded')) { add_filter('plugin_action_links', array($this, 'plugin_actions_links'), 10, 2); } } } public function define_constants() { define( 'WPBP_PLUGIN_VERSION', '0.0.1' ); define( 'WPBP_PLUGIN_FILE', __FILE__ ); define( 'WPBP_PLUGIN_BASENAME', plugin_basename( __FILE__ ) ); define( 'WPBP_PLUGIN_PATH', trailingslashit( plugin_dir_path( __FILE__ ) ) ); define( 'WPBP_PLUGIN_URL', trailingslashit( plugins_url( '/', __FILE__ ) ) ); define( 'WPBP_ADMIN_PATH', WPBP_PLUGIN_PATH.'admin/'); define( 'WPBP_ADMIN_INCLUDES_PATH', WPBP_PLUGIN_PATH.'admin/includes/'); define( 'WPBP_ADMIN_VIEW_PATH', WPBP_PLUGIN_PATH.'admin/views/'); define( 'WPBP_ADMIN_URL', WPBP_PLUGIN_URL.'admin/'); define( 'WPBP_ADMIN_INCLUDES_URL', WPBP_PLUGIN_URL.'admin/includes/'); define( 'WPBP_ADMIN_VIEW_URL', WPBP_PLUGIN_URL.'admin/views/'); define( 'WPBP_ADMIN_ASSET_URL', WPBP_PLUGIN_URL.'admin/asset/'); } public function enqueue_scripts() { wp_register_script( 'betterpayment-stripe', 'https://js.stripe.com/v3/' ); wp_register_script( 'betterpayment', WPBP_PLUGIN_URL . 'asset/js/betterpayment.min.js', [ 'jquery', 'betterpayment-stripe' ], WPBP_PLUGIN_VERSION, true ); wp_register_style( 'betterpayment-el', WPBP_PLUGIN_URL . 'asset/css/betterpayment-el.min.css' ); wp_localize_script( 'betterpayment', 'betterpayment', array( 'ajax_url' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'betterpayment' ), ) ); wp_enqueue_style( 'toastr-css', WPBP_PLUGIN_URL . 'asset/vendor/toastr/css/toastr.min.css' ); wp_enqueue_script( 'toastr-js', WPBP_PLUGIN_URL . 'asset/vendor/toastr/js/toastr.min.js', array( 'jquery' ), WPBP_PLUGIN_VERSION, true ); } /** * Activate plugin. * * @return void * @since 1.0.0 */ public function activate_plugin() { require 'includes/class-betterpayment-installer.php'; BetterPayment_Installer::install(); } public function init_plugin() { if ( defined( 'ELEMENTOR_VERSION' ) ) { require_once 'includes/class-betterpayment-handler.php'; require_once 'includes/class-betterpayment-actions.php'; require_once 'includes/elementor/class-betterpayment-el-integration.php'; $better_action = new BetterPayment_Actions(); $el_integration = new BetterPayment_EL_integration(); $el_integration->init(); require_once 'admin/includes/class-betterpayment-settings.php'; require_once 'admin/includes/class-betterpayment-db.php'; BetterPayment_Settings::save_default_settings(); } } /** * Add settings page link on plugins page */ public function plugin_actions_links($links, $file) { $betterpayment_plugin = plugin_basename(__FILE__); if ($file == $betterpayment_plugin && current_user_can('manage_options')) { $links[] = sprintf('%s', admin_url("admin.php?page=betterpayment-settings"), __('Settings', 'better-payment')); } return $links; } } register_activation_hook( __FILE__, 'wp_better_plugin_activate' ); function wp_better_plugin_activate() { require 'includes/class-betterpayment-installer.php'; BetterPayment_Installer::install(); } add_action( 'plugins_loaded', function () { BetterPayment::init(); } ); /** * Plugin migrator * * @since 1.0.0 */ add_action('wp_loaded', function () { // set current version to db if (get_option('wpbp_version') != WPBP_PLUGIN_VERSION) { // update plugin version update_option('wpbp_version', WPBP_PLUGIN_VERSION); } });