AI Verified

Name

Branded Login

About

Brand the Login with a Link and your Logo.

Language

PHP

Rating

Voted: 1 by 1 user(s)

Codevault

WebSquadron

Scroll down to see more snippets from this codevault.

Wordpress Compatability

The author has indicated that this snippet is compatable up to wordpress version: 6.1

Our AI bot has checked this snippet is compatable up to wordpress version: 6.1

Code Snippet Plugin Sync

Free & Pro

Download this snippet by clicking the download button, then head over to the Code Snippet Plugin settings in your wordpress admin dashboard, select the import menu then upload this file to import into your wordpress site.

Pro Only (Coming Soon)

You will be able to click a button and sync this snippet to your wordpress site automatically and from your dashboard manage all code snippets across all your wordpress sites that have the Code Snippets Pro plugin installed.

History

Last modified:

18/02/2024

Important Note

This snippet has the following status:

AI Verified

This snippet has been tested by our AI bot, see any comments below.

AI Bot Comments:

Found 0 vulnerabilities

Branded Login

 
                    
1/**
2 * Snippet Name: Handy Admin Tools
3 * Description: Handy Admin Tools is a WordPress plugin designed to enhance the admin experience by providing customized login screen options. This includes the ability to change the login logo, set a custom URL for the logo link, and add a designer/developer credit link under the login form.
4 * Version: 0.1
5 * Authors: Mark Harris & Imran Siddiq
6 *
7 * This plugin allows WordPress site administrators to:
8 * - Customize the WordPress login screen logo.
9 * - Specify the height and width for the login logo.
10 * - Set a custom URL for the login logo, allowing the logo to link to any URL.
11 * - Add a designer/developer credit link under the login form, including customizable anchor text and URL.
12 *
13 * Usage:
14 * - Navigate to the "Handy Admin Tools" menu in the WordPress admin dashboard.
15 * - Use the provided settings fields to customize the login screen as desired.
16 * - Save changes to see the effects on the WordPress login page.
17 *
18 * Note:
19 * - It's recommended to use proper image sizes for the login logo to ensure optimal display.
20 * - Ensure the plugin is kept up-to-date with WordPress updates for compatibility.
21 */
22 
23class HandyAdminTools
24{
25 public function __construct()
26 {
27 add_action("admin_menu", [$this, "add_admin_menu"]);
28 add_action("login_head", [$this, "customize_login_logo"]);
29 add_action("admin_init", [$this, "register_settings"]);
30 add_action("admin_enqueue_scripts", [$this, "enqueue_media_uploader"]);
31 }
32 
33 public function enqueue_media_uploader()
34 {
35 wp_enqueue_media();
36 wp_enqueue_script(
37 "handy-admin-tools-script",
38 plugin_dir_url(__FILE__) . "handy-admin-tools.js",
39 ["jquery"]
40 );
41 }
42 
43 public function add_admin_menu()
44 {
45 add_menu_page(
46 "Handy Admin Tools",
47 "Handy Admin Tools",
48 "manage_options",
49 "handy-admin-tools",
50 [$this, "admin_page_html"],
51 "dashicons-admin-tools"
52 );
53 }
54 
55 public function admin_page_html()
56 {
57 ?>
58 <div class="wrap handy-admin-tools">
59 <h1>Handy Admin Tools</h1>
60 <form method="post" action="options.php">
61 <?php
62 settings_fields("handy-admin-tools-settings");
63 do_settings_sections("handy-admin-tools-settings");
64 submit_button();
65 ?>
66 </form>
67 </div>
68 <style>
69 /* Custom CSS for the admin page */
70 .wrap.handy-admin-tools {
71 padding: 20px;
72 background-color: #f5f5f5;
73 border: 1px solid #ddd;
74 border-radius: 5px;
75 box-shadow: 0 2px 5px rgba(0,0,0,0.2);
76 }
77 
78 .handy-admin-tools h1 {
79 font-size: 28px;
80 margin-bottom: 20px;
81 color: #333;
82 }
83 
84 .handy-admin-tools input[type="text"],
85 .handy-admin-tools input[type="number"],
86 .handy-admin-tools input[type="url"] {
87 width: 100%;
88 padding: 10px;
89 margin-bottom: 10px;
90 border: 1px solid #ccc;
91 border-radius: 5px;
92 }
93 
94 .handy-admin-tools .button {
95 background-color: #0073e6;
96 color: #fff;
97 border: none;
98 border-radius: 5px;
99 padding: 10px 20px;
100 cursor: pointer;
101 }
102 
103 .handy-admin-tools .description {
104 font-style: italic;
105 margin-top: 5px;
106 color: #777;
107 }
108 </style>
109 <?php
110 }
111 
112 public function register_settings()
113 {
114 register_setting(
115 "handy-admin-tools-settings",
116 "handy_admin_tools_login_logo"
117 );
118 register_setting(
119 "handy-admin-tools-settings",
120 "handy_admin_tools_logo_width"
121 );
122 register_setting(
123 "handy-admin-tools-settings",
124 "handy_admin_tools_logo_height"
125 );
126 
127 register_setting("handy-admin-tools-settings", "custom_logo_link", [
128 "type" => "string",
129 "default" => "",
130 "sanitize_callback" => "esc_url_raw",
131 ]);
132 
133 register_setting("handy-admin-tools-settings", "designer_text", [
134 "type" => "string",
135 "default" => "",
136 "sanitize_callback" => "sanitize_text_field",
137 ]);
138 
139 add_settings_section(
140 "handy_admin_tools_main",
141 "Simple Login Editor",
142 null,
143 "handy-admin-tools-settings"
144 );
145 
146 add_settings_field(
147 "login_logo",
148 "Login Logo",
149 [$this, "login_logo_field_html"],
150 "handy-admin-tools-settings",
151 "handy_admin_tools_main"
152 );
153 add_settings_field(
154 "logo_width",
155 "Logo Width",
156 [$this, "logo_width_field_html"],
157 "handy-admin-tools-settings",
158 "handy_admin_tools_main"
159 );
160 add_settings_field(
161 "logo_height",
162 "Logo Height",
163 [$this, "logo_height_field_html"],
164 "handy-admin-tools-settings",
165 "handy_admin_tools_main"
166 );
167 add_settings_field(
168 "custom_logo_link",
169 "Designer / Developer URL",
170 [$this, "custom_logo_link_field_html"],
171 "handy-admin-tools-settings",
172 "handy_admin_tools_main"
173 );
174 add_settings_field(
175 "designer_text",
176 "Designer/Developer Text",
177 [$this, "designer_text_field_html"],
178 "handy-admin-tools-settings",
179 "handy_admin_tools_main"
180 );
181 }
182 
183 public function login_logo_field_html()
184 {
185 $login_logo = get_option("handy_admin_tools_login_logo"); ?>
186 <input type="text" id="handy_admin_tools_login_logo" name="handy_admin_tools_login_logo" value="<?php echo esc_attr($login_logo); ?>" />
187 <input type="button" class="button" id="handy_admin_tools_upload_button" value="Upload Logo" />
188 <p class="description">Recommended size: 200x100 pixels. Click 'Upload Logo' to select an image from the media library.</p>
189 <script type="text/javascript">
190 jQuery(document).ready(function($){
191 $('#handy_admin_tools_upload_button').click(function(e) {
192 e.preventDefault();
193 var image = wp.media({
194 title: 'Upload Logo',
195 multiple: false
196 }).open()
197 .on('select', function(e){
198 var uploaded_image = image.state().get('selection').first();
199 var image_url = uploaded_image.toJSON().url;
200 $('#handy_admin_tools_login_logo').val(image_url);
201 });
202 });
203 });
204 </script>
205 <?php
206 }
207 
208 public function logo_width_field_html()
209 {
210 $logo_width = get_option("handy_admin_tools_logo_width"); ?>
211 <input type="number" id="handy_admin_tools_logo_width" name="handy_admin_tools_logo_width" value="<?php echo esc_attr($logo_width); ?>" min="50" max="500" />
212 <p class="description">Recommended range: 50px to 500px. It's best to maintain the original aspect ratio of your logo.</p>
213 <?php
214 }
215 
216 public function logo_height_field_html()
217 {
218 $logo_height = get_option("handy_admin_tools_logo_height"); ?>
219 <input type="number" id="handy_admin_tools_logo_height" name="handy_admin_tools_logo_height" value="<?php echo esc_attr($logo_height); ?>" min="50" max="300" />
220 <p class="description">Recommended range: 50px to 300px. Maintaining the aspect ratio of your logo for the best visual appearance is advised.</p>
221 <?php
222 }
223 
224 public function custom_logo_link_field_html()
225 {
226 $custom_logo_link = get_option("custom_logo_link", ""); ?>
227 <input type="url" id="custom_logo_link" name="custom_logo_link" value="<?php echo esc_url($custom_logo_link); ?>" />
228 <p class="description">Enter the URL of the designer or developer's website.</p>
229 <?php
230 }
231 
232 public function designer_text_field_html()
233 {
234 $designer_text = get_option("designer_text", ""); ?>
235 <input type="text" id="designer_text" name="designer_text" value="<?php echo esc_attr($designer_text); ?>" />
236 <p class="description">Enter the text for the designer/developer link.</p>
237 <?php
238 }
239 
240 public function customize_login_logo()
241{
242 $login_logo = get_option("handy_admin_tools_login_logo");
243 $logo_width = get_option("handy_admin_tools_logo_width");
244 $logo_height = get_option("handy_admin_tools_logo_height");
245 $custom_logo_link = get_option("custom_logo_link");
246 $designer_text = get_option("designer_text");
247 
248 if ($login_logo) {
249 add_filter("login_headerurl", function () use ($custom_logo_link) {
250 return !empty($custom_logo_link) ? esc_url($custom_logo_link) : esc_url(home_url("/"));
251 });
252 
253 echo '<style type="text/css">
254 .login h1 a {
255 background-image: url(' . esc_url($login_logo) . ') !important;
256 background-size: ' . esc_attr($logo_width) . 'px ' . esc_attr($logo_height) . 'px !important;
257 height: ' . esc_attr($logo_height) . 'px !important;
258 width: ' . esc_attr($logo_width) . 'px !important;
259 display: block;
260 }
261 .custom-designer-link {
262 text-align: center;
263 margin-top: 20px;
264 padding: 10px;
265 background-color: #f1f1f1;
266 border-radius: 5px;
267 box-shadow: 0 2px 5px rgba(0,0,0,0.2);
268 }
269 </style>';
270 
271 add_action('login_footer', function() use ($custom_logo_link, $designer_text) {
272 if (!empty($designer_text) && !empty($custom_logo_link)) {
273 echo '<div class="custom-designer-link"><a href="' . esc_url($custom_logo_link) . '" target="_blank">' . esc_html($designer_text) . '</a></div>';
274 }
275 });
276 }
277}
278 
279}
280 
281new HandyAdminTools();

