Plugin Directory

Changeset 1977717


Ignore:
Timestamp:
11/20/2018 11:03:02 PM (7 years ago)
Author:
lcwakeman
Message:

2.0

  • Default User role for import.
  • No default password for newe users on import, they can set password with Forgot Pasaword link on login.
  • Clean up code for Options page. Added Dropdown to select Default User Role.
Location:
dmc-user-list
Files:
42 added
3 edited

Legend:

Unmodified
Added
Removed
  • dmc-user-list/trunk/dmc_user_list.php

    r1959389 r1977717  
    22/**
    33Plugin Name: DMC User List
    4 Version: 1.13
     4Version: 2.0
    55Plugin URI: tbd
    66Donate URI: tbd
  • dmc-user-list/trunk/objects/dmc_user_admin.php

    r1959389 r1977717  
    3232  protected $user = array();
    3333  protected $meta = array();
     34 
     35  protected $default_role;
    3436
    3537/**
     
    3941    }
    4042
    41 /**
    42 * class initialization.
    43 */
    44     function initialize ($plugin_url, $plugin_dir, $option_class) {
    45         global $wpdb;
    46         $this->plugin_url = $plugin_url;
    47         $this->plugin_dir = $plugin_dir;
    48         $this->option_class = $option_class;
     43
     44/**
     45* Page Javascript
     46*/
     47    function  header_javascript () {
     48        // Get list of user fields     
     49        $this->user = wp_get_current_user()->data;
     50        echo '<center>';
     51        foreach ($this->meta as $key => $item) {
     52            $var = '$this->user->'.$item['meta_key'].' = \''.$key.'\';';
     53            if (!strpos($item['meta_key'], '-')) @eval ($var);
     54        }
     55        echo '</center>';
     56        $flush = array('ID', 'user_pass', 'user_url', 'user_registered', 'user_activation_key', 'user_status',
     57                                     'rich_editing', 'comment_shortcuts', 'admin_color', 'show_admin_bar_front', 'wp_user_level',
     58                                     'dismissed_wp_pointers', 'show_welcome_panel', 'wp_dashboard_quick_press_last_post_id',
     59                                     'nav_menu_recently_edited',  'closedpostboxes_event', 'metaboxhidden_event', 'session_tokens', 'use_ssl', );
     60        foreach ($flush as $item) unset($this->user->$item);
     61?>
     62<script type="text/javascript" >
     63    var index = -1;
     64    var map_index = -1;
     65   
     66    function add_sort(myindex, listvalue, listorder) {
     67        var old_index = index;
     68        if (myindex === undefined) {
     69            index++;
     70        } else {
     71            if (myindex > index) index = myindex;
     72        }
     73        var save_columns = [];
     74        var save_sort = [];
     75        for (var i = 0; i < index; i++) {
     76            save_columns.push(jQuery('#column-'+i).val());
     77            save_sort.push(jQuery('#sort-'+i).val());
     78        }
     79        var contents = '';
     80        if (index != 0) contents += '<br id="break-'+old_index+'"/>\n';
     81        contents += '   <select name="column-'+index+'" id="column-'+index+'" onchange="javascript: checkdelete(this);">\n';
     82        contents += '       <option value="-1">Select a column to sort.</option>\n';
     83        contents += '       <option value="0">delete this sort.</option>\n';
     84<?php
     85        foreach ($this->user as $key => $entry) {
     86            if ($key != 'basic_user_avatar') {
     87                $key2 = str_replace('user_', '', str_replace('dbem_', '', $key));
     88?>
     89        contents += '       <option value="<?php echo $key; ?>"';
     90        if (listvalue == '<?php echo $key; ?>') contents += ' selected="selected"';
     91        contents += '><?php echo $key2; ?></option>\n';
     92<?php
     93            }
     94        }
     95?>
     96        contents += '   </select>';
     97        contents += '   <select name="sort-'+index+'" id="sort-'+index+'">\n';
     98        contents += '       <option value="asc"';
     99        if (listorder == 'asc') contents += ' selected="selected"';
     100        contents += '>ascending</option>\n';
     101        contents += '       <option value="desc"';
     102        if (listorder == 'desc') contents += ' selected="selected"';
     103        contents += '>decending</option>\n';
     104        contents += '   </select>';
     105        jQuery('#sorts_td').html(jQuery('#sorts_td').html() + contents);
     106        for (var i = 0; i < index; i++) {
     107            jQuery('#column-'+i).val(save_columns[i])
     108            jQuery('#sort-'+i).val(save_sort[i])
     109        }
     110    }
     111   
     112   
     113    function add_mapping(field, column) {
     114        var contents = '';
     115        map_index++;
     116        if (column === undefined) column = '';
     117        contents += '   <select name="mapping-'+map_index+'" id="mapping-'+map_index+'" onchange="javascript: checkmapdelete(this);">\n';
     118        contents += '       <option value="-1">Select a column to map.</option>\n';
     119        contents += '       <option value="0">delete this mapping.</option>\n';
     120<?php
     121        foreach ($this->user as $key => $entry) {
     122?>
     123        contents += '       <option value="<?php echo $key; ?>"';
     124        if (field == '<?php echo $key; ?>') contents += ' selected="selected"';
     125        contents += '><?php echo $key; ?></option>\n';
     126<?php
     127        }
     128?>
     129        contents += '   </select>';
     130        contents += '<input type="text" value="' + column + '" name="map_column-'+map_index+'" id="map_column-'+map_index+'">';
     131        contents += '<br id="map_break-'+map_index+'"/>\n';
    49132       
    50         // Get class options
     133        jQuery('#mapping_td').html(jQuery('#mapping_td').html() + contents);
     134    }
     135   
     136    jQuery( document ).ready(function() {
     137<?php
     138        foreach ($this->options['sorts'] as $key => $entry) {
     139?>
     140            add_sort(<?php echo $key;?>, '<?php echo $entry['column']; ?>', '<?php echo $entry['direction']; ?>');
     141<?php
     142        }
     143        foreach ($this->options['export_mapping'] as $key => $entry) {
     144?>
     145            add_mapping('<?php echo $key;?>', '<?php echo $entry; ?>');
     146<?php
     147        }
     148?>
     149    });
     150
     151    function checkdelete(obj) {
     152        if (jQuery(obj).val() == 0) {
     153            jQuery(obj).hide();
     154            jQuery('#'+jQuery(obj).attr("id").replace('column', 'sort')).hide();
     155            jQuery('#'+jQuery(obj).attr("id").replace('column', 'break')).hide();
     156        }
     157    }
     158
     159    function checkmapdelete(obj) {
     160        if (jQuery(obj).val() == 0) {
     161            jQuery(obj).hide();
     162            jQuery('#'+jQuery(obj).attr("id").replace('mapping', 'map_column')).hide();
     163            jQuery('#'+jQuery(obj).attr("id").replace('mapping', 'map_break')).hide();
     164        }
     165    }
     166</script>
     167<?php
     168    }
     169   
     170    function cache_javascript() {
     171?>
     172<script type="text/javascript">
     173    jQuery( document ).ready(function() {
     174        window.location.reload(true);
     175    });
     176</script>
     177<?php
     178    }
     179   
     180/**
     181* Create Admin menus
     182*/
     183    function admin_menu () {
     184        add_menu_page( 'DMC User Listing','DMC User Listing','activate_plugins','dmc-user', array( &$this, 'DMC_user' ), $this->plugin_url.'images/people.png', 12 );
     185    add_submenu_page('dmc-user','DMC User Listing Export' ,'Export', 'activate_plugins', 'dmc-user-export', array(&$this, 'DMC_export'));
     186    add_submenu_page('dmc-user','DMC User Listing Import' ,'Import', 'activate_plugins', 'dmc-user-import', array(&$this, 'DMC_import'));
     187    }
     188
     189/**
     190* Get Class Optione
     191*/
     192    protected function getClassOptions() {
    51193    $this->options = get_option($this->option_class);
    52194        if (!isset($this->options['entry-stride'])) $this->options['entry-stride'] = 10;
     
    56198                                                                                                                                                             'direction' => 'asc',
    57199                                                                                                                                                        ));
    58         if (!isset($this->options['display_roles']))
    59             $this->options['display_roles'] = array(
    60                                                                                             'administrator' => true,
    61                                                                                             'editor' => true,
    62                                                                                             'author' => true,
    63                                                                                             'contributor' => true,
    64                                                                                             'subscriber' => true,
    65                                                                                          );
     200        $temp = wp_roles()->roles;
     201        $roles = array();
     202        foreach ($temp as $key => $role) $roles[$key] = $role['name'];
     203        $temp = array();
     204        foreach ($roles as $role => $data) $temp[$data] = $role;
     205        // remove spurious roles from options
     206        foreach ($this->options['display_roles'] as $role => $data)
     207            if (!isset($temp[$role])) unset ($this->options['display_roles'][$role]);
     208        // Add new roles
     209        foreach ($temp as $role => $data)
     210            if (!isset($this->options['display_roles'][$role])) $this->options['display_roles'][$role] = 0;
     211        if (!isset($this->options['default_role'])) $this->options['default_role'] = 'Contributor';
     212        update_option($this->option_class, $this->options);
     213        return $roles;
     214    }
     215   
     216/**
     217* class initialization.
     218*/
     219    function initialize ($plugin_url, $plugin_dir, $option_class) {
     220        global $wpdb;
     221        $this->plugin_url = $plugin_url;
     222        $this->plugin_dir = $plugin_dir;
     223        $this->option_class = $option_class;
     224        $this->getClassOptions();
    66225        $query = "SELECT DISTINCT meta_value FROM `".$wpdb->prefix."usermeta` WHERE meta_key = 'wp_capabilities'";
    67226        $results = $wpdb->get_results($query, ARRAY_A);
     
    106265       
    107266    }
    108 
    109 /**
    110 * Page Javascript
    111 */
    112     function  header_javascript () {
    113         // Get list of user fields     
    114         $this->user = wp_get_current_user()->data;
    115         echo '<center>';
    116         foreach ($this->meta as $key => $item) {
    117             $var = '$this->user->'.$item['meta_key'].' = \''.$key.'\';';
    118             if (!strpos($item['meta_key'], '-')) @eval ($var);
    119         }
    120         echo '</center>';
    121         $flush = array('ID', 'user_pass', 'user_url', 'user_registered', 'user_activation_key', 'user_status',
    122                                      'rich_editing', 'comment_shortcuts', 'admin_color', 'show_admin_bar_front', 'wp_user_level',
    123                                      'dismissed_wp_pointers', 'show_welcome_panel', 'wp_dashboard_quick_press_last_post_id',
    124                                      'nav_menu_recently_edited',  'closedpostboxes_event', 'metaboxhidden_event', 'session_tokens', 'use_ssl', );
    125         foreach ($flush as $item) unset($this->user->$item);
    126 ?>
    127 <script type="text/javascript" >
    128     var index = -1;
    129     var map_index = -1;
    130    
    131     function add_sort(myindex, listvalue, listorder) {
    132         var old_index = index;
    133         if (myindex === undefined) {
    134             index++;
    135         } else {
    136             if (myindex > index) index = myindex;
    137         }
    138         var save_columns = [];
    139         var save_sort = [];
    140         for (var i = 0; i < index; i++) {
    141             save_columns.push(jQuery('#column-'+i).val());
    142             save_sort.push(jQuery('#sort-'+i).val());
    143         }
    144         var contents = '';
    145         if (index != 0) contents += '<br id="break-'+old_index+'"/>\n';
    146         contents += '   <select name="column-'+index+'" id="column-'+index+'" onchange="javascript: checkdelete(this);">\n';
    147         contents += '       <option value="-1">Select a column to sort.</option>\n';
    148         contents += '       <option value="0">delete this sort.</option>\n';
    149 <?php
    150         foreach ($this->user as $key => $entry) {
    151             if ($key != 'basic_user_avatar') {
    152                 $key2 = str_replace('user_', '', str_replace('dbem_', '', $key));
    153 ?>
    154         contents += '       <option value="<?php echo $key; ?>"';
    155         if (listvalue == '<?php echo $key; ?>') contents += ' selected="selected"';
    156         contents += '><?php echo $key2; ?></option>\n';
    157 <?php
    158             }
    159         }
    160 ?>
    161         contents += '   </select>';
    162         contents += '   <select name="sort-'+index+'" id="sort-'+index+'">\n';
    163         contents += '       <option value="asc"';
    164         if (listorder == 'asc') contents += ' selected="selected"';
    165         contents += '>ascending</option>\n';
    166         contents += '       <option value="desc"';
    167         if (listorder == 'desc') contents += ' selected="selected"';
    168         contents += '>decending</option>\n';
    169         contents += '   </select>';
    170         jQuery('#sorts_td').html(jQuery('#sorts_td').html() + contents);
    171         for (var i = 0; i < index; i++) {
    172             jQuery('#column-'+i).val(save_columns[i])
    173             jQuery('#sort-'+i).val(save_sort[i])
    174         }
    175     }
    176    
    177    
    178     function add_mapping(field, column) {
    179         var contents = '';
    180         map_index++;
    181         if (column === undefined) column = '';
    182         contents += '   <select name="mapping-'+map_index+'" id="mapping-'+map_index+'" onchange="javascript: checkmapdelete(this);">\n';
    183         contents += '       <option value="-1">Select a column to map.</option>\n';
    184         contents += '       <option value="0">delete this mapping.</option>\n';
    185 <?php
    186         foreach ($this->user as $key => $entry) {
    187 ?>
    188         contents += '       <option value="<?php echo $key; ?>"';
    189         if (field == '<?php echo $key; ?>') contents += ' selected="selected"';
    190         contents += '><?php echo $key; ?></option>\n';
    191 <?php
    192         }
    193 ?>
    194         contents += '   </select>';
    195         contents += '<input type="text" value="' + column + '" name="map_column-'+map_index+'" id="map_column-'+map_index+'">';
    196         contents += '<br id="map_break-'+map_index+'"/>\n';
    197        
    198         jQuery('#mapping_td').html(jQuery('#mapping_td').html() + contents);
    199     }
    200    
    201     jQuery( document ).ready(function() {
    202 <?php
    203         foreach ($this->options['sorts'] as $key => $entry) {
    204 ?>
    205             add_sort(<?php echo $key;?>, '<?php echo $entry['column']; ?>', '<?php echo $entry['direction']; ?>');
    206 <?php
    207         }
    208         foreach ($this->options['export_mapping'] as $key => $entry) {
    209 ?>
    210             add_mapping('<?php echo $key;?>', '<?php echo $entry; ?>');
    211 <?php
    212         }
    213 ?>
    214     });
    215 
    216     function checkdelete(obj) {
    217         if (jQuery(obj).val() == 0) {
    218             jQuery(obj).hide();
    219             jQuery('#'+jQuery(obj).attr("id").replace('column', 'sort')).hide();
    220             jQuery('#'+jQuery(obj).attr("id").replace('column', 'break')).hide();
    221         }
    222     }
    223 
    224     function checkmapdelete(obj) {
    225         if (jQuery(obj).val() == 0) {
    226             jQuery(obj).hide();
    227             jQuery('#'+jQuery(obj).attr("id").replace('mapping', 'map_column')).hide();
    228             jQuery('#'+jQuery(obj).attr("id").replace('mapping', 'map_break')).hide();
    229         }
    230     }
    231 </script>
    232 <?php
    233     }
    234    
    235     function cache_javascript() {
    236 ?>
    237 <script type="text/javascript">
    238     jQuery( document ).ready(function() {
    239         window.location.reload(true);
    240     });
    241 </script>
    242 <?php
    243     }
    244    
    245 /**
    246 * Create Admin menus
    247 */
    248     function admin_menu () {
    249         add_menu_page( 'DMC User Listing','DMC User Listing','activate_plugins','dmc-user', array( &$this, 'DMC_user' ), $this->plugin_url.'images/people.png', 12 );
    250     add_submenu_page('dmc-user','DMC User Listing Export' ,'Export', 'activate_plugins', 'dmc-user-export', array(&$this, 'DMC_export'));
    251     add_submenu_page('dmc-user','DMC User Listing Import' ,'Import', 'activate_plugins', 'dmc-user-import', array(&$this, 'DMC_import'));
     267   
     268    function get_editable_roles() {
     269        $all_roles = wp_roles()->roles;
     270        $editable_roles = apply_filters( 'editable_roles', $all_roles );
     271        return $editable_roles;
    252272    }
    253273
     
    256276*/
    257277    function DMC_user() {
    258         $save_roles = $this->options['display_roles'];
    259278        if (isset($_POST['submit'])) {
    260             $sort_index = 0;
    261             $map_index = 0;
    262             $option_update['entry-stride'] = $_POST['entry-stride'];
    263             $option_update['avatar'] = $_POST['avatar'];
    264             $option_update['display_type'] = $_POST['display_type'];
    265             foreach ($_POST as $key => $value) {
    266                 if (strpos($key, 'column') !== false && strpos($key, 'map') === false) {
    267                     if (!is_numeric($value)) {
    268                         $indexes = explode('-', $key);
    269                         $option_update['sorts'][$sort_index]['column'] = $value;
    270                         $option_update['sorts'][$sort_index]['direction'] = $_POST['sort-'.$indexes['1']];
    271                         $sort_index++;
     279            unset ($_POST['submit']);
     280            $temp = array();
     281                foreach ($_POST as $key => $value) {
     282                    if (strpos($key, 'column') !== false && strpos($key, 'map') === false) {
     283                        if (!is_numeric($value)) {
     284                            $indexes = explode('-', $key);
     285                            $_POST['sorts'][$indexes[1]]['column'] = $value;
     286                            $_POST['sorts'][$indexes[1]]['direction'] = $_POST['sort-'.$indexes[1]];
     287                        }
     288                        unset ($_POST[$key]);
     289                        unset ($_POST['sort-'.$indexes[1]]);
     290                    }
     291                    if (strpos($key, 'mapping-') !== false) {
     292                        if (!is_numeric($value)) {
     293                            $indexes = explode('-', $key);
     294                            $_POST['export_mapping'][$value] = $_POST['map_column-'.$indexes['1']];
     295                        }
     296                        unset ($_POST[$key]);
     297                        unset ($_POST['map_column-'.$indexes[1]]);
    272298                    }
    273299                }
    274                 if (strpos($key, 'mapping') !== false) {
    275                     if (!is_numeric($value)) {
    276                         $indexes = explode('-', $key);
    277                         $option_update['export_mapping'][$value] = $_POST['map_column-'.$indexes['1']];
    278                     }
    279                 }
    280             }
    281             foreach ($save_roles as $key => $value) $option_update['display_roles'][$key] = false;
    282             foreach ($_POST['display_roles'] as $key => $value) {
    283                 if ($value == 'on') $option_update['display_roles'][$key] = true;
    284             }
    285             update_option($this->option_class, $option_update);
    286         $this->options = get_option($this->option_class);
     300            update_option($this->option_class, $_POST);
    287301            add_action( 'admin_footer', array( $this, 'cache_javascript') );
    288302        }
     303        $roles = $this->getClassOptions();
    289304?>
    290305<div id="wpbody-content" tabindex="0" aria-label="Main content">
     
    324339        }
    325340?>
     341                    </td>
     342                </tr>
     343                <tr>
     344                    <th scope="row"><label for="role">Default Role</label></th>
     345                    <td id="role_td">
     346                    <?php echo $this->options['default_role']; ?>
     347                        <select name="default_role" id="default_role">
     348<?php
     349        foreach ($roles as $key => $role) {
     350            $selected = '';
     351            if ($role == $this->options['default_role'] || $key == $this->options['default_role'])
     352                 $selected = ' selected="selected"';
     353            echo '                  <option value="'.$role.'"'.$selected.'>'.$role.'</option>';
     354        }
     355?>
     356                        </select>
    326357                    </td>
    327358                </tr>
  • dmc-user-list/trunk/readme.txt

    r1959389 r1977717  
    77Requires at least: 4.2.
    88Tested up to: 5.0
    9 Stable tag: 1.13
     9Stable tag: 2.0
    1010License: GPLv2 or later
    1111License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    9494* PHP 7.1 bug fix
    9595
     96= 2.0 =
     97* Default User role for import.
     98* No default password for newe users on import, they can set password with Forgot Pasaword link on login.
     99* Clean up code for Options page. Added Dropdown to select Default User Role.
     100
    96101== Upgrade Notice ==
    97102
     
    140145* PHP 7.1 bug fix
    141146
     147= 2.0 =
     148* Default User role for import.
     149* No default password for newe users on import, they can set password with Forgot Pasaword link on login.
     150* Clean up code for Options page. Added Dropdown to select Default User Role.
     151
    142152== Customization ==
    143153
Note: See TracChangeset for help on using the changeset viewer.