-
Notifications
You must be signed in to change notification settings - Fork 63
Expand file tree
/
Copy pathmollie-payments-for-woocommerce.php
More file actions
101 lines (99 loc) · 2.69 KB
/
mollie-payments-for-woocommerce.php
File metadata and controls
101 lines (99 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
/**
* Plugin Name: Mollie Payments for WooCommerce
* Plugin URI: https://www.mollie.com
* Description: Accept payments in WooCommerce with the official Mollie plugin
* Version: 8.1.4
* Author: Mollie
* Author URI: https://www.mollie.com
* Requires at least: 5.0
* Tested up to: 6.9
* Text Domain: mollie-payments-for-woocommerce
* Domain Path: /languages
* License: GPLv2 or later
* WC requires at least: 3.9
* WC tested up to: 10.5
* Requires PHP: 7.4
* Requires Plugins: woocommerce
*/
declare (strict_types=1);
namespace Mollie\WooCommerce;
use Mollie\Psr\Container\ContainerInterface;
use Throwable;
require_once \ABSPATH . 'wp-admin/includes/plugin.php';
define('M4W_FILE', __FILE__);
define('M4W_PLUGIN_DIR', dirname(\M4W_FILE));
// Plugin folder URL.
if (!defined('M4W_PLUGIN_URL')) {
define('M4W_PLUGIN_URL', plugin_dir_url(\M4W_FILE));
}
function mollie_wc_plugin_autoload(): bool
{
$autoloader = __DIR__ . '/vendor/autoload.php';
$mollieSdkAutoload = __DIR__ . '/vendor/mollie/mollie-api-php/vendor/autoload.php';
if (file_exists($autoloader) && !class_exists('Mollie\WooCommerce\Activation\ActivationModule')) {
require $autoloader;
}
if (file_exists($mollieSdkAutoload)) {
/**
* @psalm-suppress MissingFile
*/
require $mollieSdkAutoload;
}
return \true;
}
/**
* Display an error message in the WP admin.
*
* @param string $message The message content
*
* @return void
*/
function errorNotice(string $message)
{
add_action('all_admin_notices', static function () use ($message) {
$class = 'notice notice-error';
printf('<div class="%1$s"><p>%2$s</p></div>', esc_attr($class), wp_kses_post($message));
});
}
/**
* Handle any exception that might occur during plugin setup.
*
* @param Throwable $throwable The Exception
*
* @return void
*/
function handleException(Throwable $throwable)
{
do_action('inpsyde.mollie-woocommerce.critical', $throwable);
errorNotice(sprintf('<strong>Error:</strong> %s <br><pre>%s</pre>', $throwable->getMessage(), $throwable->getTraceAsString()));
}
/**
* Initialize all the plugin things.
*
* @return ContainerInterface|null
*/
function initialize(): ?ContainerInterface
{
static $container = null;
$root_dir = \M4W_PLUGIN_DIR;
if ($container === null) {
try {
$bootstrap = require __DIR__ . '/bootstrap.php';
$container = $bootstrap($root_dir);
} catch (Throwable $throwable) {
handleException($throwable);
return null;
}
}
return $container;
}
add_action(
/**
* @throws Throwable
*/
'plugins_loaded',
static function () {
initialize();
}
);