$slots, 'promptPath' => $prompt_path, 'generatePath' => $generate_path, 'lazy' => ! empty( $config['lazy'] ), 'contextModes' => self::normalize_context_modes( $config ), 'defaultContext' => isset( $config['default_context'] ) ? sanitize_key( (string) $config['default_context'] ) : 'link', 'storageKey' => isset( $config['storage_key'] ) ? (string) $config['storage_key'] : 'forwpAiPanelPos', 'i18n' => isset( $config['i18n'] ) && is_array( $config['i18n'] ) ? $config['i18n'] : [], ] ); return true; } /** * @param array $config Panel config. * @return list */ private static function normalize_slots( $config ) { $raw = []; if ( isset( $config['slots'] ) && is_array( $config['slots'] ) ) { $raw = $config['slots']; } elseif ( ! empty( $config['field'] ) ) { $raw = [ [ 'id' => 'text', 'field' => (string) $config['field'], 'label' => '', ], ]; } $slots = []; foreach ( $raw as $slot ) { if ( ! is_array( $slot ) ) { continue; } $id = isset( $slot['id'] ) ? sanitize_key( (string) $slot['id'] ) : ''; $field = isset( $slot['field'] ) ? trim( (string) $slot['field'] ) : ''; if ( '' === $id || '' === $field ) { continue; } $slots[] = [ 'id' => $id, 'field' => $field, 'label' => isset( $slot['label'] ) ? (string) $slot['label'] : '', ]; } return $slots; } /** * @param array $config Panel config. * @return list */ private static function normalize_context_modes( $config ) { $raw = isset( $config['context_modes'] ) && is_array( $config['context_modes'] ) ? $config['context_modes'] : []; $modes = []; foreach ( $raw as $mode ) { if ( ! is_array( $mode ) ) { continue; } $id = isset( $mode['id'] ) ? sanitize_key( (string) $mode['id'] ) : ''; if ( '' === $id ) { continue; } $modes[] = [ 'id' => $id, 'label' => isset( $mode['label'] ) ? (string) $mode['label'] : $id, ]; } return $modes; } }