Это у вас не проблема конструкции, а ошибка в конфигурации nginx/apache.Я понял нужно ограничить доступ средствами сервера. Через htaccess например
Зачем .git сохранять в бекапы?Бэкап делает хостинг автоматом на всю папку.
Зачем эти бекапы разворачивать, если можно просто откатиться гитом?Верно, протупил.
Постараюсь потом выложить его как отдельный маленький плагин - чтобы можно было из каталога установить всегда.
Главное не забывайте сделать Бекап, потому что данные изменения пропадут после обновления и нужно будет их снова вносить.
<?php
/**
* Autor: Anatoliy Pychev (email: tpychev@gmail.com)
*
* Crop and correct size of image and save it in temp file
*
* @since 1.0.0
* @param string $file_name The file name that need to corrected.
*/
function crop_image( $file_name ){
$dst_ratio = 1.44; // ratio for destnage image
$fields = 10; // fields arround image in px.
// load image
$orig_img = image_create_from_any($file_name);
if ( !$orig_img ) { return; }
// crop white color arround image data
$cropped_img = imagecropauto($orig_img , IMG_CROP_THRESHOLD, 0.5, 16777215);
//Get image width / height
$crp_w = ImageSX($cropped_img);
$crp_h = ImageSY($cropped_img);
//calculate target ratio
$crp_ratio = $crp_h / $crp_w;
//calculate new sizes
if ( $crp_ratio < $dst_ratio ) {
$new_h = $crp_w * $dst_ratio + $fields * 2;
$new_w = $crp_w + $fields * 2;
$dst_x = $fields;
$dst_y = ($new_h - $crp_h) / 2;
} else {
$new_h = $crp_h + $fields * 2;
$new_w = $crp_h / $dst_ratio + $fields * 2;
$dst_x = ($new_w - $crp_w) / 2;
$dst_y = $fields;
}
// create canvas and fill it with white color
$canvas = imagecreatetruecolor($new_w, $new_h);
$white = imagecolorallocate($canvas, 255, 255, 255);
imagefilledrectangle($canvas, 0, 0, $new_w, $new_h, $white);
// сливаем картинки (по высоте убираем 1 пиксель т.к. функция обрезки imagecropauto оставляет черную полосу в 1 пиксель снизу)
imagecopyresampled($canvas, $cropped_img, $dst_x, $dst_y, 0, 0, $crp_w, $crp_h-1, $crp_w, $crp_h-1);
if ( true ) { // принудительно приводим к размеру
$new_h2 = 1024;
$new_w2 = 711;
$canvas2 = imagecreatetruecolor($new_w2, $new_h2);
imagecopyresampled($canvas2, $canvas, 0, 0, 0, 0, $new_w2, $new_h2, $new_w, $new_h);
imagedestroy($canvas);
} else {
$canvas2 = $canvas;
}
$pi = pathinfo($file_name);
$tmp_path = $pi['dirname'] . '/after_crop/'. $pi['basename'];
imagejpeg($canvas2, $tmp_path, 75);
imagedestroy($cropped_img);
imagedestroy($orig_img);
imagedestroy($canvas2);
return array('name' => $pi['basename'], 'path' => $tmp_path);
}
/**
* Create a virtual image from image file.
*
* @param string $filepath
* @return descriptor of image
*/
function image_create_from_any($filepath) {
$type = exif_imagetype($filepath); // [] if you don't have exif you could use getImageSize()
$allowedTypes = array(
1, // [] gif
2, // [] jpg
3, // [] png
6 // [] bmp
);
if (!in_array($type, $allowedTypes)) {
return false;
}
switch ($type) {
case 1 :
$im = imagecreatefromgif($filepath);
break;
case 2 :
$im = imagecreatefromjpeg($filepath);
break;
case 3 :
$im = imagecreatefrompng($filepath);
break;
case 6 :
$im = imagecreatefrombmp($filepath);
break;
}
return $im;
}
function get_files_array(){
$path = __DIR__ . '/before_crop';
foreach (glob($path . '/*.jpg') as $filename) {
//foreach (glob($path . '/*.JPG') as $filename) {
crop_image($filename);
echo $filename." cropped<br />";
}
}
get_files_array();
die();
$prd->$test
странная. Что она должна у Вас возвращать? Судя по всему у Вас сыпятся Варнинги но Вы их невидите, т.к. по умолчанию у WordPress режим отладки отключен.$color = substr($prd->get_sku(), 8, 4)
$imgcss = 'border: 0px solid black;';
, невидимой$test = get_post_meta( $clrpost ->ID, '_newsku', true );
. И потом уже делать сравнение if ( $newsku == $test )