I would love to customized and dumb down my dashboard with custom icons, shortcuts, guides, etc. I can do this already using widgets, but I would like to dare and do something better.
wp_welcome_panel on this regard, is awesome: I can customized it, I can make it show whatever I want but… only administrators can see this. So I was wondering:
1) Can I customize wp_welcome_panel so that every role can actually see it?
2) Can I add some code before the widgets in order to create a custom dashboard header similar to the one in wp_welcome_panel)? I already tried with
function mycustomcontent() {
echo '<h1>Hello world</h1>';
}
add_action('load-index.php', 'mycustomcontent');
But… the HTML output is placed before anything (right after the body tag), even pushing down the sidebar.
Thanks in advance
Where is the “Welcome Panel”?
The WordPress dashboard (which houses the “Welcome Panel”) basically is the
When does it show?
As you can see when looking at the source, there’s the following check:
How to bypass the needed capability? Make it available for everyone!
This means that the minimum role/capability (role names get assigned as capabilities as well), is
edit_theme_options
. Now you can, as @OlegButuzov showed in his answer, either hook a callback to theuser_has_cap
filter, or the filter insideget_user_meta()
– acutally a filter insideget_metadata()
– namedNow a callback would look like the following. Make sure it’s hook as close to the welcome panel action as possible.
'all_admin_notices'
would be a nice fit.Make sure that you only trigger this filter callback on the dashboard and only once. Else you’d give a user unwanted capabilities, resulting in users having access to your actual theme settings. I used the WCM Current Admin Info plugin to retrieve that data.
Additional: Show the welcome panel always
Users can dismiss the welcome panel. Sometimes we don’t want that as we assume that they haven’t read our important info/notes or for whatever reason. Note: You’ll need to internals yourself.
Custom content for the “Welcome Panel”
Now the first thing we need to do is getting rid of the original content. Then we can add our custom content based on a users ID/Name/Role/etc. Therefore we utilize
wp_get_current_user()
, which returns an instance ofWP_User
filled with all data we need.Now you should be able to customize every bit of your “Welcome Panel” for every User/Role/Capability.
Reference MarkUp
A good reference to start coding your own “Welcome Panel” content for your user is cores default
wp_welcome_panel()
function.There are two ways to do that.
You can (a) Edit capability from
edit_theme_options
toread
in wp source code.or (c) Change (override) capabilty on a fly for wp-admin/index.php for any usertype…
My recommendation – do not do a and/or b.
homepage of wp-admin) that person don’t really need. Its a security
HOLE.
In this case you can deploy your panel just nead admin_footer action and using jQuery move it to the top