initialized ) { $this->load_default_fields(); $this->initialized = true; } } /** * Get the base fields that are always available. * * @return array */ public function get_base_fields(): array { return $this->base_fields; } /** * Registers fields that come from a specific type. * * @param string $type_id * @param array $fields * * @return void */ public function register_type_fields( string $type_id, array $fields ): void { $this->type_fields[ $type_id ] = array_merge( $this->type_fields[ $type_id ] ?? [], $fields ); } /** * IDs of every base or type field that stores raw code (sanitize_type 'custom_code'). * * @return string[] */ public function get_custom_code_field_ids(): array { $fields = array_merge( $this->base_fields, ...array_values( $this->type_fields ) ); $ids = []; foreach ( $fields as $field ) { if ( ( $field['sanitize_type'] ?? '' ) === 'custom_code' && ! empty( $field['id'] ) ) { $ids[] = $field['id']; } } return array_values( array_unique( $ids ) ); } public function get_fields_for_type( ?string $type_id = null, bool $include_global = false ): array { $fields = $include_global ? $this->base_fields : []; if ( is_null( $type_id ) ) { return $fields; } if ( isset( $this->type_fields[ $type_id ] ) ) { $fields = array_merge( $fields, $this->type_fields[ $type_id ] ); } return $fields; } /** * Get fields for a specific type, optionally including global base fields. * * @param string|null $type_id * @param bool $include_global * * @return array */ public function get_fields_for_type_filtered( ?string $type_id = null, bool $include_global = false ): array { $fields = $this->get_fields_for_type( $type_id, $include_global ); /** * Filters the list of fields for a specific placement type. * * @param array $fields The list of field definitions. * @param string $type_id The ID of the placement type (e.g. 'content'). */ return apply_filters( 'adpresso_placement_type_fields', $fields, $type_id ); } }