PluginProbe
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses / 2.6.01
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses v2.6.01
2.11.0 2.10.0 2.10.01 2.9.1 2.9.0 2.8.1 2.8.0 2.7.7 2.7.5 2.7.0 2.6.01 2.6.0 2.5.0 2.4.01 trunk 1.0.90 1.0.91 1.0.92 1.0.93 1.0.94 1.0.95 1.0.96 1.0.97 1.0.98 1.0.99 All 78 releases
fluent-community / vendor / wpfluent / framework / src / WPFluent / Database / Orm / UserProxyTrait.php

UserProxyTrait.php in FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses 2.6.01, at vendor/wpfluent/framework/src/WPFluent/Database/Orm/UserProxyTrait.php

75 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentCommunity\Framework\Database\Orm;
4
5 use WP_User;
6 use BadMethodCallException;
7 use InvalidArgumentException;
8 use FluentCommunity\Framework\Http\Request\WPUserProxy;
9
10 trait UserProxyTrait
11 {
12 /**
13 * Resolve the WPUserProxy instance.
14 *
15 * Always returns a live WPUserProxy reflecting latest WP_User data.
16 *
17 * @return WPUserProxy
18 */
19 protected function resolveWPUser()
20 {
21 $userIdentifier = $this->getKey() ?: wp_get_current_user();
22
23 return new WPUserProxy($userIdentifier);
24 }
25
26 /**
27 * Dual-purpose is() method:
28 * - is(string $role) - checks user role
29 * - is(User $model) - checks model identity
30 *
31 * @param string|self $value
32 * @return bool
33 */
34 public function is($value)
35 {
36 if (is_string($value)) {
37 return $this->resolveWPUser()->is($value);
38 }
39
40 if ($value instanceof static) {
41 return parent::is($value);
42 }
43
44 return false;
45 }
46
47 /**
48 * Dynamically call methods on the WPUserProxy if not found in the model.
49 *
50 * @param string $method
51 * @param array $args
52 * @return mixed
53 *
54 * @throws BadMethodCallException|InvalidArgumentException
55 */
56 public function __call($method, $args)
57 {
58 try {
59 return parent::__call($method, $args);
60 } catch (BadMethodCallException $e) {
61 try {
62 return $this->resolveWPUser()->$method(...$args);
63 } catch (BadMethodCallException $proxyError) {
64 throw $proxyError;
65 } catch (InvalidArgumentException $invalidUser) {
66 throw new BadMethodCallException(
67 "Call to undefined method " . static::class . "::{$method}()",
68 0,
69 $invalidUser
70 );
71 }
72 }
73 }
74 }
75