Completed
Branch master (a79da2)
by
unknown
01:37
created

s214-settings-demo.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 31 and the first side effect is on line 19.

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.

Loading history...
2
/**
3
 * Plugin Name:     S214 Settings Demo
4
 * Plugin URI:      https://section214.com
5
 * Description:     Demo plugin for the S214 Settings library
6
 * Version:         1.0.0
7
 * Author:          Daniel J Griffiths
8
 * Author URI:      https://section214.com
9
 * Text Domain:     s214-settings-demo
10
 *
11
 * @package         S214_Settings_Demo
12
 * @author          Daniel J Griffiths <[email protected]>
13
 * @copyright       Copyright (c) 2016, Daniel J Griffiths
14
 */
15
16
17
// Exit if accessed directly
18
if( ! defined( 'ABSPATH' ) ) {
19
	exit;
20
}
21
22
23
if( ! class_exists( 'S214_Settings_Demo' ) ) {
24
25
26
	/**
27
	 * Main S214_Settings_Demo class
28
	 *
29
	 * @since       1.0.0
30
	 */
31
	class S214_Settings_Demo {
32
33
34
		/**
35
		 * @var         S214_Settings_Demo $instance The one true S214_Settings_Demo
36
		 * @since       1.0.0
37
		 */
38
		private static $instance;
39
40
41
		/**
42
		 * @var         object $settings The S214_Settings settings object
43
		 * @since       1.0.0
44
		 */
45
		public $settings;
46
47
48
		/**
49
		 * Get active instance
50
		 *
51
		 * @access      public
52
		 * @since       1.0.0
53
		 * @return      self::$instance The one true S214_Settings_Demo
0 ignored issues
show
The doc-type self::$instance could not be parsed: Unknown type name "self::$instance" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
54
		 */
55 1
		public static function instance() {
56 1
			if( ! self::$instance ) {
57
				self::$instance = new S214_Settings_Demo();
58
				self::$instance->setup_constants();
59
				self::$instance->includes();
60
			}
61
62 1
			return self::$instance;
63
		}
64
65
66
		/**
67
		 * Setup plugin constants
68
		 *
69
		 * @access      private
70
		 * @since       1.0.0
71
		 * @return      void
72
		 */
73
		private function setup_constants() {
74
			// Plugin version
75
			define( 'S214_SETTINGS_DEMO_VER', '1.0.0' );
76
77
			// Plugin path
78
			define( 'S214_SETTINGS_DEMO_DIR', plugin_dir_path( __FILE__ ) );
79
80
			// Plugin URL
81
			define( 'S214_SETTINGS_DEMO_URL', plugin_dir_url( __FILE__ ) );
82
		}
83
84
85
		/**
86
		 * Include necessary files
87
		 *
88
		 * @access      private
89
		 * @since       1.0.0
90
		 * @global		array $s214_settings_demo_options The S214_Settings_Demo options array
91
		 * @return      void
92
		 */
93
		private function includes() {
94
			global $s214_settings_demo_options;
95
96
			if( ! class_exists( 'S214_Settings' ) ) {
97
				require_once S214_SETTINGS_DEMO_DIR . 'includes/libraries/S214-Settings/source/class.s214-settings.php';
98
			}
99
100
			$this->settings = new S214_Settings( 's214-settings-demo', 'welcome' );
101
			$s214_settings_demo_options = $this->settings->get_settings();
102
103
			require_once S214_SETTINGS_DEMO_DIR . 'includes/actions.php';
104
			require_once S214_SETTINGS_DEMO_DIR . 'includes/settings.php';
105
		}
106
	}
107
}
108
109
110
/**
111
 * The main function responsible for returning the one true S214_Settings_Demo
112
 * instance to functions everywhere
113
 *
114
 * @since	   1.0.0
115
 * @return	  S214_Settings_Demo The one true S214_Settings_Demo
116
 */
117
function s214_settings_demo() {
118 1
	return S214_Settings_Demo::instance();
119
}
120
add_action( 'plugins_loaded', 's214_settings_demo' );
121