3

There are many plugins out there that let you order Pages and/or Posts with drag and drop.

Is there something similar to order users?

Or if not, is it possible to create a plugin for that (i.e. are there sufficient filters, actions etc. in place?

5
  • 1
    Please edit your question and explain in detail why do you need to order users? What's the purpose it will serve for you? Commented Sep 1, 2013 at 16:58
  • @MayeenulIslam All the users on my site are also authors and I'd like to have them listed on a special page. And I'd like to be able to manually sort them. I hope that explanation might help... somehow...
    – frnhr
    Commented Sep 4, 2013 at 7:01
  • Even if we can't close the question right now: It's off topic as it's a plugin recommendation. Please edit it to bring it on topic. The help center might be of help to achieve that.
    – kaiser
    Commented Sep 17, 2013 at 14:54
  • 1
    The "special page" listing authors you are talking about: are you looking for a frontend, public page that lists the authors? How many authors do you have?
    – Ben Miller
    Commented Sep 17, 2013 at 21:00
  • if you want to use the shopping cart of drag and drop you can use ecwid for this its third party integration and have drag and drop facilities Commented Sep 18, 2013 at 8:48

2 Answers 2

5
+50

Quite a specific feature, never seen any plugin. But it's a matter of taking a drag'n'drop plugin and adapting it.

Here, a stripped and adapted version of My Link Order.
Description and to-do:

  • A new submenu is created in Users, My Users Order.
  • In the plugin page, execute the function orderUsers() in your browser console, you'll see the current order as an array. Drag and drop and execute again, the array shows the new order.
  • You'll have to use the Settings API or create your AJAX code to deal with saving the order as User Meta data.
  • The styles and scripts printed within the submenu callback should go in their own CSS and JS files, and enqueued accordingly.
<?php
/* Plugin Name: My Users Order */

add_action( 'admin_menu', 'myuserorder_menu' );

function myuserorder_menu()
{    
    $page = add_users_page(
        __( 'My Users Order', 'myuserorder' ), 
        __( 'My Users Order', 'myuserorder' ), 
        'manage_links', 
        'myuserorder', 
        'myuserorder'
    );
    add_action( "admin_print_scripts-$page", 'myuserorder_js_libs' );
}

function myuserorder_js_libs() 
{
    wp_enqueue_script( 'jquery-ui-sortable', false, array( 'jquery-ui-core', 'jquery' ) );
}

function myuserorder()
{
    ?>
    <div class='wrap'>
        <form name="frmMyUserOrder" method="post" action="">
            <h2><?php _e('My Users Order', 'myuserorder') ?></h2>   
            <ul id="myUserOrderList">
            <?php
            $results = get_users();
            foreach( $results as $user )
                echo "<li id='{$user->data->ID}' class='lineitem'>" . $user->data->display_name . "</li>";
            ?>
            </ul>
        </form>
    </div>

    <style type="text/css">
        #myUserOrderList {
            width: 90%; 
            border:1px solid #B2B2B2; 
            margin:10px 10px 10px 0px;
            padding:5px 10px 5px 10px;
            list-style:none;
            background-color:#fff;
            -moz-border-radius:3px;
            -webkit-border-radius:3px;
        }
        li.lineitem {
            border:1px solid #B2B2B2;
            -moz-border-radius:3px;
            -webkit-border-radius:3px;
            background-color:#F1F1F1;
            color:#000;
            cursor:move;
            font-size:13px;
            margin-top:5px;
            margin-bottom:5px;
            padding: 2px 5px 2px 5px;
            height:1.5em;
            line-height:1.5em;
        }       
        .sortable-placeholder{ 
            border:1px dashed #B2B2B2;
            margin-top:5px;
            margin-bottom:5px; 
            padding: 2px 5px 2px 5px;
            height:1.5em;
            line-height:1.5em;  
        }
    </style>

    <script language="JavaScript" type="text/javascript">
        function orderUsers() 
        {
            var newOrder = jQuery("#myUserOrderList").sortable("toArray");
            console.log( newOrder );
        }
        function myuserorderaddloadevent()
        {
            jQuery("#myUserOrderList").sortable({ 
                placeholder: "sortable-placeholder", 
                revert: false,
                tolerance: "pointer" 
            });
        };
        addLoadEvent( myuserorderaddloadevent );
    </script>
    <?php
}
1
  • 1
    Sweet concept - straight forward. +1
    – kaiser
    Commented Sep 18, 2013 at 21:22
2

It seems there is no such plugin...

So I created my own: https://github.com/cek125i/simple-user-ordering
(~300 php lines, too long to post here)

Influenced a lot by "Simple Page Ordering" plugin, but created from scratch.

The lousy truth about this problem is that there seems to be no built-in way to sort users by meta-value. Luckily I have only 10-20 users so hopefully it won't be too performance-expensive to sort them manually after fetching (that means one additional query per user to fetch meta value).

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.