setup_classes();
add_action( 'plugins_loaded', [ $this, 'load_classes' ] );
add_filter( 'plugin_action_links_' . CPSW_BASE, [ $this, 'action_links' ] );
add_action( 'before_woocommerce_init', [ $this, 'hpos_compatibility_declaration' ] );
add_action( 'woocommerce_init', [ $this, 'frontend_scripts' ] );
add_action( 'plugins_loaded', [ $this, 'load_cpsw_textdomain' ] );
add_action( 'woocommerce_blocks_loaded', [ $this, 'woocommerce_block_supports' ] );
if ( is_admin() ) {
add_action( 'admin_init', [ $this, 'check_for_onboarding' ] );
}
}
/**
* Sets up base classes.
*
* @return void
*/
public function setup_classes() {
Admin_Controller::get_instance();
Apple_Pay::get_instance();
}
/**
* Includes frontend scripts.
*
* @since 1.1.0
*
* @return void
*/
public function frontend_scripts() {
if ( is_admin() ) {
return;
}
Frontend_Scripts::get_instance();
}
/**
* Adds links in Plugins page
*
* @param array $links existing links.
* @return array
* @since 1.0.0
*/
public function action_links( $links ) {
$plugin_links = apply_filters(
'cpsw_plugin_action_links',
[
'cpsw_settings' => '' . __( 'Settings', 'checkout-plugins-stripe-woo' ) . '',
'cpsw_documentation' => '' . __( 'Documentation', 'checkout-plugins-stripe-woo' ) . '',
]
);
return array_merge( $plugin_links, $links );
}
/**
* Loads classes on plugins_loaded hook.
*
* @return void
* @since 1.0.0
*/
public function load_classes() {
// Initializing Onboarding.
Onboarding::get_instance();
if ( ! class_exists( 'woocommerce' ) ) {
add_action( 'admin_notices', [ $this, 'wc_is_not_active' ] );
return;
}
// Initializing Gateways.
Sepa::get_instance();
Wechat::get_instance();
Bancontact::get_instance();
P24::get_instance();
Klarna::get_instance();
Ideal::get_instance();
Alipay::get_instance();
Card_Payments::get_instance();
Payment_Request_Api::get_instance();
Webhook::get_instance();
}
/**
* Loads classes on plugins_loaded hook.
*
* @return void
* @since 1.0.0
*/
public function wc_is_not_active() {
$install_url = wp_nonce_url(
add_query_arg(
array(
'action' => 'install-plugin',
'plugin' => 'woocommerce',
),
admin_url( 'update.php' )
),
'install-plugin_woocommerce'
);
echo '
';
// translators: 1$-2$: opening and closing tags, 3$-4$: link tags, takes to woocommerce plugin on wp.org, 5$-6$: opening and closing link tags, leads to plugins.php in admin.
echo sprintf( esc_html__( '%1$sCheckout Plugins - Stripe for WooCommerce is currently inactive.%2$s The %3$sWooCommerce plugin%4$s must be active for Checkout Plugins - Stripe for WooCommerce to work. Please %5$sinstall & activate WooCommerce »%6$s', 'checkout-plugins-stripe-woo' ), '', '', '', '', '', '' );
echo '
';
}
/**
* Checks for installation routine
* Loads plugins translation file
*
* @return void
* @since 1.3.0
*/
public function install() {
$admin_controller = Admin_Controller::get_instance();
if ( get_option( 'cpsw_setup_status', false ) || apply_filters( 'cpsw_prevent_onboarding_redirect', false ) || $admin_controller->is_stripe_connected() ) {
return;
}
update_option( 'cpsw_start_onboarding', true );
}
/**
* Checks whether onboarding is required or not
*
* @return void
* @since 1.3.0
*/
public function check_for_onboarding() {
if ( ! current_user_can( 'manage_options' ) ) {
return;
}
if ( ! get_option( 'cpsw_start_onboarding', false ) ) {
return;
}
$onboarding_url = admin_url( 'index.php?page=cpsw-onboarding' );
if ( ! class_exists( 'woocommerce' ) ) {
$onboarding_url = add_query_arg( 'cpsw_call', 'setup-woocommerce', $onboarding_url );
}
delete_option( 'cpsw_start_onboarding' );
wp_safe_redirect( esc_url_raw( $onboarding_url ) );
exit();
}
/**
* Loads plugins translation file
*
* @return void
* @since 1.3.0
*/
public function load_cpsw_textdomain() {
// Default languages directory.
$lang_dir = CPSW_DIR . 'languages/';
// Traditional WordPress plugin locale filter.
global $wp_version;
$get_locale = get_locale();
if ( $wp_version >= 4.7 ) {
$get_locale = get_user_locale();
}
$locale = apply_filters( 'plugin_locale', $get_locale, 'checkout-plugins-stripe-woo' );
$mofile = sprintf( '%1$s-%2$s.mo', 'checkout-plugins-stripe-woo', $locale );
// Setup paths to current locale file.
$mofile_local = $lang_dir . $mofile;
$mofile_global = WP_LANG_DIR . '/plugins/' . $mofile;
if ( file_exists( $mofile_global ) ) {
// Look in global /wp-content/languages/checkout-plugins-stripe-woo/ folder.
load_textdomain( 'checkout-plugins-stripe-woo', $mofile_global );
} elseif ( file_exists( $mofile_local ) ) {
// Look in local /wp-content/plugins/checkout-plugins-stripe-woo/languages/ folder.
load_textdomain( 'checkout-plugins-stripe-woo', $mofile_local );
} else {
// Load the default language files.
load_plugin_textdomain( 'checkout-plugins-stripe-woo', false, $lang_dir );
}
}
/**
* Declares compatibility with WooCommerce HPOS
*
* @return void
* @since 1.4.8
*/
public function hpos_compatibility_declaration() {
if ( class_exists( '\Automattic\WooCommerce\Utilities\FeaturesUtil' ) ) {
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', CPSW_FILE, true );
}
}
/**
* Adding support for woocommerce blocks
*
* @since 1.6.0
* @return void
*/
public function woocommerce_block_supports() {
$this->register_payment_methods();
}
/**
* Register payment methods for woocommerce blocks
*
* @since 1.6.0
* @return void
*/
public function register_payment_methods() {
add_action(
'woocommerce_blocks_payment_method_type_registration',
function( \Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry ) {
$container = \Automattic\WooCommerce\Blocks\Package::container();
// registers as shared instance.
$container->register(
Credit_Card_Payments::class,
function() {
return new Credit_Card_Payments();
}
);
$payment_method_registry->register(
$container->get( Credit_Card_Payments::class )
);
},
5
);
}
}
/**
* Kicking this off by calling 'get_instance()' method
*/
CPSW_Loader::get_instance();