PluginProbe
Sight – Professional Image Gallery and Portfolio / 1.0.6
Sight – Professional Image Gallery and Portfolio v1.0.6
trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8
sight / core / class-sight.php

class-sight.php in Sight – Professional Image Gallery and Portfolio 1.0.6, at core/class-sight.php

219 lines 4.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * The file that defines the core plugin class
4 *
5 * A class definition that includes attributes and functions used across both the
6 * public-facing side of the site and the admin area.
7 *
8 * @package Sight
9 */
10
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit; // Exit if accessed directly.
13 }
14
15 if ( ! class_exists( 'Sight_Portfolio' ) ) {
16 /**
17 * Main Core Class
18 */
19 class Sight_Portfolio {
20 /**
21 * The plugin version number.
22 *
23 * @var string $data The plugin version number.
24 */
25 public $version;
26
27 /**
28 * The plugin data array.
29 *
30 * @var array $data The plugin data array.
31 */
32 public $data = array();
33
34 /**
35 * The plugin settings array.
36 *
37 * @var array $settings The plugin data array.
38 */
39 public $settings = array();
40
41 /**
42 * INIT (global theme queue)
43 */
44 public function init() {
45 if ( ! function_exists( 'get_plugin_data' ) ) {
46 require_once ABSPATH . 'wp-admin/includes/plugin.php';
47 }
48
49 // Get plugin data.
50 $plugin_data = get_plugin_data( SIGHT_PATH . 'sight.php' );
51
52 // Vars.
53 $this->version = $plugin_data['Version'];
54
55 // Settings.
56 $this->settings = array(
57 'name' => esc_html__( 'Sight', 'sight' ),
58 'version' => $plugin_data['Version'],
59 );
60
61 // Include core.
62 require_once SIGHT_PATH . 'core/core-api.php';
63 require_once SIGHT_PATH . 'core/core-plugin-functions.php';
64 require_once SIGHT_PATH . 'core/core-register-post-types.php';
65 require_once SIGHT_PATH . 'core/core-register-category-fields.php';
66 require_once SIGHT_PATH . 'core/core-video-settings.php';
67
68 // Include core classes.
69 require_once SIGHT_PATH . 'core/block-renderer-controller.php';
70 require_once SIGHT_PATH . 'core/block-utils-is-field-visible.php';
71
72 // Render files.
73 require_once SIGHT_PATH . 'render/sight-entry.php';
74 require_once SIGHT_PATH . 'render/sight-load-more.php';
75
76 // Elementor integration.
77 if ( defined( 'ELEMENTOR_VERSION' ) ) {
78 require_once SIGHT_PATH . 'elementor/integration.php';
79 }
80
81 // Gutenberg integration.
82 if ( function_exists( 'register_block_type' ) ) {
83 require_once SIGHT_PATH . 'gutenberg/block-portfolio.php';
84 }
85
86 // Render.
87 require_once SIGHT_PATH . 'render/sight-render.php';
88
89 // Actions.
90 add_action( 'sight_plugin_activation', array( $this, 'activation' ) );
91 add_action( 'plugins_loaded', array( $this, 'check_version' ) );
92 }
93
94 /**
95 * This function will safely define a constant
96 *
97 * @param string $name The name.
98 * @param mixed $value The value.
99 */
100 public function define( $name, $value = true ) {
101
102 if ( ! defined( $name ) ) {
103 define( $name, $value );
104 }
105 }
106
107 /**
108 * Returns true if has setting.
109 *
110 * @param string $name The name.
111 */
112 public function has_setting( $name ) {
113 return isset( $this->settings[ $name ] );
114 }
115
116 /**
117 * Returns a setting.
118 *
119 * @param string $name The name.
120 */
121 public function get_setting( $name ) {
122 return isset( $this->settings[ $name ] ) ? $this->settings[ $name ] : null;
123 }
124
125 /**
126 * Updates a setting.
127 *
128 * @param string $name The name.
129 * @param mixed $value The value.
130 */
131 public function update_setting( $name, $value ) {
132 $this->settings[ $name ] = $value;
133 return true;
134 }
135
136 /**
137 * Returns data.
138 *
139 * @param string $name The name.
140 */
141 public function get_data( $name ) {
142 return isset( $this->data[ $name ] ) ? $this->data[ $name ] : null;
143 }
144
145 /**
146 * Sets data.
147 *
148 * @param string $name The name.
149 * @param mixed $value The value.
150 */
151 public function set_data( $name, $value ) {
152 $this->data[ $name ] = $value;
153 }
154
155 /**
156 * Hook activation
157 */
158 public function activation() {
159 if ( get_option( 'sight_db_version' ) ) {
160 return;
161 }
162
163 update_option( 'sight_db_version', sight_raw_setting( 'version' ), true );
164 }
165
166 /**
167 * Check current version
168 */
169 public function check_version() {
170
171 // Version Data.
172 $new = sight_raw_setting( 'version' );
173
174 // Get db version.
175 $current = get_option( 'sight_db_version', $new );
176
177 // If versions don't match.
178 if ( $current && $current !== $new ) {
179 /**
180 * If different versions call a special hook.
181 *
182 * @param string $current Current version.
183 * @param string $new New version.
184 */
185 do_action( 'sight_plugin_upgrade', $current, $new );
186
187 update_option( 'sight_db_version', $new, true );
188 }
189
190 if ( $current ) {
191 update_option( 'sight_db_version', $new, true );
192 }
193 }
194 }
195
196 /**
197 * The main function responsible for returning the one true sight Instance to functions everywhere.
198 * Use this function like you would a global variable, except without needing to declare the global.
199 *
200 * Example: <?php $sight = sight_portfolio(); ?>
201 */
202 function sight_portfolio() {
203
204 // Globals.
205 global $sight_instance;
206
207 // Init.
208 if ( ! isset( $sight_instance ) ) {
209 $sight_instance = new Sight_Portfolio();
210 $sight_instance->init();
211 }
212
213 return $sight_instance;
214 }
215
216 // Initialize.
217 sight_portfolio();
218 }
219