| @@ 350-368 (lines=19) @@ | ||
| 347 | * @param int $post_id Post ID. |
|
| 348 | * @return array Custom fields, if exist. |
|
| 349 | */ |
|
| 350 | public function get_custom_fields($post_id) { |
|
| 351 | $post_id = (int) $post_id; |
|
| 352 | ||
| 353 | $custom_fields = array(); |
|
| 354 | ||
| 355 | foreach ( (array) has_meta($post_id) as $meta ) { |
|
| 356 | // Don't expose protected fields. |
|
| 357 | if ( ! current_user_can( 'edit_post_meta', $post_id , $meta['meta_key'] ) ) |
|
| 358 | continue; |
|
| 359 | ||
| 360 | $custom_fields[] = array( |
|
| 361 | "id" => $meta['meta_id'], |
|
| 362 | "key" => $meta['meta_key'], |
|
| 363 | "value" => $meta['meta_value'] |
|
| 364 | ); |
|
| 365 | } |
|
| 366 | ||
| 367 | return $custom_fields; |
|
| 368 | } |
|
| 369 | ||
| 370 | /** |
|
| 371 | * Set custom fields for post. |
|
| @@ 414-433 (lines=20) @@ | ||
| 411 | * @param int $post_id Post ID. |
|
| 412 | * @return array Array of custom fields, if they exist. |
|
| 413 | */ |
|
| 414 | public function get_term_custom_fields( $term_id ) { |
|
| 415 | $term_id = (int) $term_id; |
|
| 416 | ||
| 417 | $custom_fields = array(); |
|
| 418 | ||
| 419 | foreach ( (array) has_term_meta( $term_id ) as $meta ) { |
|
| 420 | ||
| 421 | if ( ! current_user_can( 'edit_term_meta', $term_id ) ) { |
|
| 422 | continue; |
|
| 423 | } |
|
| 424 | ||
| 425 | $custom_fields[] = array( |
|
| 426 | 'id' => $meta['meta_id'], |
|
| 427 | 'key' => $meta['meta_key'], |
|
| 428 | 'value' => $meta['meta_value'], |
|
| 429 | ); |
|
| 430 | } |
|
| 431 | ||
| 432 | return $custom_fields; |
|
| 433 | } |
|
| 434 | ||
| 435 | /** |
|
| 436 | * Set custom fields for a term. |
|