1 | <?php |
||
90 | final class GravityView_Plugin { |
||
91 | |||
92 | const version = '1.16.2'; |
||
93 | |||
94 | private static $instance; |
||
95 | |||
96 | /** |
||
97 | * Singleton instance |
||
98 | * |
||
99 | * @return GravityView_Plugin GravityView_Plugin object |
||
100 | */ |
||
101 | public static function getInstance() { |
||
102 | |||
103 | if( empty( self::$instance ) ) { |
||
104 | self::$instance = new self; |
||
105 | } |
||
106 | |||
107 | return self::$instance; |
||
108 | } |
||
109 | |||
110 | private function __construct() { |
||
111 | |||
112 | |||
113 | if( ! GravityView_Compatibility::is_valid() ) { |
||
114 | return; |
||
115 | } |
||
116 | |||
117 | $this->include_files(); |
||
118 | |||
119 | $this->add_hooks(); |
||
120 | } |
||
121 | |||
122 | /** |
||
123 | * Add hooks to set up the plugin |
||
124 | * |
||
125 | * @since 1.12 |
||
126 | */ |
||
127 | private function add_hooks() { |
||
128 | // Load plugin text domain |
||
129 | add_action( 'init', array( $this, 'load_plugin_textdomain' ), 1 ); |
||
130 | |||
131 | // Load frontend files |
||
132 | add_action( 'init', array( $this, 'frontend_actions' ), 20 ); |
||
133 | } |
||
134 | |||
135 | /** |
||
136 | * Include global plugin files |
||
137 | * |
||
138 | * @since 1.12 |
||
139 | */ |
||
140 | public function include_files() { |
||
141 | |||
142 | include_once( GRAVITYVIEW_DIR .'includes/class-admin.php' ); |
||
143 | |||
144 | // Load fields |
||
145 | include_once( GRAVITYVIEW_DIR . 'includes/fields/class-gravityview-fields.php' ); |
||
146 | include_once( GRAVITYVIEW_DIR . 'includes/fields/class-gravityview-field.php' ); |
||
147 | |||
148 | // Load all field files automatically |
||
149 | foreach ( glob( GRAVITYVIEW_DIR . 'includes/fields/class-gravityview-field*.php' ) as $gv_field_filename ) { |
||
150 | include_once( $gv_field_filename ); |
||
151 | } |
||
152 | |||
153 | include_once( GRAVITYVIEW_DIR .'includes/class-gravityview-entry-notes.php' ); |
||
154 | include_once( GRAVITYVIEW_DIR .'includes/load-plugin-and-theme-hooks.php' ); |
||
155 | |||
156 | // Load Extensions |
||
157 | // @todo: Convert to a scan of the directory or a method where this all lives |
||
158 | include_once( GRAVITYVIEW_DIR .'includes/extensions/edit-entry/class-edit-entry.php' ); |
||
159 | include_once( GRAVITYVIEW_DIR .'includes/extensions/delete-entry/class-delete-entry.php' ); |
||
160 | |||
161 | // Load WordPress Widgets |
||
162 | include_once( GRAVITYVIEW_DIR .'includes/wordpress-widgets/register-wordpress-widgets.php' ); |
||
163 | |||
164 | // Load GravityView Widgets |
||
165 | include_once( GRAVITYVIEW_DIR .'includes/widgets/register-gravityview-widgets.php' ); |
||
166 | |||
167 | // Add oEmbed |
||
168 | include_once( GRAVITYVIEW_DIR . 'includes/class-oembed.php' ); |
||
169 | |||
170 | // Add logging |
||
171 | include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-logging.php' ); |
||
172 | |||
173 | include_once( GRAVITYVIEW_DIR . 'includes/class-ajax.php' ); |
||
174 | include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-settings.php' ); |
||
175 | include_once( GRAVITYVIEW_DIR . 'includes/class-frontend-views.php' ); |
||
176 | include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-admin-bar.php' ); |
||
177 | include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-entry-list.php' ); |
||
178 | include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-merge-tags.php'); /** @since 1.8.4 */ |
||
179 | include_once( GRAVITYVIEW_DIR . 'includes/class-data.php' ); |
||
180 | include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-shortcode.php' ); |
||
181 | include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-entry-link-shortcode.php' ); |
||
182 | include_once( GRAVITYVIEW_DIR . 'includes/class-gvlogic-shortcode.php' ); |
||
183 | include_once( GRAVITYVIEW_DIR . 'includes/presets/register-default-templates.php' ); |
||
184 | |||
185 | } |
||
186 | |||
187 | /** |
||
188 | * Check whether GravityView is network activated |
||
189 | * @since 1.7.6 |
||
190 | * @return bool |
||
191 | */ |
||
192 | public static function is_network_activated() { |
||
195 | |||
196 | |||
197 | /** |
||
198 | * Plugin activate function. |
||
199 | * |
||
200 | * @access public |
||
201 | * @static |
||
202 | * @return void |
||
203 | */ |
||
204 | public static function activate() { |
||
205 | |||
206 | // register post types |
||
207 | GravityView_Post_Types::init_post_types(); |
||
208 | |||
209 | // register rewrite rules |
||
210 | GravityView_Post_Types::init_rewrite(); |
||
211 | |||
212 | flush_rewrite_rules(); |
||
213 | |||
214 | // Update the current GV version |
||
215 | update_option( 'gv_version', self::version ); |
||
216 | |||
217 | // Add the transient to redirect to configuration page |
||
218 | set_transient( '_gv_activation_redirect', true, 60 ); |
||
219 | |||
220 | // Clear settings transient |
||
221 | delete_transient( 'redux_edd_license_license_valid' ); |
||
222 | |||
223 | GravityView_Roles_Capabilities::get_instance()->add_caps(); |
||
224 | } |
||
225 | |||
226 | |||
227 | /** |
||
228 | * Plugin deactivate function. |
||
229 | * |
||
230 | * @access public |
||
231 | * @static |
||
232 | * @return void |
||
233 | */ |
||
234 | public static function deactivate() { |
||
235 | |||
236 | flush_rewrite_rules(); |
||
237 | |||
238 | } |
||
239 | |||
240 | /** |
||
241 | * Include the extension class |
||
242 | * |
||
243 | * @since 1.5.1 |
||
244 | * @return void |
||
245 | */ |
||
246 | public static function include_extension_framework() { |
||
247 | if ( ! class_exists( 'GravityView_Extension' ) ) { |
||
248 | require_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-extension.php' ); |
||
249 | } |
||
250 | } |
||
251 | |||
252 | /** |
||
253 | * Load GravityView_Widget class |
||
254 | * |
||
255 | * @since 1.7.5.1 |
||
256 | */ |
||
257 | public static function include_widget_class() { |
||
260 | |||
261 | |||
262 | /** |
||
263 | * Loads the plugin's translated strings. |
||
264 | * |
||
265 | * @access public |
||
266 | * @return void |
||
267 | */ |
||
268 | public function load_plugin_textdomain() { |
||
284 | |||
285 | /** |
||
286 | * Check if is_admin(), and make sure not DOING_AJAX |
||
287 | * @since 1.7.5 |
||
288 | * @return bool |
||
289 | */ |
||
290 | public static function is_admin() { |
||
291 | |||
296 | |||
297 | /** |
||
298 | * Function to launch frontend objects |
||
299 | * |
||
300 | * @access public |
||
301 | * @return void |
||
302 | */ |
||
303 | public function frontend_actions() { |
||
327 | |||
328 | /** |
||
329 | * helper function to define the default widget areas |
||
330 | * @todo Move somewhere logical |
||
331 | * @return array definition for default widget areas |
||
332 | */ |
||
333 | public static function get_default_widget_areas() { |
||
345 | |||
346 | /** DEBUG */ |
||
347 | |||
348 | /** |
||
349 | * Logs messages using Gravity Forms logging add-on |
||
350 | * @param string $message log message |
||
351 | * @param mixed $data Additional data to display |
||
352 | * @return void |
||
353 | */ |
||
354 | public static function log_debug( $message, $data = null ){ |
||
362 | |||
363 | /** |
||
364 | * Logs messages using Gravity Forms logging add-on |
||
365 | * @param string $message log message |
||
366 | * @return void |
||
367 | */ |
||
368 | public static function log_error( $message, $data = null ){ |
||
376 | |||
377 | } // end class GravityView_Plugin |
||
378 | |||
380 |
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.