-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 755fade
Showing
2 changed files
with
150 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
|
||
/** | ||
* Plugin Name: My Plugin | ||
* Plugin URI: -- | ||
* Description: My First Plugin for WP | ||
* Version: 1.1 | ||
* Author: Manoj | ||
* Author URI: -- | ||
* License: GPL2 | ||
*/ | ||
|
||
function slf_enqueue_styles() { | ||
wp_enqueue_style('slf-custom-styles', plugin_dir_url(__FILE__) . 'style.css'); | ||
} | ||
add_action('wp_enqueue_scripts', 'slf_enqueue_styles'); | ||
|
||
function slf_login_form() { | ||
if (is_user_logged_in()) { | ||
return '<p>You are already logged in.</p>'; | ||
} | ||
|
||
// Display error message if there is one | ||
$error = get_transient('slf_login_error'); | ||
delete_transient('slf_login_error'); // Clear the error after displaying it | ||
$output = $error ? '<p style="color:red;">' . esc_html($error) . '</p>' : ''; | ||
|
||
|
||
$output .= '<form method="post" action="' . esc_url($_SERVER['REQUEST_URI']) . '">'; | ||
$output .= wp_nonce_field('slf_login_action', 'slf_login_nonce'); | ||
$output .= '<p><label for="username">Username</label><br>'; | ||
$output .= '<input type="text" name="username" required></p>'; | ||
$output .= '<p><label for="password">Password</label><br>'; | ||
$output .= '<input type="password" name="password" required></p>'; | ||
$output .= '<p><input type="submit" name="submit" value="Login"></p>'; | ||
$output .= '</form>'; | ||
|
||
return $output; | ||
} | ||
|
||
function slf_handle_login() { | ||
if (isset($_POST['submit'])) { | ||
|
||
if (!isset($_POST['slf_login_nonce']) || !wp_verify_nonce($_POST['slf_login_nonce'], 'slf_login_action')) { | ||
set_transient('slf_login_error', 'Nonce verification failed.', 5); | ||
return; | ||
} | ||
|
||
$username = sanitize_user($_POST['username']); | ||
$password = sanitize_text_field($_POST['password']); | ||
|
||
$credentials = array( | ||
'user_login' => $username, | ||
'user_password' => $password, | ||
'remember' => true | ||
); | ||
|
||
$user = wp_signon($credentials, false); | ||
|
||
if (is_wp_error($user)) { | ||
set_transient('slf_login_error', 'Login failed: ' . $user->get_error_message(), 5); | ||
} else { | ||
wp_redirect(home_url()); | ||
exit; | ||
} | ||
} | ||
} | ||
add_action('init', 'slf_handle_login'); | ||
|
||
function slf_login_shortcode() { | ||
return slf_login_form(); | ||
} | ||
add_shortcode('simple_login', 'slf_login_shortcode'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* Style container for the form */ | ||
form#scf_contact_form, | ||
form#simple_login_form { | ||
max-width: 400px; | ||
margin: 0 auto; | ||
padding: 20px; | ||
border: 1px solid #ddd; | ||
border-radius: 5px; | ||
background-color: #f9f9f9; | ||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); | ||
} | ||
|
||
/* Label styling */ | ||
form#scf_contact_form label, | ||
form#simple_login_form label { | ||
font-weight: bold; | ||
color: #333; | ||
display: block; | ||
margin-bottom: 5px; | ||
} | ||
|
||
/* Input and textarea styling */ | ||
form#scf_contact_form input[type="text"], | ||
form#scf_contact_form input[type="email"], | ||
form#scf_contact_form input[type="password"], | ||
form#scf_contact_form textarea, | ||
form#simple_login_form input[type="text"], | ||
form#simple_login_form input[type="password"] { | ||
width: 100%; | ||
padding: 10px; | ||
margin-bottom: 15px; | ||
border: 1px solid #ccc; | ||
border-radius: 4px; | ||
font-size: 16px; | ||
transition: border-color 0.3s ease; | ||
} | ||
|
||
form#scf_contact_form input[type="text"]:focus, | ||
form#scf_contact_form input[type="email"]:focus, | ||
form#scf_contact_form input[type="password"]:focus, | ||
form#scf_contact_form textarea:focus, | ||
form#simple_login_form input[type="text"]:focus, | ||
form#simple_login_form input[type="password"]:focus { | ||
border-color: #0073aa; | ||
} | ||
|
||
/* Submit button styling */ | ||
form#scf_contact_form input[type="submit"], | ||
form#simple_login_form input[type="submit"] { | ||
background-color: #0073aa; | ||
color: #fff; | ||
padding: 10px 15px; | ||
font-size: 16px; | ||
border: none; | ||
border-radius: 4px; | ||
cursor: pointer; | ||
transition: background-color 0.3s ease; | ||
} | ||
|
||
form#scf_contact_form input[type="submit"]:hover, | ||
form#simple_login_form input[type="submit"]:hover { | ||
background-color: #005d8f; | ||
} | ||
|
||
/* Error message styling */ | ||
form#scf_contact_form .scf-success, | ||
form#simple_login_form .scf-success { | ||
color: green; | ||
margin-bottom: 15px; | ||
} | ||
|
||
form#scf_contact_form p[style="color:red;"], | ||
form#simple_login_form p[style="color:red;"] { | ||
color: red; | ||
font-weight: bold; | ||
margin-bottom: 15px; | ||
} |