PluginProbe
Sight – Professional Image Gallery and Portfolio / 1.0.9
Sight – Professional Image Gallery and Portfolio v1.0.9
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.9, at core/class-sight.php

233 lines 5.3 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 add_action( 'init', array( $this, 'flush_rewrite_rules' ), 999 );
93 }
94
95 /**
96 * This function will safely define a constant
97 *
98 * @param string $name The name.
99 * @param mixed $value The value.
100 */
101 public function define( $name, $value = true ) {
102
103 if ( ! defined( $name ) ) {
104 define( $name, $value );
105 }
106 }
107
108 /**
109 * Returns true if has setting.
110 *
111 * @param string $name The name.
112 */
113 public function has_setting( $name ) {
114 return isset( $this->settings[ $name ] );
115 }
116
117 /**
118 * Returns a setting.
119 *
120 * @param string $name The name.
121 */
122 public function get_setting( $name ) {
123 return isset( $this->settings[ $name ] ) ? $this->settings[ $name ] : null;
124 }
125
126 /**
127 * Updates a setting.
128 *
129 * @param string $name The name.
130 * @param mixed $value The value.
131 */
132 public function update_setting( $name, $value ) {
133 $this->settings[ $name ] = $value;
134 return true;
135 }
136
137 /**
138 * Returns data.
139 *
140 * @param string $name The name.
141 */
142 public function get_data( $name ) {
143 return isset( $this->data[ $name ] ) ? $this->data[ $name ] : null;
144 }
145
146 /**
147 * Sets data.
148 *
149 * @param string $name The name.
150 * @param mixed $value The value.
151 */
152 public function set_data( $name, $value ) {
153 $this->data[ $name ] = $value;
154 }
155
156 /**
157 * Hook activation
158 */
159 public function activation() {
160 update_option( 'sight_db_activation', 1, true );
161
162 if ( get_option( 'sight_db_version' ) ) {
163 return;
164 }
165
166 update_option( 'sight_db_version', sight_raw_setting( 'version' ), true );
167 }
168
169 /**
170 * Removes rewrite rules and then recreate rewrite rules.
171 */
172 public function flush_rewrite_rules() {
173 if ( get_option( 'sight_db_activation' ) ) {
174 flush_rewrite_rules();
175
176 delete_option( 'sight_db_activation' );
177 }
178 }
179
180 /**
181 * Check current version
182 */
183 public function check_version() {
184
185 // Version Data.
186 $new = sight_raw_setting( 'version' );
187
188 // Get db version.
189 $current = get_option( 'sight_db_version', $new );
190
191 // If versions don't match.
192 if ( $current && $current !== $new ) {
193 /**
194 * If different versions call a special hook.
195 *
196 * @param string $current Current version.
197 * @param string $new New version.
198 */
199 do_action( 'sight_plugin_upgrade', $current, $new );
200
201 update_option( 'sight_db_version', $new, true );
202 }
203
204 if ( $current ) {
205 update_option( 'sight_db_version', $new, true );
206 }
207 }
208 }
209
210 /**
211 * The main function responsible for returning the one true sight Instance to functions everywhere.
212 * Use this function like you would a global variable, except without needing to declare the global.
213 *
214 * Example: <?php $sight = sight_portfolio(); ?>
215 */
216 function sight_portfolio() {
217
218 // Globals.
219 global $sight_instance;
220
221 // Init.
222 if ( ! isset( $sight_instance ) ) {
223 $sight_instance = new Sight_Portfolio();
224 $sight_instance->init();
225 }
226
227 return $sight_instance;
228 }
229
230 // Initialize.
231 sight_portfolio();
232 }
233