WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] [Plugin: WordPress Popular Posts] Upgrade to 2.9.1 (from 2.3) - Not Updating (10 posts)

  1. castig
    Member
    Posted 4 years ago #

    The utmost respect for you and your awesome plugin! Thanks in advance for any help!

    I upgraded from 2.3 to 2.9.1. last week - and your plugin (along with stats) have stopped updating to the database.

    Any ideas of things that could be the problem?
    BTW....
    *Ive read most of the forum
    *I have the wp_head and wp_footer placed properly in my theme.

    http://wordpress.org/extend/plugins/wordpress-popular-posts/

  2. Héctor Cabrera
    Member
    Posted 4 years ago #

    Hi castig,

    You really took your time to upgrade your blog, didn't you? :P Anyways, what version of WPP were you running before updating? What version are you using right now?

  3. castig
    Member
    Posted 4 years ago #

    Hehe, yes...I'll never let that happen again.

    I've installed this WPP on another blog of mine and really liked it - but never on this site. Strangely the WPP worked for maybe 5 minutes, and then stopped responding. So even now, if I re-import the DB from the moment I launched 2.9.1 it will (usually) work for 5 minutes and then stop. Which makes me think maybe it has to do with some DB conflict? (BTW I also upgraded to MYSQL5 during this process).

    thanks Ikki24!

  4. Héctor Cabrera
    Member
    Posted 4 years ago #

    Could be. Do you have access to phpmyadmin? If so, can you please check that:

    1. There are two tables called wp_popularpostsdata and wp_popularpostsdatacache
    2. wp_popularpostsdatacache has data on it

    Also:

    # What are the settings you're using with WPP?
    # Are you using it as a template tag (the get_mostpopular() function) or as a sidebar widget?

  5. castig
    Member
    Posted 4 years ago #

    1. Those two table are there
    2. Neither has any data in it (0 rows returned)

    I'm using it as a sidebar widget. But yes, as you can tell it isn't updating the database

    Is this the hook that updates the DB
    add_action('wp_ajax_nopriv_wpp_update', array(&$this, 'wpp_ajax_update'));
    (IF SO, this action isn't executing properly)

    I'm a bit of a newbie plugin developer, but what is "wp_ajax_nopriv_wpp_update"? Can't find documentation of that call.

  6. Héctor Cabrera
    Member
    Posted 4 years ago #

    The wp_ajax_ action is unfortunately poorly documented, there are nearly no references to it that are easy to follow / understand. The no_priv_ part just tells WordPress that the callback function will only be executed for users that aren't logged in into your wp-admin. The wpp_update part is the name of the action itself, you can call it whatever you want (eg. wp_ajax_nopriv_myaction).

    Here is the document I used as reference and after a few days of struggling with it I finally managed to make my plugin work with WordPress' Ajax API. I might try and write a nicer tutorial about it someday, but fow the time being you can start there.

    Anyways, back on topic.

    Yes, the wp_ajax_nopriv_wpp_update is the hook that updates the database. Below it, you'll find another hook:

    add_action('wp_head', array(&$this, 'wpp_print_ajax'));

    These two hooks are needed for updating the database via WordPress Ajax API. However this action only works when the visitor isn't logged in, and for posts and pages views only.

    Is this site of yours live now?

  7. castig
    Member
    Posted 4 years ago #

    Wow! What you just said probably solved the problem.
    The site I'm making is an "intranet" - and users must be logged in to view any content. Is there anyway to get around this, so that logged in users will trigger those hooks?

  8. Héctor Cabrera
    Member
    Posted 4 years ago #

    That's what I thought, however I had to ask to be sure :P

    Yes, there's a simple workaround for that. Remember that nopriv_ thing? Lose it. The update action hook should look like this after your remove it:

    add_action('wp_ajax_wpp_update', array(&$this, 'wpp_ajax_update'));

    However, I'm not sure though, you will probably have to change this piece of code (around line 393):

    // if we're on a page or post, load the script
    if ( (is_single() || is_page()) && !is_user_logged_in() ) {

    ... into this:

    // if we're on a page or post, load the script
    if ( is_single() || is_page() ) {

    I might consider adding an extra functionality to my plugin to let you determine whether to count visits from logged in users or not. That way, you won't need to keep editing my plugin on the subsequent versions.

    Anyways, give that a shot and let me know the results!

  9. castig
    Member
    Posted 4 years ago #

    PERFECT!!!!!! So amazing. I had spent hourssss looking over the code and had no idea about that Ajax API thingy. Awesome!

    How did you get so good at writing wordpress plugins? Any advice?

  10. Héctor Cabrera
    Member
    Posted 4 years ago #

    Lots of practice, and users' feedback ;) That's all it takes man. Publish your plugin, let other people test it and in time you'll improve your coding skills while developing it.

    If you need any help, let me know ok?

    By the way, you might want to mark this thread to [resolved] :P

Topic Closed

This topic has been closed to new replies.

About this Topic