Learndash_Model.php
3.1 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
137
138
139
140
141
142
143
<?php
/**
* Deprecated. Use LearnDash\Core\Models\Model instead.
*
* This class provides the easy way to operate a post.
*
* @since 4.5.0
* @deprecated 4.6.0
*
* @package LearnDash\Deprecated
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
_deprecated_file(
__FILE__,
'4.6.0',
esc_html( LEARNDASH_LMS_PLUGIN_DIR . '/src/Core/Models/Model.php' )
);
if ( ! class_exists( 'Learndash_Model' ) ) {
/**
* Model class.
*
* @since 4.5.0
* @deprecated 4.6.0
*/
abstract class Learndash_Model extends \LearnDash\Core\Models\Post {
/**
* Sets multiple attributes.
*
* @since 4.5.0
* @deprecated 4.6.0
*
* @param array<string,mixed> $attributes Attributes. Keys are attribute names, values are attribute values.
*
* @return void
*/
public function set_attributes( array $attributes ): void {
_deprecated_function( __METHOD__, '4.6.0', 'fill' );
foreach ( $attributes as $attribute_name => $attribute_value ) {
$this->set_attribute( $attribute_name, $attribute_value );
}
}
/**
* Returns an attribute value or null if not found.
*
* @since 4.5.0
* @deprecated 4.6.0
*
* @param string $attribute_name Attribute name.
* @param mixed $attribute_value Attribute value.
*
* @return void
*/
public function set_attribute( string $attribute_name, $attribute_value ): void {
_deprecated_function( __METHOD__, '4.6.0', 'setAttribute' );
$this->attributes[ $attribute_name ] = $attribute_value;
}
/**
* Returns all attributes.
*
* @since 4.5.0
* @deprecated 4.6.0
*
* @return array<string,mixed>
*/
public function get_attributes(): array {
_deprecated_function( __METHOD__, '4.6.0', 'toArray' );
return $this->toArray();
}
/**
* Returns an attribute value or null if not found.
*
* @since 4.5.0
* @deprecated 4.6.0
*
* @param string $attribute_name Attribute name.
* @param mixed $default Default value.
*
* @return mixed
*/
public function get_attribute( string $attribute_name, $default = null ) {
_deprecated_function( __METHOD__, '4.6.0', 'getAttribute' );
return $this->attributes[ $attribute_name ] ?? $default;
}
/**
* Removes all attributes.
*
* @since 4.5.0
* @deprecated 4.6.0
*
* @return void
*/
public function clear_attributes(): void {
_deprecated_function( __METHOD__, '4.6.0' );
$this->attributes = array();
}
/**
* Removes an attribute.
*
* @since 4.5.0
* @deprecated 4.6.0
*
* @param string $attribute_name Attribute name.
*
* @return void
*/
public function remove_attribute( string $attribute_name ): void {
_deprecated_function( __METHOD__, '4.6.0' );
unset( $this->attributes[ $attribute_name ] );
}
/**
* Returns true if an attribute exists. Otherwise, false.
*
* @since 4.5.0
* @deprecated 4.6.0
*
* @param string $attribute_name Attribute name.
*
* @return bool
*/
public function has_attribute( string $attribute_name ): bool {
_deprecated_function( __METHOD__, '4.6.0', 'hasAttribute' );
return isset( $this->attributes[ $attribute_name ] );
}
}
}