Need Help about Coding Elementor Plugin

I need a help about elementor coding.I made many plugin, but I couldnt make a something.To match themeforest theme requipments, I must add media size from theme function.php to images in plugin.

        'label' => __( 'Choose Image', 'plugin-domain' ),
        'type' => \Elementor\Controls_Manager::MEDIA,
        'default' => [
            'url' => \Elementor\Utils::get_placeholder_image_src(),

			'name' => 'thumbnail', // // Usage: <code>{name}_size</code> and <code>{name}_custom_dimension</code>, in this case <code>thumbnail_size</code> and <code>thumbnail_custom_dimension</code>.
			//'exclude' => [ 'custom' ],
			//'include' => [],
			'default' => 'home-post-thumbnail',

  <img class="img-responsive" src="<?php esc_html_e( $item['image']['url'], 'hekim-extension' ); ?>">
					        <?php echo  Group_Control_Image_Size::get_attachment_image_html( $item, 'thumbnail', 'image' ); ?>

in theme, function.php:
add_image_size( 'home-post-thumbnail', 360, 210, true);

I want to change image size in my plugin to home-post-thumnail size.When I add group_control_image_size:get…. command to render section in my plugin, my website crashes.

What is the problem? How can I solve it? Thanks


:label: When you develop for WordPress, you should have debugging enabled.
Add these lines to your wp-config.php file:

define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', true);

This will create a file named debug.log in your wp-content folder. You’ll see in this file afterwards all the coding errors. You should always enable this in your development environment, but not in production.

:label: Second, you should pay attention to how you pass PHP variables to HTML attributes, you have to secure the output.

You should have this (use esc_attr_e):

src="<?php esc_attr_e( $item['image']['url'], 'hekim-extension' ); ?>"

instead of this:

src="<?php esc_html_e( $item['image']['url'], 'hekim-extension' ); ?>"

:label: Third, from what I saw, this is the get_attachment_image_html method documentation:

  * @param array $settings [ image => [ id => '', url => '' ], image_size => '', hover_animation => '' ]
  * @return string
 public static function get_attachment_image_html($settings)

So you should have:

<?php echo Group_Control_Image_Size::get_attachment_image_html( $item['image']['url'], 'home-post-thumbnail', 'image' ); ?>

(and make sure you have the ‘image’ hover_animation defined)

1 Like

thanks for reply but also your code crashes my website

With respect it’s your website and your item so relying on someone else’s code is not an ideal situation.

If you can’t code the solution originally, or bug fix the recommendations then how will you support, update and made edits in the future?

I agree your message.If I cant add or have control over elementor code, how can I support my plugin.I made many plugin with elementor and they works good.I want to use elementor because its popular in themeforest but I cant get support from them quickly.Media size control is the only problem for me about elementor,so If I solve this problem, I will trust my plugin.The unknowledge is not common problem for me.

Hi @helvatica :slight_smile:

That was a guiding code, not something that will work if you copy-paste it.

Have you looked in the debug log? What does it say?

Hi @hevada There is no new log line related this issue in that file.I dont know the spesific problem also I havent php or any error message, so I havent solution way.If I upload my element file ( it doesnt require any different php file except main plugin php file so you can read and understand the code ) , can you look at that code, and to give an example, can you edit it?

Without having the entire project, it’s quite difficult to debug a code, but let’s give it a try. I’ll have a look :slight_smile:, yes

1 Like

thanks. I added
// I want to add media size for this media control.
<!-- I want to show the media control with custom size here -->
lines to the code.

here is the php file:

Use \Elementor\Group_Control_Image_Size:

$settings = $this->get_settings_for_display();
print \Elementor\Group_Control_Image_Size::get_attachment_image_html( $settings, 'thumbnail', 'image' );
1 Like