HEX
Server: Apache
System: Linux efa57bbe-abb1-400d-2985-3b056fbc2701.secureserver.net 6.1.147-1.el9.elrepo.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Jul 24 12:33:32 EDT 2025 x86_64
User: root (0)
PHP: 8.0.30.4
Disabled: NONE
Upload Files
File: /var/www/wp-content/mu-plugins/vendor/godaddy/mwc-core/src/Events/SettingsUpdatedEvent.php
<?php

namespace GoDaddy\WordPress\MWC\Core\Events;

use GoDaddy\WordPress\MWC\Common\Events\Contracts\EventBridgeEventContract;
use GoDaddy\WordPress\MWC\Common\Helpers\StringHelper;
use GoDaddy\WordPress\MWC\Common\Traits\IsEventBridgeEventTrait;

/**
 * @TODO: refactor any classes extending/using this class to use the SettingGroupEvent instead {dmagalhaes 2022-01-06}
 */
class SettingsUpdatedEvent implements EventBridgeEventContract
{
    use IsEventBridgeEventTrait;

    /** @var string The group the settings belong to (usually the plugin dasherized ID) */
    protected $group;

    /** @var array The settings values */
    protected $settings;

    /**
     * Constructor.
     *
     * @param string $group
     */
    public function __construct(string $group)
    {
        $this->resource = 'settings';
        $this->action = 'update';
        $this->group = $group;
    }

    /**
     * Sets the settings.
     *
     * @param array $settings
     * @return self
     */
    public function setSettings(array $settings) : self
    {
        $this->settings = $settings;

        return $this;
    }

    /**
     * Gets the settings, with sensitive values masked.
     *
     * @return array
     */
    public function getSettings() : array
    {
        array_walk_recursive($this->settings, [$this, 'maskSensitiveInformation']);

        return $this->settings;
    }

    /**
     * Masks sensitive information in a setting.
     */
    protected function maskSensitiveInformation(&$item, $key)
    {
        if (StringHelper::contains($key, ['password', 'secret', 'key', 'token'])) {
            $item = str_repeat('*', strlen($item));
        }
    }

    /**
     * Builds the initial data for the event.
     *
     * @return array
     */
    protected function buildInitialData() : array
    {
        return [
            'group'    => $this->group,
            'settings' => $this->getSettings(),
        ];
    }
}