'auto', 'format'=>'image/png', 'quality'=>92, 'theme'=>'light')); } function pixlio_image_editor_language() { $options = pixlio_image_editor_options(); $locale = $options['language'] === 'auto' ? get_locale() : $options['language']; $code = strtolower(substr((string)$locale, 0, 2)); return in_array($code, array('en','ja','zh','ko','es'), true) ? $code : 'en'; } function pixlio_image_editor_strings($language = null) { static $cache = array(); $options = pixlio_image_editor_options(); $locales = array('en'=>'en_US', 'ja'=>'ja', 'zh'=>'zh_CN', 'ko'=>'ko_KR', 'es'=>'es_ES'); $code = $language ?: pixlio_image_editor_language(); if (!isset($locales[$code])) { $code = 'en'; } $locale = null === $language && $options['language'] === 'auto' ? get_locale() : $locales[$code]; $key = $code . ':' . $locale; if (isset($cache[$key])) { return $cache[$key]; } $english = json_decode(file_get_contents(__DIR__ . '/languages/en.json'), true); $bundled = json_decode(file_get_contents(__DIR__ . '/languages/' . $code . '.json'), true); $strings = array_replace_recursive(is_array($english) ? $english : array(), is_array($bundled) ? $bundled : array()); // Preserve bundled language choices when that WordPress locale is not installed. $switched = false; if (determine_locale() !== $locale) { $switched = switch_to_locale($locale); } try { if ($switched || determine_locale() === $locale) { $translated = pixlio_image_editor_gettext_strings(); foreach ($translated as $name => $value) { if (is_array($value)) { foreach ($value as $message => $text) { if ($text !== $english[$name][$message]) { $strings[$name][$message] = $text; } } } elseif ($value !== $english[$name]) { $strings[$name] = $value; } } } } finally { if ($switched) { restore_previous_locale(); } } $cache[$key] = $strings; return $strings; } function pixlio_image_editor_label($key) { $strings = pixlio_image_editor_strings(); $english = pixlio_image_editor_strings('en'); return $strings[$key] ?? $english[$key] ?? $key; } function pixlio_image_editor_sanitize_options($value) { $old = pixlio_image_editor_options(); if (!is_array($value)) { return $old; } $result = $old; $allowed = array('language'=>array('auto','ja','en','zh','ko','es'), 'format'=>array('image/png','image/jpeg'), 'theme'=>array('light','dark','system')); foreach ($allowed as $key=>$choices) { if (isset($value[$key]) && is_string($value[$key]) && in_array($value[$key], $choices, true)) { $result[$key] = $value[$key]; } } if (isset($value['quality']) && is_scalar($value['quality']) && is_numeric($value['quality'])) { $result['quality'] = max(20, min(100, (int)$value['quality'])); } return $result; } add_action('admin_init', function () { register_setting('pixlio_image_editor_settings', 'pixlio_image_editor_options', array('type'=>'array', 'sanitize_callback'=>'pixlio_image_editor_sanitize_options', 'show_in_rest'=>false)); }); add_action('admin_menu', function () { add_submenu_page('pixlio-image-editor', 'Pixlio – Image Editor — ' . pixlio_image_editor_label('settings'), pixlio_image_editor_label('settings'), 'manage_options', 'pixlio-image-editor-settings', 'pixlio_image_editor_settings_page'); }, 20); add_filter('plugin_action_links_' . plugin_basename(__DIR__ . '/pixlio-image-editor.php'), function ($links) { if (current_user_can('manage_options')) { array_unshift($links, '' . esc_html(pixlio_image_editor_label('settings')) . ''); } $links['creator_support'] = 'Creator Support'; return $links; }); function pixlio_image_editor_settings_select($key, $label, $choices, $description = '') { $options = pixlio_image_editor_options(); echo '
' . esc_html(pixlio_image_editor_label($description)) . '
'; } echo '' . esc_html(pixlio_image_editor_label('settingsSaved')) . '
' . esc_html(pixlio_image_editor_label('settingsHint')) . '