Add Logo to Admin - Version 1.1

Version Description

Download this release

Release Info

Developer tinkerpriest
Plugin Icon wp plugin Add Logo to Admin
Version 1.1
Comparing to
See all releases

Code changes from version 1.0.2 to 1.1

Files changed (6) hide show
  1. add-logo.php +135 -8
  2. css/login.css +4 -0
  3. css/wp-admin.css +3 -0
  4. js/admin.js +16 -2
  5. js/login.js +17 -3
  6. readme.txt +13 -21
add-logo.php CHANGED
@@ -4,22 +4,149 @@ Plugin Name: Add Logo to Admin
4
  Plugin URI: http://bavotasan.com/tidbits/add-your-logo-to-the-wordpress-admin-and-login-page/
5
  Description: Adds a custom logo to your site's Admin header and your login page.
6
  Author: c.bavota
7
- Version: 1.0.2
8
  Author URI: http://bavotasan.com
9
  */
10
 
11
- function add_logo_to_admin() {
12
- echo '<link rel="stylesheet" type="text/css" href="' . get_settings('siteurl') . '/wp-content/plugins/add-logo-to-admin/css/wp-admin.css" />'."\n";
13
- echo '<script type="text/javascript" src="' . get_settings('siteurl') . '/wp-content/plugins/add-logo-to-admin/js/admin.js"></script>'."\n";
 
 
 
 
14
  }
15
 
16
- add_action('admin_head', 'add_logo_to_admin');
 
 
 
 
 
17
 
18
- function wp_admin_login_css() {
19
- echo '<link rel="stylesheet" type="text/css" href="' . get_settings('siteurl') . '/wp-content/plugins/add-logo-to-admin/css/login.css" />'."\n";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  echo '<script type="text/javascript" src="' . get_settings('siteurl') . '/wp-content/plugins/add-logo-to-admin/js/login.js"></script>'."\n";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  }
22
 
23
- add_action('login_head', 'wp_admin_login_css');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  ?>
4
  Plugin URI: http://bavotasan.com/tidbits/add-your-logo-to-the-wordpress-admin-and-login-page/
5
  Description: Adds a custom logo to your site's Admin header and your login page.
6
  Author: c.bavota
7
+ Version: 1.1
8
  Author URI: http://bavotasan.com
9
  */
10
 
11
+ //Initialization
12
+ add_action('admin_menu', 'add_logo_init');
13
+
14
+
15
+ //add page to admin
16
+ function add_logo_init() {
17
+ add_options_page('Add Logo to Admin', 'Add Logo to Admin', 10, __FILE__, 'my_plugin_options');
18
  }
19
 
20
+ //set default options
21
+ function set_add_logo_options() {
22
+ add_option('add_logo_on_login','yes','Do you want the logo to appear on the login page?');
23
+ add_option('add_logo_on_admin','yes','Do you want the logo to appear on the admin pages?');
24
+ add_option('add_logo_logo','/wp-content/plugins/add-logo-to-admin/images/logo.png','Logo location');
25
+ }
26
 
