' . sprintf( esc_html__( 'WooCommerce PayPal Payments requires WooCommerce to be installed and active. You can download %s here.', 'woocommerce-paypal-payments' ), 'WooCommerce' ) . '
';
}
);
return;
}
if ( version_compare( PHP_VERSION, '7.2', '<' ) ) {
add_action(
'admin_notices',
function() {
echo '' . esc_html__( 'WooCommerce PayPal Payments requires PHP 7.1 or above.', 'woocommerce-paypal-payments' ), '
';
}
);
return;
}
static $initialized;
if ( ! $initialized ) {
$bootstrap = require "$root_dir/bootstrap.php";
$app_container = $bootstrap( $root_dir );
PPCP::init( $app_container );
$initialized = true;
/**
* The hook fired after the plugin bootstrap with the app services container as parameter.
*/
do_action( 'woocommerce_paypal_payments_built_container', $app_container );
}
}
add_action(
'plugins_loaded',
function () {
init();
if ( ! function_exists( 'get_plugin_data' ) ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
$plugin_data = get_plugin_data( __DIR__ . '/woocommerce-paypal-payments.php' );
$plugin_version = $plugin_data['Version'] ?? null;
$installed_plugin_version = get_option( 'woocommerce-ppcp-version' );
if ( $installed_plugin_version !== $plugin_version ) {
/**
* The hook fired when the plugin is installed or updated.
*/
do_action( 'woocommerce_paypal_payments_gateway_migrate' );
if ( $installed_plugin_version ) {
/**
* The hook fired when the plugin is updated.
*/
do_action( 'woocommerce_paypal_payments_gateway_migrate_on_update' );
}
update_option( 'woocommerce-ppcp-version', $plugin_version );
}
}
);
register_activation_hook(
__FILE__,
function () {
init();
/**
* The hook fired in register_activation_hook.
*/
do_action( 'woocommerce_paypal_payments_gateway_activate' );
}
);
register_deactivation_hook(
__FILE__,
function () {
init();
/**
* The hook fired in register_deactivation_hook.
*/
do_action( 'woocommerce_paypal_payments_gateway_deactivate' );
}
);
// Add "Settings" link to Plugins screen.
add_filter(
'plugin_action_links_' . plugin_basename( __FILE__ ),
function( $links ) {
if ( ! is_woocommerce_activated() ) {
return $links;
}
array_unshift(
$links,
sprintf(
'%2$s',
admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=ppcp-gateway&ppcp-tab=' . Settings::CONNECTION_TAB_ID ),
__( 'Settings', 'woocommerce-paypal-payments' )
)
);
return $links;
}
);
// Add links below the description on the Plugins page.
add_filter(
'plugin_row_meta',
function( $links, $file ) {
if ( plugin_basename( __FILE__ ) !== $file ) {
return $links;
}
return array_merge(
$links,
array(
sprintf(
'%2$s',
'https://woocommerce.com/document/woocommerce-paypal-payments/',
__( 'Documentation', 'woocommerce-paypal-payments' )
),
sprintf(
'%2$s',
'https://woocommerce.com/document/woocommerce-paypal-payments/#get-help',
__( 'Get help', 'woocommerce-paypal-payments' )
),
sprintf(
'%2$s',
'https://woocommerce.com/feature-requests/woocommerce-paypal-payments/',
__( 'Request a feature', 'woocommerce-paypal-payments' )
),
sprintf(
'%2$s',
'https://github.com/woocommerce/woocommerce-paypal-payments/issues/new?assignees=&labels=type%3A+bug&template=bug_report.md',
__( 'Submit a bug', 'woocommerce-paypal-payments' )
),
)
);
},
10,
2
);
add_action(
'before_woocommerce_init',
function() {
if ( class_exists( '\Automattic\WooCommerce\Utilities\FeaturesUtil' ) ) {
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true );
}
}
);
/**
* Check if WooCommerce is active.
*
* @return bool true if WooCommerce is active, otherwise false.
*/
function is_woocommerce_activated(): bool {
return class_exists( 'woocommerce' );
}
} )();