PluginProbe
Advanced Custom Fields (ACF®) / 6.0.7
Advanced Custom Fields (ACF®) v6.0.7
6.8.9 6.8.8 6.8.7 6.8.6 6.8.5 6.8.4 6.8.3 6.8.2 6.8.1 5.8.5 5.8.6 5.8.7 5.8.8 5.8.9 5.9.0 5.9.1 5.9.2 5.9.3 5.9.4 5.9.5 5.9.6 5.9.7 5.9.8 5.9.9 6.0.0 All 230 releases
advanced-custom-fields / includes / acf-user-functions.php
acf-user-functions.php
120 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * acf_get_users
5 *
6 * Similar to the get_users() function but with extra functionality.
7 *
8 * @date 9/1/19
9 * @since 5.7.10
10 *
11 * @param array $args The query args.
12 * @return array
13 */
14 function acf_get_users( $args = array() ) {
15
16 // Get users.
17 $users = get_users( $args );
18
19 // Maintain order.
20 if ( $users && $args['include'] ) {
21
22 // Generate order array.
23 $order = array();
24 foreach ( $users as $i => $user ) {
25 $order[ $i ] = array_search( $user->ID, $args['include'] );
26 }
27
28 // Sort results.
29 array_multisort( $order, $users );
30 }
31
32 // Return
33 return $users;
34 }
35
36 /**
37 * acf_get_user_result
38 *
39 * Returns a result containing "id" and "text" for the given user.
40 *
41 * @date 21/5/19
42 * @since 5.8.1
43 *
44 * @param WP_User $user The user object.
45 * @return array
46 */
47 function acf_get_user_result( $user ) {
48
49 // Vars.
50 $id = $user->ID;
51 $text = $user->user_login;
52
53 // Add name.
54 if ( $user->first_name && $user->last_name ) {
55 $text .= " ({$user->first_name} {$user->last_name})";
56 } elseif ( $user->first_name ) {
57 $text .= " ({$user->first_name})";
58 }
59 return compact( 'id', 'text' );
60 }
61
62
63 /**
64 * acf_get_user_role_labels
65 *
66 * Returns an array of user roles in the format "name => label".
67 *
68 * @date 20/5/19
69 * @since 5.8.1
70 *
71 * @param array $roles A specific array of roles.
72 * @return array
73 */
74 function acf_get_user_role_labels( $roles = array() ) {
75 $all_roles = wp_roles()->get_names();
76
77 // Load all roles if none provided.
78 if ( empty( $roles ) ) {
79 $roles = array_keys( $all_roles );
80 }
81
82 // Loop over roles and populare labels.
83 $lables = array();
84 foreach ( $roles as $role ) {
85 if ( isset( $all_roles[ $role ] ) ) {
86 $lables[ $role ] = translate_user_role( $all_roles[ $role ] );
87 }
88 }
89
90 // Return labels.
91 return $lables;
92 }
93
94 /**
95 * acf_allow_unfiltered_html
96 *
97 * Returns true if the current user is allowed to save unfiltered HTML.
98 *
99 * @date 9/1/19
100 * @since 5.7.10
101 *
102 * @param void
103 * @return bool
104 */
105 function acf_allow_unfiltered_html() {
106
107 // Check capability.
108 $allow_unfiltered_html = current_user_can( 'unfiltered_html' );
109
110 /**
111 * Filters whether the current user is allowed to save unfiltered HTML.
112 *
113 * @date 9/1/19
114 * @since 5.7.10
115 *
116 * @param bool allow_unfiltered_html The result.
117 */
118 return apply_filters( 'acf/allow_unfiltered_html', $allow_unfiltered_html );
119 }
120