27
+ //delete options upon plugin deactivation
28
+ function unset_add_logo_options() {
29
+ delete_option('add_logo_on_login');
30
+ delete_option('add_logo_on_admin');
31
+ delete_option('add_logo_logo');
32
+ }
33
+
34
+ register_activation_hook(__FILE__,'set_add_logo_options');
35
+ register_deactivation_hook(__FILE__,'unset_add_logo_options');
36
+
37
+ //add logo to admin if "yes" selected
38
+ if(get_option('add_logo_on_admin') == "yes") {
39
+ if (is_admin()) {
40
+ add_action('admin_head', 'wp_admin_admin_css');
41
+ function wp_admin_admin_css() {
42
+ echo '<link rel="stylesheet" type="text/css" href="' . get_settings('siteurl') . '/wp-content/plugins/add-logo-to-admin/css/wp-admin.css" />'."\n";
43
+ }
44
+ wp_enqueue_script('add_logo_admin_script', get_settings('siteurl') . '/wp-content/plugins/add-logo-to-admin/js/admin.js');
45
+ wp_localize_script( 'add_logo_admin_script', 'newLogo', array(
46
+ 'logo' => get_option('add_logo_logo')
47
+ ));
48
+ }
49
+ }
50
+
51
+ //add logo to login if "yes" is selected
52
+ if(get_option('add_logo_on_login') == "yes") {
53
+ add_action('login_head', 'wp_admin_login_css');
54
+ function wp_admin_login_css() {
55
+ echo '<link rel="stylesheet" type="text/css" href="' . get_settings('siteurl') . '/wp-content/plugins/add-logo-to-admin/css/login.css" />'."\n";
56
+ echo '<script type="text/javascript">' . "\n" . '/* <![CDATA[ */' . "\n" . ' newLogo = {' . "\n" . ' logo: "' . get_option('add_logo_logo') . '"' . "\n" . ' }' . "\n" . '/* ]]> */' . "\n" . '</script>' . "\n";
57
  echo '<script type="text/javascript" src="' . get_settings('siteurl') . '/wp-content/plugins/add-logo-to-admin/js/login.js"></script>'."\n";
58
+ }
59
+ }
60
+
61
+ //creating the admin page
62
+ function my_plugin_options() {
63
+ ?>
64
+ <div class="wrap">
65
+ <h2>Add Logo to Admin</h2>
66
+ <?php
67
+ if($_REQUEST['submit']) {
68
+ update_add_logo_options();
69
+ }
70
+ print_add_logo_form();
71
+ ?>
72
+ </div>
73
+ <?php
74
  }
75
 
76
+ //updating the options
77
+ function update_add_logo_options() {
78
+ $ok = false;
79
+
80
+ if($_REQUEST['add_logo_on_login']) {
81
+ update_option('add_logo_on_login',$_REQUEST['add_logo_on_login']);
82
+ $ok = true;
83
+ }
84
+
85
+ if($_REQUEST['add_logo_on_admin']) {
86
+ update_option('add_logo_on_admin',$_REQUEST['add_logo_on_admin']);
87
+ $ok = true;
88
+ }
89
+
90
+ if($_REQUEST['add_logo_logo']) {
91
+ update_option('add_logo_logo',$_REQUEST['add_logo_logo']);
92
+ $ok = true;
93
+ }
94
+
95
+ if($ok) {
96
+ echo'<div id="message" class="updated fade">';
97
+ echo '<p>Options saved.</p>';
98
+ echo '</div>';
99
+ } else {
100
+ echo'<div id="message" class="error fade">';
101
+ echo '<p>Failed to save options.</p>';
102
+ echo '</div>';
103
+ }
104
+ }
105
 
106
+ //the actual admin page
107
+ function print_add_logo_form() {
108
+ $default_login = get_option('add_logo_on_login');
109
+ $default_admin = get_option('add_logo_on_admin');
110
+ $the_logo = get_option('add_logo_logo');
111
+ if ($default_login == "yes") { $login_yes = "checked"; } else { $login_no = "checked"; }
112
+ if ($default_admin == "yes") { $admin_yes = "checked"; } else { $admin_no = "checked"; }
113
+ ?>
114
+ <!-- Add Logo to Admin box begin-->
115
+ <form method="post">
116
+ <table class="form-table">
117
+ <tr valign="top">
118
+ <th scope="row" style="width: 370px;">
119
+ <label for="add_logo_on_login">Would you like your logo to appear on the login page?</label>
120
+ </th>
121
+ <td>
122
+ <input type="radio" name="add_logo_on_login" value="yes" <?=$login_yes?> />Yes
123
+ <input type="radio" name="add_logo_on_login" value="no" <?=$login_no?> />No
124
+ </td>
125
+ </tr>
126
+ <tr valign="top">
127
+ <th scope="row" style="width: 370px;">
128
+ <label for="add_logo_on_admin">Would you like your logo to appear on the admin pages?</label>
129
+ </th>
130
+ <td>
131
+ <input type="radio" name="add_logo_on_admin" value="yes" <?=$admin_yes?> />Yes
132
+ <input type="radio" name="add_logo_on_admin" value="no" <?=$admin_no?> />No
133
+ </td>
134
+ </tr>
135
+ <tr valign="top">
136
+ <th scope="row" style="width: 370px;">
137
+ <label for="add_logo_logo">Where is your logo located? </label>
138
+ </th>
139
+ <td>
140
+ <?php bloginfo('url'); ?><input type="text" name="add_logo_logo" size="60" value="<?=$the_logo?>" /><br />
141
+ </td>
142
+ </tr>
143
+ </table>
144
+ <p class="submit">
145
+ <input type="submit" name="submit" class="button-primary" value="Save Changes" />
146
+ </p>
147
+ </form>
148
+ <p><em>NOTE: You need to refresh this page or just navigate to another page if you switch the Admin option from "No" to "Yes" and want to see the option take affect.</em></p>
149
+ <!-- Add Logo to Admin admin box end-->
150
+ <?php
151
+ }
152
  ?>
