-
Notifications
You must be signed in to change notification settings - Fork 3
/
freemius-license-installer.php
78 lines (67 loc) · 2.11 KB
/
freemius-license-installer.php
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
<?php
/**
* Freemius License Installer.
*
* @package freemius-license-installer
* @author Andy Fragen
* @link https://github.com/afragen/freemius-license-installer
* @uses https://github.com/squarecandy/freemius-auto-activation
*
* Plugin Name: Freemius License Installer
* Plugin URI: https://github.com/afragen/freemius-license-installer
* Description: Add Freemius licensing from .env file.
* Version: 1.1.0
* Author: Andy Fragen
* License: MIT
* Requires at least: 5.9
* Requires PHP: 7.2
* GitHub Plugin URI: https://github.com/afragen/freemius-license-installer
* Primary Branch: main
*/
namespace Fragen\Freemius_License_Installer;
/*
* Exit if called directly.
* PHP version check and exit.
*/
if ( ! defined( 'WPINC' ) ) {
die;
}
require_once __DIR__ . '/vendor/autoload.php';
add_action(
'plugins_loaded',
function() {
$config = [
[
'name' => 'Freemius Auto Activation',
'host' => 'github',
'slug' => 'freemius-auto-activation/freemius-auto-activation.php',
'uri' => 'https://github.com/squarecandy/freemius-auto-activation',
'branch' => 'main',
'required' => true,
],
];
\WP_Dependency_Installer::instance( __DIR__ )->register( $config )->run();
}
);
// Load licenses from .env file.
( \Dotenv\Dotenv::createImmutable( dirname( __FILE__ ) ) )->load();
$fs_shortcodes = explode( ',', $_ENV['fs_shortcodes'] );
// Define constants for Freemius Auto Activation.
define( 'FS_SHORTCODES', $fs_shortcodes );
foreach ( $fs_shortcodes as $fs_shortcode ) {
define( 'WP__' . strtoupper( $fs_shortcode ) . '__LICENSE_KEY', $_ENV[ $fs_shortcode ] );
}
register_deactivation_hook( __FILE__, __NAMESPACE__ . '\delete_freemius_auto_activation' );
/**
* Upon deactivation, delete freemius-auto-activation plugin.
*
* @return void
*/
function delete_freemius_auto_activation() {
global $wp_filesystem;
if ( ! $wp_filesystem ) {
require_once ABSPATH . '/wp-admin/includes/file.php';
WP_Filesystem();
}
$wp_filesystem->delete( $wp_filesystem->wp_plugins_dir() . 'freemius-auto-activation', true );
}