class-wpml-links-fixed-status-for-strings.php
1.76 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_Links_Fixed_Status_For_Posts
*
* @package wpml-tm
*/
class WPML_Links_Fixed_Status_For_Strings extends WPML_Links_Fixed_Status {
private $wp_api;
private $string_id;
private $option_name = 'wpml_strings_need_links_fixed';
public function __construct( &$wp_api, $string_id ) {
$this->wp_api = &$wp_api;
$this->string_id = $string_id;
}
public function set( $status ) {
if ( $status ) {
$this->remove_string_from_strings_that_need_fixing();
} else {
$this->add_string_to_strings_that_need_fixing();
}
}
public function are_links_fixed() {
$strings_that_need_links_fixed = $this->load_strings_that_need_fixing();
return array_search( $this->string_id, $strings_that_need_links_fixed ) === false;
}
private function remove_string_from_strings_that_need_fixing() {
$strings_that_need_links_fixed = $this->load_strings_that_need_fixing();
if ( ( $key = array_search( $this->string_id, $strings_that_need_links_fixed ) ) !== false ) {
unset( $strings_that_need_links_fixed[ $key ] );
}
$this->save_strings_that_need_fixing( $strings_that_need_links_fixed );
}
private function add_string_to_strings_that_need_fixing() {
$strings_that_need_links_fixed = $this->load_strings_that_need_fixing();
if ( ( array_search( $this->string_id, $strings_that_need_links_fixed ) ) === false ) {
$strings_that_need_links_fixed[] = $this->string_id;
}
$this->save_strings_that_need_fixing( $strings_that_need_links_fixed );
}
private function load_strings_that_need_fixing() {
return $this->wp_api->get_option( $this->option_name, array() );
}
private function save_strings_that_need_fixing( $strings_that_need_links_fixed ) {
$this->wp_api->update_option( $this->option_name, $strings_that_need_links_fixed );
}
}