# غیرفعال کردن کراپ در وردپرس

**URL:** <https://forums.7ho.st/t/%D8%BA%DB%8C%D8%B1%D9%81%D8%B9%D8%A7%D9%84-%DA%A9%D8%B1%D8%AF%D9%86-%DA%A9%D8%B1%D8%A7%D9%BE-%D8%AF%D8%B1-%D9%88%D8%B1%D8%AF%D9%BE%D8%B1%D8%B3/8959>\
**Category:** عمومی\
**Tags:** وردپرس, پوسته\
**Created:** [مارس 1، 2023، 6:45ب.ظ UTC](https://forums.7ho.st/t/%D8%BA%DB%8C%D8%B1%D9%81%D8%B9%D8%A7%D9%84-%DA%A9%D8%B1%D8%AF%D9%86-%DA%A9%D8%B1%D8%A7%D9%BE-%D8%AF%D8%B1-%D9%88%D8%B1%D8%AF%D9%BE%D8%B1%D8%B3/8959 "2023-03-01T18:45:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nim](https://forums.7ho.st/letter_avatar_proxy/v4/letter/n/67e7ee/32.png) [@nim](https://forums.7ho.st/u/nim)\
**Post date:** [مارس 1، 2023، 6:45ب.ظ UTC](https://forums.7ho.st/t/%D8%BA%DB%8C%D8%B1%D9%81%D8%B9%D8%A7%D9%84-%DA%A9%D8%B1%D8%AF%D9%86-%DA%A9%D8%B1%D8%A7%D9%BE-%D8%AF%D8%B1-%D9%88%D8%B1%D8%AF%D9%BE%D8%B1%D8%B3/8959/1 "2023-03-01T18:45:39Z")

</div>

با سلام و وقت بخیر  
بنده یک قالبی دارم و تصاویر محصول من هم مربع نیست و این قالب تصاویر شاخص رو کراپ میزنه و تصاویر ناقص میشه و میخواهم بجای کراپ کردن ابعاد رو فقط کوچک کند و تصاویر خراب نشود. یک قسمت از فانکشن قالبی دیگری که در راستای هدف من هست رو قرار میدهم ولی از این امکان میخواهم برای قالب جدیدم استفاده کنم.  
if( !class\_exists(‘WPSM\_image\_resizer’) ) {  
class WPSM\_image\_resizer{

```
public $src = '';
public $width = '';
public $height = '';
public $size = 'full';
public $crop = false;
public $lazy = false;
public $title = '';
public $use_thumb = false;
public $no_thumb = '';
public $quality = '100';

```

این تیکه کد بسیار طولانی است و وابسته به همون قالب است ولی میخواستم که یک چیز عمومی تری باشه که روی هر قالبی اجرا بشه

---

<div class="post-metadata">

**Author:** ![Hosein](https://forums.7ho.st/user_avatar/forums.7ho.st/hosein/32/3108_2.png) [@Hosein](https://forums.7ho.st/u/Hosein)\
**Post date:** [مارس 2، 2023، 6:44ب.ظ UTC](https://forums.7ho.st/t/%D8%BA%DB%8C%D8%B1%D9%81%D8%B9%D8%A7%D9%84-%DA%A9%D8%B1%D8%AF%D9%86-%DA%A9%D8%B1%D8%A7%D9%BE-%D8%AF%D8%B1-%D9%88%D8%B1%D8%AF%D9%BE%D8%B1%D8%B3/8959/2 "2023-03-02T18:44:42Z")

</div>

سلام  
این کدی که قرار دادید متغیر هایی هست که در یک کلاس فراخوانی شده  
باید کد ها بررسی بشه

---

<div class="post-metadata">

**Author:** ![nim](https://forums.7ho.st/letter_avatar_proxy/v4/letter/n/67e7ee/32.png) [@nim](https://forums.7ho.st/u/nim)\
**Post date:** [مارس 2، 2023، 7:57ب.ظ UTC](https://forums.7ho.st/t/%D8%BA%DB%8C%D8%B1%D9%81%D8%B9%D8%A7%D9%84-%DA%A9%D8%B1%D8%AF%D9%86-%DA%A9%D8%B1%D8%A7%D9%BE-%D8%AF%D8%B1-%D9%88%D8%B1%D8%AF%D9%BE%D8%B1%D8%B3/8959/3 "2023-03-02T19:57:26Z")

</div>

در این فایل کاملش رو قرار دادم:  
[https://nimmarket.com/teeest/copy/css.txt](https://nimmarket.com/teeest/copy/css.txt)  
ولی من کاری به این ندارم چون مختص همون قالب هست بطور کلی به دنبال یک دستوری می گردم تا روی هر قالبی پاسخگو باشد و پابلیک عمل کند.

---

<div class="post-metadata">

**Author:** ![Hosein](https://forums.7ho.st/user_avatar/forums.7ho.st/hosein/32/3108_2.png) [@Hosein](https://forums.7ho.st/u/Hosein)\
**Post date:** [مارس 3، 2023، 7:06ق.ظ UTC](https://forums.7ho.st/t/%D8%BA%DB%8C%D8%B1%D9%81%D8%B9%D8%A7%D9%84-%DA%A9%D8%B1%D8%AF%D9%86-%DA%A9%D8%B1%D8%A7%D9%BE-%D8%AF%D8%B1-%D9%88%D8%B1%D8%AF%D9%BE%D8%B1%D8%B3/8959/4 "2023-03-03T07:06:41Z")

</div>

سلام  
این اسکریپت bfi thumbs هست گه برای کراپ در انداره وارد شده عمل میکنه  
کلا برای کراپ کردن دو راه بیشتر وجود نداره که یکی اسکریپت بالاست و یکی توابع وردپرس  
من خودم ار توابع استاندارد وردپرسدر تم هام استفاده میکنم و راحت تر میشه سایز ها رو تغییر داد  
شما در تنظیمات پوستتون میتونید این اسکریپت را غیرفعال کنید  
من کراپ را در کد هایی که ارسال کردید غیرفعال کردم

```nohighlight
//////////////////////////////////////////////////////////////////
// Resizer
//////////////////////////////////////////////////////////////////
@define('BFITHUMB_UPLOAD_FOLDER', 'thumbs_dir');
require_once('inc/BFI_Thumb.php');

//////////////////////////////////////////////////////////////////
// Resizer function
//////////////////////////////////////////////////////////////////

if( !class_exists('WPSM_image_resizer') ) {
class WPSM_image_resizer{

	public $src = '';
	public $width = '';
	public $height = '';
	public $size = 'full';
	public $crop = false;
	public $lazy = false;
	public $title = '';
	public $use_thumb = false;
	public $no_thumb = '';
	public $quality = '100';

	function __construct(){ //Enable lazy load when we need
		if (rehub_option('enable_lazy_images') == '1'){
			$this->lazy = true;
		}
	}

	public function get_resized_url() { //Show resized url with bfi_thumb function
		$params = array( 'width' => $this->width, 'height' => $this->height, 'quality' => $this->quality, 'crop' => false);
		$image_url = esc_url($this->src);
		if (empty ($this->src) && $this->use_thumb == true) {
			$image_url = $this->get_mypost_thumb_url();
			if(!rehub_option('rh_image_resize')){
				$image_url = bfi_thumb( $image_url, $params );
			}
			$image_url = apply_filters('rh_thumb_resized_url', $image_url );			
		}
		else {
			if(!rehub_option('rh_image_resize')){
				$image_url = bfi_thumb( $image_url, $params );
			}			
			$image_url = apply_filters('rh_src_resized_url', $image_url );
		}
		if (empty($image_url)) {
			$image_url = $this->no_thumb();			
		}
		return $image_url;		
	}

	public function get_not_resized_url(){ //Show not resized url of image
		$image_url = esc_url($this->src);

		if (empty ($this->src) && $this->use_thumb == true) {
			$image_url = $this->get_mypost_thumb_url();
		}
		if (empty($image_url)) {
			$image_url = $this->no_thumb();			
		}
		return apply_filters('rh_thumb_notresized_url', $image_url );
	}

	public function get_mypost_thumb_url() {
		global $post ;
		$image_url = '';
		if (function_exists('_nelioefi_url')){
			$image_nelio_url = get_post_meta( $post->ID, _nelioefi_url(), true );
			if (!empty($image_nelio_url)){
				return apply_filters('rh_thumb_url', $image_nelio_url );
			}			
		}
		if ( has_post_thumbnail($post->ID) ){
			$image_id = get_post_thumbnail_id($post->ID);  
			$image_url = wp_get_attachment_image_src($image_id, $this->size);  
			$image_url = (!empty($image_url)) ? $image_url[0] : '';
			
			return apply_filters('rh_thumb_url', $image_url );
		}	
		return apply_filters('rh_thumb_url', $image_url );	
	}

	public static function get_post_thumb_static($size = 'full'){
		global $post ;
		$image_url = '';
		if (function_exists('_nelioefi_url')){
			$image_nelio_url = get_post_meta( $post->ID, _nelioefi_url(), true );
			if (!empty($image_nelio_url)){
				return apply_filters('rh_thumb_url', $image_nelio_url );
			}			
		}		
		if ( has_post_thumbnail($post->ID) ){
			$image_id = get_post_thumbnail_id($post->ID);  
			$image_url = wp_get_attachment_image_src($image_id,$size);  
			$image_url = (!empty($image_url)) ? $image_url[0] : '';
			return apply_filters('rh_thumb_url', $image_url );
		}
		return apply_filters('rh_thumb_url', $image_url );	
	}	

	public function no_thumb(){ //Set blank image when no image url found
		if(rehub_option('featured_fallback_img')){$image_url = esc_url(rehub_option('featured_fallback_img'));}
		else if(!empty($this->no_thumb)){$image_url = $this->no_thumb;}
		else {$image_url = get_template_directory_uri() . '/images/default/blank.gif';}
		return apply_filters('rh_no_thumb_url', $image_url);
	}	

	public function show_resized_image() {
		$width_param = (!empty($this->width)) ? ' width="'.$this->width.'"': '';
		$height_param = (!empty($this->height)) ? ' height="'.$this->height.'"': '';
		$alt = (!empty($this->title)) ? $this->title : the_title_attribute (array('echo' => 0) );
		if ($this->lazy == true){
			if(function_exists('is_amp_endpoint') && is_amp_endpoint()){
				echo '<img class="lazyload" data-skip-lazy="" data-src="'.$this->get_resized_url().'"'.$width_param.$height_param.' alt="'.wp_strip_all_tags($alt).'" src="'.$this->get_resized_url().'" />';
			}else{			
				echo '<img class="lazyload" data-skip-lazy="" data-src="'.$this->get_resized_url().'"'.$width_param.$height_param.' alt="'.wp_strip_all_tags($alt).'" src="'.$this->no_thumb().'" />';
			}
		}
		else {
			echo '<img src="'.$this->get_resized_url().'"'.$width_param.$height_param.' alt="'.wp_strip_all_tags($alt).'" />';
		}
	}

	public function show_not_resized_image() {
		$width_param = (!empty($this->width)) ? ' width="'.$this->width.'"': '';
		$height_param = (!empty($this->height)) ? ' height="'.$this->height.'"': '';
		$alt = (!empty($this->title)) ? $this->title : the_title_attribute (array('echo' => 0) );		
		if ($this->lazy == true){
			if(function_exists('is_amp_endpoint') && is_amp_endpoint()){
				echo '<img class="lazyload" data-skip-lazy="" data-src="'.$this->get_not_resized_url().'"'.$width_param.$height_param.' alt="'.wp_strip_all_tags($alt).'" src="'.$this->get_not_resized_url().'" />';
			}else{
				echo '<img class="lazyload" data-skip-lazy="" data-src="'.$this->get_not_resized_url().'"'.$width_param.$height_param.' alt="'.wp_strip_all_tags($alt).'" src="'.$this->no_thumb().'" />';				
			}

		}
		else {
			echo '<img src="'.$this->get_not_resized_url().'"'.$width_param.$height_param.' alt="'.wp_strip_all_tags($alt).'" />';
		}
	}

	public static function show_static_resized_image($params = array()) {
		
		$src = $width = $height = $title = $no_thumb_url = $no_thumb_fallback = '';
		$crop = $lazy = $thumb = false;
		if (rehub_option('enable_lazy_images') == '1'){
			$lazy = true;
		}		
		@extract ($params);

		$params = array( 'width' => $width, 'height' => $height, 'crop' => false);
		$no_thumb = (!empty($no_thumb_url)) ? apply_filters('rh_no_thumb_url', $no_thumb_url) : get_template_directory_uri() . '/images/default/blank.gif';
		$image_url = esc_url($src);
		if (empty($title)) {
			$title = the_title_attribute (array('echo' => 0) );
		}
		if (!empty($image_url)) {
			if(!rehub_option('rh_image_resize')){
				$image_url = bfi_thumb( $image_url, $params );
			}
			$image_url = apply_filters('rh_static_resized_url', $image_url);		
		}	
		elseif (empty($image_url) && $thumb == true) {
			$image_url = self::get_post_thumb_static();
			if(!rehub_option('rh_image_resize')){
				$image_url = bfi_thumb( $image_url, $params );
			}
			$image_url = apply_filters('rh_thumb_resized_url', $image_url );
		}	
		if (empty($image_url)) {
			if (!empty($no_thumb_fallback)) return $no_thumb_fallback;
			$image_url = $no_thumb;	
			$image_url = apply_filters('rh_no_thumb_url', $image_url);	
		}
		$width_param = (!empty($width)) ? ' width="'.$width.'"': '';
		$height_param = (!empty($height)) ? ' height="'.$height.'"': '';
		if ($lazy == true){
			if(function_exists('is_amp_endpoint') && is_amp_endpoint()){
				echo '<img class="lazyload" data-skip-lazy="" data-src="'.$image_url.'"'.$width_param.$height_param.' alt="'.esc_html($title).'" src="'.$image_url.'" />';
			}else{
				echo '<img class="lazyload" data-skip-lazy="" data-src="'.$image_url.'"'.$width_param.$height_param.' alt="'.esc_html($title).'" src="'.$no_thumb.'" />';
			}
		}
		else {
			echo '<img class="nolazyftheme" src="'.$image_url.'"'.$width_param.$height_param.' alt="'.$title.'" />';
		}
	}

	public static function show_wp_image($image_size='full', $attachment_id = '', $attributes = array()) {
		global $post;
		$lazy = true;
		$lazy = apply_filters('rh_lazy_load', $lazy, $attachment_id);
		if (!rehub_option('enable_lazy_images') || !empty($attributes['lazydisable'])){
			$lazy = false;
		}	
		if(rehub_option('rh_image_resize')){
			$image_size='full';
		}		
		if(!empty($attributes['emptyimage'])){
			$transparent = esc_url($attributes['emptyimage']);
		}else{
			$transparent = get_template_directory_uri() . '/images/default/blank.gif';
		}
		$image_id = ($attachment_id) ? (int)$attachment_id : get_post_thumbnail_id($post->ID);  
		$image = wp_get_attachment_image_src($image_id,$image_size); 

		$image_url = (!empty($image[0])) ? $image[0] : '';
		$image_url = apply_filters('rh_thumb_url', $image_url );
		$css_class = (!empty($attributes['css_class'])) ? $attributes['css_class'] : '';

		$nofeatured = (!empty($attributes['nofeatured'])) ? true : false;

		$imagewidth = (!empty($image[1])) ? esc_attr( $image[1] ) : '';	
		$imageheight = (!empty($image[2])) ? esc_attr( $image[2] ) : '';
		if($imagewidth == 1) $imagewidth = '';

		$output = '';
		if ($lazy == true){
			$alt = trim( strip_tags( get_post_meta($image_id, '_wp_attachment_image_alt', true ) ) );
			$alt = apply_filters('wp_get_attachment_alt_attribute', $alt);
			if (empty($alt)) {
				$alt = the_title_attribute (array('echo' => 0) );
			}			
			if ( $nofeatured || has_post_thumbnail($post->ID)){
				if ( !empty($attributes )) {
					if(!empty($attributes['max_height'])){
						$attrmaxheight = esc_attr( $attributes['max_height'] );
						$max_height = ' style="max-height:'.$attrmaxheight.';width:auto;"';
					}else{
						$max_height = '';
					}
					$data_large_image = '';
					if (isset($attributes['data-large_image']))
					{
						$fullimage = wp_get_attachment_image_src($image_id, 'full' );
						if(!empty($fullimage)){
							$fullimage = $fullimage[0];
							$data_large_image =' data-large_image="'.esc_attr($fullimage).'"';
						}
					}
					$data_l_image_width = isset($attributes['data-large_image_width']) ? ' data-large_image_width="'.esc_attr( $attributes['data-large_image_width'] ).'"' : '';
					$data_l_image_height = isset($attributes['data-large_image_height']) ? ' data-large_image_height="'.esc_attr( $attributes['data-large_image_height'] ).'"' : '';
					$output = sprintf(
						'<img src="%s" data-src="%s" alt="%s" data-skip-lazy="" class="lazyload %s"%s%s%s%s width="%s" height="%s">',
						esc_url( $transparent ),
						esc_url( $image_url ),
						esc_attr( $alt ),
						esc_attr( $css_class ),
						$data_large_image,
						$data_l_image_width,
						$data_l_image_height,
						$max_height,
						$imagewidth,
						$imageheight
					);
				} else {
					$output = sprintf(
						'<img src="%s" data-src="%s" alt="%s" data-skip-lazy="" class="lazyload %s" width="%s" height="%s">',
						esc_url( $transparent ),
						esc_url( $image_url ),
						esc_attr( $alt ),
						esc_attr( $css_class ),
						$imagewidth,
						$imageheight
					);
				}
			}else{
				if(rehub_option('featured_fallback_img')){
					$nothumb_url = rehub_option('featured_fallback_img');
				}
				else if(!empty($attributes['no_thumb'])){
					$nothumb_url = $attributes['no_thumb'];
				}
				else {
					$nothumb_url = get_template_directory_uri() . '/images/default/noimage_500_500.png';
				}
				$nothumb_url = apply_filters('rh_no_thumb_url', $nothumb_url);			
				$output = sprintf(
					'<img src="%s" data-src="%s" alt="%s" data-skip-lazy="" class="lazyload %s" width="%s" height="%s">',
					esc_url( $transparent ),
					esc_url( $nothumb_url),
					esc_attr( $alt ),
					esc_attr( $css_class ),
					$imagewidth,
					$imageheight
				);
			}
		} else {
			$attributes['class'] = $css_class;
			if ( has_post_thumbnail($post->ID) ){
				$output = wp_get_attachment_image( $image_id, $image_size, false, $attributes );
			}else{
				if(rehub_option('featured_fallback_img')){
					$nothumb_url = rehub_option('featured_fallback_img');
				}
				else if(!empty($attributes['no_thumb'])){
					$nothumb_url = $attributes['no_thumb'];
				}
				else {
					$nothumb_url = get_template_directory_uri() . '/images/default/noimage_500_500.png';
				}
				$nothumb_url = apply_filters('rh_no_thumb_url', $nothumb_url);
				$alt = the_title_attribute (array('echo' => 0) );			
				$output = sprintf(
					'<img src="%s" alt="%s" class="%s">',
					esc_url( $nothumb_url),
					esc_attr( $alt ),
					esc_attr( $css_class )
				);				
			}
		}
		
		$output = apply_filters('rh_thumb_output', $output, $image_size);
		return $output;		
	}		

}}

//////////////////////////////////////////////////////////////////
// Thumbnail function
//////////////////////////////////////////////////////////////////
if( !function_exists('wpsm_thumb') ) {
function wpsm_thumb( $size = 'smallgrid', $maxheight='', $id=''){
	$attributes = array();	
	if($maxheight && is_numeric($maxheight)){
		$attributes['max_height'] = (int)$maxheight.'px';
	}
	if($size == 'smallgrid'){
		$attributes['emptyimage'] = get_template_directory_uri() . '/images/default/noimage_220_150.png';
		$attributes['no_thumb'] = get_template_directory_uri() . '/images/default/noimage_220_150.png';
	}
	elseif($size == 'mediumgrid'){
		$attributes['emptyimage'] = get_template_directory_uri() . '/images/default/noimage_336_220.png';
		$attributes['no_thumb'] = get_template_directory_uri() . '/images/default/noimage_336_220.png';
	}
	elseif($size == 'large_inner'){
		$attributes['emptyimage'] = get_template_directory_uri() . '/images/default/noimage_450_350.png';
		$attributes['no_thumb'] = get_template_directory_uri() . '/images/default/noimage_450_350.png';
	}
	elseif($size == 'minithumb'){
		$attributes['emptyimage'] = get_template_directory_uri() . '/images/default/noimage_100_70.png';
		$attributes['no_thumb'] = get_template_directory_uri() . '/images/default/noimage_100_70.png';
	}

	echo WPSM_image_resizer::show_wp_image($size, $id, $attributes);

}	
}

//Siteground fix for lazy load
add_filter( 'sgo_lazy_load_exclude_classes', 'exclude_images_with_specific_class' );
function exclude_images_with_specific_class( $classes ) {
    // Add the class name that you want to exclude from lazy load.
    $classes[] = 'lazyload';
    return $classes;
}

```

---

<div class="post-metadata">

**Author:** ![nim](https://forums.7ho.st/letter_avatar_proxy/v4/letter/n/67e7ee/32.png) [@nim](https://forums.7ho.st/u/nim)\
**Post date:** [مارس 7، 2023، 7:33ق.ظ UTC](https://forums.7ho.st/t/%D8%BA%DB%8C%D8%B1%D9%81%D8%B9%D8%A7%D9%84-%DA%A9%D8%B1%D8%AF%D9%86-%DA%A9%D8%B1%D8%A7%D9%BE-%D8%AF%D8%B1-%D9%88%D8%B1%D8%AF%D9%BE%D8%B1%D8%B3/8959/5 "2023-03-07T07:33:35Z")

</div>

سلام ممنون ولی در اصل این اسکریپ بی نقص ترین اسکریپ کراپ وردپرس هست و اصلا مشکلی نداره. مسئله اینجاست که اسکریپ یا کدی رو میخواهم که روی تمام قالب ها بجای بکراپ تصویر رو کوچک کنه نه اینکه بصورت ناقص برش بزنه. اسکریپی که فرستادم هر عکسی با هر نسبتی رو بدون کراپ بخش ها برای شما در ابعاد وردپرس درمیاره ولی مختص قالب خودش هست و من از اون قالب استفاده نمیکنم.
