• Resolved jasnon

    (@jasnon)


    I’m receiving the following PHP notices repeatedly in my website logs:

    PHP Notice: Undefined index: user_id in /wp-content/plugins/ultimate-member/includes/core/um-actions-form.php on line 433

    PHP Notice: Undefined index: custom_validate in /wp-content/plugins/ultimate-member/includes/core/um-actions-form.php on line 675

    I’m currently using WordPress version 6.1.1 and Ultimate Member plugin version 2.5.4.

Viewing 15 replies - 1 through 15 (of 22 total)
  • missveronica

    (@missveronicatv)

    @jasnon

    Which version of PHP are you using at your site?

    Thread Starter jasnon

    (@jasnon)

    @missveronicatv thanks for the reply.

    I’m currently using PHP version 7.4.33

    missveronica

    (@missveronicatv)

    @jasnon

    Do you have any custom validation code snippet for a field on any of your UM Forms?

    Thread Starter jasnon

    (@jasnon)

    @missveronicatv aha that was the culprit for the Undefined index: custom_validate error. That notice was firing every time the reg form was submitted because I had Custom Validation set on one of my fields but hadn’t defined the Custom Action associated with it.

    I’m still troubleshooting the Undefined index: user_id as that’s still firing but I think the issue may be coming from custom modifications I’ve made within my functions.php. I’m going to continue checking there.

    Thanks again for helping pointing me in the right direction!

    Plugin Support andrewshu

    (@andrewshu)

    Hello @jasnon

    Did you solve this problem? Can I close this topic?

    Thank you.

    Thread Starter jasnon

    (@jasnon)

    Hi @andrewshu I still haven’t been able to resolve the PHP Notice: Undefined index: user_id in /wp-content/plugins/ultimate-member/includes/core/um-actions-form.php on line 433

    When I look at that specific section of code within the plugin files, I can’t determine where on my site the error is originating from. If the first statement is checking for whether a user is logged in why would $args[‘user_id’] result in an undefined index? Any suggestions?

    if ( is_user_logged_in() ) {
    
        $can_edit = UM()->roles()->um_current_user_can( 'edit', $args['user_id'] );
    
        um_fetch_user( get_current_user_id() );
        $current_user_roles = um_user( 'roles' );
        um_reset_user();
    }
    • This reply was modified 2 years ago by jasnon.
    missveronica

    (@missveronicatv)

    @jasnon

    You can insert this code snippet into the um-actions-form.php before line 433

    if ( ! isset( $args['user_id'] )) {
                $e = new \Exception;
                $trace = '<div><pre>' . $e->getTraceAsString() . '</pre><div>';
                file_put_contents( WP_CONTENT_DIR . '/um_trace_log.html', $trace, FILE_APPEND );
            }

    Try to create the PHP Notice again.
    Display the stacktrace with your browser from .../wp-content/um_trace_log.html

    Thread Starter jasnon

    (@jasnon)

    @missveronicatv after triggering the notice again, the following was output to the new file you recommended above:

    #0 /wp-includes/class-wp-hook.php(308): um_submit_form_errors_hook_(Array)
    #1 /wp-includes/class-wp-hook.php(332): WP_Hook->apply_filters('', Array)
    #2 /wp-includes/plugin.php(517): WP_Hook->do_action(Array)
    #3 /wp-content/plugins/ultimate-member/includes/core/um-actions-form.php(293): do_action('um_submit_form_...', Array)
    #4 /wp-includes/class-wp-hook.php(308): um_submit_form_errors_hook(Array)
    #5 /wp-includes/class-wp-hook.php(332): WP_Hook->apply_filters('', Array)
    #6 /wp-includes/plugin.php(517): WP_Hook->do_action(Array)
    #7 /wp-content/plugins/ultimate-member/includes/core/class-form.php(569): do_action('um_submit_form_...', Array)
    #8 /wp-includes/class-wp-hook.php(308): um\core\Form->form_init('')
    #9 /wp-includes/class-wp-hook.php(332): WP_Hook->apply_filters(NULL, Array)
    #10 /wp-includes/plugin.php(517): WP_Hook->do_action(Array)
    #11 /wp-includes/template-loader.php(13): do_action('template_redire...')
    #12 /wp-blog-header.php(19): require_once('/public_html...')
    #13 /index.php(17): require('/public_html...')
    #14 {main}
    Thread Starter jasnon

    (@jasnon)

    In my functions.php I use the following actions for custom login & registration validation:

    add_action(‘um_submit_form_errors_hook_login’, ‘um_custom_login_validation’, 999, 1);

    add_action(‘um_submit_form_errors_hook__registration’, ‘um_custom_registration_validation’, 999, 1);

    Should I be using the more generic action ‘um_submit_form_errors_hook’ for both of these instead?

    Thread Starter jasnon

    (@jasnon)

    Also, one more piece of information in case it’s helpful. When the notice shows up in my error log it always occurs 5 times (example below):

    [07-Mar-2023 00:14:11 UTC] PHP Notice: Undefined index: user_id in /wp-content/plugins/ultimate-member/includes/core/um-actions-form.php on line 433
    [07-Mar-2023 00:14:16 UTC] PHP Notice: Undefined index: user_id in /wp-content/plugins/ultimate-member/includes/core/um-actions-form.php on line 433
    [07-Mar-2023 00:14:18 UTC] PHP Notice: Undefined index: user_id in /wp-content/plugins/ultimate-member/includes/core/um-actions-form.php on line 433
    [07-Mar-2023 00:14:31 UTC] PHP Notice: Undefined index: user_id in /wp-content/plugins/ultimate-member/includes/core/um-actions-form.php on line 433
    [07-Mar-2023 00:14:33 UTC] PHP Notice: Undefined index: user_id in /wp-content/plugins/ultimate-member/includes/core/um-actions-form.php on line 433

    Plugin Support andrewshu

    (@andrewshu)

    Hello @jasnon

    In my functions.php I use the following actions for custom login & registration validation:

    Try to remove custom code from your functions.php for testing and check your site again.

    Regards.

    missveronica

    (@missveronicatv)

    @jasnon

    Thanks for the stack trace.

    Verify in the HTML of the UM User Edit page, that you have a line like this, where 2 is replaced with the current users ID.

    <input type="hidden" name="user_id" id="user_id" value="2" />

    Thread Starter jasnon

    (@jasnon)

    Hi @missveronicatv the ability for users to edit their own profiles has been disabled this entire time from the User Roles -> Subscriber -> General Permissions settings. Currently, the only place for user’s to edit their information is from the Account Settings page.

    The challenge with this issue right now is I haven’t been able to re-create it myself at all, so I can’t pinpoint what’s causing it. I just see it being logged in my error logs when users visit the site at some point. But even then, I haven’t been able to pinpoint the exact page / UM functionality that’s causing them to trigger this.

    From the stack trace were you able to tell which UM form/function specifically is causing this?

    missveronica

    (@missveronicatv)

    @jasnon

    You can replace current code snippet with this new code snippet
    for additional display of form ID, form mode and number of fields in the form.

    if ( ! isset( $args['user_id'] )) {
        $trace  = '<div>form_id: ' . $form_id . '</div>';
        $trace .= '<div>mode: ' . $mode . '</div>';
        $trace .= '<div># fields: ' . count( $fields ) . '</div>';
        $e = new \Exception;
        $trace .= '<div><pre>' . $e->getTraceAsString() . '</pre><div>';
        file_put_contents( WP_CONTENT_DIR . '/um_trace_log.html', $trace, FILE_APPEND );
    }
    Thread Starter jasnon

    (@jasnon)

    @missveronicatv thanks for the additional code snippet, this actually revealed some interesting information. The PHP notice appears to always trigger on my ‘Default Registration’ form ID when the form mode is set to ‘register’ and the number of fields is ‘5’ (which explains why the notice fires 5 times whenever it shows up in my log).

    What’s interesting though is that I also added the page URL to that code snippet so I could confirm which page the issue was occurring on (as I have registration forms on two different pages). Surprisingly what I found was that the notice is triggering on both my UM Register page AND my UM Login page. I don’t understand how that would be possible though as I don’t have my registration form anywhere on my login page.

    Thanks for the continued support on this, I feel like we’re getting closer to the root of the issue.

Viewing 15 replies - 1 through 15 (of 22 total)
  • The topic ‘PHP Notice: Undefined index’ is closed to new replies.