Files
profile/inc/add_adv_checked.php
Profile Profile ed4d79b706 add files inc
2026-03-09 20:51:08 +03:00

124 lines
4.6 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
// Регистрация метабокса и обработка сохранения
add_action('add_meta_boxes', function() {
// Метабокс для рекламного материала
add_meta_box(
'advertisement_meta_box',
'Рекламный текст',
function($post) {
$is_advertisement = get_post_meta($post->ID, '_is_advertisement', true);
wp_nonce_field('advertisement_nonce', 'advertisement_nonce_field');
echo '<label><input type="checkbox" name="is_advertisement" value="1" ' . checked($is_advertisement, '1', false) . ' /> Это рекламная публикация</label>';
},
['anew', 'yellow', 'profile_article'],
'side',
'low'
);
// Метабокс для Аэрофлота (только для profile_article)
add_meta_box(
'aeroflot_meta_box',
'Лента Аэрофлота',
function($post) {
$no_aeroflot = get_post_meta($post->ID, '_no_aeroflot', true);
wp_nonce_field('aeroflot_nonce', 'aeroflot_nonce_field');
echo '<label><input type="checkbox" name="no_aeroflot" value="1" ' . checked($no_aeroflot, '1', false) . ' /> Не отправлять в Аэрофлот</label>';
},
['profile_article'], // Только для этого типа записей
'side',
'low'
);
});
add_action('save_post', function($post_id) {
// Сохранение рекламного материала
if (isset($_POST['advertisement_nonce_field']) && wp_verify_nonce($_POST['advertisement_nonce_field'], 'advertisement_nonce')) {
if (!defined('DOING_AUTOSAVE') || !DOING_AUTOSAVE) {
if (current_user_can('edit_post', $post_id)) {
update_post_meta($post_id, '_is_advertisement', isset($_POST['is_advertisement']) ? '1' : '0');
}
}
}
// Сохранение настройки Аэрофлот (только для profile_article)
if (isset($_POST['aeroflot_nonce_field']) && wp_verify_nonce($_POST['aeroflot_nonce_field'], 'aeroflot_nonce')) {
if (!defined('DOING_AUTOSAVE') || !DOING_AUTOSAVE) {
if (current_user_can('edit_post', $post_id)) {
update_post_meta($post_id, '_no_aeroflot', isset($_POST['no_aeroflot']) ? '1' : '0');
}
}
}
});
add_action('admin_head', function() {
echo '<style>
/* Стили для рекламного метабокса - теплые тона */
#advertisement_meta_box {
background: linear-gradient(135deg, #fff8e1 0%, #ffecb3 100%);
border: 2px solid #ffb300;
border-left: 4px solid #ffb300;
}
#advertisement_meta_box .hndle {
background: #ffb300;
color: white;
border-bottom: 2px solid #ff8f00;
font-weight: 600;
}
#advertisement_meta_box .hndle:before {
content: "📢";
margin-right: 8px;
font-size: 16px;
}
#advertisement_meta_box label {
display: block;
padding: 12px 0;
font-weight: 600;
color: #e65100;
}
/* Стили для Аэрофлота - синие тона как в бренде */
#aeroflot_meta_box {
background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%);
border: 2px solid #1565c0;
border-left: 4px solid #1565c0;
}
#aeroflot_meta_box .hndle {
background: #1565c0;
color: white;
border-bottom: 2px solid #0d47a1;
font-weight: 600;
}
#aeroflot_meta_box .hndle:before {
content: "✈️";
margin-right: 8px;
font-size: 16px;
}
#aeroflot_meta_box label {
display: block;
padding: 12px 0;
font-weight: 600;
color: #0d47a1;
}
/* Стили для чекбоксов */
#advertisement_meta_box input[type="checkbox"],
#aeroflot_meta_box input[type="checkbox"] {
margin-right: 8px;
transform: scale(1.2);
}
#advertisement_meta_box input[type="checkbox"]:checked {
accent-color: #ffb300;
}
#aeroflot_meta_box input[type="checkbox"]:checked {
accent-color: #1565c0;
}
/* Выравнивание иконок */
#advertisement_meta_box .hndle,
#aeroflot_meta_box .hndle {
display: flex;
align-items: center;
}
</style>';
});