Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Ajay

    (@ajay)

    What happens when you add this code at line 225 of top-10.php

    global $wpdb, $tptn_settings;
    if ( empty( $wp ) ) {
    global $wp;
    }
    Thread Starter WilliamTai

    (@williamtai)

    I’m not add the code, I just replaced it.

    function tptn_parse_request( $wp ) {
       	global $wpdb, $tptn_settings;
        if ( empty( $wp ) ) {
        global $wp;
        }
    
    	$table_name = $wpdb->base_prefix . "top_ten";
    	$top_ten_daily = $wpdb->base_prefix . "top_ten_daily";
    	$str = '';
    
    	if ( array_key_exists( 'top_ten_id', $wp->query_vars ) && array_key_exists( 'activate_counter', $wp->query_vars ) && $wp->query_vars['top_ten_id'] != '' ) {
    
    		$id = intval( $wp->query_vars['top_ten_id'] );
    		$blog_id = intval( $wp->query_vars['top_ten_blog_id'] );
    		$activate_counter = intval( $wp->query_vars['activate_counter'] );
    
    		if ( $id > 0 ) {
    
    			if ( ( 1 == $activate_counter ) || ( 11 == $activate_counter ) ) {
    
    				$tt = $wpdb->query( $wpdb->prepare( "INSERT INTO {$table_name} (postnumber, cntaccess, blog_id) VALUES('%d', '1', '%d') ON DUPLICATE KEY UPDATE cntaccess= cntaccess+1 ", $id, $blog_id ) );
    
    				$str .= ( FALSE === $tt ) ? 'tte' : 'tt' . $tt;
    			}
    
    			if ( ( 10 == $activate_counter ) || ( 11 == $activate_counter ) ) {
    
    				$current_date = gmdate( 'Y-m-d H', current_time( 'timestamp', 0 ) );
    
    				$ttd = $wpdb->query( $wpdb->prepare( "INSERT INTO {$top_ten_daily} (postnumber, cntaccess, dp_date, blog_id) VALUES('%d', '1', '%s', '%d' ) ON DUPLICATE KEY UPDATE cntaccess= cntaccess+1 ", $id, $current_date, $blog_id ) );
    
    				$str .= ( FALSE === $ttd ) ? ' ttde' : ' ttd' . $ttd;
    			}
    		}
    		Header( "content-type: application/x-javascript" );
    		echo '<!-- ' . $str . ' -->';
    
    		//stop anything else from loading as it is not needed.
    		exit;
    
    	} elseif ( array_key_exists( 'top_ten_id', $wp->query_vars ) && array_key_exists( 'view_counter', $wp->query_vars ) && $wp->query_vars['top_ten_id'] != '' ) {
    
    		$id = intval( $wp->query_vars['top_ten_id'] );
    
    		if ( $id > 0 ) {
    
    			$output = get_tptn_post_count( $id );
    
    			Header( "content-type: application/x-javascript" );
    			echo 'document.write("' . $output . '")';
    
    			//stop anything else from loading as it is not needed.
    			exit;
    		}
    
    	} else {
    		return;
    	}
    }
    add_action( 'wp', 'tptn_parse_request' );
    PHP Warning: array_key_exists() expects parameter 2 to be array, null given in /wp-content/plugins/top-10/top-10.php on line 234
    
    PHP Warning: array_key_exists() expects parameter 2 to be array, null given in /wp-content/plugins/top-10/top-10.php on line 264
    Plugin Author Ajay

    (@ajay)

    Hi,

    Could you please try changing the last line of your code i.e. the add_action to:

    add_action( 'parse_request', 'tptn_parse_request' );

    Could you please let me know if this removes the warning and also tracks the posts?

    Thread Starter WilliamTai

    (@williamtai)

    Hi,
    It works for me, all the warning is gone and the plugin also tracks the posts.

    thanks for your help.

    Plugin Author Ajay

    (@ajay)

    Thank you for confirming. I’ll put this in as a fix for the next version.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Warning: array_key_exists() expects parameter 2 to be array’ is closed to new replies.