1 | <?php |
||
90 | final class GravityView_Plugin { |
||
91 | |||
92 | const version = '1.17'; |
||
93 | |||
94 | private static $instance; |
||
95 | |||
96 | /** |
||
97 | * Singleton instance |
||
98 | * |
||
99 | * @return GravityView_Plugin GravityView_Plugin object |
||
100 | */ |
||
101 | public static function getInstance() { |
||
109 | |||
110 | private function __construct() { |
||
121 | |||
122 | /** |
||
123 | * Add hooks to set up the plugin |
||
124 | * |
||
125 | * @since 1.12 |
||
126 | */ |
||
127 | private function add_hooks() { |
||
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 | include_once( GRAVITYVIEW_DIR .'includes/extensions/entry-notes/class-gravityview-field-notes.php' ); |
||
161 | |||
162 | // Load WordPress Widgets |
||
163 | include_once( GRAVITYVIEW_DIR .'includes/wordpress-widgets/register-wordpress-widgets.php' ); |
||
164 | |||
165 | // Load GravityView Widgets |
||
166 | include_once( GRAVITYVIEW_DIR .'includes/widgets/register-gravityview-widgets.php' ); |
||
167 | |||
168 | // Add oEmbed |
||
169 | include_once( GRAVITYVIEW_DIR . 'includes/class-oembed.php' ); |
||
170 | |||
171 | // Add logging |
||
172 | include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-logging.php' ); |
||
173 | |||
174 | include_once( GRAVITYVIEW_DIR . 'includes/class-ajax.php' ); |
||
175 | include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-settings.php' ); |
||
176 | include_once( GRAVITYVIEW_DIR . 'includes/class-frontend-views.php' ); |
||
177 | include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-admin-bar.php' ); |
||
178 | include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-entry-list.php' ); |
||
179 | include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-merge-tags.php'); /** @since 1.8.4 */ |
||
180 | include_once( GRAVITYVIEW_DIR . 'includes/class-data.php' ); |
||
181 | include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-shortcode.php' ); |
||
182 | include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-entry-link-shortcode.php' ); |
||
183 | include_once( GRAVITYVIEW_DIR . 'includes/class-gvlogic-shortcode.php' ); |
||
184 | include_once( GRAVITYVIEW_DIR . 'includes/presets/register-default-templates.php' ); |
||
185 | |||
186 | } |
||
187 | |||
188 | /** |
||
189 | * Check whether GravityView is network activated |
||
190 | * @since 1.7.6 |
||
191 | * @return bool |
||
192 | */ |
||
193 | public static function is_network_activated() { |
||
196 | |||
197 | |||
198 | /** |
||
199 | * Plugin activate function. |
||
200 | * |
||
201 | * @access public |
||
202 | * @static |
||
203 | * @return void |
||
204 | */ |
||
205 | public static function activate() { |
||
226 | |||
227 | |||
228 | /** |
||
229 | * Plugin deactivate function. |
||
230 | * |
||
231 | * @access public |
||
232 | * @static |
||
233 | * @return void |
||
234 | */ |
||
235 | public static function deactivate() { |
||
240 | |||
241 | /** |
||
242 | * Include the extension class |
||
243 | * |
||
244 | * @since 1.5.1 |
||
245 | * @return void |
||
246 | */ |
||
247 | public static function include_extension_framework() { |
||
252 | |||
253 | /** |
||
254 | * Load GravityView_Widget class |
||
255 | * |
||
256 | * @since 1.7.5.1 |
||
257 | */ |
||
258 | public static function include_widget_class() { |
||
261 | |||
262 | |||
263 | /** |
||
264 | * Loads the plugin's translated strings. |
||
265 | * |
||
266 | * @access public |
||
267 | * @return void |
||
268 | */ |
||
269 | public function load_plugin_textdomain() { |
||
270 | |||
271 | $loaded = load_plugin_textdomain( 'gravityview', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); |
||
272 | |||
273 | if ( ! $loaded ) { |
||
274 | $loaded = load_muplugin_textdomain( 'gravityview', '/languages/' ); |
||
275 | } |
||
276 | if ( ! $loaded ) { |
||
277 | $loaded = load_theme_textdomain( 'gravityview', '/languages/' ); |
||
278 | } |
||
279 | if ( ! $loaded ) { |
||
280 | $locale = apply_filters( 'plugin_locale', get_locale(), 'gravityview' ); |
||
281 | $mofile = dirname( __FILE__ ) . '/languages/gravityview-'. $locale .'.mo'; |
||
282 | load_textdomain( 'gravityview', $mofile ); |
||
283 | } |
||
284 | |||
285 | } |
||
286 | |||
287 | /** |
||
288 | * Check if is_admin(), and make sure not DOING_AJAX |
||
289 | * @since 1.7.5 |
||
290 | * @return bool |
||
291 | */ |
||
292 | public static function is_admin() { |
||
298 | |||
299 | /** |
||
300 | * Function to launch frontend objects |
||
301 | * |
||
302 | * @since 1.17 Added $force param |
||
303 | * |
||
304 | * @access public |
||
305 | * |
||
306 | * @param bool $force Whether to force loading, even if GravityView_Plugin::is_admin() returns true |
||
307 | * |
||
308 | * @return void |
||
309 | */ |
||
310 | public function frontend_actions( $force = false ) { |
||
311 | |||
312 | if( self::is_admin() && ! $force ) { return; } |
||
313 | |||
314 | include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-image.php' ); |
||
315 | include_once( GRAVITYVIEW_DIR .'includes/class-template.php' ); |
||
316 | include_once( GRAVITYVIEW_DIR .'includes/class-api.php' ); |
||
317 | include_once( GRAVITYVIEW_DIR .'includes/class-frontend-views.php' ); |
||
318 | include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-change-entry-creator.php' ); |
||
319 | |||
320 | |||
321 | /** |
||
322 | * When an entry is created, check if we need to update the custom slug meta |
||
323 | * todo: move this to its own class.. |
||
324 | */ |
||
325 | add_action( 'gform_entry_created', array( 'GravityView_API', 'entry_create_custom_slug' ), 10, 2 ); |
||
326 | |||
327 | /** |
||
328 | * @action `gravityview_include_frontend_actions` Triggered after all GravityView frontend files are loaded |
||
329 | * |
||
330 | * Nice place to insert extensions' frontend stuff |
||
331 | */ |
||
332 | do_action( 'gravityview_include_frontend_actions' ); |
||
333 | } |
||
334 | |||
335 | /** |
||
336 | * helper function to define the default widget areas |
||
337 | * @todo Move somewhere logical |
||
338 | * @return array definition for default widget areas |
||
339 | */ |
||
340 | public static function get_default_widget_areas() { |
||
352 | |||
353 | /** DEBUG */ |
||
354 | |||
355 | /** |
||
356 | * Logs messages using Gravity Forms logging add-on |
||
357 | * @param string $message log message |
||
358 | * @param mixed $data Additional data to display |
||
359 | * @return void |
||
360 | */ |
||
361 | public static function log_debug( $message, $data = null ){ |
||
369 | |||
370 | /** |
||
371 | * Logs messages using Gravity Forms logging add-on |
||
372 | * @param string $message log message |
||
373 | * @return void |
||
374 | */ |
||
375 | public static function log_error( $message, $data = null ){ |
||
383 | |||
384 | } // end class GravityView_Plugin |
||
385 | |||
386 | add_action('plugins_loaded', array('GravityView_Plugin', 'getInstance'), 1); |
||
387 |
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.