wpml-st-post-slug-translation-settings.php
1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
/**
* @todo: Move these settings to an independent option
* like WPML_ST_Tax_Slug_Translation_Settings::OPTION_NAME
*/
class WPML_ST_Post_Slug_Translation_Settings extends WPML_ST_Slug_Translation_Settings {
const KEY_IN_SITEPRESS_SETTINGS = 'posts_slug_translation';
/** @var SitePress $sitepress */
private $sitepress;
private $settings;
public function __construct( SitePress $sitepress ) {
$this->sitepress = $sitepress;
$this->settings = $sitepress->get_setting( self::KEY_IN_SITEPRESS_SETTINGS, array( ) );
}
/** @param bool $enabled */
public function set_enabled( $enabled ) {
parent::set_enabled( $enabled );
/**
* Backward compatibility with 3rd part plugins
* The `on` key has been replaced by an independent option
* WPML_ST_Slug_Translation_Settings::KEY_ENABLED_GLOBALLY
*/
$this->settings['on'] = (int) $enabled;
}
/**
* @param string $type
*
* @return bool
*/
public function is_translated( $type ) {
return ! empty( $this->settings['types'][ $type ] );
}
/**
* @param string $type
* @param bool $is_enabled
*/
public function set_type( $type, $is_enabled ) {
if ( $is_enabled ) {
$this->settings['types'][ $type ] = 1;
} else {
unset( $this->settings['types'][ $type ] );
}
}
public function save() {
$this->sitepress->set_setting( self::KEY_IN_SITEPRESS_SETTINGS, $this->settings, true );
}
}