Skip to:
Content
Pages
Categories
Search
Top
Bottom

Problem using BuddyPress functions from WordPress cron


  • Jose Conti
    Participant

    @jconti

    Hi,

    Since a lot of time, I want to fix a problem with WangGuard cron.

    After testing time, I opened this ticket http://buddypress.trac.wordpress.org/ticket/5229 because I discovered that bug, but the fix, don’t fix the WordPress Cron problem.

    WangGuard cron, search every x hours a new splog users, If WangGuard find them, they are marked as spam with the WordPress function

    update_user_status( $spuserID, 'spam', '1' );

    That function fire
    bp_core_mark_user_spam_admin( $user_id );
    that make all work for BuddyPress.

    Problem, if I use this function for example in WangGuard users screen, it work fine, because I’m the super admin, but cron cannot use it.

    When update_user_status call to bp_core_mark_user_spam_admin -> bp_core_process_spammer_status from WordPress cron, it is killed, so the user is marked as spam user, but the activity are not removed.

    For testing , I placed bp_core_process_spammer_status, replacing update_user_status in WangGuard cron. Nothing happens, bp_core_process_spammer_status are blocked without errors (no logs with WP_DEBUG), users are not marked as spam, no activity removed, etc

    After that, i created a new function:

    
    function wangguard_core_mark_user_spam_admin( $user_id ) {
    
    	bp_core_process_spammer_status( $user_id, 'spam' );
    }
    

    but that function I placed in the file /buddypress/bp-loader.php (as new BuddyPress function)

    After that, I rewrite again the wangGuard cron, but using this new “BuddyPress function”, the users were marked as spam, but the activity was not removed, why? because the function bp_core_process_spammer_status use other BuddyPress function that use a BuddyPress Class for clean all user activity.

    Brief:

    There is something in BuddyPress that block functions and classes that are in the “lower levels” to be used by WordPress cron.

    Has someone a solution for this problem?

    Thank you

Viewing 3 replies - 1 through 3 (of 3 total)

  • Boone Gorges
    Keymaster

    @boonebgorges

    There are probably a couple things happening:

    1. There is a hardcoded check to is_super_admin() in bp_core_process_spammer_status(). That check would fail during a cron job. BuddyPress should probably separate out the business logic of this function from the permissions checks. This would be appropriate for an enhancement ticket.

    2. Certain parts of BuddyPress are only loaded at some times. If you’re going to modify BP’s behavior, or use functions from BP, you need to make sure you’re waiting for BP to be loaded before doing so. It’s possible that load order works differently during cron than during regular page loads, so it’s extra important to pay attention to these rules. In short, anything that needs to hook to a BuddyPress action, or use BuddyPress functions, should be in files that are loaded at 'bp_include' or later. (See https://codex.buddypress.org/plugindev/checking-buddypress-is-active/). I’m glancing at wangguard-admin.php, and it looks like there are quite a few places where you’re attempting to do BP stuff in the main plugin file – try breaking it out into a separate, BP-specific file, which is loaded in the manner described in that link.

    If you can, you might also try turning up your error reporting level on your test installation, making sure that it’s going to your Apache error log or wp-content/debug.log. It could be that something’s happening that’s causing a non-fatal error, and your php.ini settings are too low for it to be showing up. wp-cron can be sensitive to that sort of thing.


    Jose Conti
    Participant

    @jconti

    Hi @boonebgorges

    Yes, I know, I commented is_super_admin() for tried to use it.

    Ok, I will move some functions to a file loaded by 'bp_include'

    I will open a ticket with the enhancement 🙂

    And yes, I used WP_DEBUG and the debug.log for log errors, but any error was there, except this

    
    PHP Warning:  Cannot modify header information - headers already sent by (output started at /home/***/public_html/wp-includes/canonical.php:398) in /home/***/public_html/wp-includes/pluggable.php on line 899
    

    Nothing to be with BuddyPress or WangGuard (I think…)

    Thanks a lot.


    Boone Gorges
    Keymaster

    @boonebgorges

    > Nothing to be with BuddyPress or WangGuard (I think…)

    I’m guessing that this line is part of wp_redirect(), which sounds like it’s happening because of a canonical redirect. I think you’re right that it’s probably not related, but you might still want to check out what’s causing it.

    Let me know how 'bp_include' goes!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Problem using BuddyPress functions from WordPress cron’ is closed to new replies.
Skip to toolbar