PluginProbe
Webyx for Gutenberg – Fullpage Fullscreen Scrolling Websites / trunk
Webyx for Gutenberg – Fullpage Fullscreen Scrolling Websites vtrunk
trunk 1.0.0 1.0.1 1.0.2 1.1.0 1.2.0 1.3.0 1.4.0 1.4.1 1.4.2 1.5.0 1.6.0 1.6.1 1.6.10 1.6.11 1.6.12 1.6.13 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.7.1 1.6.7.2 All 31 releases
webyx / webyx.php

webyx.php in Webyx for Gutenberg – Fullpage Fullscreen Scrolling Websites trunk, at webyx.php

546 lines 19.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: Webyx
4 * Description: Create amazing fullpage fullscreen scrolling websites with our fast, configurable and easy block for Gutenberg.
5 * Requires at least: 6.9
6 * Requires PHP: 7.4
7 * Version: 2.1.1
8 * Author: Webineer Team
9 * Author URI: https://webyx.it/
10 * License: GPL-3.0-or-later
11 * License URI: https://www.gnu.org/licenses/gpl-3.0.html
12 * Text Domain: webyx
13 * @package webyx
14 */
15 if ( ! defined( 'ABSPATH' ) ) {
16 exit;
17 }
18 define( 'WEBYX_FG__FILE__', __FILE__ );
19 define( 'WEBYX_FG_PATH', plugin_dir_path( WEBYX_FG__FILE__ ) );
20 define( 'WEBYX_FG_WP_MIN_VERSION', '5.7' );
21 define( 'WEBYX_FG_PHP_MIN_VERSION', '7.4' );
22 define( 'WEBYX_FG_ASSET_MIN', TRUE );
23 define( 'WEBYX_FG_REVIEW_THRESHOLD_DATE', '-1 days' );
24 if ( ! version_compare( PHP_VERSION, WEBYX_FG_PHP_MIN_VERSION, '>=' ) ) {
25 function webyx_fg_fail_php_version () {
26 $message = sprintf( esc_html__( 'Webyx for Gutenberg plugin requires PHP version %s+, plugin is currently NOT RUNNING.' ), WEBYX_FG_PHP_MIN_VERSION );
27 $html_message = sprintf( '<div class="error">%s</div>', wpautop( $message ) );
28 echo wp_kses_post( $html_message );
29 }
30 add_action( 'admin_notices', 'webyx_fg_fail_php_version' );
31 } else if ( ! version_compare( get_bloginfo( 'version' ), WEBYX_FG_WP_MIN_VERSION, '>=' ) ) {
32 function webyx_fg_fail_wp_version () {
33 $message = sprintf( esc_html__( 'Webyx for Gutenberg plugin requires WordPress version %s+. Because you are using an earlier version, the plugin is currently NOT RUNNING.' ), WEBYX_FG_WP_MIN_VERSION );
34 $html_message = sprintf( '<div class="error">%s</div>', wpautop( $message ) );
35 echo wp_kses_post( $html_message );
36 }
37 add_action( 'admin_notices', 'webyx_fg_fail_wp_version' );
38 } else {
39 if ( ! class_exists( 'Webyx_FG' ) ) {
40 class Webyx_FG {
41 private static $instance;
42 protected $templates;
43 public function __construct () {
44 $this->templates = array(
45 'templates/page-webyx.php' => 'webyx'
46 );
47 if ( function_exists( 'register_block_type' ) ) {
48 $this->webyx_fg_register_blocks();
49 $this->webyx_fg_init_webyx_menu();
50 $this->webyx_fg_remove_top_bar();
51 $this->webyx_fg_init_page_template();
52 $this->webyx_fg_handle_review();
53 $this->webyx_fg_init_setting_admin_page();
54 }
55 }
56 public static function webyx_fg_get_instance () {
57 if ( null == self::$instance ) {
58 self::$instance = new self();
59 }
60 return self::$instance;
61 }
62 public function webyx_fg_register_blocks () {
63 add_action(
64 'init',
65 array(
66 $this,
67 'webyx_fg_register_block'
68 )
69 );
70 add_action(
71 'init',
72 array(
73 $this,
74 'webyx_fg_register_block_assets'
75 )
76 );
77 }
78 public function webyx_fg_init_webyx_menu () {
79 add_action(
80 'after_setup_theme',
81 array(
82 $this,
83 'webyx_fg_register_menu'
84 )
85 );
86 add_filter(
87 'get_custom_logo',
88 array(
89 $this,
90 'webyx_fg_get_custom_logo'
91 )
92 );
93 }
94 public function webyx_fg_remove_top_bar () {
95 add_filter(
96 'show_admin_bar',
97 array(
98 $this,
99 'webyx_fg_remove_top_admin_bar_in_preview_page'
100 )
101 );
102 }
103 public function webyx_fg_register_block_assets () {
104 $asset_file = include( plugin_dir_path( __FILE__ ) . 'build/index.asset.php');
105 wp_register_script(
106 'webyx-fg-editor',
107 plugins_url(
108 'build/index.js',
109 __FILE__
110 ),
111 $asset_file[ 'dependencies' ],
112 $asset_file[ 'version' ]
113 );
114 wp_register_style(
115 'webyx-fg-editor',
116 plugins_url(
117 'build/index.css',
118 __FILE__
119 ),
120 $asset_file[ 'version' ]
121 );
122 }
123 public function webyx_fg_register_block () {
124 register_block_type(
125 'webyx-fg/webyx-wrapper',
126 array(
127 'api_version' => 3,
128 'editor_script' => 'webyx-fg-editor',
129 'editor_style' => 'webyx-fg-editor',
130 )
131 );
132 register_block_type(
133 'webyx-fg/webyx-section',
134 array(
135 'api_version' => 3,
136 'editor_script' => 'webyx-fg-editor',
137 'editor_style' => 'webyx-fg-editor'
138 )
139 );
140 register_block_type(
141 'webyx-fg/webyx-slide',
142 array(
143 'api_version' => 3,
144 'editor_script' => 'webyx-fg-editor',
145 'editor_style' => 'webyx-fg-editor'
146 )
147 );
148 }
149 public function webyx_fg_remove_top_admin_bar_in_preview_page ( $show_admin_bar ) {
150 global $post;
151 if ( ! $post || ! isset( $post->ID ) ) {
152 return $show_admin_bar;
153 }
154 $page_id = $post->ID;
155 if ( 'page' === get_post_type( $page_id ) && 'templates/page-webyx.php' === get_page_template_slug( $page_id ) ) {
156 return ! get_option( 'webyx_fg_hide_admin_top_bar', 'true' );
157 } else {
158 return $show_admin_bar;
159 }
160 }
161 public function webyx_fg_enqueue_assets_core () {
162 wp_enqueue_style(
163 'webyx-core-free',
164 plugins_url(
165 WEBYX_FG_ASSET_MIN ? '/assets/css/webyx.min.css' : '/assets/css/webyx.css',
166 __FILE__
167 ),
168 array(),
169 filemtime(
170 plugin_dir_path( __FILE__ ) . ( WEBYX_FG_ASSET_MIN ? '/assets/css/webyx.min.css' : '/assets/css/webyx.css' )
171 )
172 );
173 wp_enqueue_style(
174 'webyx-menu-free',
175 plugins_url(
176 WEBYX_FG_ASSET_MIN ? '/assets/css/webyx-menu.min.css' : '/assets/css/webyx-menu.css',
177 __FILE__
178 ),
179 array(),
180 filemtime(
181 plugin_dir_path( __FILE__ ) . ( WEBYX_FG_ASSET_MIN ? '/assets/css/webyx-menu.min.css' : '/assets/css/webyx-menu.css' )
182 )
183 );
184 wp_enqueue_script(
185 'webyx-core-free',
186 plugins_url(
187 WEBYX_FG_ASSET_MIN ? '/assets/js/webyx.min.js' : '/assets/js/webyx.js',
188 __FILE__
189 ),
190 array(),
191 filemtime(
192 plugin_dir_path( __FILE__ ) . ( WEBYX_FG_ASSET_MIN ? '/assets/js/webyx.min.js' : '/assets/js/webyx.js' )
193 ),
194 TRUE
195 );
196 wp_enqueue_script(
197 'webyx-menu-free',
198 plugins_url(
199 WEBYX_FG_ASSET_MIN ? 'assets/js/webyx-menu.min.js' : 'assets/js/webyx-menu.js',
200 __FILE__
201 ),
202 array(),
203 filemtime(
204 plugin_dir_path( __FILE__ ) . ( WEBYX_FG_ASSET_MIN ? 'assets/js/webyx-menu.min.js' : 'assets/js/webyx-menu.js' )
205 ),
206 TRUE
207 );
208 }
209 public function webyx_fg_init_page_template () {
210 add_filter(
211 'theme_page_templates',
212 array(
213 $this,
214 'webyx_fg_add_new_template'
215 )
216 );
217 add_filter(
218 'wp_insert_post_data',
219 array(
220 $this,
221 'webyx_fg_register_project_templates'
222 )
223 );
224 add_filter(
225 'template_include',
226 array(
227 $this,
228 'webyx_fg_view_project_template'
229 ),
230 12
231 );
232 add_filter(
233 'wp_theme_json_data_default',
234 array(
235 $this,
236 'webyx_fg_wp_theme_json_data_defaults'
237 )
238 );
239 }
240 public function webyx_fg_wp_theme_json_data_defaults ( $theme_json ) {
241 if ( $theme_json && has_block( 'webyx-fg/webyx-wrapper' ) ) {
242 add_action(
243 'wp_enqueue_scripts',
244 array(
245 $this,
246 'webyx_fg_enqueue_assets_core'
247 )
248 );
249 }
250 return $theme_json;
251 }
252 public function webyx_fg_handle_review () {
253 add_action(
254 'admin_init',
255 array(
256 $this,
257 'webyx_fg_check_installation_time'
258 )
259 );
260 add_action(
261 'admin_init',
262 array(
263 $this,
264 'webyx_fg_spare_me'
265 ), 5
266 );
267 add_action(
268 'admin_enqueue_scripts',
269 array(
270 $this,
271 'webyx_fg_admin_css'
272 )
273 );
274 register_activation_hook(
275 __FILE__,
276 array(
277 $this,
278 'webyx_fg_activation_time'
279 )
280 );
281 }
282 public function webyx_fg_add_new_template ( $posts_templates ) {
283 $posts_templates = array_merge( $posts_templates, $this->templates );
284 return $posts_templates;
285 }
286 public function webyx_fg_register_project_templates ( $atts ) {
287 $cache_key = 'page_templates-' . md5( get_theme_root() . '/' . get_stylesheet() );
288 $templates = wp_get_theme()->get_page_templates();
289 if ( empty( $templates ) ) {
290 $templates = array();
291 }
292 wp_cache_delete( $cache_key , 'themes');
293 $templates = array_merge( $templates, $this->templates );
294 wp_cache_add( $cache_key, $templates, 'themes', 1800 );
295 return $atts;
296 }
297 public function webyx_fg_view_project_template ( $template ) {
298 global $post;
299 $webyx_theme = true;
300 $template_webyx_page = WEBYX_FG_PATH . 'templates\page-webyx.php';
301 if ( ! $post ) {
302 if ( $webyx_theme ) {
303 return $template_webyx_page;
304 }
305 $this->webyx_fg_enqueue_assets_core();
306 return $template;
307 }
308 $blocks = parse_blocks( $post->post_content );
309 if ( count( $blocks ) && 'webyx-fg/webyx-wrapper' === $blocks[ 0 ][ 'blockName' ] ) {
310 $template_custom_redirect = isset( $blocks[ 0 ][ 'attrs' ][ 'ctt' ] ) ? $blocks[ 0 ][ 'attrs' ][ 'ctt' ] : false;
311 $template_custom_fn = isset( $blocks[ 0 ][ 'attrs' ][ 'cttfn' ] ) ? $blocks[ 0 ][ 'attrs' ][ 'cttfn' ] : '';
312 if ( $template_custom_redirect && $template_custom_fn ) {
313 $file = get_stylesheet_directory() . '/' . $template_custom_fn;
314 if ( file_exists( $file ) ) {
315 $this->webyx_fg_enqueue_assets_core();
316 return $file;
317 }
318 }
319 }
320 $_wp_page_template = get_post_meta( $post->ID, '_wp_page_template', true );
321 if ( $_wp_page_template ) {
322 $file = WEBYX_FG_PATH . $_wp_page_template;
323 if ( file_exists( $file ) ) {
324 $this->webyx_fg_enqueue_assets_core();
325 return $file;
326 }
327 }
328 return $template;
329 }
330 public function webyx_fg_register_menu () {
331 remove_filter( 'walker_nav_menu_start_el', 'twenty_twenty_one_add_sub_menu_toggle', 10, 4 );
332 $webyx_fg_menu = get_option( 'webyx_fg_menu', 'true' );
333 if ( $webyx_fg_menu ) {
334 register_nav_menu(
335 'webyx-menu', __( 'Webyx Menu', get_template_directory() . '/languages' )
336 );
337 }
338 }
339 public function webyx_fg_get_custom_logo ( $html ) {
340 $custom_logo_id = get_theme_mod( 'custom_logo' );
341 $image = wp_get_attachment_image_src( $custom_logo_id , 'full' );
342 if ( $image && has_block( 'webyx-fg/webyx-wrapper' ) ) {
343 $html = sprintf(
344 '<div class="webyx-logo-wrapper"><a href="%1$s" class="webyx-logo-img-wrapper" rel="home" itemprop="url">%2$s</a></div>',
345 esc_url( home_url( '/' ) ),
346 wp_get_attachment_image(
347 $custom_logo_id,
348 'full',
349 false,
350 array(
351 'alt' => 'logo',
352 'class' => 'webyx-logo-img'
353 )
354 )
355 );
356 }
357 return $html;
358 }
359 public function webyx_fg_activation_time () {
360 $webyx_fg_activation_time = strtotime( 'now' );
361 add_option( 'webyx_fg_activation_time', $webyx_fg_activation_time );
362 return $webyx_fg_activation_time;
363 }
364 public function webyx_fg_check_installation_time () {
365 $webyx_fg_activation_time = get_option( 'webyx_fg_activation_time', $this->webyx_fg_activation_time() );
366 $webyx_fg_spare_me = get_option( 'webyx_fg_spare_me' );
367 $webyx_fg_review_threshold_date = strtotime( WEBYX_FG_REVIEW_THRESHOLD_DATE );
368 if ( '1' !== $webyx_fg_spare_me && ( $webyx_fg_review_threshold_date >= $webyx_fg_activation_time ) ) {
369 add_action(
370 'admin_notices',
371 array(
372 $this,
373 'webyx_fg_display_admin_notice'
374 )
375 );
376 }
377 }
378 public function webyx_fg_display_admin_notice () {
379 global $pagenow;
380 if ( 'index.php' === $pagenow ){
381 $dont_disturb = esc_url( get_admin_url() . '?spare_me=1' );
382 $plugin_info = get_plugin_data( __FILE__ , true, true );
383 $reviewurl = esc_url( 'mailto:support@webyx.it');
384 printf(
385 __( '<div class="webyx-fg-review webyx-fg-wrp">
386 <p>You have been using <b>%s</b> for a while. We hope you liked it! If for any reason you\'re having trouble using Webyx, please contact us and we\'ll try to help you and answer your questions!</p>
387 <div class="webyx-fg-review-btn">
388 <a href="%s" class="button button-primary webyx-fg-rate-now" target="_blank">Contact the Team!</a>
389 <a href="%s" class="webyx-fg-review-done">I\'m ok!</a>
390 </div>
391 </div>', $plugin_info[ 'TextDomain' ] ),
392 $plugin_info[ 'Name' ],
393 $reviewurl,
394 $dont_disturb
395 );
396 }
397 }
398 public function webyx_fg_spare_me () {
399 if ( isset( $_GET[ 'spare_me' ] ) && ! empty( $_GET[ 'spare_me' ] ) ) {
400 $spare_me = $_GET[ 'spare_me' ];
401 if ( '1' === $spare_me ) {
402 update_option( 'webyx_fg_spare_me' , 1 );
403 }
404 }
405 }
406 public function webyx_fg_admin_css () {
407 global $pagenow;
408 if( 'index.php' === $pagenow ) {
409 wp_enqueue_style(
410 'webyx-fg-admin',
411 plugins_url(
412 WEBYX_FG_ASSET_MIN ? 'assets/css/webyx-fg-admin.min.css' : 'assets/css/webyx-fg-admin.css',
413 __FILE__
414 ),
415 array(),
416 filemtime(
417 plugin_dir_path( __FILE__ ) . ( WEBYX_FG_ASSET_MIN ? 'assets/css/webyx-fg-admin.min.css' : 'assets/css/webyx-fg-admin.css' )
418 )
419 );
420 }
421 }
422 public function webyx_fg_init_setting_admin_page () {
423 add_action(
424 'init',
425 array(
426 $this,
427 'webyx_fg_register_settings_admin_page'
428 ),
429 10
430 );
431 add_action(
432 'admin_menu',
433 array(
434 $this,
435 'webyx_fg_add_setting_admin_page'
436 ),
437 10
438 );
439 add_action(
440 'admin_enqueue_scripts',
441 array(
442 $this,
443 'webyx_fg_enqueue_scripts_settings_admin_page'
444 ),
445 10
446 );
447 add_action(
448 'plugin_action_links_' . plugin_basename( __FILE__ ),
449 array(
450 $this,
451 'webyx_fg_add_settings_link'
452 ),
453 10
454 );
455 add_filter(
456 'plugin_row_meta',
457 array(
458 $this,
459 'webyx_fg_append_support_and_faq_links'
460 ),
461 10,
462 4
463 );
464 }
465 public function webyx_fg_register_settings_admin_page () {
466 register_setting(
467 'webyx_fg_plugin_settings',
468 'webyx_fg_hide_admin_top_bar',
469 array(
470 'default' => 'true',
471 'show_in_rest' => TRUE,
472 'type' => 'string',
473 )
474 );
475 register_setting(
476 'webyx_fg_plugin_settings',
477 'webyx_fg_menu',
478 array(
479 'default' => 'true',
480 'show_in_rest' => TRUE,
481 'type' => 'string',
482 )
483 );
484 }
485 public function webyx_fg_add_setting_admin_page () {
486 add_options_page(
487 __( 'Webyx FG Settings', 'webyx' ),
488 __( 'Webyx FG Settings', 'webyx' ),
489 'manage_options',
490 'webyx_fg_plugin_settings',
491 array(
492 $this,
493 'webyx_fg_print_setting_admin_page'
494 )
495 );
496 }
497 public function webyx_fg_print_setting_admin_page () {
498 echo '<div id="webyx-fg-settings"></div>';
499 }
500 public function webyx_fg_enqueue_scripts_settings_admin_page () {
501 $dir = __DIR__;
502 $script_asset_path = "$dir/build/admin.asset.php";
503 if ( ! file_exists( $script_asset_path ) ) {
504 throw new Error(
505 'You need to run `npm start` or `npm run build` for the "webyx-fg-plugin" block first.'
506 );
507 }
508 $admin_js = 'build/admin.js';
509 $script_asset = require( $script_asset_path );
510 wp_enqueue_script(
511 'webyx-fg-settings-admin-editor',
512 plugins_url( $admin_js, __FILE__ ),
513 $script_asset[ 'dependencies' ],
514 $script_asset[ 'version' ]
515 );
516 $admin_css = 'build/admin.css';
517 wp_enqueue_style(
518 'webyx-fg-settings-admin-style',
519 plugins_url( $admin_css, __FILE__ ),
520 array( 'wp-components' ),
521 filemtime( "$dir/$admin_css" )
522 );
523 }
524 public function webyx_fg_append_support_and_faq_links ( $links_array, $plugin_file_name, $plugin_data, $status ) {
525 if ( strpos( $plugin_file_name, basename(__FILE__) ) ) {
526 $new_links = array(
527 'Docs' => '<a href="https://webyx.it/" target="_blank">' . esc_html__( 'Docs', 'webyx' ) . '</a>',
528 'FAQs' => '<a href="https://webyx.it/#faq" target="_blank">' . esc_html__( 'FAQs', 'webyx' ) . '</a>',
529 'Video Tutorial' => '<a class="webyx-fg-go-pro" href="https://www.youtube.com/@webineerteam" target="_blank">' . esc_html__( 'Video Tutorial', 'webyx' ) . '</a>'
530 );
531 $links_array = array_merge( $links_array, $new_links );
532 }
533 return $links_array;
534 }
535 public function webyx_fg_add_settings_link ( $links ) {
536 $new_links = array(
537 'Settings' => '<a href="options-general.php?page=webyx_fg_plugin_settings">' . esc_html__( 'Settings', 'webyx' ) . '</a>',
538 'Go to PRO' => '<a class="webyx-fg-go-pro" href="https://gum.co/u/ojflpked" target="_blank">' . esc_html__( 'Go to PRO', 'webyx' ) . '</a>',
539 );
540 $links = array_merge( $links, $new_links );
541 return $links;
542 }
543 }
544 Webyx_FG::webyx_fg_get_instance();
545 }
546 }