1
|
|
|
<?php |
|
|
|
|
2
|
|
|
/** |
3
|
|
|
* @package Freemius |
4
|
|
|
* @copyright Copyright (c) 2015, Freemius, Inc. |
5
|
|
|
* @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3 |
6
|
|
|
* @since 1.0.3 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
10
|
|
|
exit; |
11
|
|
|
} |
12
|
|
|
|
13
|
|
|
class FS_Plugin extends FS_Scope_Entity { |
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @since 1.0.6 |
16
|
|
|
* @var null|number |
17
|
|
|
*/ |
18
|
|
|
public $parent_plugin_id; |
19
|
|
|
/** |
20
|
|
|
* @var string |
21
|
|
|
*/ |
22
|
|
|
public $title; |
23
|
|
|
/** |
24
|
|
|
* @var string |
25
|
|
|
*/ |
26
|
|
|
public $slug; |
27
|
|
|
/** |
28
|
|
|
* @author Leo Fajardo (@leorw) |
29
|
|
|
* @since 2.2.1 |
30
|
|
|
* |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
public $premium_slug; |
34
|
|
|
/** |
35
|
|
|
* @since 1.2.2 |
36
|
|
|
* |
37
|
|
|
* @var string 'plugin' or 'theme' |
38
|
|
|
*/ |
39
|
|
|
public $type; |
40
|
|
|
/** |
41
|
|
|
* @author Leo Fajardo (@leorw) |
42
|
|
|
* |
43
|
|
|
* @since 1.2.3 |
44
|
|
|
* |
45
|
|
|
* @var string|false false if the module doesn't have an affiliate program or one of the following: 'selected', 'customers', or 'all'. |
46
|
|
|
*/ |
47
|
|
|
public $affiliate_moderation; |
48
|
|
|
/** |
49
|
|
|
* @var bool Set to true if the free version of the module is hosted on WordPress.org. Defaults to true. |
50
|
|
|
*/ |
51
|
|
|
public $is_wp_org_compliant = true; |
52
|
|
|
|
53
|
|
|
#region Install Specific Properties |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @var string |
57
|
|
|
*/ |
58
|
|
|
public $file; |
59
|
|
|
/** |
60
|
|
|
* @var string |
61
|
|
|
*/ |
62
|
|
|
public $version; |
63
|
|
|
/** |
64
|
|
|
* @var bool |
65
|
|
|
*/ |
66
|
|
|
public $auto_update; |
67
|
|
|
/** |
68
|
|
|
* @var FS_Plugin_Info |
69
|
|
|
*/ |
70
|
|
|
public $info; |
71
|
|
|
/** |
72
|
|
|
* @since 1.0.9 |
73
|
|
|
* |
74
|
|
|
* @var bool |
75
|
|
|
*/ |
76
|
|
|
public $is_premium; |
77
|
|
|
/** |
78
|
|
|
* @author Leo Fajardo (@leorw) |
79
|
|
|
* @since 2.2.1 |
80
|
|
|
* |
81
|
|
|
* @var string |
82
|
|
|
*/ |
83
|
|
|
public $premium_suffix; |
84
|
|
|
/** |
85
|
|
|
* @since 1.0.9 |
86
|
|
|
* |
87
|
|
|
* @var bool |
88
|
|
|
*/ |
89
|
|
|
public $is_live; |
90
|
|
|
|
91
|
|
|
const AFFILIATE_MODERATION_CUSTOMERS = 'customers'; |
92
|
|
|
|
93
|
|
|
#endregion Install Specific Properties |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @param stdClass|bool $plugin |
97
|
|
|
*/ |
98
|
|
|
function __construct( $plugin = false ) { |
|
|
|
|
99
|
|
|
parent::__construct( $plugin ); |
100
|
|
|
|
101
|
|
|
$this->is_premium = false; |
102
|
|
|
$this->is_live = true; |
103
|
|
|
|
104
|
|
|
if ( empty( $this->premium_slug ) && ! empty( $plugin->slug ) ) { |
105
|
|
|
$this->premium_slug = "{$this->slug}-premium"; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
if ( empty( $this->premium_suffix ) ) { |
109
|
|
|
$this->premium_suffix = '(Premium)'; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
if ( isset( $plugin->info ) && is_object( $plugin->info ) ) { |
113
|
|
|
$this->info = new FS_Plugin_Info( $plugin->info ); |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Check if plugin is an add-on (has parent). |
119
|
|
|
* |
120
|
|
|
* @author Vova Feldman (@svovaf) |
121
|
|
|
* @since 1.0.6 |
122
|
|
|
* |
123
|
|
|
* @return bool |
124
|
|
|
*/ |
125
|
|
|
function is_addon() { |
|
|
|
|
126
|
|
|
return isset( $this->parent_plugin_id ) && is_numeric( $this->parent_plugin_id ); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @author Leo Fajardo (@leorw) |
131
|
|
|
* @since 1.2.3 |
132
|
|
|
* |
133
|
|
|
* @return bool |
134
|
|
|
*/ |
135
|
|
|
function has_affiliate_program() { |
|
|
|
|
136
|
|
|
return ( ! empty( $this->affiliate_moderation ) ); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
static function get_type() { |
|
|
|
|
140
|
|
|
return 'plugin'; |
141
|
|
|
} |
142
|
|
|
} |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.