/var/www/html_uk/wp-content/plugins/automatewoo/includes/Rules/Abstract_Meta.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php

namespace AutomateWoo\Rules;

defined'ABSPATH' ) || exit;

/**
 * @class Abstract_Meta
 */
abstract class Abstract_Meta extends Rule {

    
/** @var string */
    
public $type 'meta';

    
/** @var bool */
    
public $has_multiple_value_fields true;

    
/**
     * Abstract_Meta constructor.
     */
    
public function __construct() {
        
$this->compare_types $this->get_string_compare_types() + $this->get_integer_compare_types();
        
parent::__construct();
    }


    
/**
     * Validate a meta value.
     *
     * @param mixed  $actual_value
     * @param string $compare_type
     * @param mixed  $expected_value
     * @return bool
     */
    
public function validate_meta$actual_value$compare_type$expected_value ) {

        
// Meta compares are a mix of string and number comparisons.
        // Validate as a number for numeric comparisons (greater/less/multiples) and for is/is not ONLY with numeric values
        
if ( $this->is_numeric_meta_field$compare_type$expected_value ) ) {
            return 
$this->validate_number$actual_value$compare_type$expected_value );
        } else {
            return 
$this->validate_string$actual_value$compare_type$expected_value );
        }
    }

    
/**
     * Determine whether the meta field can reasonably be evaluated as a number, specifically for
     * numeric comparisons (greater/less/multiples) and for numeric is/is not.
     * This can facilitate better comparisons (for example, "5" = "5.0" in numeric comparisons,
     * but not in string comparisons).
     *
     * @since 5.1.0
     *
     * @param string $compare_type
     * @param mixed  $value
     *
     * @return bool True if the meta field is determined to be numeric.
     */
    
protected function is_numeric_meta_field$compare_type$value ) {
        
$is_numeric_compare_type = ( $this->is_integer_compare_type$compare_type ) && ! $this->is_is_or_is_not_compare_type$compare_type ) );
        
$is_numeric_is_is_not    = ( is_numeric$value ) && $this->is_is_or_is_not_compare_type$compare_type ) );

        return 
$is_numeric_compare_type || $is_numeric_is_is_not;
    }


    
/**
     * Return an associative array with 'key' and 'value' elements.
     *
     * @param mixed $value
     * @return array|false
     */
    
public function prepare_value_data$value ) {
        if ( ! 
is_array$value ) ) {
            return 
false;
        }

        return [
            
'key'   => trim$value[0] ),
            
'value' => isset( $value[1] ) ? $value[1] : false,
        ];
    }
}