File: /mnt/data/dreamsrent-wp-demo/wp-content/plugins/dreamsrent-booking/inc/metabox-month.php
<?php
add_action('load-post.php', 'rental_boxes_month_prices_setup');
add_action('load-post-new.php', 'rental_boxes_month_prices_setup');
function rental_boxes_month_prices_setup() {
add_action('add_meta_boxes', 'dreams_rental_month_prices_meta_boxes');
add_action('save_post', 'rental_save_post_month_prices_meta', 10, 2);
}
function dreams_rental_month_prices_meta_boxes() {
add_meta_box(
'rental-post-monthprices-days',
esc_html__('Add Month Price Detail', 'bookingcore'),
'rental_month_prices_meta_box',
'rental',
'normal',
'default'
);
}
function rental_month_prices_meta_box($post) {
wp_nonce_field(basename(__FILE__), 'rental_post_month_prices_nonce');
$monthprice = get_post_meta($post->ID, 'dreams_booking_meta_monthprice', true);
?>
<div class="month_prices_wrapper">
<div class="custom-row">
<div class="col-3">
<label class="mb-0"><?php echo esc_html__('Monthly Price', 'bookingcore'); ?></label>
</div>
<div class="col-9">
<input type="text" name="monthprice" id="monthprice" value="<?php echo esc_attr($monthprice); ?>" placeholder="Add Month Price">
</div>
</div>
</div>
<?php
}
function rental_save_post_month_prices_meta($post_id, $post) {
// Security checks
if (!isset($_POST['rental_post_month_prices_nonce']) ||
!wp_verify_nonce($_POST['rental_post_month_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
$monthprice = isset($_POST['monthprice']) && $_POST['monthprice'] !== '' ? sanitize_text_field($_POST['monthprice']) : null;
if ($monthprice !== null) {
update_post_meta($post_id, 'dreams_booking_meta_monthprice', $monthprice);
update_post_meta($post_id, 'dreams_booking_meta_rentaltype_month', 'month');
} else {
delete_post_meta($post_id, 'dreams_booking_meta_monthprice');
delete_post_meta($post_id, 'dreams_booking_meta_rentaltype_month');
}
}