NEXT craftinamerica.org. Base setup for headless wordpress https://www.craftinamerica.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. /** @internal */
  3. function p2p_list_cluster( $items, $callback ) {
  4. return scb_list_group_by( $items, $callback );
  5. }
  6. /** @internal */
  7. function _p2p_expand_direction( $direction ) {
  8. if ( !$direction )
  9. return array();
  10. if ( 'any' == $direction )
  11. return array( 'from', 'to' );
  12. else
  13. return array( $direction );
  14. }
  15. /** @internal */
  16. function _p2p_compress_direction( $directions ) {
  17. if ( empty( $directions ) )
  18. return false;
  19. if ( count( $directions ) > 1 )
  20. return 'any';
  21. return reset( $directions );
  22. }
  23. /** @internal */
  24. function _p2p_flip_direction( $direction ) {
  25. $map = array(
  26. 'from' => 'to',
  27. 'to' => 'from',
  28. 'any' => 'any',
  29. );
  30. return $map[ $direction ];
  31. }
  32. /** @internal */
  33. function _p2p_normalize( $items ) {
  34. if ( !is_array( $items ) )
  35. $items = array( $items );
  36. foreach ( $items as &$item ) {
  37. if ( is_a( $item, 'P2P_Item' ) )
  38. $item = $item->get_id();
  39. elseif ( is_object( $item ) )
  40. $item = $item->ID;
  41. }
  42. return $items;
  43. }
  44. /** @internal */
  45. function _p2p_wrap( $items, $class ) {
  46. foreach ( $items as &$item ) {
  47. $item = new $class( $item );
  48. }
  49. return $items;
  50. }
  51. /** @internal */
  52. function _p2p_extract_post_types( $sides ) {
  53. $ptypes = array();
  54. foreach ( $sides as $side ) {
  55. if ( 'post' == $side->get_object_type() )
  56. _p2p_append( $ptypes, $side->query_vars['post_type'] );
  57. }
  58. return array_unique( $ptypes );
  59. }
  60. /** @internal */
  61. function _p2p_meta_sql_helper( $query ) {
  62. global $wpdb;
  63. if ( isset( $query[0] ) ) {
  64. $meta_query = $query;
  65. }
  66. else {
  67. $meta_query = array();
  68. foreach ( $query as $key => $value ) {
  69. $meta_query[] = compact( 'key', 'value' );
  70. }
  71. }
  72. return get_meta_sql( $meta_query, 'p2p', $wpdb->p2p, 'p2p_id' );
  73. }
  74. /** @internal */
  75. function _p2p_pluck( &$arr, $key ) {
  76. $value = $arr[ $key ];
  77. unset( $arr[ $key ] );
  78. return $value;
  79. }
  80. /** @internal */
  81. function _p2p_append( &$arr, $values ) {
  82. $arr = array_merge( $arr, $values );
  83. }
  84. /** @internal */
  85. function _p2p_first( $args ) {
  86. if ( empty( $args ) )
  87. return false;
  88. return reset( $args );
  89. }
  90. /** @internal */
  91. function _p2p_get_other_id( $item ) {
  92. if ( $item->ID == $item->p2p_from )
  93. return $item->p2p_to;
  94. if ( $item->ID == $item->p2p_to )
  95. return $item->p2p_from;
  96. trigger_error( "Corrupted data for item $inner_item->ID", E_USER_WARNING );
  97. }