Category Archives: Wordpress

Create a Custom Forgot Password Page In WordPress

reset-password-personal

Here we will explain to you how to create a custom forgot password/reset password page in WordPress. this tutorial will help for making the custom front end page where your subscriber and author and many roles users will change there password to system.

Step 1)

Make One template page in WordPress active theme folder and put the below code there.

<?php
/*  Template Name: Forgot Password Template */
get_header();
global $wpdb;
if( (isset($_REQUEST['update_confirm'])) AND ($_REQUEST['update_confirm']='update_confirm') ){

	$newpass=md5($_POST['newpass']);
	$usernameemail=$_POST['useremail'];
	$kkey =$_POST['key'];

	$wpdb->query($wpdb->prepare("UPDATE $wpdb->users SET user_pass='".$newpass."',user_activation_key='' WHERE (user_login='".$usernameemail."' OR user_email='".$usernameemail."') AND user_activation_key='".$kkey."' "));

	echo "<span class='msgg-ok'>Your password has been reset.<br> <a href='/user-login/'>Log in</a></span>";

}

if( (isset($_REQUEST['update'])) AND ($_REQUEST['update']=='update')){
	
	$username_email=$_POST['uemail'];
	
	$Qry = $wpdb->get_results("SELECT user_login,user_email FROM $wpdb->users WHERE user_login='".$username_email."' OR user_email='".$username_email."'");
	if($Qry[0]->user_login != '' && $Qry[0]->user_email != ''){
		$email = $Qry[0]->user_email;
		$user = $Qry[0]->user_login;
		$homeurll=home_url('/');

		$autogenerate_key =crypt($username_email);

		$wpdb->query($wpdb->prepare("UPDATE $wpdb->users SET user_pass='".$newpass."',user_activation_key='".$autogenerate_key."' WHERE (user_login='".$username_email."' OR user_email='".$username_email."') "));


		$mailmsg="Someone requested that the password be reset for the following account:\n$homeurll.\n\nUsername: $user\n\nIf this was a mistake, just ignore this email and nothing will happen.\n\nTo reset your password, visit the following address:\n$homeurll/forgot-password/?action=rp&key=$autogenerate_key&login=$user";


		mail($email,'[The Pacifico Partnership] Password Reset',$mailmsg);

		echo "<span class='msgg-ok'>Check your e-mail for the confirmation link.</span>";

	}else{
		echo "<span class='msg-errr'>Username or Email is not found.</span>";
		$notfound="errror";
	}
}

?>

<?php if($_GET['action']=='rp'){ ?>

<style>
#forget_display{display:none;}
</style>
<?php } 

if((!$_POST) OR ($notfound!='')){

?>

<div id='forget_display'>
<form action='' method='post' onsubmit='return blank_field();'>
<div >  <label>Please enter your username or email address.You will receive a link to create a new password via email.</label><br /><br />
<div> <input name='uemail' type='text' id='uemail' onfocus="if(this.value=='Enter Username/E-mail') this.value=";" onblur="if (this.value=='')
this.value='Enter Username/E-mail';" placeholder='Enter Username/E-mail'/></div> <input type='submit' value='Get New Password'/> </div>
<input type='hidden' name='update' value='update' />

</form>
</div>
<?php }?>

<?php if( (isset($_REQUEST['action'])) AND ($_REQUEST['action']=='rp')) {?>
<div>
<form action="<?php echo home_url('/') ?>?page_id=9" method="post" onsubmit="return blank_pfield();">
<div>
<label>Enter new password:</label><div>  <input name="newpass" type="password"  id="newpass"/> </div></div><br />
<div><label>Repeat password:</label><div>  <input name="repeat-pass" type="password"  id="repeat-pass"/> </div></div><br />
<div><label>&nbsp;</label> <input type="submit" value="Change password" /></div>
<input type="hidden" name="update_confirm"  value="update_confirm"/>
<input type="hidden" value="<?php echo $_REQUEST['login'];?>" name="useremail" />
<input type="hidden" name="key" value="<?php echo $_REQUEST['key'];?>" />
</form>
</div>
<?php }?>

<script>

function blank_field()

{

if(document.getElementById('uemail').value=='Enter Username/E-mail')
{
alert("Please enter username or email");
return false;
}
else
{
return true;
}
}

function blank_pfield()

