offsetSet( $item_id, $attributes ); $result = true; } else { $message = sprintf( 'The attributes were missing when attempting to add the \'%1$s\' %2$s.', $item_id, static::$item_error_label ); throw new Exception( $message ); } return $result; } /** * Removes an item from the registry by ID. * * @since 3.0 * * @param string $item_id Item ID. */ public function remove_item( $item_id ) { if ( $this->offsetExists( $item_id ) ) { $this->offsetUnset( $item_id ); } } /** * Retrieves an item and its associated attributes. * * @since 3.0 * * @throws \EDD_Exception if the item does not exist. * * @param string $item_id Item ID. * @return array Array of attributes for the item if the item is set, * otherwise an empty array. */ public function get_item( $item_id ) { $item = array(); if ( $this->offsetExists( $item_id ) ) { $item = $this->offsetGet( $item_id ); } else { $message = sprintf( 'The \'%1$s\' %2$s does not exist.', $item_id, static::$item_error_label ); throw new Exception( $message ); } return $item; } /** * Retrieves registered items. * * @since 3.0 * * @return array The list of registered items. */ public function get_items() { return $this->getArrayCopy(); } /** * Retrieves the value of a given attribute for a given item. * * @since 3.0 * * @throws \EDD_Exception if the item does not exist. * @throws \EDD_Exception if the attribute and/or item does not exist. * * @param string $key Key of the attribute to retrieve. * @param string $item_id Collection to retrieve the attribute from. * @return mixed|null The attribute value if set, otherwise null. */ public function get_attribute( $key, $item_id ) { $attribute = null; $item = $this->get_item( $item_id ); if ( ! empty( $item[ $key ] ) ) { $attribute = $item[ $key ]; } else { throw Exceptions\Attribute_Not_Found::from_attr( $key, $item_id ); } return $attribute; } }