Cannot run the code after I activate the plugin

you can not, and should not be able to write to files directly. You need to use the wordpress filesystem api https://codex.wordpress.org/Filesystem_API which either requires a pre configuration on the site or user manual control. In addition it is just wrong to automatically write anything into wp-config.php as any mistake will bring down the site … Read more

How to make thumbnail image fit into a div where image dimentions are completely different?

It may be that some of your images were uploaded before you created the custom image size function. If that’s the case, a plugin like Force Regenerate Thumbnails will solve your problem. Alternatively, for more versatility you could use the images as backgrounds, like so: <div style=”background-image: url(<?php the_post_thumbnail_url(); ?>)” id=”post-thumbnail”></div> and set the background … Read more