0

I have created some content using php, js and html which shows the bandwidth the site has used (using the cPanel API and the Google Graphs API) I want this to be shown on the dashboard in Wordpress (viewable to Admins and Editors only)

How do I do this?

2
  • I'm very new to Wordpress, so I'm not sure how to achieve this. After reading this it looks like I would need to create a widget, but I don't know how to. I also don't know where I would have to add the code. Is there not an easy way to add a some static code? Or a blank widget that I could add some code to?
    – baritoneuk
    Aug 10, 2011 at 19:46

2 Answers 2

3
<?php
/*
Plugin Name: Dashboard Google Page Rank
Plugin URI: http://wordpress.org/extend/plugins/dashboard-google-pagerank/
Description: Shows your google pagerank in the wordpress dashboard
Author: Weston Deboer
Version: 1.1
Author URI: http://westondeboer.com
*/
function gpr_wp_dashboard_test() {
include('yourfile.php');


}
function gpr_wp_dashboard_setup() {
    wp_add_dashboard_widget( 'gpr_wp_dashboard_test', __( 'Google Page Rank' ),'gpr_wp_dashboard_test');
}
add_action('wp_dashboard_setup', 'gpr_wp_dashboard_setup');

?>

I have made a small modification to the above plugin. But all you should need to do is include your file which displays the data and it should show your widget in the admin dashboard.

4
  • You don't need parentheses on includes. Also note, you didn't give an example of how to limit that dashboard widget to the admin and editor roles(which was part of the original question). Add that into your answer and i'll +1 you... ;)
    – t31os
    Aug 11, 2011 at 10:18
  • You don't need paretheses but I find using them on includes more asthetically pleasing. Yes, it would be useful to know how I can show the widget for admin and editor.
    – baritoneuk
    Aug 12, 2011 at 9:03
  • Although I was hoping to know how I can show this widget for the specific roles of admin and editor, this answer has been most helpful and so I am marking it as the accepted answer.
    – baritoneuk
    Aug 18, 2011 at 14:30
  • @baritoneuk: just wrap the wp_add_dashboard_widget() call in if (current_user_can('administrator') || current_user_can('editor')) { }.
    – Geert
    Sep 20, 2011 at 11:30
0

Simply open your functions.php file and add the following code:

add_action('wp_dashboard_setup', 'my_custom_dashboard_widgets');


function my_custom_dashboard_widgets() {
global $wp_meta_boxes;

wp_add_dashboard_widget('custom_help_widget', 'Theme Support', 'custom_dashboard_help');
}

function custom_dashboard_help() {
echo '<p>your Text Here <a href="mailto:[email protected]">here</a>. Your Text : <a href="http://www.xxxx.com" target="_blank">Your Title</a></p>';
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.