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

219 lines 5.0 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', false, false );
51
52 // Vars.
53 $this->version = $plugin_data['Version'];
54
55 // Settings.
56 $this->settings = array(
57 'version' => $plugin_data['Version'],
58 );
59
60 // Include core.
61 require_once SIGHT_PATH . 'core/core-api.php';
62 require_once SIGHT_PATH . 'core/core-plugin-functions.php';
63 require_once SIGHT_PATH . 'core/core-register-post-types.php';
64 require_once SIGHT_PATH . 'core/core-register-category-fields.php';
65 require_once SIGHT_PATH . 'core/core-video-settings.php';
66
67 // Include core classes.
68 require_once SIGHT_PATH . 'core/block-renderer-controller.php';
69 require_once SIGHT_PATH . 'core/block-utils-is-field-visible.php';
70
71 // Render files.
72 require_once SIGHT_PATH . 'render/sight-entry.php';
73 require_once SIGHT_PATH . 'render/sight-load-more.php';
74
75 // Elementor integration.
76 if ( defined( 'ELEMENTOR_VERSION' ) ) {
77 require_once SIGHT_PATH . 'elementor/integration.php';
78 }
79
80 // Gutenberg integration.
81 if ( function_exists( 'register_block_type' ) ) {
82 require_once SIGHT_PATH . 'gutenberg/block-portfolio.php';
83 }
84
85 // Render.
86 require_once SIGHT_PATH . 'render/sight-render.php';
87
88 // Actions.
89 add_action( 'sight_plugin_activation', array( $this, 'activation' ) );
90 add_action( 'plugins_loaded', array( $this, 'check_version' ) );
91 add_action( 'init', array( $this, 'flush_rewrite_rules' ), 999 );
92 }
93
94 /**
95 * Returns true if has setting.
96 *
97 * @param string $name The name.
98 */
99 public function has_setting( $name ) {
100 return isset( $this->settings[ $name ] );
101 }
102
103 /**
104 * Returns a setting.
105 *
106 * @param string $name The name.
107 */
108 public function get_setting( $name ) {
109 return isset( $this->settings[ $name ] ) ? $this->settings[ $name ] : null;
110 }
111
112 /**
113 * Updates a setting.
114 *
115 * @param string $name The name.
116 * @param mixed $value The value.
117 */
118 public function update_setting( $name, $value ) {
119 $this->settings[ $name ] = $value;
120 return true;
121 }
122
123 /**
124 * Returns data.
125 *
126 * @param string $name The name.
127 */
128 public function get_data( $name ) {
129 return isset( $this->data[ $name ] ) ? $this->data[ $name ] : null;
130 }
131
132 /**
133 * Sets data.
134 *
135 * @param string $name The name.
136 * @param mixed $value The value.
137 */
138 public function set_data( $name, $value ) {
139 $this->data[ $name ] = $value;
140 }
141
142 /**
143 * Hook activation
144 */
145 public function activation() {
146 update_option( 'sight_db_activation', 1, true );
147
148 if ( get_option( 'sight_db_version' ) ) {
149 return;
150 }
151
152 update_option( 'sight_db_version', sight_raw_setting( 'version' ), true );
153 }
154
155 /**
156 * Removes rewrite rules and then recreate rewrite rules.
157 */
158 public function flush_rewrite_rules() {
159 if ( get_option( 'sight_db_activation' ) ) {
160 flush_rewrite_rules();
161
162 delete_option( 'sight_db_activation' );
163 }
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