2

I am looking for a way to achieve the following:

  1. A group of users 'students'

  2. They login to the site

  3. Each student can see a 'Custom Dashboard Widget(s)'

  4. Each widget will carry a personal message wrote by Admin for that logged-in student. Such as A] Total Days in the course B] Total attendance C] paid & due fees.

Is it possible with WP or should we look for another CMS to achieve these?

2
  • (: Why would you have to look for another CMS ¿?
    – brasofilo
    Jul 29, 2012 at 13:07
  • client deadlines come randomly with label 'urgent', they don't listen sometimes :)
    – tushonline
    Sep 18, 2012 at 13:50

1 Answer 1

4

This can be solved using custom meta fields in the user profile (only visible to administrators) and then making an individual dashboard widget containing this meta (only visible if certain criteria is met).

Adding fields to the user profile page can be done:

1) manually

2) by a plugin

The previous Answer used another plugin, but the Comments thread explains the change.
Appart from being well coded and maintained, Advanced Custom Fields is incredibly handy.

2a) Setting up Custom User Fields

acf config thumbnail snapshot
click to enlarge

2b) Administrator editing an user

/wp-admin/user-edit.php?user_id=7
acf user editing

2c) Non-admin users viewing the Dashboard

The following will display (or not) each user a personalized message.

/**
 * Add Dashboard Widget
 */
add_action('wp_dashboard_setup', 'wpse_51591_wp_dashboard_setup');


/**
 * Only builds the Widget if the display message checkbox is enabled in the user editing screen 
 */
function wpse_51591_wp_dashboard_setup() 
{
    global $current_user;
    get_currentuserinfo();
    $show_msg = get_field( 'user_message_enable', 'user_' . $current_user->ID );
    $widget_title = 'Personal Messages to ' . $current_user->data->display_name;
    if( $show_msg )
        wp_add_dashboard_widget( 'wpse_user_personal_message', $widget_title, 'wpse_51591_wp_dashboard_per_user' );
}

/**
 * Content of Dashboard Widget
 * Shows the content of each user's custom message
 */
function wpse_51591_wp_dashboard_per_user() 
{
    global $current_user;
    get_currentuserinfo();
    $the_msg = get_field( 'user_message_text', 'user_' . $current_user->ID );
    echo $the_msg;
}

Results in:
enter image description here


Bonus code
Adding a bit of UX into ACF: show/hide the Message Textbox if the Enable Message Checkbox is checked or not.
It's better to change the order of the fields in ACF config, first checkbox then textbox.

add_action( 'admin_head-user-edit.php', 'wpse_51591_acf_profile' );
add_action( 'admin_head-user-new.php', 'wpse_51591_acf_profile' );

function wpse_51591_acf_profile() 
{
    ?>
    <script type="text/javascript">
    jQuery(document).ready( function($) 
    {       
        /* Wait 1.4s for ACF to be ready */
        setTimeout(function() {
            // find our checkbox
            var the_check = $('#acf-user_message_enable').find('input:last');
            
            // default state
            if( $(the_check).is(':checked') )
                $('#acf-user_message_text').fadeIn();
            else
                $('#acf-user_message_text').fadeOut();
                
            // live changes
            $(the_check).change(function () 
            {   
                if( $(this).is(':checked') ) 
                    $('#acf-user_message_text').fadeIn();
                else
                    $('#acf-user_message_text').fadeOut();
            });
        }, 1400);
        
        });
    </script>
    <?php
}
5
  • "Cimy user extra fields" is undocumented, non-OOP bloat ware. Sorry to say that. :/
    – kaiser
    Jul 29, 2012 at 1:21
  • 1
    @kaiser : Don't be, then. Glad to hear an informed opinion. I don't even use it anymore, Advanced Custom Fields got my back now :) . . . Am marking this A for a remake.
    – brasofilo
    Jul 29, 2012 at 1:29
  • 1
    Btw: Interesting connected question on UX.
    – kaiser
    Jul 29, 2012 at 1:57
  • @kaiser What have you done?! . . The plugin just evaporated from the Repo, is this some kind of zombie power of yours? . . LOL
    – brasofilo
    Jul 29, 2012 at 10:54
  • äte it! ääähte it! :D
    – kaiser
    Jul 29, 2012 at 11:51

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.