Support » Plugins » stats bug since 2.3 (with wp-stats and SlimStats)

Viewing 15 replies - 1 through 15 (of 16 total)
  • Thread Starter ihad

    (@ihad)

    according to 082net this is a wp 2.3 issue:

    082net c-kr | October 2nd, 2007, 6:09 pm

    ihad//
    I found that it’s not related to K2 but WP_Query.

    $wp_query was overridden by plugins, themes, and widgets using ‘new WP_Query()’ or ‘query_posts()’ and ‘wp_reset_query()’ seems does not works. ( I don’t know why ‘new WP_Query()’ overrides $wp_query 🙁 Is it a bug or general? )

    So, I decided to query the request again even if it’s already queried by wordpress.

    I’ll update this plugin soon with another bug patches.

    Thanks!
    http://082net.com/2007/818/wp-slimstat-ex-v1_6/

    I guess wordpress.com stats plugin needs an update too then?

    I was wrong, it’s not about WP_Query but $post.

    $post variable overrides $wp_query->post and $wp_the_query->post.

    And any plugin or theme using ‘custom loop’ would replace the wordpress $post, and ‘latest post’ sidebar module is one of them.

    e.g.
    foreach($myposts as $post) {……}
    or
    while($myposts->have_posts): $myposts->the_post(); …… endwhile;

    $myposts would be get_posts(‘query…’) or new WP_Query(‘query…’)

    Since almost stat plugin do their job at the end of the page load, they got overridden post values.

    And here’s a temporary patch.

    WordPress.com Stats
    Find :

    if ( ( $wp_the_query->is_single || $wp_the_query->is_page ) && !$wp_the_query->is_attachment )
    		$a['post'] = $wp_the_query->get_queried_object_id();
    	else

    Replace with :

    if ( ( $wp_the_query->is_single || $wp_the_query->is_page ) && !$wp_the_query->is_attachment ) {
    		$wp_the_query->rewind_posts();
    		$a['post'] = $wp_the_query->get_queried_object_id();
    	} else

    SlimStat-Ex
    (I’ll update this plugin soon.)
    Find : (inside of function _getPostTitle – lib/functions.php)

    if($track) {
    			$_query =& $wp_query;
    		} else {

    Replace with :

    if($track) {
    			$_query =& $wp_query;
    			$_query->rewind_posts();
    		} else {

    $wp_the_query was created to ensure a copy of the first WP_Query would be available even after subsequent instantiations.

    It’s is_single and we’re asking for the queried_object_id of $wp_the_query. Why would a rewind fix the problem? Have you verified it against posts that aren’t the most recent?

    I had a big mistake on my testing. I’ve tested with $wp_the_query->post->ID not with $wp_the_query->get_queried_object_id(), so it returned wrong(overridden) value. ( I thought they are the same 😐 )

    BTW, $wp_the_query->queried_object_id was overrode by K2 and $wp_the_query->get_queried_object_id() always returned last post id of recent entries on wp_footer or shutdown hook when it has a ‘latest posts’ module on single post page.

    I’ll report this to K2 team and ask them if it’s a bug.

    It was not a K2 bug.

    It’s the matter of when $wp_the_query->get_queried_object() is firstly called.

    As I mentioned above, $wp_the_query->post is overrod by $post.

    wp-settings.php
    $wp_the_query =& new WP_Query();
    $wp_query     =& $wp_the_query;
    
    wp-includes/class.php WP::register_globals()
    $GLOBALS['posts'] = & $wp_query->posts;
    $GLOBALS['post'] = & $wp_query->post;

    If a page haven’t called $wp_the_query->get_queried_object() before a ‘custom loop’ (or something overriding $post or $posts), get_queried_object_id() would retun last post id of the ‘custom loop’.

    $wp_the_query->get_queried_object() would not stable until it is firstly called before any plugin or theme.

    It seems stable ’cause it returns pre-set value if available.

    function get_queried_object() {
    	if (isset($this->queried_object)) {
    		return $this->queried_object;
    	}

    Because almost wordpress theme use ‘wp_title()’ for <title> </title> and wp_title call ‘wp_query->get_queried_object()’, there seems no problem.

    For current K2 does not use wp_title() but the_title() which does not call ‘get_queried_object’, this issue seems related to K2.

    Here’s my suggestion to wordpress and I think it will help make $wp_the_query stable.

    wp-includes/class.php ‘WP::query_posts()’

    function query_posts() {
    	global $wp_the_query;
    	$this->build_query_string();
    	$wp_the_query->query($this->query_vars);
    	$wp_the_query->get_queried_object();// add this line
    }

    And temporary patch for K2 is replacing the_title() with wp_title() on header.php but it will not solve the whole problem.

    Thread Starter ihad

    (@ihad)

    So you are saying this is “sort of” a wordpress 2.3 bug?

    Added your modifications and it worked! Thanks a lot!

    Thread Starter ihad

    (@ihad)

    Hm, seems it still does not fully work.

    external [post] Banned Blaupunkt Commercial
    points in fact to:
    http://www.ihad.de/2006/01/12/24-season-5-starts-this-weekend/

    Oh well…

    Did you mean SlimStat-Ex?

    Maybe it’s a pre-inserted(wp_slimex_resource) title while you have the problem.

    Thread Starter ihad

    (@ihad)

    yes, I meant slim-stat ex

    in fact almost none of the “titles” displayed in the stats match the actual urls they refer to.

    same goes for wp.com stats.

    Has the plugin been updated now so it’s safe for use with WordPress 2.3?

    Not sure if this was addressed before. Can’t find it.

    I’ve been having problems with creating new static pages since upgrading to wp2.3. See my post at the support site.

    When I disabled all the plugins and reactivated them, I found out that this plugin was creating the problems.

    The bug in both plugins was caused by a WordPress bug. The plugins do not need to be updated. The next bugfix release of WordPress will have the fix. It was committed just about an hour ago. You can apply it yourself if you understand this:

    http://trac.wordpress.org/changeset/6232

    I am not running 2.3 (my host hasn’t provided it yet) and my stats stopped working when I changed my theme. In the docs, it refers to a “call to”, but I am having trouble trying to figure out what it refers to.

    Thread Starter ihad

    (@ihad)

    Thanks Andy. The only thing I’d like to add here is that I am surprised that the ticket got closed that quickly as a non WP related issue and had I and 082net pursued that matter it would have stayed that way. I just hope this does not become common practice.

    Cheers,
    Alex

Viewing 15 replies - 1 through 15 (of 16 total)
  • The topic ‘stats bug since 2.3 (with wp-stats and SlimStats)’ is closed to new replies.