Translate it to ur language

Sunday, August 8, 2010

10 WordPress Dashboard Hacks

The dashboard is a very important part of a WordPress blog. In fact,
it allows you to control your posts, your blog design, and many more
things. When building a site for a client, it is especially important
to be able to control WP’s dashboard. In this article, let’s have a
look at 10 extremely useful hacks for WordPress’ dashboard.
Remove dashboard menus

When building a WordPress blog for a client, it can be a good idea to
remove access to some dashboard menus in order to avoid future
problems such as the client “accidentally” deleting the custom theme
they paid for.

Paste the following code in the functions.php file from your theme
directory. The following example will remove all menus named in the
$restricted array.
01.function remove_menus () { $menu;
03.$restricted = array(__('Dashboard'), __('Posts'), __('Media'),
__('Links'), __('Pages'), __('Appearance'), __('Tools'), __('Users'),
__('Settings'), __('Comments'), __('Plugins'));
04.end ($menu);
05.while (prev($menu)){
06.$value = explode(' ',$menu[key($menu)][0]);
07.if(in_array($value[0] != NULL?$value[0]:""
10.add_action('admin_menu', 'remove_menus');

» Source
Define your own login logo

Although it doesn’t have any importance for the blog performance or
usability, most clients will be very happy to see their own logo on
the dashboard login page, instead of the classic WordPress logo.
The Custom admin branding plugin can do that for you, as well as the
following hack that you just have to paste in your functions.php file.
1.function my_custom_login_logo() {
2.echo '
3.h1 a { background-image:url('.get_bloginfo('template_directory').'/images/custom-login-logo.gif)
!important; }
7.add_action('login_head', 'my_custom_login_logo');

» Source
Replace dashboard logo with yours

Just as a client will love to see their own logo on WordPress login
page, there’s no doubt that they’ll enjoy viewing it on the dashboard
Simply copy the code below and paste it to your functions.php file.
1.add_action('admin_head', 'my_custom_logo');
3.function my_custom_logo() {
4.echo '
5.#header-logo { background-image:
!important; }';

» Source
Disable the “please upgrade now” message

WordPress constantly release new versions. Although for obvious
security concerns you should always upgrade; disabling the “Please
upgrade now” message on client sites can be a good idea because the
client doesn’t necessarily have to know about this, this is a
developer’s job.

One more time, nothing hard: paste the code in your functions.php,
save it, and it’s all good.
1.if ( !current_user_can( 'edit_users' ) ) {
2.add_action( 'init', create_function( '$a', "remove_action( 'init',
'wp_version_check' );" ), 2 );
3.add_filter( 'pre_option_update_core', create_function( '$a', "return
null;") );

» Source
Remove dashboard widgets

Introduced in WordPress 2.7, dashboard widgets can be pretty useful.
For example, some can display your Google Analytics stats. Though,
sometimes you don’t need it, or at least don’t need some of them.
The code below will allow you to remove WordPress’ dashboard widgets
once you paste it in yourfunctions.php file.
01.function example_remove_dashboard_widgets() {
02.// Globalize the metaboxes array, this holds all the widgets for wp-admin $wp_meta_boxes;
05.// Remove the incomming links widget
08.// Remove right now
14.// Hoook into the 'wp_dashboard_setup' action to register our function
15.add_action('wp_dashboard_setup', 'example_remove_dashboard_widgets' );

» Source
Add custom widgets to WordPress dashboard

With the previous example, I showed you how easy it is to remove
unwanted dashboard widgets. The good news is that creating your own
widgets isn’t hard either.
The well-commented code below should be self explanatory. Just insert
it in your functions.php, as usual.
01.function example_dashboard_widget_function() {
02.// Display whatever it is you want to show
03.echo "Hello World, I'm a great Dashboard Widget";
06.// Create the function use in the action hook
07.function example_add_dashboard_widgets() {
08.wp_add_dashboard_widget('example_dashboard_widget', 'Example
Dashboard Widget', 'example_dashboard_widget_function');
10.// Hoook into the 'wp_dashboard_setup' action to register our other functions
11.add_action('wp_dashboard_setup', 'example_add_dashboard_widgets' );

» Source
Change WordPress dashboard colors

If you ever wanted to be able to change WordPress dashboard colors (as
well as font or even display) without having to edit WordPress core
files, you’ll like this hack for sure.
The following example features a basic style change (grey header is
replaced by a blue one) but you can easily add as many styles as you
wish within the and tags.
1.function custom_colors() {
2.echo '#wphead{background:#069}';
5.add_action('admin_head', 'custom_colors');
Provide help messages

If you’re building a site for a client and they have some problems
with some parts of the dashboard, a good idea is to provide contextual
help to the client.
The following hack will allow you to add a custom help messages for
the blog admin. As usual, you only have to paste the code into your
functions.php file.
01.function my_admin_help($text, $screen) {
02.// Check we're only on my Settings page
03.if (strcmp($screen, MY_PAGEHOOK) == 0 ) {
05.$text = 'Here is some very useful information to help you use this
06.return $text;
08.// Let the default WP Dashboard help stuff through on other Admin pages
09.return $text;
12.add_action( 'contextual_help', 'my_admin_help' );

» Source
Monitor your server in WordPress dashboard

WordPress dashboard API allow you to do many useful things using
dashboard widgets. I recently came across this very useful code: a
dashboard widget that allows you to monitor your server directly on
WordPress’ dashboard.
Paste the code in your functions.php file, and you’re done.
01.function slt_PHPErrorsWidget() {
02.$logfile = '/home/path/logs/php-errors.log'; // Enter the server
path to your logs file here
03.$displayErrorsLimit = 100; // The maximum number of errors to
display in the widget
04.$errorLengthLimit = 300; // The maximum number of characters to
display for each error
05.$fileCleared = false;
06.$userCanClearLog = current_user_can( 'manage_options' );
07.// Clear file?
08.if ( $userCanClearLog && isset( $_GET["slt-php-errors"] ) &&
$_GET["slt-php-errors"]=="clear" ) {
09.$handle = fopen( $logfile, "w" );
10.fclose( $handle );
11.$fileCleared = true;
13.// Read file
14.if ( file_exists( $logfile ) ) {
15.$errors = file( $logfile );
16.$errors = array_reverse( $errors );
17.if ( $fileCleared ) echo '

File cleared.

18.if ( $errors ) {
19.echo '

'.count( $errors ).' error';
20.if ( $errors != 1 ) echo 's';
21.echo '.';
22.if ( $userCanClearLog ) echo ' [ CLEAR LOG FILE ]';
23.echo '

24.echo '
25.echo '
    26.$i = 0;
    27.foreach ( $errors as $error ) {
    28.echo '
  1. ';
    29.$errorOutput = preg_replace( '/\[([^\]]+)\]/', '[$1]',$error, 1 );
    30.if ( strlen( $errorOutput ) > $errorLengthLimit ) {
    31.echo substr( $errorOutput, 0, $errorLengthLimit ).' [...]';
    32.} else {
    33.echo $errorOutput;
    35.echo '
  2. ';
    37.if ( $i > $displayErrorsLimit ) {
    38.echo '
  3. More than '.$displayErrorsLimit.' errors in
  4. ';
    42.echo '
43.} else {
44.echo '

No errors currently logged.

46.} else {
47.echo '

There was a problem reading the error log file.

51.// Add widgets
52.function slt_dashboardWidgets() {
53.wp_add_dashboard_widget( 'slt-php-errors', 'PHP
errors','slt_PHPErrorsWidget' );
55.add_action( 'wp_dashboard_setup', 'slt_dashboardWidgets' );

» Source
Remove dashboard widgets according to user role

If you’re owning a multi-user blog, it may be useful to know how to
hide some dashboard widgets to keep confidential information in a safe
The following code will remove the postcustom meta box for “author”
(role 2). To apply the hack on your own blog, just copy the code below
and paste it in your functions.php file.
01.function customize_meta_boxes() {
02.//retrieve current user info $current_user;
06.//if current user level is less than 3, remove the postcustom meta box
07.if ($current_user->user_level < 3)

No comments: