Support » Fixing WordPress » Duplicate user

  • Resolved fid

    (@fid)


    I have a user created (lets call it template) and with that user I have enabled / disabled certain things in the dashboard, such as hiding some widgets, columns, etc.

    Every time I create a new user, I want it to have the same settings as that template user.

    How can I do this?

    I am familiar with php, mysql.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi @fid! When a user disables a box on their dashboard, that setting is stored in the metaboxhidden_dashboard user meta field. The user meta for a new user can be customised using the insert_user_meta filter. In this filter, you could copy over the metaboxhidden_dashboard field from the template user.

    Example:

    function customize_user_meta( $meta, $user, $update ) {
    	if ( ! $update ) { // Run only when a user is created
    		$template_user = get_user_by( 'slug', 'template' );
    		$meta['metaboxhidden_dashboard'] = get_user_meta( $template_user->ID, 'metaboxhidden_dashboard', true );
    	}
    }
    add_filter( 'insert_user_meta', 'customize_user_meta', 10, 3 );

    https://developer.wordpress.org/reference/hooks/insert_user_meta/

    Thanks! Does this also work for hidden columns, dismissing notices, etc?

    Yes, though you might have to copy over more fields than in my example above. To figure out which user meta keys contain the settings that you want to copy, I suggest setting up WP CLI and running wp user meta list template to list all of the user meta for the ‘template’ user.

    https://wp-cli.org

    Thank you!

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.