css/login.css CHANGED
@@ -1,3 +1,7 @@
1
  #newLogo {
2
  padding: 0 0 20px;
3
  }
 
 
 
 
1
  #newLogo {
2
  padding: 0 0 20px;
3
  }
4
+
5
+ #login h1 {
6
+ display: none;
7
+ }
css/wp-admin.css CHANGED
@@ -12,3 +12,6 @@
12
  width: 100%;
13
  }
14
 
 
 
 
12
  width: 100%;
13
  }
14
 
15
+ #wphead h1 a {
16
+ display: none;
17
+ }
js/admin.js CHANGED
@@ -1,14 +1,28 @@
1
- window.onload = addLogo;
2
 
 
 
 
 
 
 
 
 
 
 
 
3
  function addLogo() {
4
  var myBody = document.getElementById("wphead").getElementsByTagName("a")[0];
5
  myBody.innerHTML = "";
6
 
7
  var img = document.createElement("img");
8
- var imgSrc = "../wp-content/plugins/add-logo-to-admin/images/logo.png";
9
  img.setAttribute("src",imgSrc);
10
  img.setAttribute("id", "newLogo");
11
 
12
  myBody.appendChild(img);
 
 
 
13
  return false;
14
  }
1
+ var oldOnload = window.onload;
2
 
3
+ if(typeof oldOnload == "function") {
4
+ window.onload = function() {
5
+ if(oldOnload) {
6
+ oldOnload();
7
+ }
8
+ addLogo();
9
+ }
10
+ } else {
11
+ window.onload = addLogo;
12
+ }
13
+
14
  function addLogo() {
15
  var myBody = document.getElementById("wphead").getElementsByTagName("a")[0];
16
  myBody.innerHTML = "";
17
 
18
  var img = document.createElement("img");
19
+ var imgSrc = newLogo.logo;
20
  img.setAttribute("src",imgSrc);
21
  img.setAttribute("id", "newLogo");
22
 
23
  myBody.appendChild(img);
24
+
25
+ myBody.style.display = "block";
26
+
27
  return false;
28
  }
js/login.js CHANGED
@@ -1,14 +1,28 @@
1
- window.onload = addLogo;
 
 
 
 
 
 
 
 
 
 
 
2
 
3
  function addLogo() {
4
- var myBody = document.getElementsByTagName("h1")[0];
5
  myBody.innerHTML = "";
6
 
7
  var img = document.createElement("img");
8
- var imgSrc = "../wp-content/plugins/add-logo-to-admin/images/logo.png";
9
  img.setAttribute("src",imgSrc);
10
  img.setAttribute("id", "newLogo");
11
 
12
  myBody.appendChild(img);
 
 
 
13
  return false;
14
  }
1
+ var oldOnload = window.onload;
2
+
3
+ if(typeof oldOnload == "function") {
4
+ window.onload = function() {
5
+ if(oldOnload) {
6
+ oldOnload();
7
+ }
8
+ addLogo();
9
+ }
10
+ } else {
11
+ window.onload = addLogo;
12
+ }
13
 
14
  function addLogo() {
15
+ var myBody = document.getElementById("login").getElementsByTagName("h1")[0];
16
  myBody.innerHTML = "";
17
 
18
  var img = document.createElement("img");
19
+ var imgSrc = newLogo.logo;
20
  img.setAttribute("src",imgSrc);
21
  img.setAttribute("id", "newLogo");
22
 
23
  myBody.appendChild(img);
24
+
25
+ myBody.style.display = "block";
26
+
27
  return false;
28
  }