{

if(document.getElementById('newpass').value=='')
{
alert("Please enter new password");
return false;
}

if(document.getElementById('repeat-pass').value=='')
{
alert("Please enter repeat password");
return false;
}

if(document.getElementById('newpass').value!=document.getElementById('repeat-pass').value)
{
alert("Password do not match");
return false;
}

return true;

}
</script>
<?php get_footer(); ?>
<style>
	.choko_register_box{margin: 0 auto;width: 50%;}
	.choko_register_row_ctn{margin-bottom: 15px;}
	.choko_register_row_ctn label{display: block;margin-bottom: 10px;}
	.choko_register_row_ctn input{width: 97%;border-radius: 0}
	.choko_register_row_ctn select{width: 100%;border-radius: 0}
	.choko_register_error_msg{color: red;margin-bottom: 15px;}
</style>

Step 2)

Now make forgot password page in wp-admin/add new page. and select the “Forgot Password Template” as a template page. update your page.

Step 3)

Now visit your page in front end it will display the custom forgot password form where if user exist then sent a email link for reset new password.

Create Custom Register Page In WordPress

how-to-create-wordpress-user-registration-form

Here we will explain to you how to create a custom register page in WordPress. this tutorial will help for making the custom front end page where your subscriber and author and many roles users will register them self.

Step 1)

Make One template page in WordPress active theme folder and put the below code there.

<?php
/*  Template Name: Register Template */
get_header();

function randomPassword() {
    $alphabet = "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789";
    $pass = array(); //remember to declare $pass as an array
    $alphaLength = strlen($alphabet) - 1; //put the length -1 in cache
    for ($i = 0; $i < 8; $i++) {
        $n = rand(0, $alphaLength);
        $pass[] = $alphabet[$n];
    }
    return implode($pass); //turn the array into a string
}

$error= '';
$success = '';
global $wpdb, $PasswordHash, $current_user, $user_ID;
if(isset($_POST['task']) && $_POST['task'] == 'register' ) {

	$password1 = randomPassword();
	$first_name = $wpdb->escape(trim($_POST['first_name']));
	$last_name = $wpdb->escape(trim($_POST['last_name']));
	$email = $wpdb->escape(trim($_POST['email']));
	$username = $wpdb->escape(trim($_POST['username']));
	
	if( $email == "" || $username == "" || $first_name == "" || $last_name == "") {
		$error= 'Please don\'t leave the required fields.';
	} else if(!filter_var($email, FILTER_VALIDATE_EMAIL)) {
		$error= 'Invalid email address.';
	} else if(email_exists($email) ) {
		$error= 'Email already exist.';
	} else {
		$user_id = wp_insert_user( array ('first_name' => apply_filters('pre_user_first_name', $first_name), 'last_name' => apply_filters('pre_user_last_name', $last_name), 'user_pass' => apply_filters('pre_user_user_pass', $password1), 'user_login' => apply_filters('pre_user_user_login', $username), 'user_email' => apply_filters('pre_user_user_email', $email), 'role' => 'subscriber' ) );

		if( is_wp_error($user_id) ) {
			$error= 'Error on user creation.';
		} else {
			do_action('user_register', $user_id);
			$success = 'You\'re successfully register';

		}
	}
}
?>
<div class="wrapper">
 	<div class="choko_register_box">
		<form method="post" class="choko_register_form">
			<div class="choko_register_row_ctn">
				<label for="first_name">First Name<span>*</span>:</label>
				<input type="text" value="<?php if(isset($first_name)){echo $first_name;} ?>" name="first_name" id="first_name" />
			</div>
			<div class="choko_register_row_ctn">
				<label for="last_name">Last Name<span>*</span>:</label>
				<input type="text" value="<?php if(isset($last_name)){echo $last_name;} ?>" name="last_name" id="last_name" />
			</div>
			<div class="choko_register_row_ctn">
				<label for="username">Username<span>*</span>:</label>
				<input type="text" value="<?php if(isset($username)){echo $username;} ?>" name="username" id="username" />
			</div>	
			<div class="choko_register_row_ctn">
				<label for="email">Email<span>*</span>:</label>
				<input type="text" value="<?php if(isset($email)){echo $email;} ?>" name="email" id="email" />
			</div>
			<div class="choko_register_msg_ctn">
				<?php if($sucess != "") { echo "<div class='choko_register_success_msg'>".$sucess."</div>"; } ?> 
				<?php if($error!= "") { echo "<div class='choko_register_error_msg'>".$error."</div>"; } ?>
			</div>		
			<button type="submit" name="btnregister" class="button" >Register</button>
			<input type="hidden" name="task" value="register" />
		</form>
 	</div>
