You have to wait for wp_loaded to use get_current_user_id().
Example:
add_action( 'wp_loaded', 'wpse_80061_load_dashboard_widget' );
function wpse_80061_load_dashboard_widget()
{
if ( 1 === get_current_user_id() )
add_action( 'wp_dashboard_setup', 'wpse_80061_add_dashboard_widget' );
// your function:
// add_action( 'wp_dashboard_setup', 'my_catdb_setup' );
}
function wpse_80061_add_dashboard_widget()
{
wp_add_dashboard_widget(
'wpse_80061_widget',
'Hey!',
'wpse_80061_render_dashboard_widget'
);
}
function wpse_80061_render_dashboard_widget()
{
echo 'hey!';
}
For a dashboard widget with more details see my plugin T5 Table size dashboard widget.
Related Posts:
- wp_count_posts, wp_count_terms and wp_count_comments for specific user?
- WordPress 3.8 – Dashboard 1 Column Screen Options
- Extend WordPress 3.8 Site Activity Dashboard Widget to include more comments
- Indexes of widgets instances starts with ‘2’ in ‘wp_options’ table
- Embed iframe or html page into dashboard widget
- Storing custom dashboard widget options in wordpress
- How to Remove All Widgets from Dashboard?
- How to use control_callback when creating a widget via functions.php or plugin?
- Reorder dashboard widgets
- How do I use the control callback when creating a simple dashboard plugin
- How to Make a Custom Dashboard Widget to Display Custom Notification from Admin?
- Add a banner to the Dashboard
- Different rss feeds in a single dashboard widget
- How do I pass arguments to dashboard widget callback functions?
- Add new section to “Right Now” widget
- add widgets to dashboard for easy access for clients?
- Widgets not expanding on wordpress 3.3 widget dashbord
- Replace dashboard widgets with banner ad
- Custom dashboard widget search box
- Get widget Title from widget id
- Hide all Dashboard Widgets (not remove)
- wp_editor is not rendering shortcode
- Dashboard Widgets – Add Admin Page With Same Functionality
- Custom User Field in Dashboard Widget
- How to make a can’t hide widget?
- Create widget in dashboard displaying a custom user field?
- Fire on widgets_init only on dashboard
- RSS dashboard widget not showing visuals
- How to call widget by widget’s id?
- How to position custom dashboard widgets on side column
- Grabbing how Many Posts by Month for a Dashboard Widget
- Dashboard Widget drawn before opening HTML tag
- Remove “Content” and “Discussion” from Right Now Dashboard Widget
- Create Dashboard Widget with form to keep team’s record
- modifying title (in dashboard) for different widget instances
- Adding a single text input field to a custom Dashboard widget
- Adding dashboard widgets to show – custom post type stats, information from other plugins
- Change number of widget columns in dashboard?
- Allow users to give a dashboard widget a custom name using ACF
- Quick Draft widget in weird place on dashboard after being re-added
- A message to clients in the dashboard widget received from another site
- Set a dashboard widget to the top?
- Array showing all values of loop instead of specific value to post
- How can I remove WordPress element IDs and Class names in the HTML?
- Dynamic Bootstrap Carousel ID per widget on same page
- How can I add a widget area to the top of the Dashboard?
- Display Login user name in Thim:login Popup widget
- How to customize WordPress dashboard for different users?
- How to get widget content in WordPress based on it’s ID?
- Can I use wp_widget_rss_output to show my site’s feed in the dashboard?
- WordPress version quick check?
- Registered widget is showing up collapsed in the dashboard
- can’t edit widgets after moving from subfolder to root
- Taxonomies not showing in WP Dashboard Right Now widget
- How to make custom dashboard widget to display alert in front-end?
- How to show WordPress Dashboard Widgets on Frontend?
- class WP_Widget – Different dashboard preview for custom widget
- Unable to add options on dashboard widget ?
- Custom dashboard widget – load style only for added widget
- How to add the “page” post type to Recent Activity widget displayed in admin?
- Create custom dashboard for plugin
- Programmatically add widgets to sidebars
- Dashboard widget custom positioning?
- is_tax() not working in Widget Logic [closed]
- One register_sidebar function works, the other doesn’t?
- Modify WordPress widgets Screen
- What does apply_filters() do exactly? [duplicate]
- How to change color of registered widget areas in admin?
- Filter Text from sidebar widget?
- How to filter widget(s) based on a specific category landing page
- Search transients through widget
- Change the background color of my theme widgets
- Change Woocommerce Product Categories Widget ‘Title’ based on Product Category
- Output column number according to active sidebars
- Why isn’t my custom widget outputting any content?
- Why would apply_filters return a non-empty string, when the value returned is empty?
- Given multiple admin accounts, how can I make it so that only admin with X username can edit posts
- How to customize wordpress sidebar widget
- Jquery checkbox -show posts with checked tags
- How to translate widget titles in 2021 theme?
- Widget editing returns JSON response error
- Quick Draft widget (dashboard.php) using custom post_type
- why the code html apear in this widget in footer
- A checkbox Option for description in Widget
- How to use url formatter with integer
- My widgets do not save
- Handling dozens of sidebars
- Changed meta_key value in structures, now dashboard shows zero users
- Inkness theme sidebar
- My Email Newsletter plugin will not configure when I try to import the widget
- Automatically hide Widgets that would lengthen page
- get USER ID in functions.php using user_register action
- Add New Footer Widget Area with Limited Options?
- Imported blog page layout messed
- Widget options – where to put them?
- I add some js files from a plugin to a specific location
- Include widget within newsletter template?
- My understrap-child theme doesent have a head.php, footer.php
- Database size Widget
- How to tell if a dynamic sidebar is being displayed on page?