• Resolved Julie

    (@habannah)


    Hi Alin,

    I have been getting a PHP Warning, I believe since the last plugin update:

    call_user_func_array() expects parameter 1 to be a valid callback, class ‘GADWP_Tracking’ does not have a method ‘tracking_code’ in /public_html/wp-includes/class-wp-hook.php on line 298

    As per this topic from over a year ago, I have the following code in a custom functions file:

    add_action('init', 'ngadwp_move_trackingcode');
    function ngadwp_move_trackingcode(){
    	if (class_exists('GADWP_Manager')){
    		$gadwp = GADWP();
    		if (isset($gadwp->tracking)){
    			remove_action('wp_head', array($gadwp->tracking,'tracking_code'), 99);
    
    			$uri = $_SERVER["REQUEST_URI"];
    			$uri_array = split("/",$uri);
    			$uri_first = $uri_array[1];
    			$uri_second = $uri_array[2]; // select the second split (domain does not count as split)
    
    			if ( ($uri_first == 'subscriptions') && ( ($uri_second == 'manage')  || ($uri_second == 'confirmation') || ($uri_second == 'unsubscribe') || ($uri_second == 'comments') ) ) {
    			} else {
    				add_action('wp_footer', array($gadwp->tracking,'tracking_code'), 0);
    			}
    		}
    	}
    }

    I imagine there’s now a conflict with the new settings to choose the positioning of the tracking code. I haven’t touched those, waiting to see if my code would continue to work. It does, as far as I can tell, but I’d like to figure out how to get rid of the error message flooding my error logs. I assume the above code is no longer needed to move the tracking code to the footer, as I can now use your built-in settings, so removing it would probably do the trick, but I still need to exclude the tracking code from certain pages. Is there a way to modify the above code to do just that?

    Thanks for your help!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi,

    The tracking component changed a lot, here’s the new code. I haven’t tested it, so please drive some tests first:

    add_action('init', 'ngadwp_remove_trackingcode');
    function ngadwp_remove_trackingcode(){
    	if (class_exists('GADWP_Manager')){
    		$gadwp = GADWP();
    		if (isset($gadwp->tracking->analytics)){
    
    			$uri = $_SERVER["REQUEST_URI"];
    			$uri_array = split("/",$uri);
    			$uri_first = $uri_array[1];
    			$uri_second = $uri_array[2]; // select the second split (domain does not count as split)
    			
    			//Remove tracking for these URIs
    			if ( ($uri_first == 'subscriptions') && ( ($uri_second == 'manage')  || ($uri_second == 'confirmation') || ($uri_second == 'unsubscribe') || ($uri_second == 'comments') ) ) {
    				// Remove GA Tracking Code
    				if ( $gadwp->config->options['trackingcode_infooter'] ) {
    					remove_action( 'wp_footer', array( $gadwp->tracking->analytics, 'output' ), 99 );
    				} else {
    					remove_action( 'wp_head', array( $gadwp->tracking->analytics, 'output' ), 99 );
    				}
    				// Remove Optimize code
    				if ( $gadwp->config->options['optimize_tracking'] && $gadwp->config->options['optimize_pagehiding'] && $gadwp->config->options['optimize_containerid'] ) {
    					remove_action( 'wp_head', array( $gadwp->tracking->analytics, 'optimize_output' ), 99 );
    				}
    				// Remove AMP code
    				if ( $gadwp->config->options['amp_tracking_analytics'] ) {
    					remove_action( 'amp_post_template_head', array( $gadwp->tracking->analytics, 'amp_add_analytics_script' ) );
    					remove_action( 'amp_post_template_footer', array( $gadwp->tracking->analytics, 'amp_output' ) );
    				}
    			}
    		}
    	}
    }
    • This reply was modified 7 years, 9 months ago by Alin Marcu.
    Thread Starter Julie

    (@habannah)

    Thanks very much for this, Alin! It works for removing the code from the desired pages, and it looks like it solves the issue of the PHP warning as well ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘PHP Warning’ is closed to new replies.