WP_CLI
Formatter::find_item_key()
Find an object's key. If $prefix is set, a key with that prefix will be prioritized.
Method of the class: Formatter{}
No Hooks.
Return
String
.
Usage
// private - for code of main (parent) class only $result = $this->find_item_key( $item, $field );
- $item(object) (required)
- -
- $field(string) (required)
- -
Formatter::find_item_key() Formatter::find item key code WP-CLI 2.8.0-alpha
private function find_item_key( $item, $field ) { foreach ( [ $field, $this->prefix . '_' . $field ] as $maybe_key ) { if ( ( is_object( $item ) && ( property_exists( $item, $maybe_key ) || isset( $item->$maybe_key ) ) ) || ( is_array( $item ) && array_key_exists( $maybe_key, $item ) ) ) { $key = $maybe_key; break; } } if ( ! isset( $key ) ) { WP_CLI::error( "Invalid field: $field." ); } return $key; }