I will start by warning you that my programming skill is limited.
I need to create a dashboard widget that will display in the WP dashboard for the users with the user_id=21.
So far I have tried the following code, but it isn’t working:
function my_catdb() {
echo '<a href="http://xxxxxxxxxxx.org/?frm_display=single-catproblem">View the Problem Problem Database.</a>';
}
/**
* add Dashboard Widget via function wp_add_dashboard_widget()
*/
function my_catdb_setup() {
wp_add_dashboard_widget( 'my_catdb', __( 'Cataloging Problem Database' ), 'my_catdb' );
}
/**
* use hook, to integrate new widget
*/
$user_id = get_current_user_id();
if ( is_user_logged_in() ) {
if ( $user_id = 21 ) {
add_action('wp_dashboard_setup', 'my_wp_dashboard_setup');
}
}
Any help is appreciated.
Thanks
You have to wait for
wp_loaded
to useget_current_user_id()
.Example:
For a dashboard widget with more details see my plugin T5 Table size dashboard widget.