You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
279 lines
10 KiB
279 lines
10 KiB
<?php
|
|
|
|
|
|
add_action('init', 'register_pets');
|
|
function register_pets(){
|
|
register_post_type('pets', array(
|
|
'labels' => array(
|
|
'name' => 'Питомцы', // Основное название типа записи
|
|
'singular_name' => 'Питомец', // отдельное название записи типа Book
|
|
'add_new' => 'Добавить нового',
|
|
'add_new_item' => 'Добавить нового питомца',
|
|
'edit_item' => 'Редактировать питомца',
|
|
'new_item' => 'Новый питомец',
|
|
'view_item' => 'Посмотреть питомца',
|
|
'search_items' => 'Найти питомца',
|
|
'not_found' => 'Питомцев не найдено',
|
|
'not_found_in_trash' => 'В корзине книг не найдено',
|
|
'parent_item_colon' => '',
|
|
'menu_name' => 'Питомцы'
|
|
|
|
),
|
|
'public' => false,
|
|
'show_ui' => true,
|
|
'supports' => array('title','editor')
|
|
) );
|
|
}
|
|
|
|
|
|
function get_pet_card($item){
|
|
?>
|
|
<?php
|
|
|
|
switch (get_field('weight')){
|
|
case ('below_1_5'):
|
|
$w = esc_html__('from 0,5 kg to 1,5 kg', 'woodmart' );
|
|
break;
|
|
case ('1_5-3'):
|
|
$w = esc_html__('from 1.5 to 3 kg', 'woodmart' );
|
|
break;
|
|
case ('3-5'):
|
|
$w = esc_html__('from 3 to 5 kg', 'woodmart' );
|
|
break;
|
|
case ('5-8'):
|
|
$w = esc_html__('from 5 to 8 kg', 'woodmart' );
|
|
break;
|
|
case ('8-11'):
|
|
$w = esc_html__('from 8 to 11 kg', 'woodmart' );
|
|
break;
|
|
case ('11-15'):
|
|
$w = esc_html__('from 11 to 15 kg', 'woodmart' );
|
|
break;
|
|
case ('15-20'):
|
|
$w = esc_html__('from 15 to 20 kg', 'woodmart' );
|
|
break;
|
|
case ('20-25'):
|
|
$w = esc_html__('from 20 to 25 kg', 'woodmart' );
|
|
break;
|
|
|
|
|
|
case ('25-35'):
|
|
$w = esc_html__('from 25 to 35 kg', 'woodmart' );
|
|
break;
|
|
|
|
|
|
case ('more_35'):
|
|
$w = esc_html__('More than 35 kg', 'woodmart' );
|
|
break;
|
|
|
|
}
|
|
switch (get_field('old')){
|
|
case ('normal'):
|
|
$old = esc_html__('Adult (from 1 year to 7 years)', 'woodmart' );
|
|
break;
|
|
case ('old'):
|
|
$old = esc_html__('Elderly (from 7 to 12 years)', 'woodmart' );
|
|
break;
|
|
case ('very_old'):
|
|
$old = esc_html__('Aging (12 years and older)', 'woodmart' );
|
|
break;
|
|
case ('baby'):
|
|
$old = esc_html__('Baby (from 0 to 1 year)' );
|
|
break;
|
|
}
|
|
|
|
switch (get_field('activity')){
|
|
case ('low'):
|
|
$act = esc_html__('Low', 'woodmart' );
|
|
break;
|
|
case ('moderate'):
|
|
$act = esc_html__('Moderate', 'woodmart' );
|
|
break;
|
|
case ('high'):
|
|
$act = esc_html__('High', 'woodmart' );
|
|
break;
|
|
|
|
}
|
|
?>
|
|
<div class="cabinet-card cabinet-card--green">
|
|
<div class="cabinet-card__content">
|
|
<div class="cabinet-card__pet">
|
|
<div class="cabinet-card-pet__icon">
|
|
<div class="cabinet-card-pet-icon__content">
|
|
<img src="<?= get_template_directory_uri();?>/gp-include/assets/lk/img/pet/mini-<?php echo get_field('type', $item) ?>.png" alt="">
|
|
</div>
|
|
</div>
|
|
|
|
<p class="cabinet-card-pet__name"><?php echo get_the_title($item) ?></p>
|
|
</div>
|
|
|
|
<div class="cabinet-card__element">
|
|
<p class="cabinet-card__label"><?php echo esc_html__('Breed', 'woodmart' ) ?>:</p>
|
|
<p class="cabinet-card__text"><?php echo get_field('breed', $item) ?></p>
|
|
</div>
|
|
<div class="cabinet-card__element">
|
|
<p class="cabinet-card__label"><?php echo esc_html__('Weight', 'woodmart' ) ?>:</p>
|
|
<p class="cabinet-card__text"><?php echo $w; ?></p>
|
|
</div>
|
|
<?php if ($old): ?>
|
|
<div class="cabinet-card__element">
|
|
<p class="cabinet-card__label"><?php echo esc_html__('Age', 'woodmart' ) ?>:</p>
|
|
<p class="cabinet-card__text"><?php echo $old; ?></p>
|
|
</div>
|
|
|
|
<?php
|
|
else:
|
|
?>
|
|
<?php
|
|
$zero = '';
|
|
if (intval(get_field('month', $item)) < 10){
|
|
$zero = '0';
|
|
}
|
|
?>
|
|
<div class="cabinet-card__element">
|
|
<p class="cabinet-card__label"><?php echo esc_html__('Birhtday', 'woodmart' ) ?>:</p>
|
|
<p class="cabinet-card__text"><?php echo get_field('day', $item) . '.' . $zero . get_field('month', $item) . '.' . get_field('year', $item); ?></p>
|
|
</div>
|
|
<?php
|
|
endif;
|
|
?>
|
|
<div class="cabinet-card__element">
|
|
<p class="cabinet-card__label"><?php echo esc_html__('Activity', 'woodmart' ) ?>:</p>
|
|
<p class="cabinet-card__text"><?php echo $act; ?></p>
|
|
</div>
|
|
<?php
|
|
if (get_field('type', $item) == 'cat' && get_field('sterilized', $item)):
|
|
?>
|
|
<div class="cabinet-card__element">
|
|
<p class="cabinet-card__label"><?php echo esc_html__('Sterilized', 'woodmart' ) ?></p>
|
|
|
|
</div>
|
|
<?php
|
|
endif;
|
|
?>
|
|
<div class="cabinet-card__element">
|
|
<button class="cabinet-card__button" data-edit="<?php echo get_the_ID($item); ?>">
|
|
<?php echo esc_html__('Edit', 'woodmart' ) ?>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php
|
|
}
|
|
|
|
|
|
|
|
function ajax_add_pet() {
|
|
$current_user = wp_get_current_user();
|
|
// Подготовка данных
|
|
$pet_name = $_POST['name'];
|
|
$old_type = $_POST['old_type'];
|
|
if ($old_type == 'ex'){
|
|
$old= $_POST['old'];
|
|
}
|
|
|
|
$weight= $_POST['weight'];
|
|
$activity = $_POST['activity'];
|
|
$pet = $_POST['pet'];
|
|
$breed = $_POST['breed'];
|
|
$sex = $_POST['sex'];
|
|
$user = $current_user->ID;
|
|
|
|
$post_data = array(
|
|
'post_title' => $pet_name,
|
|
'post_type' => 'pets',
|
|
'post_status' => 'publish',
|
|
);
|
|
|
|
|
|
$post_id = wp_insert_post($post_data);
|
|
var_dump($post_id);
|
|
if ($post_id) {
|
|
// Добавление мета-полей
|
|
if ($old_type == 'ex'){
|
|
|
|
update_field( 'old', $old, $post_id );
|
|
|
|
|
|
}
|
|
else{
|
|
|
|
update_field( 'day', $_POST['day'], $post_id );
|
|
update_field( 'month', $_POST['month'], $post_id );
|
|
update_field( 'year', $_POST['year'], $post_id );
|
|
}
|
|
update_field( 'weight', $weight, $post_id );
|
|
update_field( 'breed', $breed, $post_id );
|
|
update_field( 'sex', $sex, $post_id );
|
|
update_field( 'type', $pet, $post_id );
|
|
update_field( 'user', $user, $post_id );
|
|
update_field( 'activity', $activity, $post_id );
|
|
if($_POST['sterilized']=='1' && $pet=='cat'){
|
|
update_field( 'sterilized', true );
|
|
}
|
|
else{
|
|
update_field( 'sterilized', false );
|
|
}
|
|
wp_send_json_success('Питомец успешно добавлен!');
|
|
} else {
|
|
wp_send_json_error('Ошибка при добавлении питомца.');
|
|
}
|
|
|
|
wp_die(); // Завершение работы
|
|
}
|
|
add_action('wp_ajax_add_pet', 'ajax_add_pet');
|
|
add_action('wp_ajax_nopriv_add_pet', 'ajax_add_pet'); // Если нужно разрешить для незалогиненных пользователей
|
|
|
|
|
|
|
|
function ajax_edit_pet() {
|
|
$current_user = wp_get_current_user();
|
|
// Подготовка данных
|
|
$pet_name = $_POST['name'];
|
|
$old_type = $_POST['old_type'];
|
|
if ($old_type == 'ex'){
|
|
$old= $_POST['old'];
|
|
}
|
|
else{
|
|
$old_acc = $_POST['day'] . ' ' . $_POST['month'] . ' ' . $_POST['year'];
|
|
}
|
|
$weight= $_POST['weight'];
|
|
$activity = $_POST['activity'];
|
|
$pet = $_POST['pet'];
|
|
$breed = $_POST['breed'];
|
|
$sex = $_POST['sex'];
|
|
$user = $current_user->ID;
|
|
|
|
$post_id = intval($_POST['pet_id']);
|
|
|
|
if (get_field('user', $post_id) == $user) {
|
|
// Добавление мета-полей
|
|
if ($old_type == 'ex'){
|
|
update_field( 'old', $old, $post_id );
|
|
}
|
|
else{
|
|
update_field( 'old', '', $post_id );
|
|
update_field( 'day', $_POST['day'], $post_id );
|
|
update_field( 'month', $_POST['month'], $post_id );
|
|
update_field( 'year', $_POST['year'], $post_id );
|
|
}
|
|
update_field( 'weight', $weight, $post_id );
|
|
update_field( 'breed', $breed, $post_id );
|
|
update_field( 'sex', $sex, $post_id );
|
|
update_field( 'type', $pet, $post_id );
|
|
update_field( 'activity', $activity, $post_id );
|
|
if($_POST['sterilized']=='1' && $pet=='cat'){
|
|
update_field( 'sterilized', true );
|
|
}
|
|
else{
|
|
update_field( 'sterilized', false );
|
|
}
|
|
wp_send_json_success('Питомец успешно отредактирован!');
|
|
} else {
|
|
wp_send_json_error('Ошибка при редактировании питомца.');
|
|
}
|
|
|
|
wp_die(); // Завершение работы
|
|
}
|
|
add_action('wp_ajax_edit_pet', 'ajax_edit_pet');
|
|
add_action('wp_ajax_nopriv_edit_pet', 'ajax_edit_pet');
|