Command::list_items( $args, $assoc_args )
List all items.
Contents
Source Source
File: libraries/lifterlms-cli/src/Commands/Restful/Command.php
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | public function list_items( $args , $assoc_args ) { if ( ! empty ( $assoc_args [ 'format' ] ) && 'count' === $assoc_args [ 'format' ] ) { $method = 'HEAD' ; } else { $method = 'GET' ; } list( $status , $body , $headers ) = $this ->do_request( $method , $this ->get_base_route(), $assoc_args ); if ( ! empty ( $assoc_args [ 'format' ] ) && 'ids' === $assoc_args [ 'format' ] ) { $items = array_column( $body , 'id' ); } else { $items = $body ; } if ( ! empty ( $assoc_args [ 'fields' ] ) ) { foreach ( $items as $key => $item ) { $items [ $key ] = self::limit_item_to_fields( $item , $fields ); } } if ( ! empty ( $assoc_args [ 'format' ] ) && 'count' === $assoc_args [ 'format' ] ) { echo (int) $headers [ 'X-WP-Total' ]; } elseif ( 'headers' === $assoc_args [ 'format' ] ) { echo json_encode( $headers ); } elseif ( 'body' === $assoc_args [ 'format' ] ) { echo json_encode( $body ); } elseif ( 'envelope' === $assoc_args [ 'format' ] ) { echo json_encode( array ( 'body' => $body , 'headers' => $headers , 'status' => $status , 'api_url' => $this ->api_url, ) ); } else { $formatter = $this ->get_formatter( $assoc_args ); $formatter ->display_items( $items ); } } |
Expand full source code Collapse full source code View on GitHub