get_id(); if ( isset( $this->types[ $id ] ) ) { RuntimeDebugger::add_doing_it_wrong_entry( sprintf( 'Ad Type ID "%s" was overwritten. Origin type: %s, New type: %s', esc_html( $id ), esc_html( get_class( $this->types[ $id ] ) ), esc_html( get_class( $type ) ) ) ); } $this->types[ $id ] = $type; add_action( 'adpresso_ad_types_registered', [ $type, 'register_fields' ], 10, 0 ); } /** * Get all registered ad types. * * @return AdTypeInterface[] */ public function get_all_types(): array { return $this->types; } /** * Get ad type by ID. * * @param string $id * * @return AdTypeInterface|null */ public function get_by_id( string $id ): ?AdTypeInterface { return $this->types[ $id ] ?? null; } /** * Check if an ad type exists by ID. * * @param string $id * * @return bool */ public function exists( string $id ): bool { return isset( $this->types[ $id ] ); } /** * Get all types for the select field. * * @return array */ public function get_all_types_for_select(): array { $field_registry = AdFieldRegistry::get(); return array_reduce( $this->get_all_types(), function( $carry, $type ) use ( $field_registry ) { $type_id = $type->get_id(); $carry[ $type_id ] = [ 'label' => $type->get_title(), 'image' => SvgLoader::get( ADPRESSO_ABSPATH . $type->get_image(), [ 'class' => 'adpresso-icon-unselected' ] ), 'description' => $type->get_description(), 'dependent_fields' => $field_registry->get_fields_for_type_filtered( $type_id ), ]; return $carry; }, [] ); } }