"; echo $aimtell_tracking_code; //if woocommerce is activated, abandoned browse tracking is enabled, and it's a product page, add the script if(is_woocommerce_activated()){ if(get_aimtell_woocommerce_abandoned_browse()){ if(is_product()){ $product_details = get_woocommerce_product_data(); $product_available = $product_details->available; $product_name = $product_details->name; $product_image = $product_details->image; $product_price = $product_details->price; $product_url = $product_details->url; $browse_abandoned_delay = get_aimtell_woocommerce_abandoned_browse_delay(); //json encode so values containing quotes, apostrophes or tags stay valid JS $aimtell_json_flags = JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP; $product_name_js = wp_json_encode( $product_name, $aimtell_json_flags ); $product_image_js = wp_json_encode( $product_image, $aimtell_json_flags ); $product_price_js = wp_json_encode( $product_price, $aimtell_json_flags ); $product_url_js = wp_json_encode( $product_url, $aimtell_json_flags ); $woocommerce_abaondoned_browse_tracking_code = ""; if($product_available){ echo $woocommerce_abaondoned_browse_tracking_code; } else{ echo ""; } } else{ echo ""; } } else{ echo ""; } } else{ echo ""; } } /***************Plugin Functions****************/ // Define the function in the main plugin file function get_aimtell_woocommerce_tracking() { global $wpdb; $table_name = $wpdb->prefix . 'options'; $value = $wpdb->get_var($wpdb->prepare("SELECT option_value FROM $table_name WHERE option_name = %s", 'aimtell_woocommerce_tracking')); return $value ? intval($value) : 0; } function get_aimtell_woocommerce_abandoned_browse() { global $wpdb; $table_name = $wpdb->prefix . 'options'; $value = $wpdb->get_var($wpdb->prepare("SELECT option_value FROM $table_name WHERE option_name = %s", 'aimtell_woocommerce_abandoned_browse')); return $value ? intval($value) : 0; } function get_aimtell_woocommerce_abandoned_browse_delay() { global $wpdb; $table_name = $wpdb->prefix . 'options'; $value = $wpdb->get_var($wpdb->prepare("SELECT option_value FROM $table_name WHERE option_name = %s", 'aimtell_woocommerce_abandoned_browse_delay')); return $value ? intval($value) : 10; } function get_aimtell_woocommerce_logging_level() { global $wpdb; $table_name = $wpdb->prefix . 'options'; $value = $wpdb->get_var($wpdb->prepare("SELECT option_value FROM $table_name WHERE option_name = %s", 'aimtell_woocommerce_logging_level')); return $value ? intval($value) : 0; } /** * Full path to the log file. It lives in a folder under uploads that Apache refuses to * serve, and its name carries a random key so it can't be guessed where .htaccess is * ignored (e.g. Nginx). The old plugin-folder location could be fetched by URL. */ function get_aimtell_log_path() { $key = get_option( 'aimtell_log_key' ); if ( ! $key ) { $key = wp_generate_password( 20, false ); update_option( 'aimtell_log_key', $key, 'no' ); } $uploads = wp_upload_dir( null, false ); return trailingslashit( $uploads['basedir'] ) . 'aimtell/aimtell-' . $key . '.log'; } /** * Log file location relative to the WordPress root, for display on the settings screen. */ function get_aimtell_log_file() { return '/' . str_replace( ABSPATH, '', get_aimtell_log_path() ); } /** * Create the log folder with files that block web access and directory listing. */ function aimtell_prepare_log_dir() { $dir = dirname( get_aimtell_log_path() ); if ( ! is_dir( $dir ) && ! wp_mkdir_p( $dir ) ) { return false; } if ( ! file_exists( $dir . '/.htaccess' ) ) { // Apache 2.4 and 2.2 syntax, each only where its module is loaded @file_put_contents( $dir . '/.htaccess', "\n Require all denied\n\n\n Deny from all\n\n" ); } if ( ! file_exists( $dir . '/index.php' ) ) { @file_put_contents( $dir . '/index.php', "available = $product->is_in_stock(); $product_details->name = $product->get_name(); $product_details->image = wp_get_attachment_image_url($product->get_image_id(), 'full'); $product_details->price = $product->get_price(); $product_details->url = get_permalink($product->get_id()); return $product_details; } /** * Log a message to wp-content/uploads/aimtell/aimtell.log. * @param $msg - the message to log. */ function atlog($msg, $level = 1) { if (!defined('AIMTELL_LOG_LEVEL') || !AIMTELL_LOG_LEVEL || AIMTELL_LOG_LEVEL < $level ) return; try { if ( ! aimtell_prepare_log_dir() ) return; // write to the log file $time_formatted = "[".date('Y-m-d H:i:s').'] '; $log = $time_formatted.$msg.PHP_EOL; file_put_contents(get_aimtell_log_path(), $log, FILE_APPEND); } catch (\Throwable $th) { //throw $th; } } /** * Check if WooCommerce is activated */ function is_woocommerce_activated() { if ( class_exists( 'woocommerce' ) ) { return true; } else { return false; } } /************End Admin Functions**************/ add_action( 'wp_footer', 'aimtellWP_footer', 100 ); /** * Add each post's featured image to the RSS feed as an enclosure. Aimtell's blog post * auto-send reads the image from a feed enclosure, and WordPress feeds don't include one. * Only added once auto-send has been set up from the Blog posts screen. */ function aimtell_feed_enclosure() { if ( ! get_option( 'aimtell_rss_id' ) || ! has_post_thumbnail() ) { return; } $thumb_id = get_post_thumbnail_id(); $url = wp_get_attachment_image_url( $thumb_id, 'large' ); if ( ! $url ) { return; } $file = get_attached_file( $thumb_id ); $length = ( $file && file_exists( $file ) ) ? filesize( $file ) : 0; $type = get_post_mime_type( $thumb_id ); printf( "\n", esc_url( $url ), (int) $length, esc_attr( $type ? $type : 'image/jpeg' ) ); } add_action( 'rss2_item', 'aimtell_feed_enclosure' ); //admin screens only load inside wp-admin if ( is_admin() ) { include __FOLDERDIR__ . '/admin/admin.php'; } /****** Aimtell Integrations *********/ // only include this if the aimtell_woocommerce_tracking option is active if (get_aimtell_woocommerce_tracking() || get_aimtell_woocommerce_abandoned_browse()) { include( __FOLDERDIR__ . '/integrations/aimtell-wc.php' ); } /****** End Aimtell Integrations *********/