author | ymh <ymh.work@gmail.com> |
Mon, 14 Oct 2019 18:28:13 +0200 | |
changeset 9 | 177826044cd9 |
parent 7 | cf61fcea0001 |
child 16 | a86126ab1dd4 |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
3 |
* Link/Bookmark API |
|
4 |
* |
|
5 |
* @package WordPress |
|
6 |
* @subpackage Bookmark |
|
7 |
*/ |
|
8 |
||
9 |
/** |
|
10 |
* Retrieve Bookmark data |
|
11 |
* |
|
12 |
* @since 2.1.0 |
|
13 |
* |
|
5 | 14 |
* @global wpdb $wpdb WordPress database abstraction object. |
15 |
* |
|
16 |
* @param int|stdClass $bookmark |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
17 |
* @param string $output Optional. The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which correspond to |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
18 |
* an stdClass object, an associative array, or a numeric array, respectively. Default OBJECT. |
0 | 19 |
* @param string $filter Optional, default is 'raw'. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
20 |
* @return array|object|null Type returned depends on $output value. |
0 | 21 |
*/ |
9 | 22 |
function get_bookmark( $bookmark, $output = OBJECT, $filter = 'raw' ) { |
0 | 23 |
global $wpdb; |
24 |
||
9 | 25 |
if ( empty( $bookmark ) ) { |
26 |
if ( isset( $GLOBALS['link'] ) ) { |
|
0 | 27 |
$_bookmark = & $GLOBALS['link']; |
9 | 28 |
} else { |
0 | 29 |
$_bookmark = null; |
9 | 30 |
} |
31 |
} elseif ( is_object( $bookmark ) ) { |
|
32 |
wp_cache_add( $bookmark->link_id, $bookmark, 'bookmark' ); |
|
0 | 33 |
$_bookmark = $bookmark; |
34 |
} else { |
|
9 | 35 |
if ( isset( $GLOBALS['link'] ) && ( $GLOBALS['link']->link_id == $bookmark ) ) { |
0 | 36 |
$_bookmark = & $GLOBALS['link']; |
9 | 37 |
} elseif ( ! $_bookmark = wp_cache_get( $bookmark, 'bookmark' ) ) { |
38 |
$_bookmark = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->links WHERE link_id = %d LIMIT 1", $bookmark ) ); |
|
0 | 39 |
if ( $_bookmark ) { |
40 |
$_bookmark->link_category = array_unique( wp_get_object_terms( $_bookmark->link_id, 'link_category', array( 'fields' => 'ids' ) ) ); |
|
41 |
wp_cache_add( $_bookmark->link_id, $_bookmark, 'bookmark' ); |
|
42 |
} |
|
43 |
} |
|
44 |
} |
|
45 |
||
9 | 46 |
if ( ! $_bookmark ) { |
0 | 47 |
return $_bookmark; |
9 | 48 |
} |
0 | 49 |
|
9 | 50 |
$_bookmark = sanitize_bookmark( $_bookmark, $filter ); |
0 | 51 |
|
52 |
if ( $output == OBJECT ) { |
|
53 |
return $_bookmark; |
|
54 |
} elseif ( $output == ARRAY_A ) { |
|
9 | 55 |
return get_object_vars( $_bookmark ); |
0 | 56 |
} elseif ( $output == ARRAY_N ) { |
9 | 57 |
return array_values( get_object_vars( $_bookmark ) ); |
0 | 58 |
} else { |
59 |
return $_bookmark; |
|
60 |
} |
|
61 |
} |
|
62 |
||
63 |
/** |
|
64 |
* Retrieve single bookmark data item or field. |
|
65 |
* |
|
66 |
* @since 2.3.0 |
|
67 |
* |
|
68 |
* @param string $field The name of the data field to return |
|
69 |
* @param int $bookmark The bookmark ID to get field |
|
70 |
* @param string $context Optional. The context of how the field will be used. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
71 |
* @return string|WP_Error |
0 | 72 |
*/ |
73 |
function get_bookmark_field( $field, $bookmark, $context = 'display' ) { |
|
74 |
$bookmark = (int) $bookmark; |
|
75 |
$bookmark = get_bookmark( $bookmark ); |
|
76 |
||
9 | 77 |
if ( is_wp_error( $bookmark ) ) { |
0 | 78 |
return $bookmark; |
9 | 79 |
} |
0 | 80 |
|
9 | 81 |
if ( ! is_object( $bookmark ) ) { |
0 | 82 |
return ''; |
9 | 83 |
} |
0 | 84 |
|
9 | 85 |
if ( ! isset( $bookmark->$field ) ) { |
0 | 86 |
return ''; |
9 | 87 |
} |
0 | 88 |
|
9 | 89 |
return sanitize_bookmark_field( $field, $bookmark->$field, $bookmark->link_id, $context ); |
0 | 90 |
} |
91 |
||
92 |
/** |
|
93 |
* Retrieves the list of bookmarks |
|
94 |
* |
|
95 |
* Attempts to retrieve from the cache first based on MD5 hash of arguments. If |
|
96 |
* that fails, then the query will be built from the arguments and executed. The |
|
97 |
* results will be stored to the cache. |
|
98 |
* |
|
5 | 99 |
* @since 2.1.0 |
100 |
* |
|
101 |
* @global wpdb $wpdb WordPress database abstraction object. |
|
102 |
* |
|
103 |
* @param string|array $args { |
|
104 |
* Optional. String or array of arguments to retrieve bookmarks. |
|
0 | 105 |
* |
5 | 106 |
* @type string $orderby How to order the links by. Accepts post fields. Default 'name'. |
107 |
* @type string $order Whether to order bookmarks in ascending or descending order. |
|
108 |
* Accepts 'ASC' (ascending) or 'DESC' (descending). Default 'ASC'. |
|
109 |
* @type int $limit Amount of bookmarks to display. Accepts 1+ or -1 for all. |
|
110 |
* Default -1. |
|
111 |
* @type string $category Comma-separated list of category ids to include links from. |
|
112 |
* Default empty. |
|
113 |
* @type string $category_name Category to retrieve links for by name. Default empty. |
|
114 |
* @type int|bool $hide_invisible Whether to show or hide links marked as 'invisible'. Accepts |
|
115 |
* 1|true or 0|false. Default 1|true. |
|
116 |
* @type int|bool $show_updated Whether to display the time the bookmark was last updated. |
|
117 |
* Accepts 1|true or 0|false. Default 0|false. |
|
118 |
* @type string $include Comma-separated list of bookmark IDs to include. Default empty. |
|
119 |
* @type string $exclude Comma-separated list of bookmark IDs to exclude. Default empty. |
|
120 |
* } |
|
121 |
* @return array List of bookmark row objects. |
|
0 | 122 |
*/ |
5 | 123 |
function get_bookmarks( $args = '' ) { |
0 | 124 |
global $wpdb; |
125 |
||
126 |
$defaults = array( |
|
9 | 127 |
'orderby' => 'name', |
128 |
'order' => 'ASC', |
|
129 |
'limit' => -1, |
|
130 |
'category' => '', |
|
131 |
'category_name' => '', |
|
132 |
'hide_invisible' => 1, |
|
133 |
'show_updated' => 0, |
|
134 |
'include' => '', |
|
135 |
'exclude' => '', |
|
136 |
'search' => '', |
|
0 | 137 |
); |
138 |
||
139 |
$r = wp_parse_args( $args, $defaults ); |
|
140 |
||
9 | 141 |
$key = md5( serialize( $r ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
142 |
$cache = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
143 |
if ( 'rand' !== $r['orderby'] && $cache = wp_cache_get( 'get_bookmarks', 'bookmark' ) ) { |
5 | 144 |
if ( is_array( $cache ) && isset( $cache[ $key ] ) ) { |
145 |
$bookmarks = $cache[ $key ]; |
|
146 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
147 |
* Filters the returned list of bookmarks. |
5 | 148 |
* |
149 |
* The first time the hook is evaluated in this file, it returns the cached |
|
150 |
* bookmarks list. The second evaluation returns a cached bookmarks list if the |
|
151 |
* link category is passed but does not exist. The third evaluation returns |
|
152 |
* the full cached results. |
|
153 |
* |
|
154 |
* @since 2.1.0 |
|
155 |
* |
|
156 |
* @see get_bookmarks() |
|
157 |
* |
|
158 |
* @param array $bookmarks List of the cached bookmarks. |
|
159 |
* @param array $r An array of bookmark query arguments. |
|
160 |
*/ |
|
161 |
return apply_filters( 'get_bookmarks', $bookmarks, $r ); |
|
162 |
} |
|
0 | 163 |
} |
164 |
||
5 | 165 |
if ( ! is_array( $cache ) ) { |
0 | 166 |
$cache = array(); |
5 | 167 |
} |
0 | 168 |
|
169 |
$inclusions = ''; |
|
5 | 170 |
if ( ! empty( $r['include'] ) ) { |
9 | 171 |
$r['exclude'] = ''; //ignore exclude, category, and category_name params if using include |
172 |
$r['category'] = ''; |
|
5 | 173 |
$r['category_name'] = ''; |
9 | 174 |
$inclinks = wp_parse_id_list( $r['include'] ); |
5 | 175 |
if ( count( $inclinks ) ) { |
0 | 176 |
foreach ( $inclinks as $inclink ) { |
5 | 177 |
if ( empty( $inclusions ) ) { |
9 | 178 |
$inclusions = ' AND ( link_id = ' . $inclink . ' '; |
5 | 179 |
} else { |
9 | 180 |
$inclusions .= ' OR link_id = ' . $inclink . ' '; |
5 | 181 |
} |
0 | 182 |
} |
183 |
} |
|
184 |
} |
|
9 | 185 |
if ( ! empty( $inclusions ) ) { |
0 | 186 |
$inclusions .= ')'; |
5 | 187 |
} |
0 | 188 |
|
189 |
$exclusions = ''; |
|
5 | 190 |
if ( ! empty( $r['exclude'] ) ) { |
9 | 191 |
$exlinks = wp_parse_id_list( $r['exclude'] ); |
5 | 192 |
if ( count( $exlinks ) ) { |
0 | 193 |
foreach ( $exlinks as $exlink ) { |
5 | 194 |
if ( empty( $exclusions ) ) { |
9 | 195 |
$exclusions = ' AND ( link_id <> ' . $exlink . ' '; |
5 | 196 |
} else { |
9 | 197 |
$exclusions .= ' AND link_id <> ' . $exlink . ' '; |
5 | 198 |
} |
0 | 199 |
} |
200 |
} |
|
201 |
} |
|
5 | 202 |
if ( ! empty( $exclusions ) ) { |
0 | 203 |
$exclusions .= ')'; |
5 | 204 |
} |
0 | 205 |
|
5 | 206 |
if ( ! empty( $r['category_name'] ) ) { |
9 | 207 |
if ( $r['category'] = get_term_by( 'name', $r['category_name'], 'link_category' ) ) { |
5 | 208 |
$r['category'] = $r['category']->term_id; |
0 | 209 |
} else { |
210 |
$cache[ $key ] = array(); |
|
211 |
wp_cache_set( 'get_bookmarks', $cache, 'bookmark' ); |
|
5 | 212 |
/** This filter is documented in wp-includes/bookmark.php */ |
0 | 213 |
return apply_filters( 'get_bookmarks', array(), $r ); |
214 |
} |
|
215 |
} |
|
216 |
||
5 | 217 |
$search = ''; |
218 |
if ( ! empty( $r['search'] ) ) { |
|
9 | 219 |
$like = '%' . $wpdb->esc_like( $r['search'] ) . '%'; |
220 |
$search = $wpdb->prepare( ' AND ( (link_url LIKE %s) OR (link_name LIKE %s) OR (link_description LIKE %s) ) ', $like, $like, $like ); |
|
0 | 221 |
} |
222 |
||
223 |
$category_query = ''; |
|
9 | 224 |
$join = ''; |
5 | 225 |
if ( ! empty( $r['category'] ) ) { |
9 | 226 |
$incategories = wp_parse_id_list( $r['category'] ); |
227 |
if ( count( $incategories ) ) { |
|
0 | 228 |
foreach ( $incategories as $incat ) { |
5 | 229 |
if ( empty( $category_query ) ) { |
9 | 230 |
$category_query = ' AND ( tt.term_id = ' . $incat . ' '; |
5 | 231 |
} else { |
9 | 232 |
$category_query .= ' OR tt.term_id = ' . $incat . ' '; |
5 | 233 |
} |
0 | 234 |
} |
235 |
} |
|
236 |
} |
|
5 | 237 |
if ( ! empty( $category_query ) ) { |
0 | 238 |
$category_query .= ") AND taxonomy = 'link_category'"; |
9 | 239 |
$join = " INNER JOIN $wpdb->term_relationships AS tr ON ($wpdb->links.link_id = tr.object_id) INNER JOIN $wpdb->term_taxonomy as tt ON tt.term_taxonomy_id = tr.term_taxonomy_id"; |
0 | 240 |
} |
241 |
||
5 | 242 |
if ( $r['show_updated'] ) { |
9 | 243 |
$recently_updated_test = ', IF (DATE_ADD(link_updated, INTERVAL 120 MINUTE) >= NOW(), 1,0) as recently_updated '; |
0 | 244 |
} else { |
245 |
$recently_updated_test = ''; |
|
246 |
} |
|
247 |
||
5 | 248 |
$get_updated = ( $r['show_updated'] ) ? ', UNIX_TIMESTAMP(link_updated) AS link_updated_f ' : ''; |
0 | 249 |
|
5 | 250 |
$orderby = strtolower( $r['orderby'] ); |
9 | 251 |
$length = ''; |
0 | 252 |
switch ( $orderby ) { |
253 |
case 'length': |
|
9 | 254 |
$length = ', CHAR_LENGTH(link_name) AS length'; |
0 | 255 |
break; |
256 |
case 'rand': |
|
257 |
$orderby = 'rand()'; |
|
258 |
break; |
|
259 |
case 'link_id': |
|
260 |
$orderby = "$wpdb->links.link_id"; |
|
261 |
break; |
|
262 |
default: |
|
263 |
$orderparams = array(); |
|
9 | 264 |
$keys = array( 'link_id', 'link_name', 'link_url', 'link_visible', 'link_rating', 'link_owner', 'link_updated', 'link_notes', 'link_description' ); |
5 | 265 |
foreach ( explode( ',', $orderby ) as $ordparam ) { |
266 |
$ordparam = trim( $ordparam ); |
|
267 |
||
268 |
if ( in_array( 'link_' . $ordparam, $keys ) ) { |
|
0 | 269 |
$orderparams[] = 'link_' . $ordparam; |
5 | 270 |
} elseif ( in_array( $ordparam, $keys ) ) { |
0 | 271 |
$orderparams[] = $ordparam; |
5 | 272 |
} |
0 | 273 |
} |
5 | 274 |
$orderby = implode( ',', $orderparams ); |
0 | 275 |
} |
276 |
||
5 | 277 |
if ( empty( $orderby ) ) { |
0 | 278 |
$orderby = 'link_name'; |
5 | 279 |
} |
0 | 280 |
|
5 | 281 |
$order = strtoupper( $r['order'] ); |
282 |
if ( '' !== $order && ! in_array( $order, array( 'ASC', 'DESC' ) ) ) { |
|
0 | 283 |
$order = 'ASC'; |
5 | 284 |
} |
0 | 285 |
|
286 |
$visible = ''; |
|
5 | 287 |
if ( $r['hide_invisible'] ) { |
0 | 288 |
$visible = "AND link_visible = 'Y'"; |
5 | 289 |
} |
0 | 290 |
|
9 | 291 |
$query = "SELECT * $length $recently_updated_test $get_updated FROM $wpdb->links $join WHERE 1=1 $visible $category_query"; |
0 | 292 |
$query .= " $exclusions $inclusions $search"; |
293 |
$query .= " ORDER BY $orderby $order"; |
|
5 | 294 |
if ( $r['limit'] != -1 ) { |
295 |
$query .= ' LIMIT ' . $r['limit']; |
|
296 |
} |
|
0 | 297 |
|
5 | 298 |
$results = $wpdb->get_results( $query ); |
0 | 299 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
300 |
if ( 'rand()' !== $orderby ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
301 |
$cache[ $key ] = $results; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
302 |
wp_cache_set( 'get_bookmarks', $cache, 'bookmark' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
303 |
} |
0 | 304 |
|
5 | 305 |
/** This filter is documented in wp-includes/bookmark.php */ |
306 |
return apply_filters( 'get_bookmarks', $results, $r ); |
|
0 | 307 |
} |
308 |
||
309 |
/** |
|
310 |
* Sanitizes all bookmark fields |
|
311 |
* |
|
312 |
* @since 2.3.0 |
|
313 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
314 |
* @param stdClass|array $bookmark Bookmark row |
0 | 315 |
* @param string $context Optional, default is 'display'. How to filter the |
9 | 316 |
* fields |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
317 |
* @return stdClass|array Same type as $bookmark but with fields sanitized. |
0 | 318 |
*/ |
9 | 319 |
function sanitize_bookmark( $bookmark, $context = 'display' ) { |
320 |
$fields = array( |
|
321 |
'link_id', |
|
322 |
'link_url', |
|
323 |
'link_name', |
|
324 |
'link_image', |
|
325 |
'link_target', |
|
326 |
'link_category', |
|
327 |
'link_description', |
|
328 |
'link_visible', |
|
329 |
'link_owner', |
|
330 |
'link_rating', |
|
331 |
'link_updated', |
|
332 |
'link_rel', |
|
333 |
'link_notes', |
|
334 |
'link_rss', |
|
335 |
); |
|
0 | 336 |
|
9 | 337 |
if ( is_object( $bookmark ) ) { |
0 | 338 |
$do_object = true; |
9 | 339 |
$link_id = $bookmark->link_id; |
0 | 340 |
} else { |
341 |
$do_object = false; |
|
9 | 342 |
$link_id = $bookmark['link_id']; |
0 | 343 |
} |
344 |
||
345 |
foreach ( $fields as $field ) { |
|
346 |
if ( $do_object ) { |
|
9 | 347 |
if ( isset( $bookmark->$field ) ) { |
348 |
$bookmark->$field = sanitize_bookmark_field( $field, $bookmark->$field, $link_id, $context ); |
|
349 |
} |
|
0 | 350 |
} else { |
9 | 351 |
if ( isset( $bookmark[ $field ] ) ) { |
352 |
$bookmark[ $field ] = sanitize_bookmark_field( $field, $bookmark[ $field ], $link_id, $context ); |
|
353 |
} |
|
0 | 354 |
} |
355 |
} |
|
356 |
||
357 |
return $bookmark; |
|
358 |
} |
|
359 |
||
360 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
361 |
* Sanitizes a bookmark field. |
0 | 362 |
* |
363 |
* Sanitizes the bookmark fields based on what the field name is. If the field |
|
364 |
* has a strict value set, then it will be tested for that, else a more generic |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
365 |
* filtering is applied. After the more strict filter is applied, if the `$context` |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
366 |
* is 'raw' then the value is immediately return. |
0 | 367 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
368 |
* Hooks exist for the more generic cases. With the 'edit' context, the {@see 'edit_$field'} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
369 |
* filter will be called and passed the `$value` and `$bookmark_id` respectively. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
370 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
371 |
* With the 'db' context, the {@see 'pre_$field'} filter is called and passed the value. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
372 |
* The 'display' context is the final context and has the `$field` has the filter name |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
373 |
* and is passed the `$value`, `$bookmark_id`, and `$context`, respectively. |
0 | 374 |
* |
375 |
* @since 2.3.0 |
|
376 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
377 |
* @param string $field The bookmark field. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
378 |
* @param mixed $value The bookmark field value. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
379 |
* @param int $bookmark_id Bookmark ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
380 |
* @param string $context How to filter the field value. Accepts 'raw', 'edit', 'attribute', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
381 |
* 'js', 'db', or 'display' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
382 |
* @return mixed The filtered value. |
0 | 383 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
384 |
function sanitize_bookmark_field( $field, $value, $bookmark_id, $context ) { |
0 | 385 |
switch ( $field ) { |
9 | 386 |
case 'link_id': // ints |
387 |
case 'link_rating': |
|
388 |
$value = (int) $value; |
|
389 |
break; |
|
390 |
case 'link_category': // array( ints ) |
|
391 |
$value = array_map( 'absint', (array) $value ); |
|
392 |
// We return here so that the categories aren't filtered. |
|
393 |
// The 'link_category' filter is for the name of a link category, not an array of a link's link categories |
|
394 |
return $value; |
|
5 | 395 |
|
9 | 396 |
case 'link_visible': // bool stored as Y|N |
397 |
$value = preg_replace( '/[^YNyn]/', '', $value ); |
|
398 |
break; |
|
399 |
case 'link_target': // "enum" |
|
400 |
$targets = array( '_top', '_blank' ); |
|
401 |
if ( ! in_array( $value, $targets ) ) { |
|
402 |
$value = ''; |
|
403 |
} |
|
404 |
break; |
|
0 | 405 |
} |
406 |
||
9 | 407 |
if ( 'raw' == $context ) { |
0 | 408 |
return $value; |
9 | 409 |
} |
0 | 410 |
|
411 |
if ( 'edit' == $context ) { |
|
5 | 412 |
/** This filter is documented in wp-includes/post.php */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
413 |
$value = apply_filters( "edit_{$field}", $value, $bookmark_id ); |
0 | 414 |
|
415 |
if ( 'link_notes' == $field ) { |
|
416 |
$value = esc_html( $value ); // textarea_escaped |
|
417 |
} else { |
|
9 | 418 |
$value = esc_attr( $value ); |
0 | 419 |
} |
5 | 420 |
} elseif ( 'db' == $context ) { |
421 |
/** This filter is documented in wp-includes/post.php */ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
422 |
$value = apply_filters( "pre_{$field}", $value ); |
0 | 423 |
} else { |
5 | 424 |
/** This filter is documented in wp-includes/post.php */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
425 |
$value = apply_filters( "{$field}", $value, $bookmark_id, $context ); |
0 | 426 |
|
5 | 427 |
if ( 'attribute' == $context ) { |
428 |
$value = esc_attr( $value ); |
|
429 |
} elseif ( 'js' == $context ) { |
|
430 |
$value = esc_js( $value ); |
|
431 |
} |
|
0 | 432 |
} |
433 |
||
434 |
return $value; |
|
435 |
} |
|
436 |
||
437 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
438 |
* Deletes the bookmark cache. |
0 | 439 |
* |
440 |
* @since 2.7.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
441 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
442 |
* @param int $bookmark_id Bookmark ID. |
0 | 443 |
*/ |
444 |
function clean_bookmark_cache( $bookmark_id ) { |
|
445 |
wp_cache_delete( $bookmark_id, 'bookmark' ); |
|
446 |
wp_cache_delete( 'get_bookmarks', 'bookmark' ); |
|
9 | 447 |
clean_object_term_cache( $bookmark_id, 'link' ); |
0 | 448 |
} |