admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'adct_log_click' ), 'mode' => 'site', ); if ( function_exists( 'is_product' ) && is_product() ) { $product_id = get_the_ID(); $snapshot = ADCT_Database::get_product_snapshot( $product_id ); $config['mode'] = 'product'; $config['product'] = array( 'id' => $product_id, 'title' => get_the_title(), 'url' => get_permalink(), 'price' => $snapshot['product_price'], 'mileage' => $snapshot['product_mileage'], 'image_url' => $snapshot['product_image_url'], ); } else { $config['page'] = self::get_page_context(); } wp_localize_script( 'adct-tracker', 'adctConfig', $config ); } private static function get_page_context() { if ( is_singular() ) { return array( 'title' => get_the_title(), 'url' => get_permalink(), ); } if ( is_tax() || is_category() || is_tag() ) { $term = get_queried_object(); if ( $term && ! is_wp_error( $term ) ) { $link = get_term_link( $term ); return array( 'title' => $term->name, 'url' => is_wp_error( $link ) ? self::get_current_url() : $link, ); } } if ( is_post_type_archive() ) { $post_type = get_query_var( 'post_type' ); $link = get_post_type_archive_link( is_array( $post_type ) ? reset( $post_type ) : $post_type ); return array( 'title' => post_type_archive_title( '', false ), 'url' => $link ? $link : self::get_current_url(), ); } return array( 'title' => wp_strip_all_tags( html_entity_decode( wp_get_document_title(), ENT_QUOTES, 'UTF-8' ) ), 'url' => self::get_current_url(), ); } private static function get_current_url() { if ( isset( $_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI'] ) ) { $scheme = is_ssl() ? 'https://' : 'http://'; return esc_url_raw( $scheme . sanitize_text_field( wp_unslash( $_SERVER['HTTP_HOST'] ) ) . wp_unslash( $_SERVER['REQUEST_URI'] ) ); } return home_url( '/' ); } } ADCT_Plugin::init();