• Resolved bmcalhoun

    (@bmcalhoun)


    I’m trying to customize the update message for a custom account tab. It looks like there is a filter to hook into according to the ultimate member docs.

    However, I tried using that code and I can’t get anything but the default text to appear: “Your account was updated successfully.”

    Here is my code:

    add_filter( 'um_custom_success_message_handler', 'my_custom_success_message', 10, 2 );
    function my_custom_success_message( $success, $updated ) {
    	echo 'ARRRRGGGGGG!!!!';
    	return $success;
    }
    • This topic was modified 5 years, 11 months ago by bmcalhoun.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter bmcalhoun

    (@bmcalhoun)

    After a lot more research I realized that I needed one more step.

    I needed to tell it add a different query string when that custom tab is updated, and then use that query string to then run the custom success message.

    For any others, here is my working code. Obviously it will need to be adjusted for your use:

    add_action( 'um_after_user_account_updated', 'moran_user_account_update', 99, 2 );
    function moran_user_account_update( $user_id, $changes ) {
    	
    	if ( get_query_var('um_tab') == 'invoice' ) {
    		exit( wp_redirect( add_query_arg('updated','invoice') ) );
    	}
    	
    }
    
    add_filter( 'um_custom_success_message_handler', 'moran_custom_success_message', 10, 2 );
    function moran_custom_success_message( $success, $updated ) {
    	if ( $updated == 'invoice' ) {
    		$success = __('Thank you for submiting your invoice.','moran');
    	}
    	return $success;
    }
    • This reply was modified 5 years, 11 months ago by bmcalhoun.

    Hi,

    How can you make a custom tab to save their fields ?
    I tried the given sample by UM source code without success :
    https://docs.ultimatemember.com/article/65-extend-ultimate-member-account-page-with-custom-tabs-content

    
    global $ultimatemember;
        $id = um_user('ID');
         $names = [ 'pilot_total_hours','pilot_hours_cdb','pilot_hours_cdb_last_year','pilot_hours_cdb_3months','pilot_hours_since_ppl'];
        
        $fields = [];
        foreach($names as $name)
           	$fields[$name] = UM()->builtin()->get_specific_field($name);
        
        $fields = apply_filters('um_account_secure_fields', $fields, get_current_user_id());
    
        foreach( $fields as $key => $data )
           	$output2 .= UM()->fields()->edit_field( $key, $data );
    
        echo str_ireplace("\\", "", $output2);
    

    I think you’re looking for the filter um_after_user_account_updated which you can find here.

    Below is my example which is working for me. I only started using it yesterday so can’t tell if this is the best way.

    First add a new tab:

    /**
     * Add account tabs
     *
     * @param $tabs
     *
     * @return mixed
     */
    function beee_custom_account_tabs( $tabs ) {
    
        $tabs[ 250 ][ 'settings' ][ 'icon' ]         = 'um-faicon-wrench';
        $tabs[ 250 ][ 'settings' ][ 'title' ]        = __( 'Settings', 'beee' );
        $tabs[ 250 ][ 'settings' ][ 'custom' ]       = true;
        $tabs[ 250 ][ 'settings' ][ 'show_button' ]  = true;
        $tabs[ 250 ][ 'settings' ][ 'submit_title' ] = __( 'SAVE', 'beee' );
        
        return $tabs;
    }
    add_filter( 'um_account_page_default_tabs_hook', 'beee_custom_account_tabs', 100 );

    Then call the tab content:

    /**
     * Call output tab settings
     *
     * @param $info
     */
    function beee_account_tab_settings( $info ) {
        global $ultimatemember;
        extract( $info ); // this one is probably redundant
        
        $output = $ultimatemember->account->get_tab_output( 'settings' );
        if ( $output ) {
            echo $output;
        }
    }
    add_action( 'um_account_tab__settings', 'beee_account_tab_settings' );

    Output the tab content:

    /**
     * Output tab settings
     *
     * @param $output
     *
     * @return string
     */
    function beee_account_content_hook_settings( $output ) {
        ob_start();
        ?>
    
        <div class="um-field">
    
            <p>
                <?php _e( 'Here you can find some general settings.', 'beee' ); ?>
            </p>
    
            <p>
                <label for="um_account_instagram">Your Instagram name</label>
                <input type="text" name="um_account_instagram" id="um_account_instagram" class="" value="" placeholder="@yourname"/>
            </p>
    
            <p>
                <label for="um_account_twitter">Your Twitter name</label>
                <input type="text" name="um_account_twitter" id="um_account_twitter" class="" value="" placeholder="@yourname"/>
            </p>
    
            <p>
                <label for="um_account_lanuage">Default language</label>
                <br/>
                <select id="um_account_lanuage" name="um_account_lanuage">
                    <option value="en"><?php _e( 'English', 'beee' ); ?>
                    <option value="nl"><?php _e( 'Dutch', 'beee' ); ?>
                    <option value="de"><?php _e( 'German', 'beee' ); ?>
                </select>
            </p>
    
        </div>
        
        <?php
        $output .= ob_get_contents();
        ob_end_clean();
        
        return $output;
    }
    add_filter( 'um_account_content_hook_settings', 'beee_account_content_hook_settings' );

    Then after the account is saved, you can access the $_POST data and do whatever you need to do with the data.

    /**
     * Do stuff after "Update Account"
     *
     * @param $user_id
     * @param $changes
     */
    function beee_after_user_account_updated( $user_id, $changes ) {
        if ( ! empty( $_POST[ 'um_account_instagram' ] ) ) {
            update_user_meta( $user_id, 'um_account_instagram', $_POST[ 'um_account_instagram' ] );
        }
    }
    add_action( 'um_after_user_account_updated', 'beee_after_user_account_updated', 10, 2 );

    Hope this helps…

    • This reply was modified 5 years, 10 months ago by Beee. Reason: fix link
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Ultimate Member Custom Tab Update Message’ is closed to new replies.