</div>
<?php get_footer() ?>
<style>
	.choko_register_box{margin: 0 auto;width: 50%;}
	.choko_register_row_ctn{margin-bottom: 15px;}
	.choko_register_row_ctn label{display: block;margin-bottom: 10px;}
	.choko_register_row_ctn input{width: 97%;border-radius: 0}
	.choko_register_error_msg{color: red;margin-bottom: 15px;}
</style>

Step 2)

Now make register page in wp-admin/add new page. and select the “Register Template” as a template page. update your page.

Step 3)

Now visit your page in front end it will display the custom register form.

How to Create a WordPress Child Theme?

wpchildtheme

You want to make a child theme in your WordPress platform and don’t know how to make the child theme in the WordPress then follow the tutorial step and you can get your WordPress child theme in few minutes. It’s a simple tutorial that can give you a better solution.

Step 1)

Make one folder in your theme folder as we make “techinternet”.

wordpresschildtheme1.png

Step 2)

Copy files as display in the below image.

wordpresschildtheme2.png

Step 3)

Open the style.css file and remove all code from that file and put the below code according to change instruction and save it.

/*
Theme Name: Hashencrypted Child (change name as you like)
Theme URL: https://www.garudatechhub.com/ (change URL as your display)
Description: Techinternet WordPress Blog Theme (Set your description)
Author: Ravi Sukhadia (set author name here)
Author URL: https://www.garudatechhub.com/ (set author URL here)
Template: twenty-twelve (set your primary theme folder name here)
Version: 1.0.0 (set theme version here)
Text Domain: Hashencrypted-child (set child theme folder name here)
*/

Step 4)

Open the functions.php file and remove all code from that file and put the below code for taking your style in child theme.

<?php
add_action( 'wp_enqueue_scripts', 'enqueue_parent_styles' );

function enqueue_parent_styles() {
   wp_enqueue_style( 'parent-style', get_template_directory_uri().'/style.css' );
}
?>

Step 5)

Now your child theme is ready. go to wordpress admin section and active your child theme.

Register Custom Sidebar in WordPress

Customsidebar

If you are new in WordPress and don’t know how to register the custom sidebar and how to get the custom sidebar value on any page then simply follow the tutorial steps and you can get your custom sidebar.

Step 1)

Copy the below code in your functions.php for register a new custom sidebar.

register_sidebar( array(
‘id’ => ‘ID of your sidebar without space and special character’,
‘name’ => ‘Name of your sidebar without space and special character’,
‘description’ => __( ‘Enter Placeholder Text Here’, ‘text_domain’ ),
) );

Step 2)

Now, You can view the sidebar in you wp-admin widget section.

Step 3)

If you need to get that new custom sidebar value in the wordpress pages then copy the below code with starting and ending of php code in your pages.

dynamic_sidebar( ‘Your custom register sidebar id’ );

Step 4)

Now if you put any widget inside the custom sidebar it will display the widget where you put the code which is define in the step 3.

How to Install wordpress?

Wordpress

If you are new in WordPress and don’t know how to install the WordPress in your local system or live system then follow the below steps and get newly installed WordPress.

Download Latest WordPress

You can download the latest WordPress version from this link https://wordpress.org/download/

Step 1)

Abstract the zip where you need to set up the WordPress, if you need to set up in your local server then make a new folder which is your project name like “Blogging” and put all files and folder into the new folder from the abstract zip folder. if you need to set up in live server then just copy all files and folder into the hosting panel from the abstract zip folder.

Step 2)

Now make one new empty database to your local or live system. like “blogging”.

Step 3)

Run the URL in the browser. if you set up your WordPress in the local server then run URL in the browser like “http://localhost/blogging”. if you set up your WordPress in the live server then run the URL in the browser like “http://blogging.com”.

Step 4)

wordpress-install-step4.png

In your browser, you can see one form like below.

  • Enter your database name in the first field which u make in the database like “blogging”.
  • Enter your database username and password in the next two fields.
  • In the database host, if you use local server then put hostname as it is if you use live server then check your hostname from the database and insert that hostname in that fields.
  • If you want another prefix then you can enter in the prefix section otherwise put as it is.
  • Submit the form and you can get new form as see in the step 5.

Step 5)

wordpress-install-step5.png
  • Now enter your website title
  • Enter your username and password in the next two fields. which is your WordPress admin login access.
  • Enter your email address where you can get notification from the wordpress.
  • Click on the install wordpress button.

Step 6)

Now your wordpress was completed.