PluginProbe
Elementor Website Builder – more than just a page builder / 3.2.0
Elementor Website Builder – more than just a page builder v3.2.0
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
← All changes | includes/managers/image.php +15 -64 4.1.0-dev23.2.0 View file →
@@ -1,10 +1,7 @@
1 1 <?php
2 2 namespace Elementor;
3 3
4 -use Elementor\Core\Editor\Editor;
5 -use Elementor\Core\Utils\Collection;
6 -
7 4 if ( ! defined( 'ABSPATH' ) ) {
8 5 exit; // Exit if accessed directly.
9 6 }
10 7
@@ -28,14 +25,9 @@
28 25 * @since 1.0.0
29 26 * @access public
30 27 */
31 28 public function get_images_details() {
32 - if ( ! current_user_can( 'publish_posts' ) ) {
33 - wp_send_json_error( 'Permission denied' );
34 - }
35 -
36 - // PHPCS - Already validated by wp_ajax.
37 - $items = Utils::get_super_global_value( $_POST, 'items' ) ?? []; // phpcs:ignore WordPress.Security.NonceVerification.Missing
29 + $items = $_POST['items'];
38 30 $urls = [];
39 31
40 32 foreach ( $items as $item ) {
41 33 $urls[ $item['id'] ] = $this->get_details( $item['id'], $item['size'], $item['is_first_time'] );
@@ -80,11 +72,8 @@
80 72 foreach ( $sizes as $size ) {
81 73 if ( 0 === strpos( $size, 'custom_' ) ) {
82 74 preg_match( '/custom_(\d*)x(\d*)/', $size, $matches );
83 75
84 - $matches[1] = (int) $matches[1];
85 - $matches[2] = (int) $matches[2];
86 -
87 76 $instance = [
88 77 'image_size' => 'custom',
89 78 'image_custom_dimension' => [
90 79 'width' => $matches[1],
@@ -91,25 +80,9 @@
91 80 'height' => $matches[2],
92 81 ],
93 82 ];
94 83
95 - $url = Group_Control_Image_Size::get_attachment_image_src( $id, 'image', $instance );
96 -
97 - $thumbs_path = BFITHUMB_UPLOAD_DIR . '/' . basename( $url );
98 -
99 - $image_meta = wp_get_attachment_metadata( $id );
100 -
101 - // Attach custom image to original.
102 - $image_meta['sizes'][ 'elementor_' . $size ] = [
103 - 'file' => $thumbs_path,
104 - 'width' => $matches[1],
105 - 'height' => $matches[2],
106 - 'mime-type' => get_post_mime_type( $id ),
107 - ];
108 -
109 - wp_update_attachment_metadata( $id, $image_meta );
110 -
111 - $urls[ $size ] = $url;
84 + $urls[ $size ] = Group_Control_Image_Size::get_attachment_image_src( $id, 'image', $instance );
112 85 } else {
113 86 $urls[ $size ] = wp_get_attachment_image_src( $id, $size )[0];
114 87 }
115 88 }
@@ -121,14 +94,15 @@
121 94 * Get Light-Box Image Attributes
122 95 *
123 96 * Used to retrieve an array of image attributes to be used for displaying an image in Elementor's Light Box module.
124 97 *
125 - * @param int $id The ID of the image.
98 + * @param int $id The ID of the image
126 99 *
127 100 * @return array An array of image attributes including `title` and `description`.
128 101 * @since 2.9.0
129 102 * @access public
130 103 */
104 +
131 105 public function get_lightbox_image_attributes( $id ) {
132 106 $attributes = [];
133 107 $kit = Plugin::$instance->kits_manager->get_active_kit();
134 108 $lightbox_title_src = $kit->get_settings( 'lightbox_title_src' );
@@ -133,44 +107,26 @@
133 107 $kit = Plugin::$instance->kits_manager->get_active_kit();
134 108 $lightbox_title_src = $kit->get_settings( 'lightbox_title_src' );
135 109 $lightbox_description_src = $kit->get_settings( 'lightbox_description_src' );
136 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 + ];
137 117
138 - if ( $attachment ) {
139 - $image_data = [
140 - 'alt' => get_post_meta( $attachment->ID, '_wp_attachment_image_alt', true ),
141 - 'caption' => $attachment->post_excerpt,
142 - 'description' => $attachment->post_content,
143 - 'title' => $attachment->post_title,
144 - ];
118 + if ( $lightbox_title_src && $image_data[ $lightbox_title_src ] ) {
119 + $attributes['title'] = $image_data[ $lightbox_title_src ];
120 + }
145 121
146 - if ( $lightbox_title_src && $image_data[ $lightbox_title_src ] ) {
147 - $attributes['title'] = $image_data[ $lightbox_title_src ];
148 - }
149 -
150 - if ( $lightbox_description_src && $image_data[ $lightbox_description_src ] ) {
151 - $attributes['description'] = $image_data[ $lightbox_description_src ];
152 - }
122 + if ( $lightbox_description_src && $image_data[ $lightbox_description_src ] ) {
123 + $attributes['description'] = $image_data[ $lightbox_description_src ];
153 124 }
154 125
155 126 return $attributes;
156 127 }
157 128
158 - private function delete_custom_images( $post_id ) {
159 - $image_meta = wp_get_attachment_metadata( $post_id );
160 - if ( ! empty( $image_meta ) && ! empty( $image_meta['sizes'] ) ) {
161 - ( new Collection( $image_meta['sizes'] ) )
162 - ->filter( function ( $value, $key ) {
163 - return ( 0 === strpos( $key, 'elementor_custom_' ) );
164 - } )
165 - ->pluck( 'file' )
166 - ->each( function ( $path ) {
167 - $base_dir = wp_get_upload_dir()['basedir'];
168 - wp_delete_file( $base_dir . '/' . $path );
169 - } );
170 - }
171 - }
172 -
173 129 /**
174 130 * Images manager constructor.
175 131 *
176 132 * Initializing Elementor images manager.
@@ -179,11 +135,6 @@
179 135 * @access public
180 136 */
181 137 public function __construct() {
182 138 add_action( 'wp_ajax_elementor_get_images_details', [ $this, 'get_images_details' ] );
183 -
184 - // Delete elementor thumbnail files on deleting its main image.
185 - add_action( 'delete_attachment', function ( $post_id ) {
186 - $this->delete_custom_images( $post_id );
187 - } );
188 139 }
189 140 }