/var/www/html_uk/wp-content/plugins/automatewoo/includes/AbstractOptionsStore.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
54
55
56
57
58
59
60
61
62
63
64
65
<?php

namespace AutomateWoo;

use 
AutomateWoo\Exceptions\InvalidArgument;

/**
 * Class AbstractOptionsStore.
 *
 * @since 5.1.0
 */
abstract class AbstractOptionsStore {

    
/**
     * Get the prefix for options used the wp_options table.
     *
     * @return string
     */
    
abstract public function get_prefix(): string;

    
/**
     * Get an array of option defaults.
     *
     * @return array
     */
    
abstract public function get_defaults(): array;

    
/**
     * Get bool WP option.
     *
     * Booleans are stored as 'yes' 'no' values in the database.
     *
     * @param string $option_name
     *
     * @return bool
     *
     * @throws InvalidArgument If the option value is invalid.
     */
    
protected function get_bool_optionstring $option_name ): bool {
        switch ( 
$this->get_option$option_name ) ) {
            case 
'yes':
                return 
true;
            case 
'no':
                return 
false;
            default:
                throw 
InvalidArgument::invalid_argument'yes or no' );
        }
    }

    
/**
     * Get the value of an option or fallback to the default.
     *
     * @param string $option_name
     *
     * @return mixed The value of the option.
     *               Returns null if there is no default and the option doesn't exist or is an empty string.
     */
    
protected function get_optionstring $option_name ) {
        
$default $this->get_defaults()[ $option_name ] ?? null;
        
$value   get_option$this->get_prefix() . $option_name$default );

        
// If the value is an empty string fall back to the default
        
return ( '' === $value ) ? $default $value;
    }
}