-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
class-visual-portfolio.php
348 lines (304 loc) · 11.2 KB
/
class-visual-portfolio.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
<?php
/**
* Plugin Name: Visual Portfolio, Posts & Image Gallery
* Description: Modern gallery and portfolio plugin with advanced layouts editor. Clean and powerful gallery styles with enormous settings in the Gutenberg block.
* Version: 3.2.3
* Author: Visual Portfolio Team
* Author URI: https://visualportfolio.co/?utm_source=wordpress.org&utm_medium=readme&utm_campaign=byline
* License: GPLv2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: visual-portfolio
*
* @package visual-portfolio
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! defined( 'VISUAL_PORTFOLIO_VERSION' ) ) {
define( 'VISUAL_PORTFOLIO_VERSION', '3.2.3' );
}
if ( ! class_exists( 'Visual_Portfolio' ) ) :
/**
* Visual Portfolio Class
*/
class Visual_Portfolio {
/**
* The single class instance.
*
* @var $instance
*/
private static $instance = null;
/**
* Main Instance
* Ensures only one instance of this class exists in memory at any one time.
*/
public static function instance() {
if ( is_null( self::$instance ) ) {
self::$instance = new self();
self::$instance->init();
}
return self::$instance;
}
/**
* Name of the plugin
*
* @var $plugin_name
*/
public $plugin_name;
/**
* Basename of plugin main file
*
* @var $plugin_basename
*/
public $plugin_basename;
/**
* Path to the plugin directory
*
* @var $plugin_path
*/
public $plugin_path;
/**
* URL to the plugin directory
*
* @var $plugin_url
*/
public $plugin_url;
/**
* Path to the pro plugin directory
*
* @var $plugin_path
*/
public $pro_plugin_path;
/**
* URL to the pro plugin directory
*
* @var $plugin_url
*/
public $pro_plugin_url;
/**
* Visual_Portfolio constructor.
*/
public function __construct() {
/* We do nothing here! */
}
/**
* Init options
*/
public function init() {
$this->plugin_name = esc_html__( 'Visual Portfolio', 'visual-portfolio' );
$this->plugin_basename = plugin_basename( __FILE__ );
$this->plugin_path = plugin_dir_path( __FILE__ );
$this->plugin_url = plugin_dir_url( __FILE__ );
// Check for new standalone Pro plugin and for old Pro addon plugin for back compatibility.
if ( defined( 'VISUAL_PORTFOLIO_PRO' ) || function_exists( 'visual_portfolio_pro' ) ) {
$this->pro_plugin_path = plugin_dir_path( WP_PLUGIN_DIR . '/visual-portfolio-pro/class-visual-portfolio-pro.php' );
$this->pro_plugin_url = plugin_dir_url( WP_PLUGIN_DIR . '/visual-portfolio-pro/class-visual-portfolio-pro.php' );
}
// load textdomain.
load_plugin_textdomain( 'visual-portfolio', false, basename( dirname( __FILE__ ) ) . '/languages' );
// Hooks.
add_action( 'init', array( $this, 'run_deferred_rewrite_rules' ), 20 );
// include helper files.
$this->include_dependencies();
}
/**
* Rewrite Flush Rules if set Transient right after we registered the Portfolio post type.
* ! This is important part, since flush will work only once the post type registered.
*
* TODO: re-check this code, as it looks strange.
*
* @return void
*/
public function run_deferred_rewrite_rules() {
if ( get_transient( 'vp_flush_rewrite_rules' ) ) {
$this->flush_rewrite_rules();
delete_transient( 'vp_flush_rewrite_rules' );
}
}
/**
* Deferred Rewrite Flush Rules.
*
* @return void
*/
public function defer_flush_rewrite_rules() {
set_transient( 'vp_flush_rewrite_rules', true );
}
/**
* Rewrite Flush Rules.
*
* @return void
*/
public function flush_rewrite_rules() {
flush_rewrite_rules();
}
/**
* Activation Hook
*/
public function activation_hook() {
// Welcome Page Flag.
set_transient( '_visual_portfolio_welcome_screen_activation_redirect', true, 30 );
$this->defer_flush_rewrite_rules();
}
/**
* Deactivation Hook
*/
public function deactivation_hook() {
// Sometimes users can't access projects.
// As a workaround user may deactivate and activate the plugin to resolve this problem.
update_option( 'visual_portfolio_updated_caps', '' );
$this->flush_rewrite_rules();
}
/**
* Include dependencies
*/
private function include_dependencies() {
// Deprecations run before all features.
require_once $this->plugin_path . 'classes/class-deprecated.php';
require_once $this->plugin_path . 'classes/class-security.php';
require_once $this->plugin_path . 'gutenberg/utils/control-condition-check/index.php';
require_once $this->plugin_path . 'gutenberg/utils/control-get-value/index.php';
require_once $this->plugin_path . 'gutenberg/utils/controls-dynamic-css/index.php';
require_once $this->plugin_path . 'gutenberg/utils/encode-decode/index.php';
require_once $this->plugin_path . 'classes/class-templates.php';
require_once $this->plugin_path . 'classes/class-parse-blocks.php';
require_once $this->plugin_path . 'classes/class-assets.php';
require_once $this->plugin_path . 'classes/class-breakpoints.php';
require_once $this->plugin_path . 'classes/class-image-placeholder.php';
// this settings class order is required.
require_once $this->plugin_path . 'classes/class-settings.php';
require_once $this->plugin_path . 'classes/class-welcome-screen.php';
require_once $this->plugin_path . 'classes/class-ask-review.php';
require_once $this->plugin_path . 'classes/class-images.php';
require_once $this->plugin_path . 'classes/class-rest.php';
require_once $this->plugin_path . 'classes/class-get-portfolio.php';
require_once $this->plugin_path . 'classes/class-gutenberg.php';
require_once $this->plugin_path . 'classes/class-gutenberg-saved.php';
require_once $this->plugin_path . 'classes/class-shortcode.php';
require_once $this->plugin_path . 'classes/class-preview.php';
require_once $this->plugin_path . 'classes/class-custom-post-type.php';
require_once $this->plugin_path . 'classes/class-custom-post-meta.php';
require_once $this->plugin_path . 'classes/class-admin.php';
require_once $this->plugin_path . 'classes/class-controls.php';
require_once $this->plugin_path . 'classes/class-supported-themes.php';
require_once $this->plugin_path . 'classes/class-archive-mapping.php';
require_once $this->plugin_path . 'classes/class-sitemap.php';
require_once $this->plugin_path . 'classes/class-seo-optimization.php';
require_once $this->plugin_path . 'classes/class-deactivate-duplicate-plugin.php';
// 3rd code integration.
require_once $this->plugin_path . 'classes/3rd/plugins/class-a3-lazy-load.php';
require_once $this->plugin_path . 'classes/3rd/plugins/class-divi.php';
require_once $this->plugin_path . 'classes/3rd/plugins/class-elementor.php';
require_once $this->plugin_path . 'classes/3rd/plugins/class-ewww-image-optimizer.php';
require_once $this->plugin_path . 'classes/3rd/plugins/class-imagify.php';
require_once $this->plugin_path . 'classes/3rd/plugins/class-jetpack.php';
require_once $this->plugin_path . 'classes/3rd/plugins/class-lazy-loading-responsive-images.php';
require_once $this->plugin_path . 'classes/3rd/plugins/class-paid-memberships-pro.php';
require_once $this->plugin_path . 'classes/3rd/plugins/class-sg-cachepress.php';
require_once $this->plugin_path . 'classes/3rd/plugins/class-tinymce.php';
require_once $this->plugin_path . 'classes/3rd/plugins/class-vc.php';
require_once $this->plugin_path . 'classes/3rd/plugins/class-wp-rocket.php';
require_once $this->plugin_path . 'classes/3rd/plugins/class-wpml.php';
require_once $this->plugin_path . 'classes/3rd/plugins/class-rank-math.php';
require_once $this->plugin_path . 'classes/3rd/plugins/class-yoast.php';
require_once $this->plugin_path . 'classes/3rd/plugins/class-all-in-one-seo.php';
require_once $this->plugin_path . 'classes/3rd/themes/class-avada.php';
require_once $this->plugin_path . 'classes/3rd/themes/class-enfold.php';
require_once $this->plugin_path . 'classes/3rd/themes/class-thrive-architect.php';
// Migration run after all features.
require_once $this->plugin_path . 'classes/class-migration.php';
}
/**
* Include template
*
* @param string $template_name file name.
* @param array $args args for template.
*/
public function include_template( $template_name, $args = array() ) {
Visual_Portfolio_Templates::include_template( $template_name, $args );
}
/**
* Find css template file
*
* @param string $template_name file name.
*
* @return string
*/
public function find_template_styles( $template_name ) {
return Visual_Portfolio_Templates::find_template_styles( $template_name );
}
/**
* Include template style
*
* @param string $handle style handle name.
* @param string $template_name file name.
* @param array $deps dependencies array.
* @param string|bool|null $ver version string.
* @param string $media media string.
*/
public function include_template_style( $handle, $template_name, $deps = array(), $ver = false, $media = 'all' ) {
Visual_Portfolio_Templates::include_template_style( $handle, $template_name, $deps, $ver, $media );
}
/**
* Get oEmbed data
*
* @param string $url - url of oembed.
* @param int $width - width of oembed.
* @param int $height - height of oembed.
*
* @return array|bool|false|object
*/
public function get_oembed_data( $url, $width = null, $height = null ) {
$cache_name = 'vp_oembed_data_' . $url . ( $width ? $width : '' ) . ( $height ? $height : '' );
$cached = get_transient( $cache_name );
if ( $cached ) {
return $cached;
}
if ( function_exists( '_wp_oembed_get_object' ) ) {
require_once ABSPATH . WPINC . '/class-oembed.php';
}
$args = array();
if ( $width ) {
$args['width'] = $width;
}
if ( $height ) {
$args['height'] = $height;
}
// If height is not given, but the width is, use 1080p aspect ratio. And vice versa.
if ( $width && ! $height ) {
$args['height'] = $width * ( 1080 / 1920 );
}
if ( ! $width && $height ) {
$args['width'] = $height * ( 1920 / 1080 );
}
$oembed = _wp_oembed_get_object();
$provider = $oembed->get_provider( $url, $args );
$data = $oembed->fetch( $provider, $url, $args );
if ( $data ) {
$data = (array) $data;
if ( ! isset( $data['url'] ) ) {
$data['url'] = $url;
}
if ( ! isset( $data['provider'] ) ) {
$data['provider'] = $provider;
}
// Convert url to hostname, eg: "youtube" instead of "https://youtube.com/".
$data['provider-name'] = pathinfo( str_replace( array( 'www.' ), '', wp_parse_url( $url, PHP_URL_HOST ) ), PATHINFO_FILENAME );
// save cache.
set_transient( $cache_name, $data, DAY_IN_SECONDS );
return $data;
}
return false;
}
}
/**
* Function works with the Visual_Portfolio class instance
*
* @return object Visual_Portfolio
*/
function visual_portfolio() {
return Visual_Portfolio::instance();
}
add_action( 'plugins_loaded', 'visual_portfolio' );
register_activation_hook( __FILE__, array( visual_portfolio(), 'activation_hook' ) );
register_deactivation_hook( __FILE__, array( visual_portfolio(), 'deactivation_hook' ) );
endif;