/var/www/html_it/wp-content/plugins/loco-translate/src/data/Option.php


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
<?php
/**
 * Data object persisted as a WordPress "option"
 */
abstract class Loco_data_Option extends Loco_data_Serializable {

    
    
/**
     * Get short suffix for use as end of option_name field.
     * DB allows 191 characters including "loco_" prefix, leaving 185 bytes
     * @return string
     */
    
abstract public function getKey();

    
/**
     * Persist object in WordPress options database
     * @return bool
     */
    
public function persist(){
        
$key 'loco_'.$this->getKey();
        return 
update_option$key$this->getSerializable(), false );
    }


    
/**
     * Retrieve and unserialize this object from WordPress options table
     * @return bool whether object existed in cache
     */
    
public function fetch(){
        
$key 'loco_'.$this->getKey();
        if( 
$data get_option($key) ){
            try {
                
$this->setUnserialized($data);
                return 
true;
            }
            catch( 
InvalidArgumentException $e ){
                
// suppress validation error
                // @codeCoverageIgnore
            
}
        }
        return 
false;
    }
    
    
    
/**
     * Delete option from WordPress
     */
    
public function remove(){
        
$key 'loco_'.$this->getKey();
        return 
delete_option$key );
    }
    
}