-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathclass-rop-model-abstract.php
More file actions
136 lines (118 loc) · 3.36 KB
/
class-rop-model-abstract.php
File metadata and controls
136 lines (118 loc) · 3.36 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<?php
/**
* The file that defines the abstract class inherited by all models
*
* A class that is used to define the models class and utility methods.
*
* @link https://themeisle.com/
* @since 8.0.0
*
* @package Rop
* @subpackage Rop/includes/admin/abstract
*/
/**
* Class Rop_Model_Abstract
*
* @since 8.0.0
* @link https://themeisle.com/
*/
abstract class Rop_Model_Abstract {
/**
* The namespace for the data inside the wp_options table.
*
* @since 8.0.0
* @access protected
* @var string $namespace The namespace to use for the model.
*/
protected $namespace = 'rop_data';
/**
* The data used by the model.
*
* @since 8.0.0
* @access protected
* @var array $data The data used by the model.
*/
protected $data;
/**
* Rop_Model_Abstract constructor.
*
* @param bool|string $namespace Optional. Used to specify a new namespace for a model.
*
* @since 8.0.0
* @access public
*/
public function __construct( $namespace = false ) {
if ( $namespace != false ) {
$this->namespace = $namespace;
}
$this->data = get_option( $this->namespace, array() );
}
/**
* The get method for the model data.
*
* @param string $key The key to retrieve from model data.
*
* @return mixed
* @since 8.0.0
* @access protected
*/
protected function get( $key ) {
$value = null;
if ( isset( $this->data[ $key ] ) ) {
$value = $this->data[ $key ];
}
return apply_filters( 'rop_get_key_' . $key, $value, $key );
}
/**
* The set method for the model data.
*
* @param string $key The key to set inside the model data.
* @param mixed $value The value for the specified key.
* @param bool $refresh Whether to refresh the rop_data property in class with new rop_data option values.
*
* @return mixed
* @since 8.0.0
* @access protected
*/
protected function set( $key, $value = '', $refresh = false ) {
if ( is_array( $this->data ) && ! array_key_exists( $key, $this->data ) ) {
$this->data[ $key ] = '';
}
if ( $refresh ) {
$this->data = get_option( 'rop_data' );
}
$this->data[ $key ] = apply_filters( 'rop_set_key_' . $key, $value );
return update_option( $this->namespace, $this->data, false );
}
/**
* This method will treat the exception that may exist in Linkedin service account key.
*
* @param string $index The long concatenated string.
* @param bool $is_treat_any Treat any exception, not just for Linkedin.
*
* @return array
* @since 8.5.3
*/
protected function handle_underscore_exception( $index, $is_treat_any = false ) {
$explode_index = explode( '_', $index );
$count_underscore = count( $explode_index );
list( $service, $service_key, $account_id ) = $explode_index;
if ( 'linkedin' === $service || $is_treat_any ) {
// Exception: When there are 2 extra underscores e.g. "linkedin_33_test_33_test"
if ( 5 === $count_underscore ) {
$service_key = $explode_index[1] . '_' . $explode_index[2];
$account_id = $explode_index[3] . '_' . $explode_index[4];
} elseif ( 4 === $count_underscore ) {
// Exception: When there is one extra underscore "linkedin_33_test_33test"
$service_key = $explode_index[1] . '_' . $explode_index[2];
$account_id = $explode_index[3];
}
}
$return_correct_format = array(
$service,
$service_key,
$account_id,
);
return $return_correct_format;
}
}