| 1 |
<?php |
| 2 |
/** |
| 3 |
* OpenStation App Framework — WordPress Settings adapter. |
| 4 |
* |
| 5 |
* User preferences come from the OpenStation Preferences blob |
| 6 |
* (`openstation_get_os_settings()`), site options from `get_option()`. |
| 7 |
* |
| 8 |
* @package OpenStation |
| 9 |
*/ |
| 10 |
|
| 11 |
namespace OpenStation\App\WordPress; |
| 12 |
|
| 13 |
use OpenStation\App\Contracts\Settings as SettingsContract; |
| 14 |
|
| 15 |
defined( 'ABSPATH' ) || exit; |
| 16 |
|
| 17 |
/** |
| 18 |
* OpenStation Preferences + site options. |
| 19 |
*/ |
| 20 |
final class Settings implements SettingsContract { |
| 21 |
|
| 22 |
/** {@inheritDoc} */ |
| 23 |
public function user_preference( $key, $fallback = null ) { |
| 24 |
if ( ! function_exists( 'openstation_get_os_settings' ) ) { |
| 25 |
return $fallback; |
| 26 |
} |
| 27 |
$settings = openstation_get_os_settings( get_current_user_id() ); |
| 28 |
return is_array( $settings ) && array_key_exists( $key, $settings ) ? $settings[ $key ] : $fallback; |
| 29 |
} |
| 30 |
|
| 31 |
/** {@inheritDoc} */ |
| 32 |
public function site_option( $key, $fallback = null ) { |
| 33 |
return get_option( (string) $key, $fallback ); |
| 34 |
} |
| 35 |
} |
| 36 |
|