These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
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 | * Get active instance |
||
43 | * |
||
44 | * @access public |
||
45 | * @since 1.0.0 |
||
46 | * @return self::$instance The one true S214_Settings_Demo |
||
47 | */ |
||
48 | public static function instance() { |
||
49 | if( ! self::$instance ) { |
||
50 | self::$instance = new S214_Settings_Demo(); |
||
51 | self::$instance->setup_constants(); |
||
52 | self::$instance->includes(); |
||
53 | } |
||
54 | |||
55 | return self::$instance; |
||
56 | } |
||
57 | |||
58 | |||
59 | /** |
||
60 | * Setup plugin constants |
||
61 | * |
||
62 | * @access private |
||
63 | * @since 1.0.0 |
||
64 | * @return void |
||
65 | */ |
||
66 | private function setup_constants() { |
||
67 | // Plugin version |
||
68 | define( 'S214_SETTINGS_DEMO_VER', '1.0.0' ); |
||
69 | |||
70 | // Plugin path |
||
71 | define( 'S214_SETTINGS_DEMO_DIR', plugin_dir_path( __FILE__ ) ); |
||
72 | |||
73 | // Plugin URL |
||
74 | define( 'S214_SETTINGS_DEMO_URL', plugin_dir_url( __FILE__ ) ); |
||
75 | } |
||
76 | |||
77 | |||
78 | /** |
||
79 | * Include necessary files |
||
80 | * |
||
81 | * @access private |
||
82 | * @since 1.0.0 |
||
83 | * @global array $s214_settings_demo_options The S214_Settings_Demo options array |
||
84 | * @return void |
||
85 | */ |
||
86 | private function includes() { |
||
87 | global $s214_settings_demo_options; |
||
1 ignored issue
–
show
|
|||
88 | |||
89 | if( ! class_exists( 'S214_Settings' ) ) { |
||
90 | require_once S214_SETTINGS_DEMO_DIR . 'includes/libraries/S214-Settings/source/class.s214-settings.php'; |
||
91 | } |
||
92 | |||
93 | $settings = new S214_Settings( 's214-settings-demo', 'welcome' ); |
||
94 | $s214_settings_demo_options = $settings->get_settings(); |
||
95 | |||
96 | require_once S214_SETTINGS_DEMO_DIR . 'includes/actions.php'; |
||
97 | require_once S214_SETTINGS_DEMO_DIR . 'includes/settings.php'; |
||
98 | |||
99 | // Install file is only for unit tests |
||
100 | require_once S214_SETTINGS_DEMO_DIR . 'includes/install.php'; |
||
101 | } |
||
102 | } |
||
103 | } |
||
104 | |||
105 | |||
106 | /** |
||
107 | * The main function responsible for returning the one true S214_Settings_Demo |
||
108 | * instance to functions everywhere |
||
109 | * |
||
110 | * @since 1.0.0 |
||
111 | * @return S214_Settings_Demo The one true S214_Settings_Demo |
||
112 | */ |
||
113 | function s214_settings_demo() { |
||
114 | return S214_Settings_Demo::instance(); |
||
115 | } |
||
116 | add_action( 'plugins_loaded', 's214_settings_demo' ); |
||
117 |
Instead of relying on
global
state, we recommend one of these alternatives:1. Pass all data via parameters
2. Create a class that maintains your state