PluginProbe
Metricool – Social media and site statistics / 2.1.1
Metricool – Social media and site statistics v2.1.1
2.1.1 2.1.0 2.0.2 2.0.1 2.0.0 1.27 trunk
← All changes | app/Traits/HasUserAccess.php +40 -0 2.0.1 → 2.1.1 View file →
@@ -1,0 +1,40 @@
1 +<?php
2 +
3 +declare(strict_types=1);
4 +
5 +namespace Metricool\Traits;
6 +
7 +trait HasUserAccess
8 +{
9 + /**
10 + * Return the first name of the current user
11 + */
12 + protected function getCurrentUserFirstName(): string
13 + {
14 + $cacheName = 'metricool_current_user_first_name';
15 + $cacheGroup = 'metricool_has_user_access';
16 + $cacheValue = wp_cache_get($cacheName, $cacheGroup);
17 +
18 + if (!empty($cacheValue)) {
19 + return $cacheValue;
20 + }
21 +
22 + $firstName = '';
23 + $user = wp_get_current_user();
24 +
25 + if (!empty($user->first_name)) {
26 + $firstName = ucfirst($user->first_name);
27 + }
28 +
29 + if (empty($firstName) && !empty($user->user_nicename)) {
30 + $firstName = ucfirst($user->user_nicename);
31 + }
32 +
33 + if (empty($firstName) && !empty($user->display_name)) {
34 + $firstName = ucfirst($user->display_name);
35 + }
36 +
37 + wp_cache_set($cacheName, $firstName, $cacheGroup);
38 + return $firstName;
39 + }
40 +}