PluginProbe
Buttonizer – Floating Menus, Sticky Buttons, & Popup Builder / 3.6.0
Buttonizer – Floating Menus, Sticky Buttons, & Popup Builder v3.6.0
3.6.0 3.5.0 trunk 1.0.10 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.6.1 1.0.7 1.0.8 1.0.9 1.1 1.1.1 1.2 1.3 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.5 1.5.1 All 110 releases
← All changes | freemius/includes/managers/class-fs-plugin-manager.php +232 -153 1.33.6.0 View file →
@@ -1,154 +1,233 @@
1 -<?php
2 - /**
3 - * @package Freemius
4 - * @copyright Copyright (c) 2015, Freemius, Inc.
5 - * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6 - * @since 1.0.6
7 - */
8 -
9 - if ( ! defined( 'ABSPATH' ) ) {
10 - exit;
11 - }
12 -
13 - class FS_Plugin_Manager {
14 - /**
15 - * @var string
16 - */
17 - protected $_slug;
18 - /**
19 - * @var FS_Plugin
20 - */
21 - protected $_plugin;
22 -
23 - /**
24 - * @var FS_Plugin_Manager[]
25 - */
26 - private static $_instances = array();
27 - /**
28 - * @var FS_Logger
29 - */
30 - protected $_logger;
31 -
32 - /**
33 - * @param string $slug
34 - *
35 - * @return FS_Plugin_Manager
36 - */
37 - static function instance( $slug ) {
38 - if ( ! isset( self::$_instances[ $slug ] ) ) {
39 - self::$_instances[ $slug ] = new FS_Plugin_Manager( $slug );
40 - }
41 -
42 - return self::$_instances[ $slug ];
43 - }
44 -
45 - protected function __construct( $slug ) {
46 - $this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_' . $slug . '_' . 'plugins', WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
47 -
48 - $this->_slug = $slug;
49 - $this->load();
50 - }
51 -
52 - protected function get_option_manager() {
53 - return FS_Option_Manager::get_manager( WP_FS__ACCOUNTS_OPTION_NAME, true );
54 - }
55 -
56 - protected function get_all_plugins() {
57 - return $this->get_option_manager()->get_option( 'plugins', array() );
58 - }
59 -
60 - /**
61 - * Load plugin data from local DB.
62 - *
63 - * @author Vova Feldman (@svovaf)
64 - * @since 1.0.6
65 - */
66 - function load() {
67 - $all_plugins = $this->get_all_plugins();
68 - $this->_plugin = isset( $all_plugins[ $this->_slug ] ) ?
69 - $all_plugins[ $this->_slug ] :
70 - null;
71 - }
72 -
73 - /**
74 - * Store plugin on local DB.
75 - *
76 - * @author Vova Feldman (@svovaf)
77 - * @since 1.0.6
78 - *
79 - * @param bool|FS_Plugin $plugin
80 - * @param bool $flush
81 - *
82 - * @return bool|\FS_Plugin
83 - */
84 - function store( $plugin = false, $flush = true ) {
85 - $all_plugins = $this->get_all_plugins();
86 -
87 - if ( false !== $plugin ) {
88 - $this->_plugin = $plugin;
89 - }
90 -
91 - $all_plugins[ $this->_slug ] = $this->_plugin;
92 -
93 - $options_manager = $this->get_option_manager();
94 - $options_manager->set_option( 'plugins', $all_plugins, $flush );
95 -
96 - return $this->_plugin;
97 - }
98 -
99 - /**
100 - * Update local plugin data if different.
101 - *
102 - * @author Vova Feldman (@svovaf)
103 - * @since 1.0.6
104 - *
105 - * @param \FS_Plugin $plugin
106 - * @param bool $store
107 - *
108 - * @return bool True if plugin was updated.
109 - */
110 - function update( FS_Plugin $plugin, $store = true ) {
111 - if ( ! ( $this->_plugin instanceof FS_Plugin ) ||
112 - $this->_plugin->slug != $plugin->slug ||
113 - $this->_plugin->public_key != $plugin->public_key ||
114 - $this->_plugin->secret_key != $plugin->secret_key ||
115 - $this->_plugin->parent_plugin_id != $plugin->parent_plugin_id ||
116 - $this->_plugin->title != $plugin->title
117 - ) {
118 - $this->store( $plugin, $store );
119 -
120 - return true;
121 - }
122 -
123 - return false;
124 - }
125 -
126 - /**
127 - * @author Vova Feldman (@svovaf)
128 - * @since 1.0.6
129 - *
130 - * @param FS_Plugin $plugin
131 - * @param bool $store
132 - */
133 - function set( FS_Plugin $plugin, $store = false ) {
134 - $this->_plugin = $plugin;
135 -
136 - if ( $store ) {
137 - $this->store();
138 - }
139 - }
140 -
141 - /**
142 - * @author Vova Feldman (@svovaf)
143 - * @since 1.0.6
144 - *
145 - * @return bool|\FS_Plugin
146 - */
147 - function get() {
148 - return isset( $this->_plugin ) ?
149 - $this->_plugin :
150 - false;
151 - }
152 -
153 -
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.6
7 + */
8 +
9 + if ( ! defined( 'ABSPATH' ) ) {
10 + exit;
11 + }
12 +
13 + class FS_Plugin_Manager {
14 + /**
15 + * @since 1.2.2
16 + *
17 + * @var string|number
18 + */
19 + protected $_module_id;
20 + /**
21 + * @since 1.2.2
22 + *
23 + * @var FS_Plugin
24 + */
25 + protected $_module;
26 +
27 + /**
28 + * @var FS_Plugin_Manager[]
29 + */
30 + private static $_instances = array();
31 + /**
32 + * @var FS_Logger
33 + */
34 + protected $_logger;
35 +
36 + /**
37 + * Option names
38 + *
39 + * @author Leo Fajardo (@leorw)
40 + * @since 1.2.2
41 + */
42 + const OPTION_NAME_PLUGINS = 'plugins';
43 + const OPTION_NAME_THEMES = 'themes';
44 +
45 + /**
46 + * @param string|number $module_id
47 + *
48 + * @return FS_Plugin_Manager
49 + */
50 + static function instance( $module_id ) {
51 + $key = 'm_' . $module_id;
52 +
53 + if ( ! isset( self::$_instances[ $key ] ) ) {
54 + self::$_instances[ $key ] = new FS_Plugin_Manager( $module_id );
55 + }
56 +
57 + return self::$_instances[ $key ];
58 + }
59 +
60 + /**
61 + * @param string|number $module_id
62 + */
63 + protected function __construct( $module_id ) {
64 + $this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_' . $module_id . '_' . 'plugins', WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
65 + $this->_module_id = $module_id;
66 +
67 + $this->load();
68 + }
69 +
70 + protected function get_option_manager() {
71 + return FS_Option_Manager::get_manager( WP_FS__ACCOUNTS_OPTION_NAME, true, true );
72 + }
73 +
74 + /**
75 + * @author Leo Fajardo (@leorw)
76 + * @since 1.2.2
77 + *
78 + * @param string|bool $module_type "plugin", "theme", or "false" for all modules.
79 + *
80 + * @return array
81 + */
82 + protected function get_all_modules( $module_type = false ) {
83 + $option_manager = $this->get_option_manager();
84 +
85 + if ( false !== $module_type ) {
86 + return fs_get_entities( $option_manager->get_option( $module_type . 's', array() ), FS_Plugin::get_class_name() );
87 + }
88 +
89 + return array(
90 + self::OPTION_NAME_PLUGINS => fs_get_entities( $option_manager->get_option( self::OPTION_NAME_PLUGINS, array() ), FS_Plugin::get_class_name() ),
91 + self::OPTION_NAME_THEMES => fs_get_entities( $option_manager->get_option( self::OPTION_NAME_THEMES, array() ), FS_Plugin::get_class_name() ),
92 + );
93 + }
94 +
95 + /**
96 + * Load plugin data from local DB.
97 + *
98 + * @author Vova Feldman (@svovaf)
99 + * @since 1.0.6
100 + */
101 + function load() {
102 + $all_modules = $this->get_all_modules();
103 +
104 + if ( ! is_numeric( $this->_module_id ) ) {
105 + unset( $all_modules[ self::OPTION_NAME_THEMES ] );
106 + }
107 +
108 + foreach ( $all_modules as $modules ) {
109 + /**
110 + * @since 1.2.2
111 + *
112 + * @var $modules FS_Plugin[]
113 + */
114 + foreach ( $modules as $module ) {
115 + $found_module = false;
116 +
117 + /**
118 + * If module ID is not numeric, it must be a plugin's slug.
119 + *
120 + * @author Leo Fajardo (@leorw)
121 + * @since 1.2.2
122 + */
123 + if ( ! is_numeric( $this->_module_id ) ) {
124 + if ( $this->_module_id === $module->slug ) {
125 + $this->_module_id = $module->id;
126 + $found_module = true;
127 + }
128 + } else if ( $this->_module_id == $module->id ) {
129 + $found_module = true;
130 + }
131 +
132 + if ( $found_module ) {
133 + $this->_module = $module;
134 + break;
135 + }
136 + }
137 + }
138 + }
139 +
140 + /**
141 + * Store plugin on local DB.
142 + *
143 + * @author Vova Feldman (@svovaf)
144 + * @since 1.0.6
145 + *
146 + * @param bool|FS_Plugin $module
147 + * @param bool $flush
148 + *
149 + * @return bool|\FS_Plugin
150 + */
151 + function store( $module = false, $flush = true ) {
152 + if ( false !== $module ) {
153 + $this->_module = $module;
154 + }
155 +
156 + $all_modules = $this->get_all_modules( $this->_module->type );
157 + $all_modules[ $this->_module->slug ] = $this->_module;
158 +
159 + $options_manager = $this->get_option_manager();
160 + $options_manager->set_option( $this->_module->type . 's', $all_modules, $flush );
161 +
162 + return $this->_module;
163 + }
164 +
165 + /**
166 + * Update local plugin data if different.
167 + *
168 + * @author Vova Feldman (@svovaf)
169 + * @since 1.0.6
170 + *
171 + * @param \FS_Plugin $plugin
172 + * @param bool $store
173 + *
174 + * @return bool True if plugin was updated.
175 + */
176 + function update( FS_Plugin $plugin, $store = true ) {
177 + if ( ! ($this->_module instanceof FS_Plugin ) ||
178 + $this->_module->slug != $plugin->slug ||
179 + $this->_module->public_key != $plugin->public_key ||
180 + $this->_module->secret_key != $plugin->secret_key ||
181 + $this->_module->parent_plugin_id != $plugin->parent_plugin_id ||
182 + $this->_module->title != $plugin->title
183 + ) {
184 + $this->store( $plugin, $store );
185 +
186 + return true;
187 + }
188 +
189 + return false;
190 + }
191 +
192 + /**
193 + * @author Vova Feldman (@svovaf)
194 + * @since 1.0.6
195 + *
196 + * @param FS_Plugin $plugin
197 + * @param bool $store
198 + */
199 + function set( FS_Plugin $plugin, $store = false ) {
200 + $this->_module = $plugin;
201 +
202 + if ( $store ) {
203 + $this->store();
204 + }
205 + }
206 +
207 + /**
208 + * @author Vova Feldman (@svovaf)
209 + * @since 1.0.6
210 + *
211 + * @return bool|\FS_Plugin
212 + */
213 + function get() {
214 + if ( isset( $this->_module ) ) {
215 + return $this->_module;
216 + }
217 +
218 + if ( empty( $this->_module_id ) ) {
219 + return false;
220 + }
221 +
222 + /**
223 + * Return an FS_Plugin entity that has its `id` and `is_live` properties set (`is_live` is initialized in the FS_Plugin constructor) to avoid triggering an error that is relevant to these properties when the FS_Plugin entity is used before the `parse_settings()` method is called. This can happen when creating a regular WordPress site by cloning a subsite of a multisite network and the data that is stored in the network-level storage is not cloned.
224 + *
225 + * @author Leo Fajardo (@leorw)
226 + * @since 2.5.0
227 + */
228 + $plugin = new FS_Plugin();
229 + $plugin->id = $this->_module_id;
230 +
231 + return $plugin;
232 + }
154 233 }