WordPress.org

Ready to get started?Download WordPress

Forums

P2 Theme - Real Time Updating Not Working (46 posts)

  1. archondigital
    Member
    Posted 4 years ago #

    I also suspect the issue is with the latest WordPress release as I've been using the latest P2 before I upgraded to the 2.9 branch

  2. dwj
    Member
    Posted 4 years ago #

    Hi,
    i've investigated the problem and i've come to a solution (at least for me) by editing the file in p2/inc/ajax.php.

    1st of all I'm running a PHP version lower than 5.2 which lacks native support for JSON.
    For what i can see, wordpress 2.9x has introduced a compatibility file to provide json_encode e json_decode for PHP < 5.2 in wp-include/compat.php which requires wp-include/class-json.php, the JSON_service class.

    Now, also P2 provides this class since for updates it relies on json encoded AJAX responses (see line 199 in p2/inc/ajax.php), but in a different version, which i think causes some conflicts:

    WordPress 2.9x : v 1.3 2009/05/22 23:51:00
    P2:              v 1.31 2006/06/28 05:54:17

    My solution has been to call directly the WP class (p2/inc/ajax.php from line 198):

    nocache_headers();
    echo json_encode( array(
        'numberofnewposts' => $number_of_new_posts,
        'html' => $posts_html,
        'lastposttime' => gmdate('Y-m-d H:i:s')
    ) );

    changed to:

    require (ABSPATH . WPINC . '/class-json.php');
    $json = new Services_JSON();
    nocache_headers();
    echo $json->encode( array(
        'numberofnewposts' => $number_of_new_posts,
        'html' => $posts_html,
        'html' => '',
        'lastposttime' => gmdate('Y-m-d H:i:s')
    ) );
  3. dwj
    Member
    Posted 4 years ago #

    uh... and in reply to myself:
    i also had to comment line 7 in p2/functions.php to prevent the inclusion of P2 JSON file.

  4. Hesadanza
    Member
    Posted 4 years ago #

    I think you solved it dwj!

    I tried what you did, and replaced the lines in ajax.php and commented out line 7 in functions.php, and P2 1.1.3 is now working on my WP 2.9.1 blog.

    One change I had to make was I edited out the following line. Including it made the page look like it was going to refresh, but the update did not appear:

    'html' => '',

    What was that additional line supposed to do?

    So, it looks like they've included the same JSON class twice in different versions, and that's causing the conflict. Hopefully this gets fixed in the next version of P2.

  5. archondigital
    Member
    Posted 4 years ago #

    great! thanks dwj I will try this as soon as possible and get back here for any updates

  6. Simon Blackbourn
    Member
    Posted 4 years ago #

    thanks dwj, works properly now for me

  7. dwj
    Member
    Posted 4 years ago #

    @Hesadanza Yep thanx for feedback, the 'html' => '' thing is a typo. for future reference here is the correct code:

    in p2/inc/ajax.php from line 198 change:

    nocache_headers();
    echo json_encode( array(
        'numberofnewposts' => $number_of_new_posts,
        'html' => $posts_html,
        'lastposttime' => gmdate('Y-m-d H:i:s')
    ) );

    to:

    require (ABSPATH . WPINC . '/class-json.php');
    $json = new Services_JSON();
    nocache_headers();
    echo $json->encode( array(
        'numberofnewposts' => $number_of_new_posts,
        'html' => $posts_html,
        'lastposttime' => gmdate('Y-m-d H:i:s')
    ) );

    and comment line 7 in p2/functions.php

  8. Hesadanza
    Member
    Posted 4 years ago #

    One thing that I still seem to be missing is the yellow fading flash when I enter a new post. Now it just inserts the post, and everything drops down, but without the P2 yellow flash. Comments still seem to show the yellow flash when they update the page, but newly created posts don't.

  9. equalmark
    Member
    Posted 4 years ago #

    I have recently changed from using the P2 theme on WPMU to using it on standard WP and it is now working no problem.

    Must be something to do with WP MU?

  10. patung
    Member
    Posted 4 years ago #

    "Must be something to do with WP MU? "

    Looks like it, doesn't work for me out of the box on Multisite 3.0 in *any* browser.

  11. patung
    Member
    Posted 4 years ago #

    Ah, do both things dwj mentioned, not just the first, doh, works a treat.

  12. mscappa
    Member
    Posted 4 years ago #

    I tried doing both items DWJ recommended and it didn't fix it back for me?

    Does anyone know what actually causes this to break in the first place?

    I like others had it working fine, then suddenly it breaks!

    Any other suggestions on how I can fix?

  13. Joe Beaudoin Jr.
    Member
    Posted 4 years ago #

    I've done a quick write up based on what DWJ recommended. It covers not only fixing Auto Update for new posts, but for replies as well, as they are handled by two different functions.

    http://www.joebeaudoin.net/2010/07/getting-p2-to-auto-update/

  14. spurs-fan
    Member
    Posted 3 years ago #

    I caanot get this to work?

    Using

    wordpress Version 3.0.1

    P2 1.1.6.2

    Also cannot get the reply to show just permalink showing?

  15. errantthought
    Member
    Posted 3 years ago #

    FYI: dwj's solution worked for me.

    Running: wordpress 3.0.1 and p2 1.1.7 on apache 2.0.55, php 5.1.2

  16. errantthought
    Member
    Posted 3 years ago #

    Fix has to be reapplied after theme update.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags