Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Shows how to set up a Participants Database WP Profile template that uses a tabbed interface.
<?php
/**
* shows a WP user profile edit form with Participants Database fields in a tabbed interface
*
*/
global $PDb_WP_Users, $PDb_Frontend_Profile, $post, $wp;
/** @var \pdbwpu\Plugin $PDb_WP_Users */
/** @var \pdbwpu\Frontend_Profile $PDb_Frontend_Profile */
$profileuser = $PDb_Frontend_Profile->this_user();
// you can change the title of the WP Profile core group here
$core_group_title = 'WordPress Profile';
// this code sets up the main object and adds the WP Core group to it
$this_record = new PDb_Template( $this );
$core_group = array('wp-core' => (object) array('name' => 'wp-core', 'title' => $core_group_title));
$this_record->groups = $core_group + $this_record->groups;
/**
* @filter pdbwpu-display_frontend_profile
* @param int post id of the page where the form appears
* @param \WP_User user the profile belongs to
*/
do_action( 'pdbwpu-display_frontend_profile', $post->id, $profileuser );
/**
* prints the tab interface
*
* $param PDb_Template $this_record
*/
function pdb_profile_field_group_tabs( $this_record )
{
global $PDb_Field_Group_Tabs;
echo $PDb_Field_Group_Tabs->get_tab_control( $this_record );
}
?>
<div class="wrap <?php echo $this->wrap_class ?>">
<?php if ( $PDb_Frontend_Profile->show_profile_form() ) : ?>
<?php
if ( !empty( $this->participant_id ) ) :
// output any validation errors
$this->print_errors();
// show any profile update feedback messages
echo $PDb_Frontend_Profile->profile_errors();
?>
<h2><?php _e( 'Profile' ) ?></h2>
<?php
// print the form header
$this->print_form_head();
pdb_profile_field_group_tabs( $this_record );
?>
<fieldset class="field-group field-group-wp-core group-with-title">
<legend><?php echo $core_group_title ?></legend>
<label><?php _e( 'Avatar' ) ?></label>
<?php echo $PDb_Frontend_Profile->get_avatar( 64 ); // 64 is the size of the image to get ?>
<!-- WP Profile Core Name Group -->
<div class="form-group wp-user_login">
<label for="user_login"><?php _e( 'Username' ); ?></label>
<div class="input-group" >
<input type="text" name="user_login" id="user_login" value="<?php echo esc_attr( $profileuser->user_login ); ?>" disabled="disabled" class="regular-text" />
</div>
<p class="help-block helptext"><?php _e( 'Usernames cannot be changed.' ); ?></p>
</div>
<div class="form-group wp-first_name">
<label for="first_name"><?php _e( 'First Name' ); ?></label>
<div class="input-group" >
<input type="text" name="first_name" id="first_name" value="<?php echo esc_attr( $profileuser->first_name ); ?>" class="regular-text" />
</div>
</div>
<div class="form-group wp-last_name">
<label for="last_name"><?php _e( 'Last Name' ); ?></label>
<div class="input-group" >
<input type="text" name="last_name" id="last_name" value="<?php echo esc_attr( $profileuser->last_name ); ?>" class="regular-text" />
</div>
</div>
<div class="form-group wp-nickname">
<label for="nickname"><?php printf( \Participants_Db::plugin_setting_value( 'required_field_marker' ), _e( 'Nickname' ) ); ?></label>
<div class="input-group" >
<input type="text" name="nickname" id="nickname" value="<?php echo esc_attr( $profileuser->nickname ); ?>" class="regular-text" />
</div>
</div>
<div class="form-group wp-display_name">
<label for="display_name"><?php _e( 'Display name publicly as' ); ?></label>
<div class="input-group" >
<select name="display_name" id="display_name">
<?php echo $PDb_Frontend_Profile->display_name_options() ?>
</select>
</div>
</div>
<!-- WP Profile Core Contact Group -->
<legend><?php _e( 'Contact Info' ) ?></legend>
<div class="form-group wp-email">
<label for="email"><?php printf( \Participants_Db::plugin_setting_value( 'required_field_marker' ), _e( 'Email' ) ); ?></label>
<div class="input-group" >
<input type="text" name="email" id="email" value="<?php echo esc_attr( $profileuser->user_email ); ?>" class="regular-text" />
</div>
<p class="help-block helptext"><?php _e( 'If you change this we will send you an email at your new address to confirm it. <strong>The new address will not become active until confirmed.</strong>' ); ?></p>
<?php
$new_email = get_user_meta( $profileuser->ID, '_new_email', true );
if ( isset( $new_email['newemail'] ) && $new_email['newemail'] !== $profileuser->user_email ) : // show pending email notice
?>
<div class="updated inline published">
<p>
<?php
printf(
/* translators: %s: new email */
__( 'There is a pending change of your email to %s.' ),
'<code>' . esc_html( $new_email['newemail'] ) . '</code>'
);
printf(
' <a href="%1$s">%2$s</a>',
esc_url( wp_nonce_url( home_url( add_query_arg( array('dismiss' => $profileuser->ID . '_new_email'), $wp->request ) ), 'dismiss-' . $profileuser->ID . '_new_email' ) ),
__( 'Cancel' )
);
?>
</p>
</div>
<?php endif; // pending email notice ?>
</div>
<div class="form-group wp-url">
<label for="url"><?php _e( 'Website' ); ?></label>
<div class="input-group" >
<input type="text" name="url" id="url" value="<?php echo esc_attr( $profileuser->user_url ); ?>" class="regular-text" />
</div>
</div>
<?php
foreach ( wp_get_user_contact_methods( $profileuser ) as $name => $desc ) {
?>
<div class="form-group wp-contact user-<?php echo $name; ?>-">
<label for="<?php echo $name; ?>">
<?php
/**
* Filters a user contactmethod label.
*
* @filter user_{$name}_label
* @param string $desc The translatable label for the contactmethod.
*/
echo apply_filters( "user_{$name}_label", $desc );
?>
</label>
<div class="input-group">
<input type="text" name="<?php echo $name; ?>" id="<?php echo $name; ?>" value="<?php echo esc_attr( $profileuser->$name ); ?>" class="regular-text" /></td>
</div>
</div>
<?php
}
?>
</fieldset>
<!-- Participants Database Groups -->
<?php while ( $this->have_groups() ) : $this->the_group(); ?>
<fieldset class="field-group field-group-<?php echo $this->group->name ?> <?php echo $this->group->printing_title() ? 'group-with-title' : 'group-no-title' ?>">
<?php $this->group->print_title( '<legend>', '</legend>' ) ?>
<?php $this->group->print_description() ?>
<?php
// step through the fields in the current group
while ( $this->have_fields() ) : $this->the_field();
?>
<div class="form-group <?php $this->field->print_element_class() ?>">
<?php if ( $this->field->has_title() ) : ?>
<label>
<?php $this->field->print_label() ?>
</label>
<?php endif ?>
<div class="input-group" >
<?php $this->field->print_element_with_id(); ?>
</div><!-- .input-group -->
<?php if ( $this->field->has_help_text() ) : ?>
<p class="help-block helptext"><?php $this->field->print_help_text() ?></p>
<?php endif ?>
</div><!-- .form-group -->
<?php endwhile; // field loop ?>
</fieldset><!-- .field-group-<?php echo $this->group->name ?> -->
<?php endwhile; // group loop ?>
<fieldset class="field-group field-group-submit">
<legend><?php $this->print_save_changes_label() ?></legend>
<div class="form-group">
<input type="hidden" name="user_id" id="user_id" value="<?php echo esc_attr( $profileuser->ID ); ?>" />
<?php $PDb_Frontend_Profile->nonce_field() ?>
<?php pdb_field_group_tabs_submit_button( $this ) ?>
</div>
</fieldset>
<?php $this->print_form_close() ?>
<?php else : ?>
<?php
$error_message = Participants_Db::plugin_setting( 'no_record_error_message', '' );
if ( !empty( $error_message ) ) :
?>
<p class="alert alert-error"><?php echo $error_message ?></p>
<?php endif ?>
<?php endif ?>
<?php else: ?>
<?php echo $PDb_Frontend_Profile->no_profile_message() ?>
<?php endif; // show profile ?>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment