setValue(null, null); } catch (\ReflectionException) { // Divi without that property: its reads are not cached this way. } } /** @return array The stored inventory (GlobalPreset::get_data(), formats §3). */ public function presets(): array { $data = GlobalPreset::get_data(); return is_array($data) ? $data : []; } /** * @param array $rest REST/sync format, see PresetBook::toRest(). * @param bool $mayRemove Deleting or restoring: fewer presets are allowed and removed ones * leave Divi's legacy option (like a DELETE_* sync). * @return array The inventory Divi stored. * @throws DiviLocked When preset-write is not released – before anything is written. * @throws RuntimeException When Divi refuses the inventory. */ public function savePresets(array $rest, bool $mayRemove): array { ReleaseGate::assertFeature(DiviFeature::PresetWrite); $prepared = GlobalPreset::prepare_data($rest); $current = GlobalPreset::get_data(); $refusal = GlobalPreset::validate_preset_count( $current, $prepared, $mayRemove ? self::ACTION_DELETE_MODULE : self::ACTION_SAVE ); if ($refusal instanceof WP_Error) { throw new RuntimeException('preset sync refused: ' . $refusal->get_error_code() . ' ' . $refusal->get_error_message()); } if ($mayRemove) { foreach (['module', 'group'] as $kind) { foreach (GlobalPreset::get_deleted_preset_ids($current, $prepared, $kind) as $deleted) { GlobalPreset::remove_preset_from_legacy_option( (string) ($deleted['id'] ?? ''), (string) ($deleted['moduleName'] ?? '') ); } } } $saved = GlobalPreset::save_data($prepared); return is_array($saved) ? $saved : []; } /** * The option groups of $moduleName that take group presets: attribute path (groupId) => group name, e.g. * "module.decoration.spacing" => "divi/spacing" (formats §3). [] without Divi or for an unknown module. * * @return array */ public function groupsOf(string $moduleName): array { if (! class_exists(ModuleRegistration::class)) { return []; } $settings = ModuleRegistration::get_module_settings($moduleName); if ($settings === null) { return []; } $groups = []; foreach (GlobalPreset::get_group_preset_default_attr($settings) as $groupId => $group) { if (is_array($group) && is_string($group['groupName'] ?? null)) { $groups[(string) $groupId] = $group['groupName']; } } return $groups; } /** * The parts of $attrs a preset of $moduleName carries (Divi's preset attribute mapping): all, style * (styleAttrs) and render (renderAttrs: html + script). * * @param array $attrs * @return array{all: array, style: array, render: array} */ public function presetAttrs(string $moduleName, array $attrs): array { $map = Conversion::get_preset_attrs_mapping($moduleName); return [ 'all' => (array) Conversion::get_preset_attrs($attrs, self::PRESET_TYPES, $map), 'style' => (array) Conversion::get_preset_attrs($attrs, ['style'], $map), 'render' => (array) Conversion::get_preset_attrs($attrs, ['html', 'script'], $map), ]; } /** Divi's role right "Visual Builder verwenden"; fail closed without Divi. */ public function canUseVisualBuilder(): bool { return class_exists(UserRole::class) && UserRole::can_current_user_use_visual_builder(); } }