Viewing 6 replies - 1 through 6 (of 6 total)
  • Dominor Novus

    (@dominor-novus)

    I’m currently looking into this.

    The edit profile page is my initial basis:
    https://github.com/tombenner/front-end-users/blob/master/views/settings.php

    Dominor Novus

    (@dominor-novus)

    It’s pretty straight forward.

    1) Create a page named “test_feu2.php” in your theme directory.

    2) Paste this code inside of it:

    <?php
    /**
    * Template Name: Test FEU
    *
    * Using FEU within Theme.
    *
    */
    ?>

    …and then this just beneath it:

    <?php
    
    global $feu;
    
    $user = wp_get_current_user();
    $update_status = null;
    $user_avatar_enabled = $feu->is_user_avatar_enabled();
    
    if (!empty($_POST)) {
    	$update_status = $feu->update_user_settings($user, $_POST);
    }
    
    if ($user_avatar_enabled) {
    	$feu->enqueue_user_avatar_resources();
    }
    
    feu_header();
    
    ?>
    
    <?php feu_box_(); ?>
    
    	<h1>Settings</h1>
    
    	<?php feu_form_message($update_status); ?>
    
    	<div class="feu-form">
    
    		<?php
    			if ($user_avatar_enabled) {
    				user_avatar_form($user);
    			}
    		?>
    
    		<form action="<?php echo feu_get_url('settings'); ?>" method="post">
    
    			<fieldset>
    
    				<legend>Name</legend>
    
    				<div>
    
    					<label>Username</label>
    
    					<div>
    						<?php echo $user->user_login; ?>
    					</div>
    
    				</div>
    
    				<div>
    
    					<label for="first_name">First Name</label>
    
    					<div>
    						<input type="text" name="first_name" value="<?php echo esc_attr($user->first_name); ?>" />
    					</div>
    
    				</div>
    
    				<div>
    
    					<label for="last_name">Last Name</label>
    
    					<div>
    						<input type="text" name="last_name" value="<?php echo esc_attr($user->last_name); ?>" />
    					</div>
    
    				</div>
    
    				<div>
    
    					<label for="nickname">Nickname <span>(required)</span></label>
    
    					<div>
    						<input type="text" name="nickname" value="<?php echo esc_attr($user->nickname); ?>" />
    					</div>
    
    				</div>
    
    				<div>
    
    					<label for="display_name">Display Name</label>
    
    					<div>
    						<select name="display_name">
    							<?php echo feu_get_display_names_options_html($user); ?>
    						</select>
    					</div>
    
    				</div>
    
    			</fieldset>
    
    			<fieldset>
    
    				<legend>Contact Info</legend>
    
    				<div>
    
    					<label for="email">Email</label>
    
    					<div>
    						<input type="text" name="email" value="<?php echo esc_attr($user->user_email); ?>" />
    					</div>
    
    				</div>
    
    			</fieldset>
    
    			<fieldset>
    
    				<legend>Password</legend>
    
    				<div>
    
    					<label for="pass1">New Password</label>
    
    					<div>
    						<input type="password" name="pass1" value="" autocomplete="off" /> <span class="description">If you would like to change the password type a new one. Otherwise leave this blank.</span><br />
    						<input type="password" name="pass2" value="" autocomplete="off" /> <span class="description">Type your new password again.</span>
    					</div>
    
    				</div>
    
    			</fieldset>
    
    			<?php if ($feu->get_display_custom_profile_settings()): ?>
    
    				<?php do_action( 'show_user_profile', $user ); ?>
    
    			<?php endif; ?>
    
    			<div class="submit">
    
    				<input type="hidden" name="user_id" value="<?php echo esc_attr($user->ID); ?>" />
    				<input type="submit" name="submit" value="Update" />
    
    			</div>
    
    		</form>
    
    	</div>
    
    <?php _feu_box(); ?>
    
    <?php feu_footer(); ?>

    Note that this code comes from front-end-users/views/settings.php in your plugin directory. You can view it here: https://github.com/tombenner/front-end-users/blob/master/views/settings.php

    3) Create a page from the admin area, name it “Test FEU”, slug it “test-feu” and set the template as “Test FEU”.

    4) Go to https://www.yourwebsitename.com/test-feu. You should have a working version of the form but you may need to reapply some CSS.

    Thanks to the author for great plugin. It works well with the author slug plugin I’m using.

    Plugin Author tombenner

    (@tombenner)

    I’ve added a function to simplify this a bit in the recent update to version 1.2. In the “Test FEU” template above, instead of copying the big block of PHP code that begins with “global $feu”, you can just put this:

    feu_display_settings_page();

    Btw, many thanks for helping with these questions, Dominor; I’ve been swamped as usual.

    The feu_display_settings_page() function is unaffected by the set_custom_feu_views_directory filter.

    feu_display_settings_page(): I had to edit front-end-users/lib/front_end_users.php and manually define the path to my custom views directory.

    Example of code

    set_custom_feu_views_directory: In case it’s related, it might be worth knowing that I also had to manually define the path for the filter.

    Example of code

    An extra field in the plugin’s setting page to specify the custom view URL would be handy.

    In a separate issue, I’ve also had to edit lib/front_end_users.php directly to pass a variable back to my settings.php using the URL

    Example of code

    Plugin Author tombenner

    (@tombenner)

    The feu_display_settings_page()/set_custom_feu_views_directory() issue is now resolved in 1.2.1. I’m not sure why get_theme_root().'/'.get_template() wasn’t working in set_custom_feu_views_directory() in your case, but I’ve replaced it with get_template_directory() in case that helps.

    I’ve also added a feu_settings_update_url_params filter that will let you set additional URL params after a settings update (there’s an example in example_hooks.php).

    The feu_settings_update_url_params hook is greatly appreciated and works like a charm.

    The path returned by the feu_display_settings_page() function is now working as of 1.2.1.

    Regarding get_template_directory() of set_custom_feu_views_directory(), the issue was on my end. I’m using a child theme (of the Thematic framework) therefore the absolute path needs to be called as get_stylesheet_directory().

    See here:

    Retrieve current theme directory. In the event a child theme is being used, the parent theme directory will be returned, not the child theme directory (use get_stylesheet_directory() instead).

    Source: https://codex.www.ads-software.com/Function_Reference/get_template_directory

    I no longer have to apply hacks to the core plugin files. Cheers.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘[Plugin: Front-End Users] Using FEU within Theme’ is closed to new replies.