&$attribute) { // Convert stdClass to array if needed if (is_object($attribute)) { $attribute = (array) $attribute; } if (isset($attribute['customizationKey'])) { if (is_array($attribute['customizationKey'])) { foreach ($attribute['customizationKey'] as $path) { if (is_object($path)) { $path = (array) $path; } $customization_value = self::get_value_by_path(self::$customization_data, explode('.', $path['customizationPath'])); if ($customization_value !== null) { self::set_value_by_path($attribute, explode('.', $path['blockPath']), $customization_value); } } } else { $customization_value = self::get_value_by_path(self::$customization_data, explode('.', $attribute['customizationKey'])); if ($customization_value !== null) { $attribute['default'] = $customization_value; } } } self::replace_plugin_url($attribute); } return $attributes; } private static function get_value_by_path($array, $path) { foreach ($path as $key) { if (!isset($array[$key])) { return null; } $array = $array[$key]; } return $array; } private static function set_value_by_path(&$array, $path, $value) { $current = &$array; foreach ($path as $key) { if (!isset($current[$key])) { $current[$key] = []; } $current = &$current[$key]; } $current = $value; } private static function replace_plugin_url(&$attribute) { if (is_array($attribute)) { array_walk_recursive($attribute, function(&$item) { if (is_string($item) && strpos($item, 'PLUGIN_URL_PLACEHOLDER') !== false) { $item = str_replace('PLUGIN_URL_PLACEHOLDER', self::$plugin_url, $item); } }); } else if (is_string($attribute) && strpos($attribute, 'PLUGIN_URL_PLACEHOLDER') !== false) { $attribute = str_replace('PLUGIN_URL_PLACEHOLDER', self::$plugin_url, $attribute); } } /** * Get specific customization value from the customization settings data. * Direct method without initializing the class with caching support. * * @param string $keys_string Key of required value. Multiple keys can be separated by a dot. E.g. 'typography.family' * @param mixed $default The default fallback value. * @return mixed The value. */ public static function get_value( $keys_string, $default = null ) { $data = affx_get_customization_settings( false, false ); $keys = explode( '.', $keys_string ); $value = self::get_value_by_path( $data, $keys ); if ( $value === null ) { $value = $default; } else { // Convert variation format to numeric font weight value if ( 'typography.variation' === $keys_string && is_string( $value ) && preg_match( '/^n([0-9])$/', $value, $matches ) ) { $value = intval( $matches[1] ) * 100; } } return $value; } } // Initialize the customization helper AffiliateX_Customization_Helper::init(); }