kudos-donations.php 3.85 KB
Newer Older
Michael Iseard's avatar
Michael Iseard committed
1
2
<?php
/**
Michael Iseard's avatar
Michael Iseard committed
3
4
 * Add a donation button to any page on your website. Easy & fast setup. Works with Mollie payments.
 *
Michael Iseard's avatar
Michael Iseard committed
5
 * @link              https://www.linkedin.com/in/michael-iseard/
Michael Iseard's avatar
Michael Iseard committed
6
 * @author            Michael Iseard
7
 * @package           Kudos-Donations
Michael Iseard's avatar
Michael Iseard committed
8
9
 *
 * @wordpress-plugin
Michael Iseard's avatar
Michael Iseard committed
10
 * Plugin Name:       Kudos Donations
Michael Iseard's avatar
Michael Iseard committed
11
 * Plugin URI:        https://gitlab.iseard.media/michael/kudos-donations
Michael Iseard's avatar
Michael Iseard committed
12
 * Description:       Add a donation button to any page on your website. Easy & fast setup. Works with Mollie payments.
Michael Iseard's avatar
Michael Iseard committed
13
 * Version:           3.1.0-beta
Michael Iseard's avatar
Michael Iseard committed
14
15
 * Author:            Iseard Media
 * Author URI:        https://iseard.media
16
 * Requires at least: 5.5
Michael Iseard's avatar
Michael Iseard committed
17
 * Requires PHP:      7.2
Michael Iseard's avatar
Michael Iseard committed
18
19
 * License:           GPL-2.0+
 * License URI:       http://www.gnu.org/licenses/gpl-2.0.txt
20
 * Text Domain:       kudos-donations
Michael Iseard's avatar
Michael Iseard committed
21
22
23
 * Domain Path:       /languages
 */

Michael Iseard's avatar
Michael Iseard committed
24
25
namespace Kudos;

26
27
use DI\ContainerBuilder;
use Dotenv\Dotenv;
Michael Iseard's avatar
Michael Iseard committed
28
29
30
use Kudos\Service\ActivatorService;
use Kudos\Service\CompatibilityService;
use Kudos\Service\DeactivatorService;
31
32
use Whoops\Handler\PrettyPageHandler;
use Whoops\Run;
33

Michael Iseard's avatar
Michael Iseard committed
34
35
36
37
38
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
	die;
}

39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/vendor/woocommerce/action-scheduler/action-scheduler.php';

/**
 * Load the .env file if present.
 *
 * @link https://github.com/vlucas/phpdotenv
 */
if ( class_exists( Dotenv::class ) ) {
	$dotenv = Dotenv::createImmutable( __DIR__ );
	$dotenv->safeLoad();
}

/**
 * Define all the Kudos Donations constants for use throughout the plugin.
 */
Michael Iseard's avatar
Michael Iseard committed
55
define( 'KUDOS_VERSION', '3.1.0-beta' );
56
57
define( 'KUDOS_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
define( 'KUDOS_PLUGIN_DIR', dirname( __FILE__ ) );
58
59
define( 'KUDOS_STORAGE_URL', wp_upload_dir()['baseurl'] . '/kudos-donations/' );
define( 'KUDOS_STORAGE_DIR', wp_upload_dir()['basedir'] . '/kudos-donations/' );
Michael Iseard's avatar
Michael Iseard committed
60
define( 'KUDOS_DEBUG', get_option( '_kudos_debug_mode' ) );
Michael Iseard's avatar
Michael Iseard committed
61

62
63
64
65
66
67
68
69
70
71
72
/**
 * Check if we are in development mode and if so replace the default
 * error handler with a more developer friendly one.
 *
 * @link https://github.com/filp/whoops
 */
if ( class_exists( Run::class ) && ( $_ENV['WP_ENV'] ?? '' ) === 'development' ) {

	$run     = new Run();
	$handler = new PrettyPageHandler;

73
	// Set the title of the error page.
74
75
76
	$handler->setPageTitle( "Whoops! There was a problem." );
	$run->pushHandler( $handler );

77
	// Register the handler with PHP.
78
79
80
	$run->register();
}

Michael Iseard's avatar
Michael Iseard committed
81
82
83
/**
 * The code that runs during plugin activation.
 */
Michael Iseard's avatar
Michael Iseard committed
84
function activate_kudos() {
85
	$activator = new ActivatorService();
86
	$activator->activate();
Michael Iseard's avatar
Michael Iseard committed
87
88
89
90
91
}

/**
 * The code that runs during plugin deactivation.
 */
Michael Iseard's avatar
Michael Iseard committed
92
function deactivate_kudos() {
93
	DeactivatorService::deactivate();
Michael Iseard's avatar
Michael Iseard committed
94
95
}

Michael Iseard's avatar
Michael Iseard committed
96
register_activation_hook( __FILE__, __NAMESPACE__ . '\activate_kudos' );
Michael Iseard's avatar
Michael Iseard committed
97
register_deactivation_hook( __FILE__, __NAMESPACE__ . '\deactivate_kudos' );
Michael Iseard's avatar
Michael Iseard committed
98
99

/**
100
101
 * The core plugin class that is used to define admin-specific hooks
 * and public-facing site hooks.
Michael Iseard's avatar
Michael Iseard committed
102
 */
103
require KUDOS_PLUGIN_DIR . '/app/KudosDonations.php';
Michael Iseard's avatar
Michael Iseard committed
104
105
106
107
108
109
110
111

/**
 * Begins execution of the plugin.
 *
 * Since everything within the plugin is registered via hooks,
 * then kicking off the plugin from this point in the file does
 * not affect the page life cycle.
 */
112
function run_kudos_donations() {
Michael Iseard's avatar
Michael Iseard committed
113

114
	// Check compatibility and run kudos if OK
115
116
	$compatibility = new CompatibilityService();

117
	if ( $compatibility->init() ) {
118
119
120
121
122

		// Create our container for dependency injection.
		$builder = new ContainerBuilder();
		$builder->useAutowiring(true);
		$builder->addDefinitions( KUDOS_PLUGIN_DIR . '/app/config.php' );
123
		if(isset($_ENV['WP_ENV']) && $_ENV['WP_ENV']  !== 'development') {
124
125
126
127
128
129
			$builder->enableCompilation(KUDOS_STORAGE_DIR . '/php-di/cache');
		}
		$container = $builder->build();

		// Create and run our main plugin class.
		$plugin = new KudosDonations( $container, KUDOS_VERSION, 'kudos-donations' );
130
131
		$plugin->run();
	}
Michael Iseard's avatar
Michael Iseard committed
132
}
133

134
run_kudos_donations();