1

Related Snippets

Please see some snippets below related to this snippet..

WordPress Admin

AI Verified

0

Remove WordPress Version Number

Added: 1 year ago

Last Updated: 1 year ago

Removes wordpress version that is present

WordPress Admin

AI Verified

0

Block Editor: Select on Enter/Return in the Block Inserter Text Input [SnipSnip.pro]

Added: 7 months ago

Last Updated: 7 months ago

ADMIN ONLY • When using Block Editor and searching for the name of a block or pattern, you can hit enter to jump focus to the results, hit enter again to select. This snippet adds JS to the admin foot...

WordPress Admin

AI Verified

1

Remove items from admin bar

Added: 1 year ago

Last Updated: 11 months ago

Other Snippets in this Codevault

These are some popular snippets from this users codevault..

Performance

AI Verified

32

Remove Unused Javascript

Added: 1 year ago

Last Updated: 3 days ago

Remove Unused Javascript - and improve your Page Speed Insight Score

WooCommerce

Pro Verified

10

Deactivate some WooCommerce Checkout Fields

Added: 1 year ago

Last Updated: 2 weeks ago

Deactivate some WooCommerce Checkout Fields from showing

Elementor

AI Verified

6

CSS Grid Aid

Added: 8 months ago

Last Updated: 1 month ago

This can be used for any WordPress Builder to aid working with CSS Grids.