46 lines
1.7 KiB
PHP
46 lines
1.7 KiB
PHP
<?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'
|
|
);
|
|
});
|
|
|
|
add_action('save_post', function($post_id) {
|
|
if (!isset($_POST['advertisement_nonce_field']) || !wp_verify_nonce($_POST['advertisement_nonce_field'], 'advertisement_nonce')) return;
|
|
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return;
|
|
if (!current_user_can('edit_post', $post_id)) return;
|
|
|
|
update_post_meta($post_id, '_is_advertisement', isset($_POST['is_advertisement']) ? '1' : '0');
|
|
});
|
|
|
|
add_action('admin_head', function() {
|
|
echo '<style>
|
|
#advertisement_meta_box {
|
|
background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%);
|
|
border: 2px solid #2196f3;
|
|
border-left: 4px solid #2196f3;
|
|
}
|
|
#advertisement_meta_box .hndle {
|
|
background: #2196f3;
|
|
color: white;
|
|
border-bottom: 2px solid #1976d2;
|
|
}
|
|
#advertisement_meta_box label {
|
|
display: block;
|
|
padding: 12px 0;
|
|
font-weight: 600;
|
|
color: #1565c0;
|
|
}
|
|
</style>';
|
|
}); |