1
1
<?php
2
2
3
- function is_assoc_array ( $ array ) {
4
- return is_array ( $ array ) && array_values ( $ array ) !== $ array ;
3
+ function is_assoc_array ( $ assoc ) {
4
+ return is_array ( $ assoc ) && array_values ( $ assoc ) !== $ assoc ;
5
5
}
6
6
7
7
@@ -23,10 +23,10 @@ function getallheaders() {
23
23
}
24
24
25
25
if ( ! function_exists ( 'mp_get ' ) ) {
26
- function mp_get ( $ array , $ key , $ default = array (), $ index = false ) {
27
- $ return = $ default ;
28
- if ( is_array ( $ array ) && isset ( $ array [ $ key ] ) ) {
29
- $ return = $ array [ $ key ];
26
+ function mp_get ( $ data , $ key , $ def = array (), $ index = false ) {
27
+ $ return = $ def ;
28
+ if ( is_array ( $ data ) && isset ( $ data [ $ key ] ) ) {
29
+ $ return = $ data [ $ key ];
30
30
}
31
31
if ( $ index && wp_is_numeric_array ( $ return ) && ! empty ( $ return ) ) {
32
32
$ return = $ return [0 ];
@@ -37,10 +37,10 @@ function mp_get( $array, $key, $default = array(), $index = false ) {
37
37
38
38
if ( ! function_exists ( 'mp_filter ' ) ) {
39
39
// Searches for partial matches in an array of strings
40
- function mp_filter ( $ array , $ filter ) {
40
+ function mp_filter ( $ a , $ filter ) {
41
41
return array_values (
42
42
array_filter (
43
- $ array ,
43
+ $ a ,
44
44
function ( $ value ) use ( $ filter ) {
45
45
return ( false !== stripos ( $ value , $ filter ) );
46
46
}
@@ -55,6 +55,24 @@ function micropub_get_response() {
55
55
}
56
56
}
57
57
58
+ if ( ! function_exists ( 'is_micropub_post ' ) ) {
59
+ function is_micropub_post ( $ post = null ) {
60
+ $ post = get_post ( $ post );
61
+ if ( ! $ post ) {
62
+ return false ;
63
+ }
64
+ $ response = get_post_meta ( $ post ->ID , 'micropub_version ' , true );
65
+ if ( $ response ) {
66
+ return true ;
67
+ }
68
+ $ response = get_post_meta ( $ post ->ID , 'micropub_auth_response ' , true );
69
+ if ( ! $ response ) {
70
+ return false ;
71
+ }
72
+ return true ;
73
+ }
74
+ }
75
+
58
76
if ( ! function_exists ( 'micropub_get_client_info ' ) ) {
59
77
function micropub_get_client_info ( $ post = null ) {
60
78
$ post = get_post ( $ post );
@@ -160,41 +178,47 @@ function micropub_get_post_datetime( $post = null, $field = 'date', $timezone =
160
178
}
161
179
}
162
180
163
- function get_micropub_error ( $ obj ) {
164
- if ( is_array ( $ obj ) ) {
165
- // When checking the result of wp_remote_post
166
- if ( isset ( $ obj ['body ' ] ) ) {
167
- $ body = json_decode ( $ obj ['body ' ], true );
168
- if ( isset ( $ body ['error ' ] ) ) {
169
- return new WP_Micropub_Error (
170
- $ body ['error ' ],
171
- isset ( $ body ['error_description ' ] ) ? $ body ['error_description ' ] : null ,
172
- $ obj ['response ' ]['code ' ]
173
- );
181
+ if ( ! function_exists ( 'get_micropub_error ' ) ) {
182
+ function get_micropub_error ( $ obj ) {
183
+ if ( is_array ( $ obj ) ) {
184
+ // When checking the result of wp_remote_post
185
+ if ( isset ( $ obj ['body ' ] ) ) {
186
+ $ body = json_decode ( $ obj ['body ' ], true );
187
+ if ( isset ( $ body ['error ' ] ) ) {
188
+ return new WP_Micropub_Error (
189
+ $ body ['error ' ],
190
+ isset ( $ body ['error_description ' ] ) ? $ body ['error_description ' ] : null ,
191
+ $ obj ['response ' ]['code ' ]
192
+ );
193
+ }
194
+ }
195
+ } elseif ( is_object ( $ obj ) && 'WP_Micropub_Error ' === get_class ( $ obj ) ) {
196
+ $ data = $ obj ->get_data ();
197
+ if ( isset ( $ data ['error ' ] ) ) {
198
+ return $ obj ;
174
199
}
175
200
}
176
- } elseif ( is_object ( $ obj ) && 'WP_Micropub_Error ' === get_class ( $ obj ) ) {
177
- $ data = $ obj ->get_data ();
178
- if ( isset ( $ data ['error ' ] ) ) {
179
- return $ obj ;
180
- }
201
+ return false ;
181
202
}
182
- return false ;
183
203
}
184
204
185
- function is_micropub_error ( $ obj ) {
186
- return ( $ obj instanceof WP_Micropub_Error );
205
+ if ( ! function_exists ( 'is_micropub_error ' ) ) {
206
+ function is_micropub_error ( $ obj ) {
207
+ return ( $ obj instanceof WP_Micropub_Error );
208
+ }
187
209
}
188
210
189
- // Converts WP_Error into Micropub Error
190
- function micropub_wp_error ( $ error ) {
191
- if ( is_wp_error ( $ error ) ) {
192
- $ data = $ error ->get_error_data ();
193
- $ status = isset ( $ data ['status ' ] ) ? $ data ['status ' ] : 200 ;
194
- if ( is_array ( $ data ) ) {
195
- unset( $ data ['status ' ] );
211
+ if ( ! function_exists ( 'micropub_wp_error ' ) ) {
212
+ // Converts WP_Error into Micropub Error
213
+ function micropub_wp_error ( $ error ) {
214
+ if ( is_wp_error ( $ error ) ) {
215
+ $ data = $ error ->get_error_data ();
216
+ $ status = isset ( $ data ['status ' ] ) ? $ data ['status ' ] : 200 ;
217
+ if ( is_array ( $ data ) ) {
218
+ unset( $ data ['status ' ] );
219
+ }
220
+ return new WP_Micropub_Error ( $ error ->get_error_code (), $ error ->get_error_message (), $ status , $ data );
196
221
}
197
- return new WP_Micropub_Error ( $ error -> get_error_code (), $ error -> get_error_message (), $ status , $ data ) ;
222
+ return null ;
198
223
}
199
- return null ;
200
224
}
0 commit comments