readme.txt CHANGED
@@ -4,47 +4,31 @@ Donate Link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_i
4
  Tags: custom logo, admin, login
5
  Requires at least: 2.7
6
  Tested up to: 2.7
7
- Stable tag: 1.0.2
8
 
9
  Add a custom logo to your admin header and to your login page.
10
 
11
  == Description ==
12
 
13
- Add a custom logo to your admin header and to your login page.
14
-
15
  This plugin allows a user to customize their admin panel by adding their own logo to the header. It also replaces the WordPress logo on the login screen with the same custom logo.
16
 
17
  == Installation ==
18
 
19
  1. Unzip the add-logo-to-admin.zip file.
20
- 2. Create your own logo and name it logo.png. Add it to add-logo-to-admin/images folder.
21
- 3. Upload the `add-logo-to-admin` folder to the `/wp-content/plugins/` directory.
22
- 4. Activate the plugin through the 'Plugins' menu in WordPress.
23
 
24
  == Frequently Asked Questions ==
25
 
26
  1) How do I add my own logo?
27
 
28
- Create your own logo and name it logo.png. Add it to add-logo-to-admin/images folder.
29
 
30
  2) How big does my logo need to be?
31
 
32
  You can make it any width or height.
33
 
34
- 3) Can my logo by a jpg file?
35
-
36
- Yes it can. But you would need to edit two lines in two files of the plugin to make it work.
37
-
38
- Open file js/login.js and change line 8 to
39
-
40
- var imgSrc = "../wp-content/plugins/add-logo-to-admin/images/logo.jpg";
41
-
42
- Open file js/admin.js and change line 8 to
43
-
44
- var imgSrc = "../wp-content/plugins/add-logo-to-admin/images/logo.jpg";
45
-
46
- NOTE: You can also change it to logo.gif or whichever file format you prefer. I chose .png to take advantage of the high quality transparency it offers.
47
-
48
  == Screenshots ==
49
 
50
  1. Admin before and after
@@ -52,6 +36,14 @@ NOTE: You can also change it to logo.gif or whichever file format you prefer. I
52
 
53
  == Change Log ==
54
 
 
 
 
 
 
 
 
 
55
  1.0.2 (2008-12-16)
56
  Fixed weirdness with extra folder
57
 
4
  Tags: custom logo, admin, login
5
  Requires at least: 2.7
6
  Tested up to: 2.7
7
+ Stable tag: 1.1
8
 
9
  Add a custom logo to your admin header and to your login page.
10
 
11
  == Description ==
12
 
 
 
13
  This plugin allows a user to customize their admin panel by adding their own logo to the header. It also replaces the WordPress logo on the login screen with the same custom logo.
14
 
15
  == Installation ==
16
 
17
  1. Unzip the add-logo-to-admin.zip file.
18
+ 2. Upload the `add-logo-to-admin` folder to the `/wp-content/plugins/` directory.
19
+ 3. Activate the plugin through the 'Plugins' menu in WordPress.
20
+ 4. Go to Settings => Add Logo to Admin and set your options and add the location of your logo.
21
 
22
  == Frequently Asked Questions ==
23
 
24
  1) How do I add my own logo?
25
 
26
+ You have two options. You can create your own logo and name it logo.png, then add it to the add-logo-to-admin/images folder. Or you can go to Settings => Add Logo to Admin and add the location of you logo in the appropriate box.
27
 
28
  2) How big does my logo need to be?
29
 
30
  You can make it any width or height.
31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
  == Screenshots ==
33
 
34
  1. Admin before and after
36
 
37
  == Change Log ==
38
 
39
+ 1.1 (2008-12-24)
40
+ <ul>
41
+ <li>Added admin page with options</li>
42
+ <li>Fixed window.onload JavaScript issue</li>
43
+ <li>Fixed issue with blogs not located in the root directory</li>
44
+ <li>Removed extraneous code</li>
45
+ </ul>
46
+
47
  1.0.2 (2008-12-16)
48
  Fixed weirdness with extra folder
49