Can anyone help me with this code and / or direct me to information on how to make the plugin for listinghive?
```php
<?php
/**
* Plugin Name: ListingHive Realtime Availability
* Description: Adds real-time availability feature to ListingHive theme.
* Version: 1.0.0
* Author: Your Name
*/
// Enqueue the necessary scripts and styles
function lh_realtime_availability_enqueue_scripts() {
wp_enqueue_style( 'lh-realtime-availability-style', plugin_dir_url( __FILE__ ) . 'css/style.css' );
wp_enqueue_script( 'lh-realtime-availability-script', plugin_dir_url( __FILE__ ) . 'js/script.js', array( 'jquery' ), '1.0.0', true );
}
add_action( 'wp_enqueue_scripts', 'lh_realtime_availability_enqueue_scripts' );
// Add the real-time availability filter to the search form
function lh_realtime_availability_search_filter( $query_args ) {
if ( isset( $_GET['realtime_availability'] ) && $_GET['realtime_availability'] === 'on' ) {
$query_args['meta_query'][] = array(
'key' => '_lh_realtime_availability',
'value' => '1',
'compare' => '=',
);
}
return $query_args;
}
add_filter( 'hivepress/v1/listing/query_args', 'lh_realtime_availability_search_filter' );
// Add the real-time availability option to the user dashboard
function lh_realtime_availability_user_dashboard() {
$user_id = get_current_user_id();
$realtime_availability = get_user_meta( $user_id, '_lh_realtime_availability', true );
?>
<div class="lh-realtime-availability-toggle">
<label>
<input type="checkbox" name="lh_realtime_availability" <?php checked( $realtime_availability, '1' ); ?>>
<?php esc_html_e( 'Real-time Availability', 'listinghive-realtime-availability' ); ?>
</label>
</div>
<?php
}
add_action( 'hivepress/v1/user/dashboard', 'lh_realtime_availability_user_dashboard' );
// Save the real-time availability option in the user dashboard
function lh_realtime_availability_save_user_dashboard() {
$user_id = get_current_user_id();
if ( isset( $_POST['lh_realtime_availability'] ) ) {
update_user_meta( $user_id, '_lh_realtime_availability', '1' );
update_user_meta( $user_id, '_lh_realtime_availability_timestamp', time() );
} else {
update_user_meta( $user_id, '_lh_realtime_availability', '0' );
}
}
add_action( 'hivepress/v1/user/dashboard/save', 'lh_realtime_availability_save_user_dashboard' );
// Automatically toggle off real-time availability after 4 hours
function lh_realtime_availability_auto_toggle_off() {
$users = get_users( array( 'meta_key' => '_lh_realtime_availability', 'meta_value' => '1' ) );
foreach ( $users as $user ) {
$timestamp = get_user_meta( $user->ID, '_lh_realtime_availability_timestamp', true );
if ( $timestamp && ( time() - $timestamp ) > 4 * HOUR_IN_SECONDS ) {
update_user_meta( $user->ID, '_lh_realtime_availability', '0' );
}
}
}
add_action( 'wp', 'lh_realtime_availability_auto_toggle_off' );
CSS
.lh-realtime-availability-toggle {
margin-bottom: 10px;
}
```
JS
```javascript
jQuery( document ).ready( function( $ ) {
$( '.lh-realtime-availability-toggle input' ).on( 'change', function() {
if ( $('.lh-realtime-availability-toggle input').is(':checked') ) {
$(this).closest('.lh-realtime-availability-toggle').addClass('active');
} else {
$(this).closest('.lh-realtime-availability-toggle').removeClass('active');
}
});
});```