PluginProbe
Elementor Website Builder – more than just a page builder / 3.5.6
Elementor Website Builder – more than just a page builder v3.5.6
4.3.0-beta3 4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 All 452 releases
← All changes | modules/library/user-favorites.php +25 -25 4.1.0-beta23.5.6 View file →
@@ -28,14 +28,14 @@
28 28 }
29 29
30 30 /**
31 31 * @param null $vendor
32 - * @param null $resource_name
32 + * @param null $resource
33 33 * @param false $ignore_cache
34 34 *
35 35 * @return array
36 36 */
37 - public function get( $vendor = null, $resource_name = null, $ignore_cache = false ) {
37 + public function get( $vendor = null, $resource = null, $ignore_cache = false ) {
38 38 if ( $ignore_cache || empty( $this->cache ) ) {
39 39 $this->cache = get_user_meta( $this->user_id, self::USER_META_KEY, true );
40 40 }
41 41
@@ -42,10 +42,10 @@
42 42 if ( ! $this->cache || ! is_array( $this->cache ) ) {
43 43 return [];
44 44 }
45 45
46 - if ( $vendor && $resource_name ) {
47 - $key = $this->get_key( $vendor, $resource_name );
46 + if ( $vendor && $resource ) {
47 + $key = $this->get_key( $vendor, $resource );
48 48
49 49 return isset( $this->cache[ $key ] ) ? $this->cache[ $key ] : [];
50 50 }
51 51
@@ -53,34 +53,34 @@
53 53 }
54 54
55 55 /**
56 56 * @param $vendor
57 - * @param $resource_name
57 + * @param $resource
58 58 * @param $id
59 59 *
60 60 * @return bool
61 61 */
62 - public function exists( $vendor, $resource_name, $id ) {
63 - return in_array( $id, $this->get( $vendor, $resource_name ), true );
62 + public function exists( $vendor, $resource, $id ) {
63 + return in_array( $id, $this->get( $vendor, $resource ), true );
64 64 }
65 65
66 66 /**
67 67 * @param $vendor
68 - * @param $resource_name
68 + * @param $resource
69 69 * @param array $value
70 70 *
71 71 * @return $this
72 - * @throws \Exception If the favorites cannot be saved.
72 + * @throws \Exception
73 73 */
74 - public function save( $vendor, $resource_name, $value = [] ) {
74 + public function save( $vendor, $resource, $value = [] ) {
75 75 $all_favorites = $this->get();
76 76
77 - $all_favorites[ $this->get_key( $vendor, $resource_name ) ] = $value;
77 + $all_favorites[ $this->get_key( $vendor, $resource ) ] = $value;
78 78
79 79 $result = update_user_meta( $this->user_id, self::USER_META_KEY, $all_favorites );
80 80
81 81 if ( false === $result ) {
82 - throw new \Exception( 'Failed to save user favorites.' );
82 + throw new \Exception( __( 'Failed to save user favorites', 'elementor' ) );
83 83 }
84 84
85 85 $this->cache = $all_favorites;
86 86
@@ -88,16 +88,16 @@
88 88 }
89 89
90 90 /**
91 91 * @param $vendor
92 - * @param $resource_name
92 + * @param $resource
93 93 * @param $id
94 94 *
95 95 * @return $this
96 - * @throws \Exception If the favorites cannot be added.
96 + * @throws \Exception
97 97 */
98 - public function add( $vendor, $resource_name, $id ) {
99 - $favorites = $this->get( $vendor, $resource_name );
98 + public function add( $vendor, $resource, $id ) {
99 + $favorites = $this->get( $vendor, $resource );
100 100
101 101 if ( in_array( $id, $favorites, true ) ) {
102 102 return $this;
103 103 }
@@ -103,9 +103,9 @@
103 103 }
104 104
105 105 $favorites[] = $id;
106 106
107 - $this->save( $vendor, $resource_name, $favorites );
107 + $this->save( $vendor, $resource, $favorites );
108 108
109 109 return $this;
110 110 }
111 111
@@ -110,16 +110,16 @@
110 110 }
111 111
112 112 /**
113 113 * @param $vendor
114 - * @param $resource_name
114 + * @param $resource
115 115 * @param $id
116 116 *
117 117 * @return $this
118 - * @throws \Exception If the favorites cannot be removed.
118 + * @throws \Exception
119 119 */
120 - public function remove( $vendor, $resource_name, $id ) {
121 - $favorites = $this->get( $vendor, $resource_name );
120 + public function remove( $vendor, $resource, $id ) {
121 + $favorites = $this->get( $vendor, $resource );
122 122
123 123 if ( ! in_array( $id, $favorites, true ) ) {
124 124 return $this;
125 125 }
@@ -127,9 +127,9 @@
127 127 $favorites = array_filter( $favorites, function ( $item ) use ( $id ) {
128 128 return $item !== $id;
129 129 } );
130 130
131 - $this->save( $vendor, $resource_name, $favorites );
131 + $this->save( $vendor, $resource, $favorites );
132 132
133 133 return $this;
134 134 }
135 135
@@ -134,12 +134,12 @@
134 134 }
135 135
136 136 /**
137 137 * @param $vendor
138 - * @param $resource_name
138 + * @param $resource
139 139 *
140 140 * @return string
141 141 */
142 - private function get_key( $vendor, $resource_name ) {
143 - return "{$vendor}/{$resource_name}";
142 + private function get_key( $vendor, $resource ) {
143 + return "{$vendor}/{$resource}";
144 144 }
145 145 }