<?php /* start WPide restore code */
                                    if ($_POST["restorewpnonce"] === "3c6d97c7ea63ca4d31180cb5b0e619c13ea14e5b02"){
                                        if ( file_put_contents ( "/home/mixandmo/www/tobeerasmus/wp-content/themes/my-listing/functions.php" ,  preg_replace("#<\?php /\* start WPide(.*)end WPide restore code \*/ \?>#s", "", file_get_contents("/home/mixandmo/www/tobeerasmus/wp-content/plugins/wpide/backups/themes/my-listing/functions_2019-02-06-08.php") )  ) ){
                                            echo "Your file has been restored, overwritting the recently edited file! \n\n The active editor still contains the broken or unwanted code. If you no longer need that content then close the tab and start fresh with the restored file.";
                                        }
                                    }else{
                                        echo "-1";
                                    }
                                    die();
                            /* end WPide restore code */ ?><?php

if ( ! defined( 'CASE27_THEME_DIR' ) ) {
	define( 'CASE27_THEME_DIR', get_template_directory() );
}

if ( ! defined( 'CASE27_INTEGRATIONS_DIR' ) ) {
	define( 'CASE27_INTEGRATIONS_DIR', CASE27_THEME_DIR . '/includes/integrations' );
}

if ( ! defined( 'CASE27_ASSETS_DIR' ) ) {
	define( 'CASE27_ASSETS_DIR', CASE27_THEME_DIR . '/assets' );
}

if ( ! defined( 'CASE27_ENV' ) ) {
	define( 'CASE27_ENV', 'production' );
}

if ( ! defined( 'PT_OCDI_PATH' ) ) {
	define( 'PT_OCDI_PATH', trailingslashit( CASE27_THEME_DIR ) . 'includes/extensions/demo-import/plugin/' );
}

if ( ! defined( 'PT_OCDI_URL' ) ) {
	define( 'PT_OCDI_URL', trailingslashit( get_template_directory_uri() ) . 'includes/extensions/demo-import/plugin/' );
}

if ( ! defined( 'CASE27_THEME_VERSION' ) ) {
	if (CASE27_ENV == 'dev') {
		define( 'CASE27_THEME_VERSION', rand(1, 10e3) );
	} else {
		define( 'CASE27_THEME_VERSION', wp_get_theme( get_template() )->get('Version') );
	}
}

if ( ! defined( 'ELEMENTOR_PARTNER_ID' ) ) {
	define( 'ELEMENTOR_PARTNER_ID', 2124 );
}

// Load textdomain early to include strings that are localized before
// the 'after_setup_theme' is called.
load_theme_textdomain( 'my-listing', CASE27_THEME_DIR . '/languages' );

// Load classes.
require_once CASE27_THEME_DIR . '/includes/autoload.php';


add_action( 'mylisting/get-listings/before-query', function ( &$args ) {
    $listing_types = ['activity'];
    
    if ( empty( $args['meta_query'] ) || empty( $args['meta_query']['listing_type_query'] ) ) {
        return $args;
    }
    
    $meta_value = $args['meta_query']['listing_type_query']['value'];
   
    if ( ! isset( $meta_value ) ) {
        return $args;
    }
    
    if ( is_array( $meta_value ) && ! empty( $meta_value ) ) {
        $meta_value = $meta_value[0];
    }
    
    // Only apply to the listing types defined in $listing_types.
    if ( ! in_array( $meta_value, $listing_types ) ) {
        return $args;
    }

    $args['meta_query'] = [
    //   'relation' => 'OR',
        'listing_type_query' => [
            'key' => '_case27_listing_type',
            'value' => 'activity',
            'compare' => '='
        ],
        [
            'key' => '_date-fin',
            'value' => date('Y-m-d'),
            'compare' => '>=',
            'type' => 'DATE',
        ],
    ];
    
    // if ( $meta_value == 'activity' ) {
    //     print_r( $args );exit();
    // }
}, 10 );