Blocks
1 week ago
Datastore
1 month ago
Meta
1 year ago
abilities
1 week ago
admin
1 week ago
ajax
1 month ago
api
2 days ago
fields
2 days ago
forms
2 days ago
legacy
1 year ago
locations
1 year ago
post-types
2 months ago
rest-api
1 week ago
walkers
1 year ago
acf-bidirectional-functions.php
1 year ago
acf-field-functions.php
2 months ago
acf-field-group-functions.php
7 months ago
acf-form-functions.php
1 year ago
acf-helper-functions.php
1 year ago
acf-hook-functions.php
1 year ago
acf-input-functions.php
7 months ago
acf-internal-post-type-functions.php
7 months ago
acf-meta-functions.php
3 weeks ago
acf-post-functions.php
1 year ago
acf-post-type-functions.php
1 year ago
acf-taxonomy-functions.php
1 year ago
acf-user-functions.php
1 week ago
acf-utility-functions.php
1 year ago
acf-value-functions.php
1 year ago
acf-wp-functions.php
2 days ago
assets.php
1 week ago
blocks-auto-inline-editing.php
2 months ago
blocks.php
3 weeks ago
class-acf-data.php
10 months ago
class-acf-internal-post-type.php
1 week ago
class-acf-options-page.php
1 year ago
class-acf-site-health.php
3 months ago
class-scf-json-schema-validator.php
6 months ago
class-scf-schema-builder.php
2 months ago
compatibility.php
1 year ago
datastore.php
1 month ago
deprecated.php
1 year ago
fields.php
10 months ago
index.php
1 year ago
l10n.php
1 year ago
local-fields.php
1 year ago
local-json.php
1 month ago
local-meta.php
1 year ago
locations.php
1 year ago
loop.php
10 months ago
media.php
1 year ago
rest-api.php
10 months ago
revisions.php
1 month ago
scf-ui-options-page-functions.php
1 year ago
third-party.php
7 months ago
upgrades.php
3 weeks ago
validation.php
10 months ago
wpml.php
1 year ago
acf-user-functions.php
116 lines
| 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 ACF 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 && ! empty( $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 ACF 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 ACF 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 populate 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 | * Returns true if the current user is allowed to save unfiltered HTML. |
| 96 | * |
| 97 | * @since ACF 5.7.10 |
| 98 | * |
| 99 | * @return boolean |
| 100 | */ |
| 101 | function acf_allow_unfiltered_html() { |
| 102 | |
| 103 | // Check capability. |
| 104 | $allow_unfiltered_html = current_user_can( 'unfiltered_html' ); |
| 105 | |
| 106 | /** |
| 107 | * Filters whether the current user is allowed to save unfiltered HTML. |
| 108 | * |
| 109 | * @date 9/1/19 |
| 110 | * @since ACF 5.7.10 |
| 111 | * |
| 112 | * @param bool $allow_unfiltered_html Can the current user save unfiltered HTML. |
| 113 | */ |
| 114 | return apply_filters( 'acf/allow_unfiltered_html', $allow_unfiltered_html ); |
| 115 | } |
| 116 |