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