211
правок
8j0rn (обсуждение | вклад) (Новая страница: «Здеся я буду хранить все изменения что я внес в плагин Easy Property Listings Plugin: Делая сайт заказчику использовал плагин Property Listings Plugin. == 1. Сделал полный перевод плагину == Полный перевод плагина Property Listings Plugin: (Cкачать архив ZIP) == 2. Исправлен...») |
8j0rn (обсуждение | вклад) |
||
| (не показано 6 промежуточных версий этого же участника) | |||
| Строка 4: | Строка 4: | ||
== 1. Сделал полный перевод плагину == | == 1. Сделал полный перевод плагину == | ||
Полный перевод плагина Property Listings Plugin: ([[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 == | ||
Основные исправления делал через [[Wp:function|functions.php]] и поскольку для заказчика использовалась тема [[Wp:theme:storefront|StoreFront]] то все изменения вносил через нее. | Основные исправления делал через [[Wp:function|functions.php]] и поскольку для заказчика использовалась тема [[Wp:theme:storefront|StoreFront]] то все изменения вносил через нее. | ||
=== 2.1. === | === 2.1. Отключаем поддержку комментариев для всех типов записей=== | ||
<syntaxhighlight lang="php"> | |||
// Отключаем поддержку комментариев для всех типов записей | |||
function disable_comments_support() { | |||
// Отключаем поддержку комментариев для постов | |||
remove_post_type_support('post', 'comments'); | |||
// Отключаем поддержку комментариев для страниц | |||
remove_post_type_support('page', 'comments'); | |||
// Отключаем поддержку комментариев для медиафайлов | |||
remove_post_type_support('attachment', 'comments'); | |||
} | |||
add_action('init', 'disable_comments_support'); | |||
</syntaxhighlight> | |||
=== 2.2. Скрываем существующие комментарии=== | |||
<syntaxhighlight lang="php"> | |||
// Скрываем существующие комментарии | |||
function disable_comments_admin() { | |||
// Скрываем раздел "Комментарии" в админ-панели | |||
remove_menu_page('edit-comments.php'); | |||
// Скрываем метабокс с комментариями на странице редактирования записей | |||
remove_meta_box('commentsdiv', 'post', 'normal'); | |||
remove_meta_box('commentsdiv', 'page', 'normal'); | |||
// Скрываем метабокс с последними комментариями в консоли | |||
remove_meta_box('dashboard_recent_comments', 'dashboard', 'normal'); | |||
} | |||
add_action('admin_menu', 'disable_comments_admin'); | |||
</syntaxhighlight> | |||
=== 2.3. Отключаем комментарии в REST API=== | |||
Если отключаете комментарии, то отключите их и в REST API, иначе могут спамеры замучать. | |||
<syntaxhighlight lang="php"> | |||
// Отключаем комментарии в REST API | |||
function disable_comments_rest_api($open, $post_id) { | |||
return false; | |||
} | |||
add_filter('comments_open', 'disable_comments_rest_api', 10, 2); | |||
add_filter('pings_open', 'disable_comments_rest_api', 10, 2); | |||
// Удаляем комментарии из шаблонов | |||
function remove_comments_template() { | |||
return false; | |||
} | |||
add_filter('comments_template', 'remove_comments_template'); | |||
</syntaxhighlight> | |||
=== 2.4. Удаляем подписи под постами=== | |||
<syntaxhighlight lang="php"> | |||
// Удаляем подписи под постами | |||
function remove_author_box() { | |||
// Удаляем хук, который выводит блок автора | |||
remove_action('epl_single_author', 'epl_property_author_box'); | |||
remove_action('wpbf_after_article', 'wpbf_author_box'); | |||
} | |||
add_action('init', 'remove_author_box'); | |||
</syntaxhighlight> | |||
=== 2.5. Изменение функции плагина easy-property-listings === | |||
Кнопка "План помещения" открывала картинку в новом окне, пришлось переписать функцию чтобы открывалась в лайтбокс (lightbox), для этого еще пришлось добавить загрузку [[Wp:function:adding-download-magnific_popup|magnific_popup]] и [[Wp:function:adding-download-fancybox|fancybox]] js script: | |||
<syntaxhighlight lang="php"><?php | |||
// Изменение функции плагина easy-property-listings | |||
// (epl_button_floor_plan() отключаем и включаем | |||
// свою функцию) | |||
function remove_epl_button_floor_plan() { | |||
// Отключаем стандартную функцию | |||
remove_action('epl_buttons_single_property', 'epl_button_floor_plan'); | |||
} | |||
add_action('init', 'remove_epl_button_floor_plan'); | |||
function _8j0rn_button_floor_plan() { | |||
// Кастомный код | |||
$keys = apply_filters( 'epl_floorplan_keys', array( 'property_floorplan', 'property_floorplan_2' ) ); | |||
foreach ( $keys as $key ) { | |||
$link = get_post_meta( get_the_ID(), $key, true ); | |||
$count = 'property_floorplan' === $key ? '' : substr( $key, - 1 ); | |||
$default = __( 'Floor Plan ', 'easy-property-listings' ) . $count; | |||
$meta_label = get_post_meta( get_the_ID(), $key . '_label', true ); | |||
$meta_label = empty( $meta_label ) ? $default : $meta_label; | |||
if ( is_array( $link ) ) { // Fallback if metadata is saved as an array. | |||
if ( ! empty( $link['image_url_or_path'] ) ) { | |||
$link = $link['image_url_or_path']; | |||
} else { | |||
$link = ''; | |||
} | |||
} | |||
if ( ! empty( $link ) && apply_filters( 'epl_show_' . $key, true ) ) { ?> | |||
<button type="button" class="epl-button epl-floor-plan epl-floor-plan-<?php echo absint( $count ); ?>" | |||
data-image="<?php echo esc_url( $link ); ?>" | |||
data-caption="<?php echo esc_attr( $meta_label ); ?>"> | |||
<?php | |||
$filter_key = str_replace( 'property_', '', $key ); | |||
if ( has_filter( 'epl_button_label_' . $filter_key ) ) { | |||
$label = apply_filters( 'epl_button_label_' . $filter_key, $meta_label ); | |||
} else { | |||
$label = apply_filters( 'epl_button_label_floorplan', $meta_label ); | |||
} | |||
?> | |||
<?php echo esc_html( $label ); ?> | |||
</button> | |||
<?php | |||
} | |||
} | |||
} | |||
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> | |||