| @@ -21,16 +21,8 @@ | ||
| 21 | 21 | */ |
| 22 | 22 | private $has_api; |
| 23 | 23 | |
| 24 | 24 | /** |
| 25 | - * Pin every derived read/write to the acting user, bypassing the | |
| 26 | - * global-login fallback in user_id(). | |
| 27 | - * | |
| 28 | - * @var bool | |
| 29 | - */ | |
| 30 | - private $force_current_user = false; | |
| 31 | - | |
| 32 | - /** | |
| 33 | 25 | * Automatically invoked and set up the properties. |
| 34 | 26 | */ |
| 35 | 27 | public function __construct(){ |
| 36 | 28 | $this->current_user = get_current_user_id(); |
| @@ -79,28 +71,12 @@ | ||
| 79 | 71 | return $_who_am_i; |
| 80 | 72 | } |
| 81 | 73 | |
| 82 | 74 | /** |
| 83 | - * Pin the acting user as the target for every derived read/write. | |
| 84 | - * | |
| 85 | - * @param bool $force Whether to force the current user. | |
| 86 | - * @return Options | |
| 87 | - */ | |
| 88 | - public function use_current_user( bool $force = true ): Options { | |
| 89 | - $this->force_current_user = $force; | |
| 90 | - | |
| 91 | - return $this; | |
| 92 | - } | |
| 93 | - | |
| 94 | - /** | |
| 95 | 75 | * Get user id determine dynamically |
| 96 | 76 | * @return integer |
| 97 | 77 | */ |
| 98 | 78 | private function user_id(): int { |
| 99 | - if ( $this->force_current_user ) { | |
| 100 | - return $this->current_user; | |
| 101 | - } | |
| 102 | - | |
| 103 | 79 | $_who_am_i = $this->who_am_i(); |
| 104 | 80 | |
| 105 | 81 | if( ! empty( $_SERVER['REQUEST_URI'] ) ) { |
| 106 | 82 | $parse_uri = explode( '/', substr( $_SERVER['REQUEST_URI'], 0, strpos( $_SERVER['REQUEST_URI'], '?' ) ) ); |
| @@ -208,16 +184,10 @@ | ||
| 208 | 184 | return get_user_option( $key, $user_id ); |
| 209 | 185 | } |
| 210 | 186 | |
| 211 | 187 | public function update_user_meta($user_id, $meta_key, $meta_value) { |
| 212 | - if ( is_null( $user_id ) ) { | |
| 213 | - if ( ! $this->can_write() ) { | |
| 214 | - return false; | |
| 215 | - } | |
| 188 | + $user_id = is_null( $user_id ) ? $this->user_id() : $user_id; | |
| 216 | 189 | |
| 217 | - $user_id = $this->user_id(); | |
| 218 | - } | |
| 219 | - | |
| 220 | 190 | if( ! is_multisite() ) { |
| 221 | 191 | return update_user_meta( $user_id, $meta_key, $meta_value ); |
| 222 | 192 | } |
| 223 | 193 | |
| @@ -224,12 +194,8 @@ | ||
| 224 | 194 | return update_user_option( $user_id, $meta_key, $meta_value, $this->_is_global() ); |
| 225 | 195 | } |
| 226 | 196 | |
| 227 | 197 | public function delete_user_meta( $meta_key ): bool { |
| 228 | - if ( ! $this->can_write() ) { | |
| 229 | - return false; | |
| 230 | - } | |
| 231 | - | |
| 232 | 198 | if( ! is_multisite() ) { |
| 233 | 199 | return delete_user_meta( $this->user_id(), $meta_key ); |
| 234 | 200 | } |
| 235 | 201 | |
| @@ -235,20 +201,8 @@ | ||
| 235 | 201 | |
| 236 | 202 | return delete_user_option( $this->user_id(), $meta_key, $this->_is_global() ); |
| 237 | 203 | } |
| 238 | 204 | |
| 239 | - /** | |
| 240 | - * Whether the current request may write to a derived user target. | |
| 241 | - * | |
| 242 | - * Reads retain the global-login fallback for unauthenticated cloud callbacks, | |
| 243 | - * but an anonymous request must never write through it to the administrator. | |
| 244 | - * | |
| 245 | - * @return bool | |
| 246 | - */ | |
| 247 | - private function can_write(): bool { | |
| 248 | - return $this->current_user > 0; | |
| 249 | - } | |
| 250 | - | |
| 251 | 205 | private function _is_global() { |
| 252 | 206 | return apply_filters( 'templately_multisite_is_global', false ); |
| 253 | 207 | } |
| 254 | 208 | |
| @@ -279,5 +233,5 @@ | ||
| 279 | 233 | */ |
| 280 | 234 | public function update_option( $key, $value, $autoload = 'no' ): bool { |
| 281 | 235 | return update_option( $key, $value, $autoload ); |
| 282 | 236 | } |
| 283 | -} | |
| 237 | +} | |