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/post.php
// Register 'location' taxonomy for 'rental'
function dreams_register_location_taxonomy() {
    $labels = array(
        'name'              => 'Locations',
        'singular_name'     => 'Location',
        'search_items'      => 'Search Locations',
        'all_items'         => 'All Locations',
        'edit_item'         => 'Edit Location',
        'update_item'       => 'Update Location',
        'add_new_item'      => 'Add New Location',
        'new_item_name'     => 'New Location Name',
        'menu_name'         => 'Locations',
    );

    register_taxonomy('location', ['rental'], array(
        'hierarchical'      => false,
        'labels'            => $labels,
        'show_ui'           => true,
        'show_admin_column' => true,
        'rewrite'           => array('slug' => 'location'),
    ));
}
add_action('init', 'dreams_register_location_taxonomy');

// Add custom fields to Add form
function dreams_add_location_taxonomy_fields() {
    ?>
    <h3>Location Details</h3>
    <div class="form-field">
        <label>Email</label>
        <input type="email" name="location_email" />
    </div>
    <div class="form-field">
        <label>Phone</label>
        <input type="text" name="location_phone" />
    </div>
    <div class="form-field">
        <label>Address</label>
        <input type="text" name="location_address" />
    </div>
    <div class="form-field">
        <label>Country</label>
        <input type="text" name="location_country" />
    </div>
    <div class="form-field">
        <label>State</label>
        <input type="text" name="location_state" />
    </div>
    <div class="form-field">
        <label>City</label>
        <input type="text" name="location_city" />
    </div>
    <div class="form-field">
        <label>Pincode</label>
        <input type="text" name="location_pincode" />
    </div>

    <h3>Working Days</h3>
    <?php foreach (['monday','tuesday','wednesday','thursday','friday','saturday','sunday'] as $day): ?>
        <div class="form-field">
            <label><?php echo ucfirst($day); ?> (From - To)</label>
            <input type="checkbox" name="working_days[<?php echo $day; ?>][enabled]" value="1" /> Enable
            <input type="text" name="working_days[<?php echo $day; ?>][from]" placeholder="From time" />
            <input type="text" name="working_days[<?php echo $day; ?>][to]" placeholder="To time" />
        </div>
    <?php endforeach; ?>
    <?php
}
add_action('location_add_form_fields', 'dreams_add_location_taxonomy_fields');

// Edit form
function dreams_edit_location_taxonomy_fields($term) {
    $meta = get_term_meta($term->term_id);
    ?>
    <h3>Location Details</h3>
    <table class="form-table">
        <tr><th>Email</th><td><input type="email" name="location_email" value="<?php echo esc_attr($meta['location_email'][0] ?? ''); ?>"></td></tr>
        <tr><th>Phone</th><td><input type="text" name="location_phone" value="<?php echo esc_attr($meta['location_phone'][0] ?? ''); ?>"></td></tr>
        <tr><th>Address</th><td><input type="text" name="location_address" value="<?php echo esc_attr($meta['location_address'][0] ?? ''); ?>"></td></tr>
        <tr><th>Country</th><td><input type="text" name="location_country" value="<?php echo esc_attr($meta['location_country'][0] ?? ''); ?>"></td></tr>
        <tr><th>State</th><td><input type="text" name="location_state" value="<?php echo esc_attr($meta['location_state'][0] ?? ''); ?>"></td></tr>
        <tr><th>City</th><td><input type="text" name="location_city" value="<?php echo esc_attr($meta['location_city'][0] ?? ''); ?>"></td></tr>
        <tr><th>Pincode</th><td><input type="text" name="location_pincode" value="<?php echo esc_attr($meta['location_pincode'][0] ?? ''); ?>"></td></tr>
    </table>

    <h3>Working Days</h3>
    <table class="form-table">
    <?php
    $working_days = maybe_unserialize($meta['location_working_days'][0] ?? []);
    foreach (['monday','tuesday','wednesday','thursday','friday','saturday','sunday'] as $day):
        $enabled = !empty($working_days[$day]['enabled']);
        $from = $working_days[$day]['from'] ?? '';
        $to = $working_days[$day]['to'] ?? '';
    ?>
        <tr>
            <th><?php echo ucfirst($day); ?></th>
            <td>
                <input type="checkbox" name="working_days[<?php echo $day; ?>][enabled]" <?php checked($enabled); ?> value="1" /> Enable
                <input type="text" name="working_days[<?php echo $day; ?>][from]" value="<?php echo esc_attr($from); ?>" placeholder="From" />
                <input type="text" name="working_days[<?php echo $day; ?>][to]" value="<?php echo esc_attr($to); ?>" placeholder="To" />
            </td>
        </tr>
    <?php endforeach; ?>
    </table>
    <?php
}
add_action('location_edit_form_fields', 'dreams_edit_location_taxonomy_fields', 10, 2);

// Save custom fields
function dreams_save_location_meta_taxonomy($term_id) {
    $fields = [
        'location_email',
        'location_phone',
        'location_address',
        'location_country',
        'location_state',
        'location_city',
        'location_pincode'
    ];
    foreach ($fields as $field) {
        if (isset($_POST[$field])) {
            update_term_meta($term_id, $field, sanitize_text_field($_POST[$field]));
        }
    }

    if (isset($_POST['working_days'])) {
        $data = [];
        foreach ($_POST['working_days'] as $day => $times) {
            $data[$day] = [
                'enabled' => !empty($times['enabled']),
                'from'    => sanitize_text_field($times['from'] ?? ''),
                'to'      => sanitize_text_field($times['to'] ?? ''),
            ];
        }
        update_term_meta($term_id, 'location_working_days', $data);
    }
}
add_action('created_location', 'dreams_save_location_meta_taxonomy', 10, 2);
add_action('edited_location', 'dreams_save_location_meta_taxonomy', 10, 2);