• Resolved majidmad

    (@majidmad)


    Hi,

    I’m using ultimate member for years, I created a custom tab in Edit Profile to update a value. In fact my users (students) can edit (add or remove) their pre-registered courses. The problem is that when they try to add or remove course, an error occurs, “An error has encountered”. Surprisingly, they can remove the course even though it shows an error, but they can’t add any course. It was working flawlessly till the latest update of Ultimate member. The code is as follows:

    * */
    /* create new tab */
      add_filter('um_account_page_default_tabs_hook', 'CoursesTab', 100 );
        function CoursesTab( $tabs ) {
        $tabs[800]['CoursesTab']['icon'] = 'um-faicon-pencil'; // tab icon
        $tabs[800]['CoursesTab']['title'] = 'Registered Courses'; // tab title
        $tabs[800]['CoursesTab']['submit_title'] = 'Update'; // button text
        $tabs[800]['CoursesTab']['custom'] = true;
        return $tabs;
      }
    
      /* make our new tab hookable */
      add_action('um_account_tab__CoursesTab', 'um_account_tab__CoursesTab');
        function um_account_tab__CoursesTab( $info ) {
        extract( $info );
        $output = UM()->account->get_tab_output('CoursesTab');
        if ( $output ) { echo $output; }
      }
    
      /* Finally we add some content in the tab */
      add_filter('um_account_content_hook_CoursesTab', 'um_account_content_hook_CoursesTab');
      function um_account_content_hook_CoursesTab( $output ){
        ob_start();
        $id = um_user('ID');
        $output = '<div class="um-field">';
        $names = array('course','course'); 
    
        $fields = array(); 
        foreach( $names as $name ){
          $fields[ $name ] = UM()->builtin()->get_specific_field( $name );
        }
        $fields = apply_filters('um_account_secure_fields', $fields, $id);
        foreach( $fields as $key => $data ){
          $output .= UM()->fields()->edit_field( $key, $data );
        }
    
        $output .= '</div>';
    
        $output .= ob_get_contents();
        ob_end_clean();
        return $output;
      }
    
      /* ensure that the custom fields are updated when the account is updated */
      add_action('um_account_pre_update_profile', 'getUMFormData', 100);
    
      function getUMFormData(){
        $id = um_user('ID');
        $names = array('course','course');  // ADD THE META-KEYS HERE
        foreach( $names as $name )
          update_user_meta( $id, $name, $_POST[$name] );
      }

    I searched a lot, however, found no clue how to solve the issue.
    Thank you

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @majidmad

    I’ve added codes in this function:

    add_filter('um_account_content_hook_CoursesTab', 'um_account_content_hook_CoursesTab');
    function um_account_content_hook_CoursesTab( $output ){
        ob_start();
            $id = um_user('ID');
            $output = '<div class="um-field">';
            $names = array('course','course'); 
    
            $fields = array(); 
            foreach( $names as $name ){
            $fields[ $name ] = UM()->builtin()->get_specific_field( $name );
            }
            $fields = apply_filters('um_account_secure_fields', $fields, $id);
            foreach( $fields as $key => $data ){
            $output .= UM()->fields()->edit_field( $key, $data );
            }
    
            $output .= '<input type="hidden" name="um_account_nonce_'. esc_attr( 'coursestab' ).'" value="'.esc_attr( wp_create_nonce( 'um_update_account_coursestab' ) ).'" />';
                                        
            $output .= '</div>';
    
            $output .= ob_get_contents();
        ob_end_clean();
    
        return $output;
    }

    I’ve added a hidden nonce field:
    $output .= '<input type="hidden" name="um_account_nonce_'. esc_attr( 'coursestab' ).'" value="'.esc_attr( wp_create_nonce( 'um_update_account_coursestab' ) ).'" />';

    Please try it and let me know if you’re still encountering issue.

    Regards,

    Thread Starter majidmad

    (@majidmad)

    Dear @champsupertramp

    I’m very grateful for your prompt reply and great support.
    Yessss. I DID SOLVED my problem. The added code FIXED the issue. Thank you very much for your help.

    Sincerely,
    Majid

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Thanks for letting us know.

    Regards,

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Don’t submit value after update’ is closed to new replies.