| 578 | // Ignore relationships that weren't requested. |
| 579 | if ( $requested_fields && ! array_key_exists( $rel, $requested_fields ) ) { |
| 580 | continue; |
| 581 | } |
| 582 | |
| 583 | // Add the requested fields to the soon-to-be-dispatched request. |
| 584 | if ( array_key_exists( $rel, $requested_fields ) ) { |
| 585 | $item['href'] = add_query_arg( |
| 586 | '_fields', |
| 587 | implode( ',', $requested_fields[ $rel ] ), |
| 588 | $item['href'] |
| 589 | ); |
| 590 | } |
| 591 | |
| 628 | * todo |
| 629 | * |
| 630 | * @return array |
| 631 | */ |
| 632 | protected function get_requested_embedded_fields() { |
| 633 | $raw_fields = isset( $_GET['_fields'] ) ? wp_parse_list( $_GET['_fields'] ) : ''; |
| 634 | // todo sanitize |
| 635 | |
| 636 | // handle back-compat? |
| 637 | // some people may already using _fields and _embed in order to limit the main response, but might expect full embedded results to stay |
| 638 | |
| 639 | // add tests |
| 640 | // success |
| 641 | // nested |
| 642 | // _embedded.author.avatar_urls.24 doesn't work yet |
| 643 | // handle case where nothing was requested |
| 644 | // where something was requested but doesn't exist -probably nothing to do here, just test |
| 645 | // what else? |
| 646 | |
| 647 | if ( empty( $raw_fields ) ) { |
| 648 | return array(); |
| 649 | } |
| 650 | |
| 651 | foreach ( $raw_fields as $raw_field ) { |
| 652 | if ( '_embedded.' !== substr( $raw_field, 0, 10 ) ) { |
| 653 | continue; |
| 654 | } |
| 655 | |
| 656 | $rel_with_nested = str_replace( '_embedded.', '', $raw_field ); |
| 657 | $delimiter_position = strpos( $rel_with_nested, '.' ); |
| 658 | $rel = substr( $rel_with_nested, 0, $delimiter_position ); |
| 659 | |
| 660 | if ( false !== $delimiter_position ) { |
| 661 | $nested_field = substr( $rel_with_nested, $delimiter_position + 1 ); |
| 662 | |
| 663 | $requested_fields[ $rel ][] = $nested_field; |
| 664 | } else { |
| 665 | $requested_fields[ $rel ] = array(); |
| 666 | } |
| 667 | } |
| 668 | |
| 669 | return $requested_fields; |
| 670 | } |
| 671 | |
| 672 | /** |