wpml-st-tax-slug-translation-settings.php
1.34 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
58
59
60
<?php
class WPML_ST_Tax_Slug_Translation_Settings extends WPML_ST_Slug_Translation_Settings {
const OPTION_NAME = 'wpml_tax_slug_translation_settings';
/** @var array $types */
private $types = array();
public function __construct() {
$this->init();
}
/** @param array $types */
public function set_types( array $types ) {
$this->types = $types;
}
/** @return array */
public function get_types() {
return $this->types;
}
/**
* @param string $taxonomy_name
*
* @return bool
*/
public function is_translated( $taxonomy_name ) {
return array_key_exists( $taxonomy_name, $this->types ) && (bool) $this->types[ $taxonomy_name ];
}
/**
* @param string $taxonomy_name
* @param bool $is_enabled
*/
public function set_type( $taxonomy_name, $is_enabled ) {
$this->types[ $taxonomy_name ] = (int) $is_enabled;
}
/** @return array */
private function get_properties() {
return get_object_vars( $this );
}
public function init() {
$options = get_option( self::OPTION_NAME, array() );
foreach ( $this->get_properties() as $name => $value ) {
$callback = array( $this, 'set_' . $name );
if ( array_key_exists( $name, $options ) && is_callable( $callback ) ) {
call_user_func( $callback, $options[ $name ] );
}
}
}
public function save() {
update_option( self::OPTION_NAME, $this->get_properties() );
}
}