HEX
Server: nginx/1.24.0
System: Linux DGT-WORDPRESS-VM-SERVER 6.14.0-1014-azure #14~24.04.1-Ubuntu SMP Fri Oct 3 20:52:11 UTC 2025 x86_64
User: ubuntu (1000)
PHP: 8.4.12
Disabled: NONE
Upload Files
File: /mnt/data/dreamsrent-wp-demo/wp-content/plugins/dreamsrent-booking/inc/metabox-week.php
<?php

add_action('load-post.php', 'rental_boxes_week_prices_setup');
add_action('load-post-new.php', 'rental_boxes_week_prices_setup');

function rental_boxes_week_prices_setup() {
    add_action('add_meta_boxes', 'dreams_rental_week_prices_meta_boxes');
    add_action('save_post', 'rental_save_post_week_prices_meta', 10, 2);
}

function dreams_rental_week_prices_meta_boxes() {
    add_meta_box(
        'rental-post-weekprices-days',
        esc_html__('Add Week Price Detail', 'bookingcore'),
        'rental_week_prices_meta_box',
        'rental',
        'normal',
        'default'
    );
}

function rental_week_prices_meta_box($post) {
    wp_nonce_field(basename(__FILE__), 'rental_post_week_prices_nonce');
    $weekprice = get_post_meta($post->ID, 'dreams_booking_meta_weekprice', true);
    ?>
    <div class="week_prices_wrapper">
        <div class="custom-row">
            <div class="col-3">
                <label class="mb-0"><?php echo esc_html__('Week Price', 'bookingcore'); ?></label>
            </div>
            <div class="col-9">
                <input type="text" name="weekprice" id="weekprice" value="<?php echo esc_attr($weekprice); ?>" placeholder="Add Week Price">
            </div>
        </div>
    </div>
    <?php
}

function rental_save_post_week_prices_meta($post_id, $post) {
    // Security checks
    if (!isset($_POST['rental_post_week_prices_nonce']) || 
        !wp_verify_nonce($_POST['rental_post_week_prices_nonce'], basename(__FILE__))) {
        return;
    }

    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
        return;
    }

    if (!is_object($post) || !isset($post->post_type) || $post->post_type !== 'rental') {
        return;
    }

    if (!current_user_can('edit_post', $post_id)) {
        return;
    }

    // Sanitize and save the value
    $weekprice = isset($_POST['weekprice']) && $_POST['weekprice'] !== '' ? sanitize_text_field($_POST['weekprice']) : null;

    if ($weekprice !== null) {
        update_post_meta($post_id, 'dreams_booking_meta_weekprice', $weekprice);
        update_post_meta($post_id, 'dreams_booking_meta_rentaltype_week', 'week');
    } else {
        delete_post_meta($post_id, 'dreams_booking_meta_weekprice');
        delete_post_meta($post_id, 'dreams_booking_meta_rentaltype_week');
    }
}