3

On the Dashboard tab in wp-admin in my user account, I have certain items hidden in Screen Options and I have the panels arranged in a particular way.

I want to copy the same layout to my other administrative users, so that they can see certain information and so that I can more easily remotely explain things when I need to.

I assume that this information is contained in a database table.

What would I need to copy to where?

0
6

Original code (License: MIT)

The following code is altered from my "Meta Box Order debug" plugin (available on GitHub as Gist). The explanation can be found in the code comments.

Benefit

The nice thing with this solution is, that it does not alter the DB values, but alters the data on the fly. This way you can any time revert the changes and/or use another user as "data origin".

Another benefit is, that you can add a single dummy user that you simply use as blueprint. Every time you want to change the layout for everyone, simply log in with this user and alter the meta boxes on the dashboard. This way you can alter the configuration without writing a single line of code.

@TODO

You will have to change the user ID - this is marked as @TODO - to the user ID that you actually want to clone from/use as "origin".

<?php

namespace WPSE;

/**
 * Plugin Name: (#144583) Clone Meta Box Order
 */

add_filter( 'get_user_metadata', 'WPSE\disableMetaBoxOrder', 10, 4 );
function disableMetaBoxOrder( $abort, $userID, $key, $single )
{
    // Too early: abort
    if (
        ! function_exists( 'get_current_screen' )
        OR NULL === get_current_screen()
        OR ! property_exists( get_current_screen(), 'base' )
    )
        return $abort;

    // Don't trigger on the wrong screens
    if ( 'dashboard' !== get_current_screen()->base  )
    {
        remove_filter( current_filter(), __FUNCTION__ );
        return $abort;
    }

    $target  = 'meta-box-order_dashboard';

    // This is the part that actually alters/clones the user data
    // Trigger on default as on site specific settings
    if (
        $key === $target
        OR $key === $GLOBALS['wpdb']->prefix.$target
        )
    {
        // Prevent endless loop
        remove_filter( current_filter(), __FUNCTION__ );

        return get_user_meta(
            # @TODO Replace the next line with the user ID 
            # that you want to clone from (the origin)
            get_current_user_id(),
            $target,
            TRUE
        );
    }

    return $abort;
}
10
  • Sorry about the delay in replying, lol. I cannot figure out where to add the user ID, which is 7.
    – paradroid
    Feb 23 '17 at 15:27
  • @paradroid Exactly where I added the @TODO-comment in the code. get_current_user_id() should be replaced by the User ID (or better: a function that returns the ID of the user) you want to clone from.
    – kaiser
    Feb 23 '17 at 16:07
  • I'm sorry, but I do not understand. I replaced get_current_user_id(), with 7,, but of course it didn't work.
    – paradroid
    Feb 23 '17 at 16:09
  • I currently do not have a WP installation around to test this, but you can remove the above if statements to see if they are blocking things. Keep in mind that this is for the dashboard and the meta box order.
    – kaiser
    Feb 23 '17 at 16:19
  • I tried removing the if statements, but it still didn't work. :/
    – paradroid
    Feb 23 '17 at 16:25
1

Take a look in the Database in the {$prefix}usermeta table. There is a field named:

meta-box-order_dashboard

You'll need to poke around and get some more fields however. There are a number of other tables which store dashboard panes and states, this i cant guess at as depending on your user base, plugins, etc.. the values you'll need will depend on that.

The majority of usermeta is dedicated to these and other administrative settings.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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