From 74ba85d6a98540d61fc9aa011b5e4775d4612d9a Mon Sep 17 00:00:00 2001 From: Scott Kingsley Clark Date: Sun, 19 Feb 2023 20:41:36 -0600 Subject: [PATCH] Normalize object_type for get_table_info() and related method Slightly related to #7007 but does not resolve the UI issue there --- classes/PodsAPI.php | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/classes/PodsAPI.php b/classes/PodsAPI.php index ff35c64ca9..735c2b8651 100644 --- a/classes/PodsAPI.php +++ b/classes/PodsAPI.php @@ -9916,6 +9916,8 @@ public function get_table_info_load( $object_type, $object, $name = null, $pod = } } } elseif ( ! empty( $pod ) ) { + $object_type = pods_v( 'type', $pod, $object_type, true ); + $info['pod'] = $pod; } @@ -10002,6 +10004,16 @@ public function get_table_info( $object_type, $object, $name = null, $pod = null // @todo Handle $object arrays for Post Types, Taxonomies, Comments (table pulled from first object in array) + if ( empty( $object_type ) ) { + $object_type = 'post_type'; + $object = 'post'; + } elseif ( empty( $object ) && in_array( $object_type, array( 'user', 'media', 'comment' ), true ) ) { + $object = $object_type; + } elseif ( 'post_type' === $object_type && 'attachment' === $object ) { + $object_type = 'media'; + $object = $object_type; + } + $info = array( //'select' => '`t`.*', 'object_type' => $object_type, @@ -10041,16 +10053,6 @@ public function get_table_info( $object_type, $object, $name = null, $pod = null 'recurse' => false ); - if ( empty( $object_type ) ) { - $object_type = 'post_type'; - $object = 'post'; - } elseif ( empty( $object ) && in_array( $object_type, array( 'user', 'media', 'comment' ), true ) ) { - $object = $object_type; - } elseif ( 'post_type' === $object_type && 'attachment' === $object ) { - $object_type = 'media'; - $object = $object_type; - } - $pod_name = $pod; if ( is_array( $pod_name ) || $pod_name instanceof Pods\Whatsit ) { @@ -10111,6 +10113,13 @@ public function get_table_info( $object_type, $object, $name = null, $pod = null $object_type = $_info['type']; } $info = array_merge( $info, $_info ); + + // Attempt to normalize the object type. + if ( ! empty( $info['pod']['type'] ) ) { + $object_type = $info['pod']['type']; + + $info['object_type'] = $object_type; + } } if (