PluginProbe ʕ •ᴥ•ʔ
Gallery : FooGallery / 3.3.0
Gallery : FooGallery v3.3.0
3.3.0 3.1.31 3.1.32 3.1.34 3.1.36 3.2.0 3.2.6 trunk 1.10.3 2.0.24 2.1.34 2.2.44 2.3.3 2.4.32 3.0.6 3.1.11 3.1.12 3.1.13 3.1.20 3.1.25 3.1.26 3.1.26.1 3.1.26.2
foogallery / includes / compatibility / class-elementor-compatibility.php
foogallery / includes / compatibility Last commit date
divi 1 week ago elementor 1 week ago class-autoptimize-compatibility.php 1 week ago class-elasticpress-compatibility.php 1 week ago class-elementor-compatibility.php 1 week ago class-foobox-compatibility.php 1 week ago class-foogallery-breeze-compatibility.php 1 week ago class-foogallery-compatibility.php 1 week ago class-foogallery-divi-compatibility.php 1 week ago class-foovideo-compatibility.php 1 week ago class-jetpack-compatibility.php 1 week ago class-polylang-compatibility.php 1 week ago class-responsive-lightbox-dfactory-compatibility.php 1 week ago class-speed-optimizer-compatibility.php 1 week ago class-wpoptimize-compatibility.php 1 week ago class-wprocket-compatibility.php 1 week ago view-foovideo-offer.php 1 week ago
class-elementor-compatibility.php
123 lines
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit;
5 }
6
7 /**
8 * Elementor Compatibility Class
9 * Date: 23/09/2019
10 */
11 if ( ! class_exists( 'FooGallery_Elementor_Compatibility' ) ) {
12
13 class FooGallery_Elementor_Compatibility {
14 function __construct() {
15 add_action( 'elementor/editor/after_save', array( $this, 'save_elementor_data' ), 10, 2 );
16 add_action( 'plugins_loaded', array( $this, 'init' ) );
17
18 add_action( 'elementor/preview/enqueue_scripts', array( $this, 'enqueue_assets' ) );
19 add_action( 'wp_ajax_foogallery_elementor_refresh_galleries', array( $this, 'ajax_refresh_galleries' ) );
20
21 // Add attribute to foogallery image links to prevent Elementor from trasitioning to the image.
22 if ( defined( 'ELEMENTOR_VERSION' ) ) {
23 add_filter( 'foogallery_attachment_html_link_attributes', array( $this, 'add_elementor_prevent_transition' ), 10, 3 );
24 }
25 }
26
27 function add_elementor_prevent_transition( $attributes, $args, $foogallery_attachment ) {
28 $attributes['data-e-disable-page-transition'] = 'true';
29 return $attributes;
30 }
31
32 function init() {
33 if ( did_action( 'elementor/loaded' ) ) {
34 add_action( 'elementor/widgets/widgets_registered', array( $this, 'init_widget' ) );
35 }
36 }
37
38 public function init_widget() {
39
40 // Include Widget files
41 require_once( FOOGALLERY_PATH . 'includes/compatibility/elementor/class-elementor-foogallery-widget.php' );
42
43 // Register widget
44 \Elementor\Plugin::instance()->widgets_manager->register( new Elementor_FooGallery_Widget() );
45
46 }
47
48 public function enqueue_assets() {
49 foogallery_enqueue_core_gallery_template_script();
50 foogallery_enqueue_core_gallery_template_style();
51
52 wp_enqueue_script( 'foogallery-elementor', FOOGALLERY_URL . 'js/admin-foogallery-elementor.js', array('jquery'), FOOGALLERY_VERSION );
53
54 // Pass admin URLs to JS.
55 wp_localize_script( 'foogallery-elementor', 'FooGalleryElementor', [
56 'editUrlBase' => admin_url( 'post.php?action=edit&post=' ),
57 'newUrl' => foogallery_admin_add_gallery_url(),
58 'ajaxUrl' => admin_url( 'admin-ajax.php' ),
59 'refreshNonce'=> wp_create_nonce( 'foogallery-elementor-refresh' ),
60 'refreshError'=> esc_html__( 'Unable to refresh galleries. Please reload the page.', 'foogallery' ),
61 ] );
62 }
63
64 public function ajax_refresh_galleries() {
65 check_ajax_referer( 'foogallery-elementor-refresh', 'nonce' );
66
67 if ( ! current_user_can( 'edit_posts' ) ) {
68 wp_send_json_error( esc_html__( 'You are not allowed to refresh galleries.', 'foogallery' ), 403 );
69 }
70
71 if ( ! class_exists( 'Elementor_FooGallery_Widget' ) ) {
72 require_once FOOGALLERY_PATH . 'includes/compatibility/elementor/class-elementor-foogallery-widget.php';
73 }
74
75 $options = Elementor_FooGallery_Widget::get_gallery_options();
76
77 wp_send_json_success([
78 'options' => $options,
79 ]);
80 }
81
82 function save_elementor_data( $post_id, $editor_data) {
83 //loop through the $editor_data and find any FooGallery widgets or shortcodes
84
85 $gallery_ids = $this->find_galleries_recursive( $editor_data );
86
87 if ( is_array( $gallery_ids ) && count( $gallery_ids ) > 0 ) {
88
89 foreach ( $gallery_ids as $gallery_id) {
90 //if the content contains the foogallery shortcode then add a custom field
91 add_post_meta( $post_id, FOOGALLERY_META_POST_USAGE, $gallery_id, false );
92 do_action( 'foogallery_attach_gallery_to_post', $post_id, $gallery_id );
93 }
94 }
95 }
96
97 function find_galleries_recursive( $array ) {
98 $found = array();
99 if ( is_array( $array ) ) {
100 foreach ( $array as $element ) {
101 if (array_key_exists('widgetType', $element) && $element['widgetType'] === 'shortcode') {
102
103 $shortcode = $element['settings']['shortcode'];
104
105 $gallery_ids = foogallery_extract_gallery_shortcodes($shortcode);
106
107 if (count($gallery_ids) > 0) {
108 $found = array_merge($found, array_keys($gallery_ids));
109 }
110 } else if ( array_key_exists( 'widgetType', $element) && $element['widgetType'] === 'foogallery' ) {
111
112 $found[] = intval( $element['settings']['gallery_id'] );
113
114 } else if ( array_key_exists( 'elements', $element ) && count( $element['elements'] ) > 0 ) {
115 $found = array_merge($found, $this->find_galleries_recursive( $element['elements'] ) );
116 }
117 }
118 }
119 return $found;
120 }
121 }
122 }
123