PluginProbe
Elementor Website Builder – more than just a page builder / 3.0.2
Elementor Website Builder – more than just a page builder v3.0.2
4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
elementor / includes / managers / image.php

image.php in Elementor Website Builder – more than just a page builder 3.0.2, at includes/managers/image.php

141 lines 3.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor;
3
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit; // Exit if accessed directly.
6 }
7
8 /**
9 * Elementor images manager.
10 *
11 * Elementor images manager handler class is responsible for retrieving image
12 * details.
13 *
14 * @since 1.0.0
15 */
16 class Images_Manager {
17
18 /**
19 * Get images details.
20 *
21 * Retrieve details for all the images.
22 *
23 * Fired by `wp_ajax_elementor_get_images_details` action.
24 *
25 * @since 1.0.0
26 * @access public
27 */
28 public function get_images_details() {
29 $items = $_POST['items'];
30 $urls = [];
31
32 foreach ( $items as $item ) {
33 $urls[ $item['id'] ] = $this->get_details( $item['id'], $item['size'], $item['is_first_time'] );
34 }
35
36 wp_send_json_success( $urls );
37 }
38
39 /**
40 * Get image details.
41 *
42 * Retrieve single image details.
43 *
44 * Fired by `wp_ajax_elementor_get_image_details` action.
45 *
46 * @since 1.0.0
47 * @access public
48 *
49 * @param string $id Image attachment ID.
50 * @param string|array $size Image size. Accepts any valid image
51 * size, or an array of width and height
52 * values in pixels (in that order).
53 * @param string $is_first_time Set 'true' string to force reloading
54 * all image sizes.
55 *
56 * @return array URLs with different image sizes.
57 */
58 public function get_details( $id, $size, $is_first_time ) {
59 if ( ! class_exists( 'Group_Control_Image_Size' ) ) {
60 require_once ELEMENTOR_PATH . '/includes/controls/groups/image-size.php';
61 }
62
63 if ( 'true' === $is_first_time ) {
64 $sizes = get_intermediate_image_sizes();
65 $sizes[] = 'full';
66 } else {
67 $sizes = [];
68 }
69
70 $sizes[] = $size;
71 $urls = [];
72 foreach ( $sizes as $size ) {
73 if ( 0 === strpos( $size, 'custom_' ) ) {
74 preg_match( '/custom_(\d*)x(\d*)/', $size, $matches );
75
76 $instance = [
77 'image_size' => 'custom',
78 'image_custom_dimension' => [
79 'width' => $matches[1],
80 'height' => $matches[2],
81 ],
82 ];
83
84 $urls[ $size ] = Group_Control_Image_Size::get_attachment_image_src( $id, 'image', $instance );
85 } else {
86 $urls[ $size ] = wp_get_attachment_image_src( $id, $size )[0];
87 }
88 }
89
90 return $urls;
91 }
92
93 /**
94 * Get Light-Box Image Attributes
95 *
96 * Used to retrieve an array of image attributes to be used for displaying an image in Elementor's Light Box module.
97 *
98 * @param int $id The ID of the image
99 *
100 * @return array An array of image attributes including `title` and `description`.
101 * @since 2.9.0
102 * @access public
103 */
104
105 public function get_lightbox_image_attributes( $id ) {
106 $attributes = [];
107 $kit = Plugin::$instance->kits_manager->get_active_kit();
108 $lightbox_title_src = $kit->get_settings( 'lightbox_title_src' );
109 $lightbox_description_src = $kit->get_settings( 'lightbox_description_src' );
110 $attachment = get_post( $id );
111 $image_data = [
112 'alt' => get_post_meta( $attachment->ID, '_wp_attachment_image_alt', true ),
113 'caption' => $attachment->post_excerpt,
114 'description' => $attachment->post_content,
115 'title' => $attachment->post_title,
116 ];
117
118 if ( $lightbox_title_src && $image_data[ $lightbox_title_src ] ) {
119 $attributes['title'] = $image_data[ $lightbox_title_src ];
120 }
121
122 if ( $lightbox_description_src && $image_data[ $lightbox_description_src ] ) {
123 $attributes['description'] = $image_data[ $lightbox_description_src ];
124 }
125
126 return $attributes;
127 }
128
129 /**
130 * Images manager constructor.
131 *
132 * Initializing Elementor images manager.
133 *
134 * @since 1.0.0
135 * @access public
136 */
137 public function __construct() {
138 add_action( 'wp_ajax_elementor_get_images_details', [ $this, 'get_images_details' ] );
139 }
140 }
141