OwlCyberSecurity - MANAGER
Edit File: ovaev-core-functions.php
<?php if ( !defined( 'ABSPATH' ) ) { exit; } if ( ! function_exists( 'dd' ) ) { function dd( ...$args ) { echo '<pre>'; var_dump( ...$args ); echo '</pre>'; die; } } if( !function_exists( 'ovaev_asYmd' ) ){ function ovaev_asYmd($d) { if(is_null($d) || $d == '') { return '----'; } $d = str_replace('.', '-', $d); return $d; } } if( !function_exists( 'ovaev_locate_template' ) ){ function ovaev_locate_template( $template_name, $template_path = '', $default_path = '' ) { // Set variable to search in ovaev-templates folder of theme. if ( ! $template_path ) : $template_path = 'ovaev-templates/'; endif; // Set default plugin templates path. if ( ! $default_path ) : $default_path = OVAEV_PLUGIN_PATH . 'templates/'; // Path to the template folder endif; // Search template file in theme folder. $template = locate_template( array( $template_path . $template_name // $template_name ) ); // Get plugins template file. if ( ! $template ) : $template = $default_path . $template_name; endif; return apply_filters( 'ovaev_locate_template', $template, $template_name, $template_path, $default_path ); } } function ovaev_get_template( $template_name, $args = array(), $tempate_path = '', $default_path = '' ) { if ( is_array( $args ) && isset( $args ) ) : extract( $args ); endif; $template_file = ovaev_locate_template( $template_name, $tempate_path, $default_path ); if ( ! file_exists( $template_file ) ) : _doing_it_wrong( __FUNCTION__, sprintf( '<code>%s</code> does not exist.', $template_file ), '1.0.0' ); return; endif; include $template_file; } add_filter( 'chursy_header_customize', 'chursy_header_customize_event', 10, 1 ); function chursy_header_customize_event( $header ){ if( is_tax( 'event_category' ) || get_query_var( 'event_category' ) != '' || is_tax( 'event_tag' ) || get_query_var( 'event_tag' ) != '' || is_post_type_archive( 'event' ) ){ $header = OVAEV_Settings::archive_event_header(); }else if( is_singular( 'event' ) ){ $header = OVAEV_Settings::single_event_header(); } return $header; } add_filter( 'chursy_footer_customize', 'chursy_footer_customize_event', 10, 1 ); function chursy_footer_customize_event( $footer ){ if( is_tax( 'event_category' ) || get_query_var( 'event_category' ) != '' || is_tax( 'event_tag' ) || get_query_var( 'event_tag' ) != '' || is_post_type_archive( 'event' ) ){ $footer = OVAEV_Settings::archive_event_footer(); }else if( is_singular( 'event' ) ){ $footer = OVAEV_Settings::single_event_footer(); } return $footer; } /** in_array() and multidimensional array **/ function in_array_r($needle, $haystack, $strict = false) { foreach ($haystack as $item) { foreach ($item as $value) { if ( $value['date'] === $needle ) { return true; break; } } } return false; } add_action( 'widgets_init', 'ovaev_event_sidebar' ); function ovaev_event_sidebar() { $args = array( 'name' => esc_html__( 'Event Sidebar', 'ovaev' ), 'id' => 'event-sidebar', 'description' => esc_html__( 'Display in event sidebar', 'ovaev' ), 'class' => '', 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div>', 'before_title' => '<h4 class="widget-title">', 'after_title' => '</h4>' ); register_sidebar( $args ); } function ovaev_get_category_event_by_id( $id = '' ){ if( $id === '' ) return; $cat_event = get_the_terms( $id, 'event_category' ); $i = 0; if( ! empty( $cat_event ) ){ $count_cat = count( $cat_event ); ?> <i class="far fa-list-alt"></i> <?php foreach ($cat_event as $cat) { $i++; $separator = ( $count_cat !== $i ) ? "," : ""; $link = get_term_link($cat->term_id); $name = $cat->name; ?> <span class="cat-ovaev"> <a class="second_font" href="<?php echo esc_url( $link ) ?>"><?php echo esc_html( $name ) ?></a> </span> <span class="separator"> <?php echo esc_html( $separator ) ?> </span> <?php } } } function ovaev_get_tag_event_by_id( $id = '' ){ if( $id === '' ) return; $tag_event = get_the_terms( $id, 'event_tag' ); if( ! empty( $tag_event ) ){ ?> <div class="event-tags"> <span class="ovatags second_font"><?php esc_html_e('Tags: ', 'ovaev'); ?></span> <?php foreach ($tag_event as $tag) { $link = get_term_link($tag->term_id); $name = $tag->name; ?> <a class="ovaev-tag second_font" href="<?php echo esc_url( $link ) ?>"><?php echo esc_html( $name ) ?></a> <?php } ?> </div> <?php } } function ovaev_get_event_related_by_id( $id = '', $posts_per_page = 2 ) { if ( ! $id ) return; $time = OVAEV_Settings::archive_event_format_time(); $terms_type = get_the_terms( $id, 'event_category' ); $terms_tag = get_the_terms( $id, 'event_tag' ); $arr_type = []; if ( $terms_type ) { foreach( $terms_type as $type ){ $arr_type[] = $type->term_id; } } $arr_tag = []; if ( $terms_tag ) { foreach ( $terms_tag as $tag ) { $arr_tag[] = $tag->term_id; } } $args_related = array( 'post_type' => 'event', 'posts_per_page' => $posts_per_page, 'post__not_in' => array( $id ), 'tax_query' => array( 'relation' => 'OR', array( 'taxonomy' => 'event_category', 'field' => 'term_id', 'terms' => $arr_type, ), array( 'taxonomy' => 'event_tag', 'field' => 'term_id', 'terms' => $arr_tag, ), ), ); // Time $args_time = []; $time = apply_filters( 'ovaev_single_related_time', '' ); if ( $time === 'upcoming' ) { $args_time = array( 'meta_query' => array( array( 'key' => 'ovaev_start_date_time', 'value' => current_time( 'timestamp' ), 'compare' => '>' ), ) ); } elseif ( $time === 'past' ) { $args_time = array( 'meta_query' => array( array( 'key' => 'ovaev_end_date_time', 'value' => current_time( 'timestamp' ), 'compare' => '<' ), ) ); } else { $args_time = []; } $event_related = new WP_Query( array_merge_recursive( $args_related, $args_time ) ); return $event_related; } function ovaev_get_events_elements( $args ){ if( $args['category'] === 'all'){ if( $args['time_event'] === 'current'){ $args_event= array( 'post_type' => 'event', 'post_status' => 'publish', 'posts_per_page' => $args['total_count'], 'meta_query' => array( array( array( 'relation' => 'AND', array( 'key' => 'ovaev_start_date_time', 'value' => current_time('timestamp' ), 'compare' => '<' ), array( 'key' => 'ovaev_end_date_time', 'value' => current_time('timestamp' ), 'compare' => '>=' ) ) ) ) ); } elseif( $args['time_event'] === 'upcoming' ){ $args_event= array( 'post_type' => 'event', 'post_status' => 'publish', 'posts_per_page' => $args['total_count'], 'meta_query' => array( array( array( 'key' => 'ovaev_start_date_time', 'value' => current_time( 'timestamp' ), 'compare' => '>' ), ) ) ); } elseif( $args['time_event'] === 'past' ){ $args_event= array( 'post_type' => 'event', 'post_status' => 'publish', 'posts_per_page' => $args['total_count'], 'meta_query' => array( array( 'key' => 'ovaev_end_date_time', 'value' => current_time('timestamp' ), 'compare' => '<', ), ), ); } else{ $args_event= array( 'post_type' => 'event', 'post_status' => 'publish', 'posts_per_page' => $args['total_count'], ); } } elseif( $args['category'] != 'all' ) { if( $args['time_event'] === 'current'){ $args_event= array( 'post_type' => 'event', 'post_status' => 'publish', 'posts_per_page' => $args['total_count'], 'tax_query' => array( array( 'taxonomy' => 'event_category', 'field' => 'slug', 'terms' => $args['category'], ) ), 'meta_query' => array( array( 'relation' => 'OR', array( 'key' => 'ovaev_start_date_time', 'value' => array( current_time('timestamp' )-1, current_time('timestamp' )+(24*60*60)+1 ), 'type' => 'numeric', 'compare' => 'BETWEEN' ), array( 'relation' => 'AND', array( 'key' => 'ovaev_start_date_time', 'value' => current_time('timestamp' ), 'compare' => '<' ), array( 'key' => 'ovaev_end_date_time', 'value' => current_time('timestamp' ), 'compare' => '>=' ) ) ) ) ); } elseif( $args['time_event'] === 'upcoming' ){ $args_event= array( 'post_type' => 'event', 'post_status' => 'publish', 'posts_per_page' => $args['total_count'], 'tax_query' => array( array( 'taxonomy' => 'event_category', 'field' => 'slug', 'terms' => $args['category'], ) ), 'meta_query' => array( array( array( 'key' => 'ovaev_start_date_time', 'value' => current_time( 'timestamp' ), 'compare' => '>' ), ) ) ); } elseif( $args['time_event'] === 'past' ){ $args_event= array( 'post_type' => 'event', 'post_status' => 'publish', 'posts_per_page' => $args['total_count'], 'tax_query' => array( array( 'taxonomy' => 'event_category', 'field' => 'slug', 'terms' => $args['category'], ) ), 'meta_query' => array( array( 'key' => 'ovaev_end_date_time', 'value' => current_time('timestamp' ), 'compare' => '<', ), ), ); } else{ $args_event= array( 'post_type' => 'event', 'post_status' => 'publish', 'tax_query' => array( array( 'taxonomy' => 'event_category', 'field' => 'slug', 'terms' => explode(',', $args['category'] ), ) ), 'posts_per_page' => $args['total_count'] ); } } $args_event_order = []; if( $args['order_by'] === 'ovaev_start_date_time' || $args['order_by'] === 'event_custom_sort' ) { $args_event_order = [ 'meta_key' => $args['order_by'], 'orderby' => 'meta_value_num', 'order' => $args['order'], ]; } else { $args_event_order = [ 'orderby' => $args['order_by'], 'order' => $args['order'], ]; } $args_event = array_merge( $args_event, $args_event_order ); $events = new \WP_Query($args_event); return $events; } function ovaev_get_events_elements_by_get_posts( $args ){ if( $args['category'] === 'all'){ if( $args['time_event'] === 'current'){ $args_event= array( 'post_type' => 'event', 'post_status' => 'publish', 'posts_per_page' => $args['total_count'], 'meta_query' => array( array( array( 'relation' => 'AND', array( 'key' => 'ovaev_start_date_time', 'value' => current_time('timestamp' ), 'compare' => '<' ), array( 'key' => 'ovaev_end_date_time', 'value' => current_time('timestamp' ), 'compare' => '>=' ) ) ) ) ); } elseif( $args['time_event'] === 'upcoming' ){ $args_event= array( 'post_type' => 'event', 'post_status' => 'publish', 'posts_per_page' => $args['total_count'], 'meta_query' => array( array( array( 'key' => 'ovaev_start_date_time', 'value' => current_time( 'timestamp' ), 'compare' => '>' ), ) ) ); } elseif( $args['time_event'] === 'past' ){ $args_event= array( 'post_type' => 'event', 'post_status' => 'publish', 'posts_per_page' => $args['total_count'], 'meta_query' => array( array( 'key' => 'ovaev_end_date_time', 'value' => current_time('timestamp' ), 'compare' => '<', ), ), ); } else{ $args_event= array( 'post_type' => 'event', 'post_status' => 'publish', 'posts_per_page' => $args['total_count'], ); } } elseif( $args['category'] != 'all' ) { if( $args['time_event'] === 'current'){ $args_event= array( 'post_type' => 'event', 'post_status' => 'publish', 'posts_per_page' => $args['total_count'], 'tax_query' => array( array( 'taxonomy' => 'event_category', 'field' => 'slug', 'terms' => $args['category'], ) ), 'meta_query' => array( array( 'relation' => 'OR', array( 'key' => 'ovaev_start_date_time', 'value' => array( current_time('timestamp' )-1, current_time('timestamp' )+(24*60*60)+1 ), 'type' => 'numeric', 'compare' => 'BETWEEN' ), array( 'relation' => 'AND', array( 'key' => 'ovaev_start_date_time', 'value' => current_time('timestamp' ), 'compare' => '<' ), array( 'key' => 'ovaev_end_date_time', 'value' => current_time('timestamp' ), 'compare' => '>=' ) ) ) ) ); } elseif( $args['time_event'] === 'upcoming' ){ $args_event= array( 'post_type' => 'event', 'post_status' => 'publish', 'posts_per_page' => $args['total_count'], 'tax_query' => array( array( 'taxonomy' => 'event_category', 'field' => 'slug', 'terms' => $args['category'], ) ), 'meta_query' => array( array( array( 'key' => 'ovaev_start_date_time', 'value' => current_time( 'timestamp' ), 'compare' => '>' ), ) ) ); } elseif( $args['time_event'] === 'past' ){ $args_event= array( 'post_type' => 'event', 'post_status' => 'publish', 'posts_per_page' => $args['total_count'], 'tax_query' => array( array( 'taxonomy' => 'event_category', 'field' => 'slug', 'terms' => $args['category'], ) ), 'meta_query' => array( array( 'key' => 'ovaev_end_date_time', 'value' => current_time('timestamp' ), 'compare' => '<', ), ), ); } else{ $args_event= array( 'post_type' => 'event', 'post_status' => 'publish', 'tax_query' => array( array( 'taxonomy' => 'event_category', 'field' => 'slug', 'terms' => explode(',', $args['category'] ), ) ), 'posts_per_page' => $args['total_count'] ); } } $args_event_order = []; if( $args['order_by'] === 'ovaev_start_date_time' || $args['order_by'] === 'event_custom_sort' ) { $args_event_order = [ 'meta_key' => $args['order_by'], 'orderby' => 'meta_value_num', 'order' => $args['order'], ]; } else { $args_event_order = [ 'orderby' => $args['order_by'], 'order' => $args['order'], ]; } $args_event = array_merge( $args_event, $args_event_order ); $events = get_posts($args_event); return $events; } /** * Get Events ( Demo ) */ if ( ! function_exists( 'ovaev_get_events_demo' ) ) { function ovaev_get_events_demo() { $args = array( 'post_type' => 'event', 'fields' => 'ids', 'post_status' => 'publish', 'posts_per_page' => '-1', 'orderby' => 'ID', 'order' => 'ASC', ); $events = get_posts( $args ); return $events; } } // Get event categories if ( ! function_exists( 'ovaev_get_categories_events' ) ) { function ovaev_get_categories_events( $events, $incl = [], $excl = [] ) { $result = []; $names = []; if ( $events->have_posts() ) { while ( $events->have_posts() ) { $events->the_post(); $terms = get_the_terms( get_the_ID(), 'event_category' ); if ( ! empty( $terms ) && is_array( $terms ) ) { foreach ( $terms as $term ) { $term_id = $term->term_id; $term_name = $term->name; $term_slug = $term->slug; if ( $excl && in_array( $term_id, $excl ) ) continue; if ( $incl ) { if ( in_array( $term_id, $incl ) ) { if ( isset( $result[$term_id] ) && $result[$term_id] ) { $result[$term_id]['count'] += 1; } else { $result[$term_id] = [ 'term_id' => $term_id, 'name' => $term_name, 'slug' => $term_slug, 'count' => 1, 'icon_class' => get_term_meta( $term_id, 'ovaev_icon_class', true ), ]; $names[$term_id] = $term_name; } } } else { if ( isset( $result[$term_id] ) && $result[$term_id] ) { $result[$term_id]['count'] += 1; } else { $result[$term_id] = [ 'term_id' => $term_id, 'name' => $term_name, 'slug' => $term_slug, 'count' => 1, 'icon_class' => get_term_meta( $term_id, 'ovaev_icon_class', true ), ]; $names[$term_id] = $term_name; } } } } } } wp_reset_postdata(); if ( ! empty( $names ) && is_array( $names ) && ! empty( $result ) && is_array( $result ) ) { array_multisort( $names, SORT_ASC, $result ); } return $result; } } // Get end date if ( ! function_exists( 'ovaev_get_end_date' ) ) { function ovaev_get_end_date( $time = '' ) { $end = ''; $date_format = OVAEV_Settings::archive_event_format_date(); $today = current_time( 'timestamp' ); if ( $time == 'today' ) { $end = strtotime( date( $date_format, $today ) . ' 23:59' ); } elseif ( $time == 'week' || $time == 'weekend' ) { $end = strtotime( date( $date_format, strtotime( 'this Sunday' ) ) . ' 23:59' ); } else { $end = $today; } return $end; } } /** Booking, Checkout Woo */ // Get checkout woo page if ( ! function_exists( 'ovaev_get_checkout_woo_page' ) ) { function ovaev_get_checkout_woo_page(){ $woocommerce_checkout_page_id = get_option( ' woocommerce_checkout_page_id ' ) ; $woocommerce_checkout_page_id_wpml = apply_filters( 'wpml_object_id', $woocommerce_checkout_page_id, 'product' ); return $woocommerce_checkout_page_id_wpml ? esc_url( get_permalink( $woocommerce_checkout_page_id_wpml ) ) : home_url(); } } // Get cart woo page if ( ! function_exists( 'ovaev_get_cart_woo_page' ) ) { function ovaev_get_cart_woo_page(){ $woocommerce_cart_page_id = get_option( 'woocommerce_cart_page_id' ); $woocommerce_cart_page_id_wpml = apply_filters( 'wpml_object_id', $woocommerce_cart_page_id, 'product' ); return $woocommerce_cart_page_id_wpml ? esc_url( get_permalink( $woocommerce_cart_page_id_wpml ) ) : home_url(); } } if ( ! function_exists( 'ovaev_process_checkout' ) ) { function ovaev_process_checkout( $post_data ) { if ( empty( $post_data ) ) $post_data = $_POST; $event_id = isset($post_data['ide']) ? $post_data['ide'] : []; if( !$event_id ) return false; // Setup a session for cart OVAEV()->cart_session->remove(); OVAEV()->cart_session->set( 'event_id', $event_id ); $Payment_Woo = new Ovaev_Payment_Woo(); $result = $Payment_Woo->process(); if( isset( $result['status'] ) && $result['status'] == 'success' ){ // Send Mail $data['el_url'] = $result['url']; echo json_encode($data); exit(); } else { return false; } return false; } } add_action( 'woocommerce_before_calculate_totals', 'ovaev_woo_before_calculate_totals'); function ovaev_woo_before_calculate_totals( $cart ) { if ( is_admin() && ! defined( 'DOING_AJAX' ) ) return; if ( did_action( 'woocommerce_before_calculate_totals' ) >= 2 ) return; // Loop through cart items foreach ( $cart->get_cart() as $cart_item ) { $event_id = isset( $cart_item['event_id'] ) && $cart_item['event_id'] ? $cart_item['event_id'] : ''; if ( ! $event_id ) continue; $event_obj = get_post( $event_id ); $new_price = get_post_meta( $event_id, 'ovaev_price', true ); // Get an instance of the WC_Product object $product = $cart_item['data']; // Get the product name (Added Woocommerce 3+ compatibility) $original_name = method_exists( $product, 'get_name' ) ? $product->get_name() : $product->post->post_title; // SET THE NEW NAME if( is_object( $event_obj ) && isset( $event_obj->post_title ) ){ $new_name = $event_obj->post_title; // Set the new name (WooCommerce versions 2.5.x to 3+) if( method_exists( $product, 'set_name' ) ) $product->set_name( $new_name ); else $product->post->post_title = $new_name; } $cart_item['data']->set_price( $new_price ); } } add_action( 'woocommerce_checkout_create_order_line_item', 'ovaev_checkout_create_order_line_item', 10, 4 ); function ovaev_checkout_create_order_line_item( $item, $cart_item_key, $values, $order ) { // Get booking id in session if ( isset( $values['event_id'] ) && $values['event_id'] ) { // Add data event_id $item->add_meta_data( 'event_id', $values['event_id'] ); } } add_filter( 'woocommerce_cart_item_permalink' , 'ovaev_cart_item_permalink', 10, 3 ); function ovaev_cart_item_permalink( $permalink, $cart_item, $cart_item_key ) { $product_id = $cart_item['product_id']; $event_id = isset( $cart_item['event_id'] ) && $cart_item['event_id'] ? $cart_item['event_id'] : ''; $permalink = '#'; if ( $event_id ) { $permalink = get_permalink( $event_id ); } else { $permalink = get_permalink( $product_id ); } return $permalink; } add_filter( 'woocommerce_order_item_permalink' , 'ovaev_order_item_permalink', 10, 3 ); function ovaev_order_item_permalink( $permalink, $item, $order ) { $product_id = $item['product_id']; $event_id = isset( $item['event_id'] ) && $item['event_id'] ? $item['event_id'] : ''; $permalink = '#'; if ( $event_id ) { $permalink = get_permalink( $event_id ); } else { $permalink = get_permalink( $product_id ); } return $permalink; } add_filter( 'woocommerce_order_item_get_formatted_meta_data', 'ovaev_order_item_hide_fields', 10, 2 ); function ovaev_order_item_hide_fields( $meta_data, $item ) { $field_hide = array( 'event_id', ); $new_meta = array(); foreach ( $meta_data as $id => $meta_array ) { if ( in_array( $meta_array->key, $field_hide ) ) { continue; } $new_meta[ $id ] = $meta_array; } return $new_meta; }