Files
Minecraft-Server-News/includes/metaboxes.php
2026-05-11 09:17:15 +02:00

61 lines
2.2 KiB
PHP
Raw Permalink 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
if ( ! defined( 'ABSPATH' ) ) exit;
add_action( 'add_meta_boxes', 'mcn_add_metaboxes' );
function mcn_add_metaboxes() {
add_meta_box(
'mcn_news_options',
'⛏ News-Einstellungen',
'mcn_render_metabox',
'mc_news',
'side',
'high'
);
}
function mcn_render_metabox( $post ) {
wp_nonce_field( 'mcn_save_meta', 'mcn_nonce' );
$pinned = get_post_meta( $post->ID, '_mcn_pinned', true );
$badge = get_post_meta( $post->ID, '_mcn_badge', true );
$server_ip = get_post_meta( $post->ID, '_mcn_server_ip', true );
?>
<p>
<label><strong>📌 Angepinnt (immer oben)</strong></label><br>
<input type="checkbox" name="mcn_pinned" value="1" <?php checked( $pinned, '1' ); ?>>
<span>Diese News oben anzeigen</span>
</p>
<hr>
<p>
<label><strong>🏷️ Badge / Label</strong></label><br>
<select name="mcn_badge" style="width:100%">
<option value=""> Kein Badge </option>
<?php
$badges = [ 'NEU', 'WICHTIG', 'HOT', 'BETA', 'LIVE', 'BALD' ];
foreach ( $badges as $b ) {
printf( '<option value="%s" %s>%s</option>', $b, selected( $badge, $b, false ), $b );
}
?>
</select>
</p>
<hr>
<p>
<label><strong>🖥️ Server-IP (optional)</strong></label><br>
<input type="text" name="mcn_server_ip" value="<?php echo esc_attr( $server_ip ); ?>"
placeholder="play.deinserver.de" style="width:100%">
<small>Wird in der News-Karte angezeigt</small>
</p>
<?php
}
add_action( 'save_post_mc_news', 'mcn_save_metabox' );
function mcn_save_metabox( $post_id ) {
if ( ! isset( $_POST['mcn_nonce'] ) || ! wp_verify_nonce( $_POST['mcn_nonce'], 'mcn_save_meta' ) ) return;
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
if ( ! current_user_can( 'edit_post', $post_id ) ) return;
update_post_meta( $post_id, '_mcn_pinned', isset( $_POST['mcn_pinned'] ) ? '1' : '' );
update_post_meta( $post_id, '_mcn_badge', sanitize_text_field( $_POST['mcn_badge'] ?? '' ) );
update_post_meta( $post_id, '_mcn_server_ip', sanitize_text_field( $_POST['mcn_server_ip'] ?? '' ) );
}