• Resolved simonavshalom

    (@simonavshalom)


    Hello,

    I’m experiencing an issue with the pmpro_cron_expire_memberships function in Paid Memberships Pro.

    Here’s the issue:

    • When the cron runs automatically, it sends the expiration emails but does not reset the membership level to 0 (i.e., it doesn’t expire the membership).
    • However, when I run the pmpro_cron_expire_memberships manually using the WP Control plugin, it works correctly and resets the expired memberships as expected.

    Important setup details:

    • I am using a server cron and have disabled WP Cron by adding define('DISABLE_WP_CRON', true); in the wp-config.php file.
    • The server cron is set up to trigger wp-cron.php regularly, and other cron tasks seem to run fine.
    • The cron was working perfectly about a week ago, but now it has stopped resetting membership levels. I have not made any changes to the site, so there is no new custom code or updates that could have impacted this functionality.

    I’ve checked the logs and don’t see any obvious errors. I would appreciate any insights into why the automatic cron is sending emails but not resetting the membership levels, while manual execution works perfectly.

    Thanks for your help!

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Support Jarryd Long

    (@jarryd-long)

    Hi there, thank you for reaching out to the Paid Memberships Pro team and for the detailed feedback about your issue.

    We have a code recipe available here (https://gist.github.com/dparker1005/1e9b988ebc4dbb18b51067323dbe8111) that can be used to log a member’s information before expiring them. You can add this to your theme’s functions.php or any other folder with custom code in it.

    Please try adding this to your site as well as setting WP_DEBUG and WP_DEBUG_LOG to true. Once done, give the cron some time to run through any expired members over the next day or two, and then check the logs. Please let me know if anything shows up in there?

    Kind Regards,
    Jarryd
    Support Manager at Paid Memberships Pro

    Thread Starter simonavshalom

    (@simonavshalom)

    Hi Jarryd

    Thank you for your guidance on the issue.

    This is what i get in the logs:

    0 /home/12815.cloudwaysapps.com/nwdf*msy/public_html/wp-includes/plugin.php(205): WP_Hook->apply_filters() 1 /home/12815.cloudwaysapps.com/nwdf*msy/public_html/wp-content/plugins/paid-memberships-pro/scheduled/crons.php(76): apply_filters() 2 /home/12815.cloudwaysapps.com/nwdf*msy/public_html/wp-includes/class-wp-hook.php(324): pmpro_cron_expiration_warnings() 3 /home/12815.cloudwaysapps.com/nwdf*msy/public_html/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters() 4 /home/12815.cloudwaysapps.com/nwdf*msy/public_html/wp-includes/plugin.php(565): WP_Hook->do_action() 5 /home/12815.cloudwaysapps.com/nwdf*msy/public_html/wp-cron.php(191): do_action_ref_array() 6 {main}

    thrown in /home/12815.cloudwaysapps.com/nwdfmsy/public_html/wp-includes/class-wp-hook.php on line 324 [26-Sep-2024 10:05:23 UTC] PHP Warning: Undefined array key "SERVER_NAME" in /home/12815.cloudwaysapps.com/nwdfmsy/public_html/wp-content/plugins/paid-memberships-pro/includes/email.php on line 31
    [26-Sep-2024 10:05:24 UTC] Account has expired, email sent to [email protected]
    [26-Sep-2024 10:05:24 UTC] PHP Fatal error: Uncaught TypeError: call_user_func_array(): Argument #1 ($callback) must be a valid callback, function "my_pmpro_email_expiration_date_change;" not found or invalid function name in /home/12815.cloudwaysapps.com/nwdf*msy/public_html/wp-includes/class-wp-hook.php:324



    While following the logging instructions, I noticed a recurring fatal error in the logs related to a custom filter I added to change the email expiration timing. Here’s the relevant log entry:

    PHP Fatal error: Uncaught TypeError: call_user_func_array(): Argument #1 ($callback) must be a valid callback, function "my_pmpro_email_expiration_date_change;" not found or invalid function name in /home/12815.cloudwaysapps.com/nwdfmsy/public_html/wp-includes/class-wp-hook.php:324

    The error seems to be caused by this custom code I had implemented:

    function my_pmpro_email_expiration_date_change( $days ) {
    return 3;
    }
    add_filter( 'pmpro_email_days_before_expiration', 'my_pmpro_email_expiration_date_change;' );

    It looks like the issue is due to the semicolon after the function name in the add_filter line, which I will correct. I’ll continue to monitor after making this fix.

    Thank you for your help, and I’ll keep you updated if this resolves the issue.

    Plugin Support Jarryd Long

    (@jarryd-long)

    Thank you for your feedback and fixing the error in your code. Please keep an eye on it and let me know if the issue persists.

    Kind Regards,
    Jarryd
    Support Manager at Paid Memberships Pro

    Thread Starter simonavshalom

    (@simonavshalom)

    Hi @jarryd-long ,

    This did not help. When the membership expires, the email is sent, but the membership level is not reset. this is the log:



    Logged On: 09/27/2024 07:05:02
    Today: 2024-09-27
    User ID: 351
    Expired Level: 22
    Original Enddate: 2024-09-23 09:08:00

    Logged On: 09/27/2024 07:05:03
    Today: 2024-09-27
    User ID: 351
    Expired Level: 22
    Original Enddate: 2024-09-23 09:08:00

    Logged On: 09/27/2024 08:05:02
    Today: 2024-09-27
    User ID: 351
    Expired Level: 22
    Original Enddate: 2024-09-23 09:08:00

    Logged On: 09/27/2024 08:05:03
    Today: 2024-09-27
    User ID: 351
    Expired Level: 22
    Original Enddate: 2024-09-23 09:08:00

    Logged On: 09/27/2024 08:10:02
    Today: 2024-09-27
    User ID: 351
    Expired Level: 22
    Original Enddate: 2024-09-23 09:08:00

    and this is debug log:

    [27-Sep-2024 05:05:03 UTC] PHP Warning: Undefined array key "SERVER_NAME" in /home/1305815.cloudwaysapps.com/nwnqmzy/public_html/wp-content/plugins/paid-memberships-pro/includes/email.php on line 31 [27-Sep-2024 05:05:03 UTC] Account has expired, email sent to [email protected] [27-Sep-2024 05:05:04 UTC] Account has expired, email sent to [email protected] [27-Sep-2024 05:10:02 UTC] Account has expired, email sent to [email protected] [27-Sep-2024 05:48:50 UTC] str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated [27-Sep-2024 05:48:50 UTC] PHP Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/1305815.cloudwaysapps.com/nwnqmzy/public_html/wp-content/plugins/gravityformsadvancedpostcreation/class-gf-advancedpostcreation.php on line 2135
    [27-Sep-2024 06:05:03 UTC] Account has expired, email sent to [email protected]
    [27-Sep-2024 06:05:22 UTC] PHP Warning: Undefined array key "SERVER_NAME" in /home/1305815.cloudwaysapps.com/nwn***qmzy/public_html/wp-content/plugins/paid-memberships-pro/includes/email.php on line 31

    Thread Starter simonavshalom

    (@simonavshalom)

    Hi,

    I just want to update that I found the issue. It was with the code for canceling on the next payment that I got from here: https://github.com/strangerstudios/pmpro-cancel-on-next-payment-date/blob/dev/pmpro-cancel-on-next-payment-date.php.

    The line causing the issue was:

    if ( 'error' === $old_level_status ) {
    return $level;
    }

    I changed it to this, and it fixed the issue:

    if ( 'error' === $old_level_status || 'expired' === $old_level_status ) {
    return $level;
    }

    Plugin Support Jarryd Long

    (@jarryd-long)

    Thank you for your feedback and sharing your solution with us here. I’m so glad to hear it’s working as expected for you.

    Feel free to reach out if there’s anything else we can assist you with.

    Kind Regards,
    Jarryd
    Support Manager at Paid Memberships Pro

Viewing 6 replies - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.