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/SettingGroupEvent.php
<?php

namespace GoDaddy\WordPress\MWC\Core\Events;

use GoDaddy\WordPress\MWC\Common\Events\ModelEvent;
use GoDaddy\WordPress\MWC\Common\Helpers\ArrayHelper;
use GoDaddy\WordPress\MWC\Common\Helpers\StringHelper;
use GoDaddy\WordPress\MWC\Common\Models\Contracts\ModelContract;

/**
 * Event to be reused by setting group classes.
 */
class SettingGroupEvent extends ModelEvent
{
    /**
     * Setting group event constructor.
     */
    public function __construct(ModelContract $model, string $action)
    {
        parent::__construct($model, 'settings', $action);
    }

    /**
     * Builds the initial data for the event, with sensitive values masked.
     *
     * @return array
     */
    protected function buildInitialData() : array
    {
        return $this->maskSensitiveInformation(parent::buildInitialData());
    }

    /**
     * Recursively masks sensitive information in all setting arrays on a given array.
     */
    protected function maskSensitiveInformation($item)
    {
        if (ArrayHelper::accessible($item)) {
            // is a setting array
            if (! empty($value = ArrayHelper::get($item, 'value'))) {
                // contains sensitive information
                if (StringHelper::contains(ArrayHelper::get($item, 'id'), [
                    'password',
                    'secret',
                    'key',
                    'token',
                ])) {
                    if (is_string($value)) {
                        $item['value'] = str_repeat('*', strlen($value));
                    } elseif (ArrayHelper::accessible($value)) {
                        foreach ($value as $key => $subValue) {
                            if (is_string($subValue)) {
                                $item['value'][$key] = str_repeat('*', strlen($subValue));
                            }
                        }
                    }
                }
            } else {
                foreach ($item as $key => $value) {
                    $item[$key] = $this->maskSensitiveInformation($value);
                }
            }
        }

        return $item;
    }
}