-function get_author_user_ids() {
- global $wpdb;
- $level_key = $wpdb->prefix . 'user_level';
-
- $query = "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$level_key' AND meta_value != '0'";
-
- return $wpdb->get_col( $query );
-}
-
-function get_editable_authors( $user_id ) {
- global $wpdb;
-
- $editable = get_editable_user_ids( $user_id );
-
- if( !$editable ) {
- return false;
- } else {
- $editable = join(',', $editable);
- $authors = $wpdb->get_results( "SELECT * FROM $wpdb->users WHERE ID IN ($editable) ORDER BY display_name" );
- }
-
- return apply_filters('get_editable_authors', $authors);
-}
-
-function get_editable_user_ids( $user_id, $exclude_zeros = true ) {
- global $wpdb;
-
- $user = new WP_User( $user_id );
-
- if ( ! $user->has_cap('edit_others_posts') ) {
- if ( $user->has_cap('edit_posts') || $exclude_zeros == false )
- return array($user->id);
- else
- return false;
- }
-
- $level_key = $wpdb->prefix . 'user_level';
-
- $query = "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$level_key'";
- if ( $exclude_zeros )
- $query .= " AND meta_value != '0'";
-
- return $wpdb->get_col( $query );
-}
-
-function get_nonauthor_user_ids() {
- global $wpdb;
- $level_key = $wpdb->prefix . 'user_level';
-
- $query = "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$level_key' AND meta_value = '0'";
-
- return $wpdb->get_col( $query );
-}
-
-function get_others_unpublished_posts($user_id, $type='any') {
- global $wpdb;
-
- $editable = get_editable_user_ids( $user_id );
-
- if ( in_array($type, array('draft', 'pending')) )
- $type_sql = " post_status = '$type' ";
- else
- $type_sql = " ( post_status = 'draft' OR post_status = 'pending' ) ";
-
- $dir = ( 'pending' == $type ) ? 'ASC' : 'DESC';
-
- if( !$editable ) {
- $other_unpubs = '';
- } else {
- $editable = join(',', $editable);
- $other_unpubs = $wpdb->get_results("SELECT ID, post_title, post_author FROM $wpdb->posts WHERE post_type = 'post' AND $type_sql AND post_author IN ($editable) AND post_author != '$user_id' ORDER BY post_modified $dir");
- }
-
- return apply_filters('get_others_drafts', $other_unpubs);
-}
-
-function get_others_drafts($user_id) {
- return get_others_unpublished_posts($user_id, 'draft');
-}
-
-function get_others_pending($user_id) {
- return get_others_unpublished_posts($user_id, 'pending');
+/**
+ * Fetch a filtered list of user roles that the current user is
+ * allowed to edit.
+ *
+ * Simple function who's main purpose is to allow filtering of the
+ * list of roles in the $wp_roles object so that plugins can remove
+ * inappropriate ones depending on the situation or user making edits.
+ * Specifically because without filtering anyone with the edit_users
+ * capability can edit others to be administrators, even if they are
+ * only editors or authors. This filter allows admins to delegate
+ * user management.
+ *
+ * @since 2.8.0
+ *
+ * @return unknown
+ */
+function get_editable_roles() {
+ global $wp_roles;
+
+ $all_roles = $wp_roles->roles;
+
+ /**
+ * Filter the list of editable roles.
+ *
+ * @since 2.8.0
+ *
+ * @param array $all_roles List of roles.
+ */
+ $editable_roles = apply_filters( 'editable_roles', $all_roles );
+
+ return $editable_roles;