| @@ -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,10 @@ | ||
| 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 | 29 | // PHPCS - Already validated by wp_ajax. |
| 37 | - $items = Utils::get_super_global_value( $_POST, 'items' ) ?? []; // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 30 | + $items = $_POST['items']; // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 38 | 31 | $urls = []; |
| 39 | 32 | |
| 40 | 33 | foreach ( $items as $item ) { |
| 41 | 34 | $urls[ $item['id'] ] = $this->get_details( $item['id'], $item['size'], $item['is_first_time'] ); |
| @@ -80,11 +73,8 @@ | ||
| 80 | 73 | foreach ( $sizes as $size ) { |
| 81 | 74 | if ( 0 === strpos( $size, 'custom_' ) ) { |
| 82 | 75 | preg_match( '/custom_(\d*)x(\d*)/', $size, $matches ); |
| 83 | 76 | |
| 84 | - $matches[1] = (int) $matches[1]; | |
| 85 | - $matches[2] = (int) $matches[2]; | |
| 86 | - | |
| 87 | 77 | $instance = [ |
| 88 | 78 | 'image_size' => 'custom', |
| 89 | 79 | 'image_custom_dimension' => [ |
| 90 | 80 | 'width' => $matches[1], |
| @@ -91,25 +81,9 @@ | ||
| 91 | 81 | 'height' => $matches[2], |
| 92 | 82 | ], |
| 93 | 83 | ]; |
| 94 | 84 | |
| 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; | |
| 85 | + $urls[ $size ] = Group_Control_Image_Size::get_attachment_image_src( $id, 'image', $instance ); | |
| 112 | 86 | } else { |
| 113 | 87 | $urls[ $size ] = wp_get_attachment_image_src( $id, $size )[0]; |
| 114 | 88 | } |
| 115 | 89 | } |
| @@ -121,14 +95,15 @@ | ||
| 121 | 95 | * Get Light-Box Image Attributes |
| 122 | 96 | * |
| 123 | 97 | * Used to retrieve an array of image attributes to be used for displaying an image in Elementor's Light Box module. |
| 124 | 98 | * |
| 125 | - * @param int $id The ID of the image. | |
| 99 | + * @param int $id The ID of the image | |
| 126 | 100 | * |
| 127 | 101 | * @return array An array of image attributes including `title` and `description`. |
| 128 | 102 | * @since 2.9.0 |
| 129 | 103 | * @access public |
| 130 | 104 | */ |
| 105 | + | |
| 131 | 106 | public function get_lightbox_image_attributes( $id ) { |
| 132 | 107 | $attributes = []; |
| 133 | 108 | $kit = Plugin::$instance->kits_manager->get_active_kit(); |
| 134 | 109 | $lightbox_title_src = $kit->get_settings( 'lightbox_title_src' ); |
| @@ -154,23 +129,8 @@ | ||
| 154 | 129 | |
| 155 | 130 | return $attributes; |
| 156 | 131 | } |
| 157 | 132 | |
| 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 | 133 | /** |
| 174 | 134 | * Images manager constructor. |
| 175 | 135 | * |
| 176 | 136 | * Initializing Elementor images manager. |
| @@ -179,11 +139,6 @@ | ||
| 179 | 139 | * @access public |
| 180 | 140 | */ |
| 181 | 141 | public function __construct() { |
| 182 | 142 | 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 | 143 | } |
| 189 | 144 | } |