-
Notifications
You must be signed in to change notification settings - Fork 16
/
freemius.php
133 lines (111 loc) · 2.88 KB
/
freemius.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
/**
* Freemius integration
* @since 1.9.1
* @since 1.10 Made instantiable.
*/
class GeoMashupFreemius {
/**
* @since 1.10.0
* @var string
*/
protected static $init_data_option_name = 'geo_mashup_freemius_init';
/**
* @since 1.10.0
* @var array
*/
protected $init_data;
/**
* @since 1.10.0
* @var Freemius
*/
protected $freemius;
/**
* Instantiate a Freemius integration object.
* @since 1.10.0
*/
public function __construct() {
}
/**
* @since 1.10.0
* @return bool
*/
public function is_loaded() {
return isset( $this->freemius );
}
/**
* Load Freemius integrations.
* @since 1.9.1
*/
public function load() {
if ( $this->is_loaded() ) {
return;
}
include_once( GEO_MASHUP_DIR_PATH . '/vendor/freemius/wordpress-sdk/start.php' );
$defaults = array(
'id' => '472',
'slug' => 'geo-mashup',
'type' => 'plugin',
'public_key' => 'pk_c28784eaec74e8b93e422064f2f99',
'is_premium' => false,
'has_premium_version' => false,
'has_addons' => false,
'has_paid_plans' => true,
'navigation' => 'tabs',
'menu' => array(
'slug' => 'geo-mashup/geo-mashup.php',
'contact' => false,
'support' => false,
'parent' => array(
'slug' => 'options-general.php',
),
),
);
$this->init_data = defined( 'GEO_MASHUP_FREEMIUS_INIT' ) ? unserialize( GEO_MASHUP_FREEMIUS_INIT ) : array();
$this->init_data = array_replace_recursive( $defaults, $this->init_data );
$this->init_data = array_replace_recursive( $this->init_data, get_option( self::$init_data_option_name, array() ) );
$this->freemius = fs_dynamic_init( $this->init_data );
$this->freemius->add_action( 'after_license_change', array( $this, 'after_license_change' ) );
$this->freemius->add_action( 'after_account_delete', array( $this, 'after_account_delete' ) );
$this->freemius->add_action( 'after_uninstall', array( $this, 'uninstall' ) );
}
/**
* Track premium status when license changes.
*
* @since 1.10.0
* @param string $event The Freemius license event.
*/
public function after_license_change( $event ) {
$is_paying = ! in_array( $event, array( 'cancelled', 'expired', 'trial_expired' ) );
$this->update_init_data( $is_paying );
}
/**
* Track premium status when account is deleted.
*
* @since 1.10.0
*/
public function after_account_delete() {
$this->update_init_data( false );
}
/**
* @since 1.9.1
*/
public function uninstall() {
delete_option( self::$init_data_option_name );
include_once( GEO_MASHUP_DIR_PATH . '/uninstaller.php' );
$uninstaller = new GeoMashupUninstaller();
$uninstaller->geo_mashup_uninstall_options();
}
/**
* @since 1.10.0
* @param bool $is_paying
*/
public function update_init_data( $is_paying = false ) {
$init_data = array(
'menu' => array(
'contact' => $is_paying,
),
);
update_option( self::$init_data_option_name, $init_data, false );
}
}