includes(); //Load Tracking Analytics add_action( 'wp_head', array( $this, 'hook_analytics' ) ); //Load Tracking Analytics Remarketing add_action( 'wp_footer', array( $this, 'hook_analytics_remarketing' ) ); //Load Tracking Facebook ID add_action( 'wp_head', array( $this, 'hook_facebook_pixel_code' ) ); //Load Tracking Google Tag Manager in Head and after Body add_action('wp_head', array($this, 'hook_google_tag_manager_head')); add_filter('template_include', array( $this, 'custom_include' ),0 ); add_filter('shutdown', array( $this, 'hook_google_tag_manager_body' ),0); } /** * Return an instance of this class. * * @return object A single instance of this class. */ public static function get_instance() { // If the single instance hasn't been set, set it now. if ( null == self::$instance ) { self::$instance = new self; } return self::$instance; } /** * Get templates path. * * @return string */ public static function get_templates_path() { return plugin_dir_path( __FILE__ ) . 'templates/'; } /** * Load the plugin text domain for translation. */ public function load_plugin_textdomain() { load_plugin_textdomain( 'wp-tracking-codes', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); } /** * Instalation Plugin */ public function wp_tracking_codes_install() { // Trigger our function that registers the custom post type pluginprefix_setup_post_types(); // Clear the permalinks after the post type has been registered flush_rewrite_rules(); } /** * Includes */ private function includes() { include_once 'includes/class-register-codes.php'; } /** * Debug */ public function log_me($message) { if (WP_DEBUG === true) { if (is_array($message) || is_object($message)) { error_log(print_r($message, true)); } else { error_log($message); } } } public function hook_analytics(){ $this->options = get_option( 'tracking_option' ); if( empty( $this->options['tracking_option']['analytics'] ) && !empty( $this->options['analytics'] ) ) if($analytics = $this->options['analytics']): echo " "; endif; } public function hook_analytics_remarketing(){ $this->options = get_option( 'tracking_option' ); if( empty( $this->options['tracking_option']['analytics_remarketing'] ) && !empty( $this->options['analytics_remarketing'] ) ) if($analytics_remarketing = $this->options['analytics_remarketing']): echo ' '; endif; } public function hook_facebook_pixel_code(){ $this->options = get_option( 'tracking_option' ); if( empty( $this->options['tracking_option']['facebook_pixel_code'] ) && !empty( $this->options['facebook_pixel_code'] ) ) if($facebook_pixel_code = $this->options['facebook_pixel_code']): echo " "; endif; } public function custom_include($template) { ob_start(); return $template; } public function hook_google_tag_manager_head(){ $this->options = get_option('tracking_option'); if (empty($this->options['tracking_option']['google_tag_manager']) && !empty($this->options['google_tag_manager'])) if ($google_tag_manager = $this->options['google_tag_manager']) : echo " "; endif; } public function hook_google_tag_manager_body($classes){ $this->options = get_option( 'tracking_option' ); if( empty( $this->options['tracking_option']['google_tag_manager'] ) && !empty( $this->options['google_tag_manager'] ) ) if($google_tag_manager = $this->options['google_tag_manager']): $content = ob_get_clean(); $code_tag = " "; $content = preg_replace('#]*)>#i',"{$code_tag}",$content); echo $content; endif; } } add_action( 'plugins_loaded', array( 'Wp_Tracking_Codes', 'get_instance' ) ); endif; //register_deactivation_hook ( __FILE__ , 'pluginprefix_function_to_run' );