211
правок
8j0rn (обсуждение | вклад) Нет описания правки |
8j0rn (обсуждение | вклад) |
||
| (не показаны 4 промежуточные версии этого же участника) | |||
| Строка 5: | Строка 5: | ||
== 1. Сделал полный перевод плагину == | == 1. Сделал полный перевод плагину == | ||
Полный перевод плагина Property Listings Plugin: ([[:File:Easy-property-listings-ru RU.zip|Cкачать архив ZIP]]) | Полный перевод плагина Property Listings Plugin: ([[:File:Easy-property-listings-ru RU.zip|Cкачать архив ZIP]]) | ||
Важно помнить, перевод плагина нужно размещать в: <code>/wp-content/languages/epl/</code> | |||
Так уж сделал автор плагина, хотя и не по кодексу WP. | |||
== 2. Исправления через functions.php == | == 2. Исправления через functions.php == | ||
| Строка 71: | Строка 74: | ||
=== 2.5. Изменение функции плагина easy-property-listings === | === 2.5. Изменение функции плагина easy-property-listings === | ||
Кнопка "План помещения" открывала картинку в новом окне, пришлось переписать функцию чтобы открывалась в лайтбокс (lightbox), для этого еще пришлось добавить загрузку [[Wp:function:adding-download-magnific_popup|magnific_popup]] и [[Wp:function:adding-download-fancybox|fancybox]] js script | Кнопка "План помещения" открывала картинку в новом окне, пришлось переписать функцию чтобы открывалась в лайтбокс (lightbox), для этого еще пришлось добавить загрузку [[Wp:function:adding-download-magnific_popup|magnific_popup]] и [[Wp:function:adding-download-fancybox|fancybox]] js script: | ||
<syntaxhighlight lang="php"> | <syntaxhighlight lang="php"><?php | ||
// Изменение функции плагина easy-property-listings (epl_button_floor_plan() отключаем и включаем свою функцию) | // Изменение функции плагина easy-property-listings | ||
// (epl_button_floor_plan() отключаем и включаем | |||
// свою функцию) | |||
function remove_epl_button_floor_plan() { | function remove_epl_button_floor_plan() { | ||
// Отключаем стандартную функцию | // Отключаем стандартную функцию | ||
| Строка 122: | Строка 127: | ||
} | } | ||
add_action('epl_buttons_single_property', '_8j0rn_button_floor_plan'); | add_action('epl_buttons_single_property', '_8j0rn_button_floor_plan'); | ||
</syntaxhighlight> | |||
=== 2.6. Изменение кривой функции плагина easy-property-listings (epl_button_floor_plan() отключаем и включаем свою функцию)=== | |||
<syntaxhighlight lang="php"> | |||
// Изменение кривой функции плагина easy-property-listings | |||
// (epl_button_floor_plan() отключаем и включаем свою функцию) | |||
// Удаляем существующий хук | |||
function remove_epl_manage_listing_column_listing_type_callback() { | |||
remove_action( 'epl_manage_listing_column_listing_type', 'epl_manage_listing_column_listing_type_callback' ); | |||
} | |||
add_action('init', 'remove_epl_manage_listing_column_listing_type_callback'); | |||
// Добавляем новый хук с кастомной функцией | |||
function _8j0rn_epl_manage_listing_column_listing_type_callback() { | |||
global $post; | |||
// Get the post meta. | |||
$listing_type = get_post_meta( $post->ID, 'property_com_listing_type', true ); | |||
// If no duration is found, output a default message. | |||
if ( ! empty( $listing_type ) ) { | |||
switch ($listing_type) { | |||
case 'lease': | |||
echo esc_html__( 'For Lease', 'easy-property-listings' ); | |||
break; | |||
case 'sale': | |||
echo esc_html__( 'For Sale', 'easy-property-listings' ); | |||
break; | |||
case 'both': | |||
echo esc_html__( 'For Sale & Lease', 'easy-property-listings' ); | |||
break; | |||
} | |||
} | |||
} | |||
add_action( 'epl_manage_listing_column_listing_type', '_8j0rn_epl_manage_listing_column_listing_type_callback' ); | |||
</syntaxhighlight> | |||
=== 2.7. Изменяем список категорий в разделе Коммерческие=== | |||
<syntaxhighlight lang="php"> | |||
// Изменяем список категорий в разделе Коммерческие | |||
function _8j0rn_epl_listing_meta_commercial_category($defaults) { | |||
// Удаляем ненужные категории | |||
unset($defaults['Commercial Farming']); | |||
unset($defaults['Land/Development']); | |||
unset($defaults['Other']); | |||
// Изменяем или добавляем новые категории | |||
//$defaults['Commercial Farming'] = __( 'Farming', 'easy-property-listings' ); // Изменяем существующую категорию | |||
$defaults['Public catering'] = __( 'Public catering', 'easy-property-listings' ); // Добавляем новую категорию | |||
// Добавляем в конец Другое | |||
$defaults['Other'] = __( 'Other', 'easy-property-listings' ); // Добавляем новую категорию | |||
return $defaults; | |||
} | |||
add_filter('epl_listing_meta_commercial_category', '_8j0rn_epl_listing_meta_commercial_category'); | |||
</syntaxhighlight> | |||
=== 2.8. Переопределяем список единиц измерения площади=== | |||
<syntaxhighlight lang="php"> | |||
// Переопределяем список единиц измерения площади | |||
function _8j0rn_epl_opts_area_unit_filter($defaults) { | |||
// Удаляем ненужные единицы | |||
unset($defaults['square']); | |||
unset($defaults['acre']); | |||
unset($defaults['sqft']); | |||
// Изменяем или добавляем новые единицы измерения | |||
$defaults['squareMeter'] = __( 'square meter', 'easy-property-listings' ); // Изменяем существующую единицу | |||
$defaults['sotka'] = __( 'Sotka', 'easy-property-listings' ); // Добавляем новую единицу | |||
return $defaults; | |||
} | |||
add_filter('epl_opts_area_unit_filter', '_8j0rn_epl_opts_area_unit_filter'); | |||
</syntaxhighlight> | |||
=== 2.9. Переопределяем периоды оплаты=== | |||
<syntaxhighlight lang="php"> | |||
// Переопределяем периоды оплаты | |||
function _8j0rn_epl_rent_period_opts($options) { | |||
// Удаляем ненужные опции | |||
unset( $options['day'] ); | |||
unset( $options['daily'] ); | |||
unset( $options['week'] ); | |||
unset( $options['weekly'] ); | |||
unset( $options['month'] ); | |||
unset( $options['monthly'] ); | |||
// Добавляем нужные опции | |||
$options['_in_month'] = __( ' in month', 'easy-property-listings' ); | |||
$options['_in_year'] = __( ' in year', 'easy-property-listings' ); | |||
$options['_in_week'] = __( ' in week', 'easy-property-listings' ); | |||
$options['_in_day'] = __( ' in day', 'easy-property-listings' ); | |||
return $options; | |||
} | |||
add_filter( 'epl_opts_rent_period_filter', '_8j0rn_epl_rent_period_opts' ); | |||
</syntaxhighlight> | |||
=== 2.10. Исправляем отсутствие перевода периода оплаты в админке в столбце Аренда=== | |||
<syntaxhighlight lang="php"> | |||
// Исправляем отсутствие перевода периода оплаты в админке в столбце Аренда | |||
function _8j0rn_translate_rent_period( $price_rent_period ) { | |||
// Массив переводов (должен совпадать с тем, что в _8j0rn_epl_rent_period_opts) | |||
$rent_period_translations = array( | |||
'_in_month' => __( ' in month', 'easy-property-listings' ), | |||
'_in_year' => __( ' in year', 'easy-property-listings' ), | |||
'_in_week' => __( ' in week', 'easy-property-listings' ), | |||
'_in_day' => __( ' in day', 'easy-property-listings' ), | |||
); | |||
// Если значение $price_rent_period есть в массиве, возвращаем перевод | |||
if ( isset( $rent_period_translations[$price_rent_period] ) ) { | |||
return $rent_period_translations[$price_rent_period]; | |||
} | |||
// Если значение не найдено, возвращаем оригинальное значение | |||
return $price_rent_period; | |||
} | |||
add_filter( 'epl_price_rent_period', '_8j0rn_translate_rent_period' ); | |||
</syntaxhighlight> | |||
=== 2.11. Исправляем адреса в карточках объектов=== | |||
====2.11.1. Функция для форматирования адреса==== | |||
<syntaxhighlight lang="php"> | |||
// Кастомная функция для форматирования адреса | |||
function _8i0rn_get_formatted_property_address($street, $street_separator = true, $separator_symbol = ',') { | |||
// Получаем объект текущего свойства | |||
global $property; | |||
/* | |||
// Проверяем, что $property является объектом и имеет метод get_property_meta | |||
if (!is_object($property) || !method_exists($property, 'get_property_meta')) { | |||
return $street; // Возвращаем оригинальный адрес, если объект не корректен | |||
} | |||
*/ | |||
$_8i0rn_street = ''; | |||
// Добавляем название улицы | |||
$street_name = $property->get_property_meta( 'property_address_street' ); | |||
if ( ! empty( $street_name ) ) { | |||
$_8i0rn_street .= $street_name; | |||
} | |||
// Добавляем номер дома | |||
$street_number = $property->get_property_meta( 'property_address_street_number' ); | |||
if ( ! empty( $street_number ) ) { | |||
$_8i0rn_street .= ' дом ' . $street_number; | |||
} | |||
//Добавляем саб-номер дома | |||
$sub_number = $property->get_property_meta( 'property_address_sub_number' ); | |||
if ( ! empty( $sub_number ) ) { | |||
$_8i0rn_street .= ' кв. ' . $sub_number . ' '; | |||
} | |||
// Добавляем номер квартиры | |||
$lot_number = $property->get_property_meta( 'property_address_lot_number' ); | |||
if ( ! empty( $lot_number ) ) { | |||
$_8i0rn_street .= 'лот № ' . $lot_number . ' '; | |||
if ( true === $street_separator ) { | |||
$separator_symbol = apply_filters( 'epl_property_address_separator', $separator_symbol ); | |||
$_8i0rn_street .= $separator_symbol; | |||
} | |||
} | |||
return $_8i0rn_street; | |||
} | |||
// Подключаем кастомную функцию через фильтр | |||
add_filter('epl_get_formatted_property_address', '_8i0rn_get_formatted_property_address', 10, 1); | |||
</syntaxhighlight> | |||
====2.11.2. Новая функция формирования адресов==== | |||
<syntaxhighlight lang="php"> | |||
// Новая функция формирования адресов | |||
function _8j0rn_epl_property_the_address( $full = true, $street_separator = true, $separator_symbol = ',' ) { | |||
global $property, $epl_settings; | |||
if ( ! is_bool( $full ) ) { | |||
$full = true; | |||
} | |||
$epl_property_address_separator = apply_filters( 'epl_property_address_separator', ',' ); // Улица и дом | |||
$epl_property_address_separator_suburb = apply_filters( 'epl_property_address_separator_suburb', false ); // | |||
$epl_property_address_separator_city = apply_filters( 'epl_property_address_separator_city', false ); | |||
?> | |||
<?php | |||
$text_link = ''; | |||
if ( true === $full ) { | |||
?> | |||
<span class="entry-title-sub"> | |||
<span class="item-pcode"><?php | |||
// Выводим индекс | |||
echo esc_attr( $property->get_property_meta( 'property_address_postal_code' ) ); | |||
$text_link .= esc_attr( $property->get_property_meta( 'property_address_postal_code' ) ) ?></span> | |||
<?php | |||
// Выводим страну (если настройки того требуют) | |||
if ( 'yes' === $property->get_epl_settings( 'epl_enable_country_field' ) ) { | |||
?> | |||
<span class="item-country"><?php | |||
echo esc_attr( $property->get_property_meta( 'property_address_country' ) ); | |||
$text_link .= ' ' . esc_attr( $property->get_property_meta( 'property_address_country' ) ); ?></span> | |||
<?php | |||
} | |||
?> | |||
<span class="item-state"><?php | |||
// Выводим область | |||
echo esc_attr( $property->get_property_meta( 'property_address_state' ) ); | |||
$text_link .= ' ' . esc_attr( $property->get_property_meta( 'property_address_state' ) ); ?></span> | |||
<?php | |||
if ( 'yes' === $property->get_epl_settings( 'epl_enable_city_field' ) ) { | |||
?> | |||
<span class="item-city"><?php | |||
// Выводим город | |||
echo esc_attr( $property->get_property_meta( 'property_address_city' ) ); | |||
$text_link .= ' ' . esc_attr( $property->get_property_meta( 'property_address_city' ) ); ?></span> | |||
<?php | |||
if ( true === $epl_property_address_separator_city && strlen( trim( $property->get_property_meta( 'property_address_city' ) ) ) ) { | |||
echo '<span class="item-separator">' . esc_attr( $epl_property_address_separator ) . '</span>'; | |||
$text_link .= ' ' . esc_attr( $epl_property_address_separator ); | |||
} | |||
} | |||
?> | |||
<?php | |||
// Определяем категорию объекта Коммерческая/Бизнес или Аренда/Продажа (Коммерческая/Бизнес не обновлял за ненадобностью) | |||
if ( 'commercial' === $property->post_type || 'business' === $property->post_type ) { | |||
if ( 'yes' === $property->get_property_meta( 'property_com_display_suburb' ) || 'yes' === $property->get_property_meta( 'property_address_display' ) ) { | |||
?> | |||
<span class="item-suburb">(Коммерческие-Бизнес требует настройки)<?php echo esc_attr( $property->get_property_meta( 'property_address_suburb' ) ); | |||
$text_link .= ' ' . esc_attr( $property->get_property_meta( 'property_address_suburb' ) ); ?></span> | |||
<?php | |||
if ( true === $epl_property_address_separator_suburb && strlen( trim( $property->get_property_meta( 'property_address_suburb' ) ) ) ) { | |||
echo '<span class="item-separator">' . esc_attr( $epl_property_address_separator ) . '</span>'; | |||
$text_link .= ' ' . esc_attr( $epl_property_address_separator ); | |||
} | |||
} | |||
} else { | |||
?> | |||
<span class="item-suburb"><?php | |||
// выводим город-область-индекс (нужно исправить на индекс-область-город) | |||
echo esc_attr( $property->get_property_meta( 'property_address_suburb' ) ); | |||
$text_link .= ' ' . esc_attr( $property->get_property_meta( 'property_address_suburb' ) ); ?></span> | |||
<?php | |||
if ( true === $epl_property_address_separator_suburb && strlen( trim( $property->get_property_meta( 'property_address_suburb' ) ) ) ) { | |||
echo '<span class="item-separator">' . esc_attr( $epl_property_address_separator ) . '</span>'; | |||
$text_link .= ' ' . esc_attr( $epl_property_address_separator ); | |||
} | |||
} | |||
?> | |||
</span> | |||
<?php // выводим дом и улицу (нужно исправить на улица-дом) | |||
if ( 'yes' === $property->get_property_meta( 'property_address_display' ) ) { ?> | |||
<span class="item-street"><?php | |||
echo wp_kses_post( $property->get_formatted_property_address( $street_separator, $separator_symbol ) ); | |||
$text_link .= ' ' . wp_kses_post( $property->get_formatted_property_address( $street_separator, $separator_symbol ) ); ?></span> | |||
<?php } ?> | |||
<?php | |||
} | |||
echo '<a href="#">' . $text_link . '</a>'; | |||
} | |||
// Отключаем старые экшены | |||
function remove_epl_default_actions() { | |||
remove_action('epl_property_title', 'epl_property_the_address', 10); | |||
remove_action('epl_property_tab_address', 'epl_property_the_address', 10); | |||
remove_action('epl_property_address', 'epl_property_the_address', 10); | |||
} | |||
add_action('init', 'remove_epl_default_actions'); | |||
</syntaxhighlight> | |||
====2.11.3. Заключительные настройки исправления адресов карточек==== | |||
<syntaxhighlight lang="php"> | |||
// Подключаем новые экшены | |||
function add_custom_epl_actions() { | |||
add_action('epl_property_title', '_8j0rn_epl_property_the_address', 10, 3); | |||
add_action('epl_property_tab_address', '_8j0rn_epl_property_the_address', 10, 3); | |||
add_action('epl_property_address', '_8j0rn_epl_property_the_address', 10, 3); | |||
} | |||
add_action('init', 'add_custom_epl_actions'); | |||
</syntaxhighlight> | </syntaxhighlight> | ||