EditorChangeTracker.php
1 week ago
ForceUpdateEndpoint.php
1 week ago
HooksFactory.php
1 week ago
Mode.php
1 week ago
Notices.php
1 week ago
Settings.php
1 week ago
SyncGate.php
1 week ago
Mode.php
35 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WCML\EditorScopedSync; |
| 4 | |
| 5 | class Mode { |
| 6 | |
| 7 | const VALUE_COMPLETE = 'complete'; |
| 8 | const VALUE_EDITOR_SCOPED = 'editor_scoped'; |
| 9 | |
| 10 | const SETTING_KEY = 'editor_scoped_save_mode'; |
| 11 | |
| 12 | private $woocommerce_wpml; |
| 13 | |
| 14 | public function __construct( \woocommerce_wpml $woocommerce_wpml ) { |
| 15 | $this->woocommerce_wpml = $woocommerce_wpml; |
| 16 | } |
| 17 | |
| 18 | public function current() { |
| 19 | $settings = $this->woocommerce_wpml->get_settings(); |
| 20 | $value = isset( $settings[ self::SETTING_KEY ] ) ? $settings[ self::SETTING_KEY ] : self::VALUE_COMPLETE; |
| 21 | return self::VALUE_EDITOR_SCOPED === $value ? self::VALUE_EDITOR_SCOPED : self::VALUE_COMPLETE; |
| 22 | } |
| 23 | |
| 24 | public function isEditorScoped() { |
| 25 | return self::VALUE_EDITOR_SCOPED === $this->current(); |
| 26 | } |
| 27 | |
| 28 | public function set( $value ) { |
| 29 | $value = self::VALUE_EDITOR_SCOPED === $value ? self::VALUE_EDITOR_SCOPED : self::VALUE_COMPLETE; |
| 30 | $settings = $this->woocommerce_wpml->get_settings(); |
| 31 | $settings[ self::SETTING_KEY ] = $value; |
| 32 | $this->woocommerce_wpml->update_settings( $settings ); |
| 33 | } |
| 34 | } |
| 35 |