Changeset 3742586 for langforge/trunk/admin/class-admin.php
- Timestamp:
- 10/12/2026 10:54:31 PM (2 weeks ago)
- File:
-
- 1 edited
-
langforge/trunk/admin/class-admin.php (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
langforge/trunk/admin/class-admin.php
r3739707 r3742586 1647 1647 } 1648 1648 1649 // Languages that just went away and still have posts. Counted here, stored 1650 // at the very end of the method (see "Orphaned translations" below). 1651 $pending = []; 1649 1652 if ($save_languages) { 1650 1653 // Tester feedback 2026-04-18: removing a language from the active … … 1658 1661 $new_codes = array_keys($active); 1659 1662 $removed = array_diff($old_codes, $new_codes); 1660 $pending = [];1661 1663 foreach ($removed as $code) { 1662 1664 if ($code === $default) continue; … … 1675 1677 } 1676 1678 } 1677 if (!empty($pending)) {1678 set_transient('langforge_removed_lang_pending_' . get_current_user_id(), $pending, HOUR_IN_SECONDS);1679 }1680 1679 } 1681 1680 … … 1700 1699 // Flush rewrite rules 1701 1700 flush_rewrite_rules(); 1701 1702 // Orphaned translations: hand the list to the next admin screen LAST, 1703 // after every purge above. With a persistent object cache (Redis, 1704 // Memcached) a transient lives in that cache only, and wp_cache_flush 1705 // (and the cache plugins' "purge all") empties it: written before the 1706 // purge, the list was gone in the same request and the owner who removed 1707 // a language was never told about its posts. Without a persistent cache 1708 // the transient is an options row and nothing changes. 1709 if (!empty($pending)) { 1710 set_transient('langforge_removed_lang_pending_' . get_current_user_id(), $pending, HOUR_IN_SECONDS); 1711 } 1702 1712 // phpcs:enable WordPress.Security.NonceVerification.Missing 1703 1713 } … … 1739 1749 } 1740 1750 1741 // Build unique strings. For source_lang, use the record with the lowest id 1742 // (= the first language registered for this string name). 1743 $unique = []; 1744 foreach ($all_strings as $string) { 1745 $name = $string->string_name; 1746 if (!isset($unique[$name])) { 1747 $unique[$name] = [ 1748 'source_lang' => $string->string_language, 1749 'source_id' => (int) $string->id, 1750 'domain' => $string->string_domain, 1751 'translations' => [] 1752 ]; 1753 } elseif ((int) $string->id < $unique[$name]['source_id']) { 1754 // Earlier record = real source 1755 $unique[$name]['source_lang'] = $string->string_language; 1756 $unique[$name]['source_id'] = (int) $string->id; 1757 } 1758 $unique[$name]['translations'][$string->string_language] = $string->string_value; 1759 } 1760 1761 return $unique; 1751 // One entry per name (source language = the earliest record; two domains with one name are not mixed). 1752 return LANGFORGE_Strings_Screen::group_rows((array) $all_strings); 1762 1753 } 1763 1754 … … 1819 1810 $strings = LANGFORGE_String_Translation::instance()->get_strings($current_domain ?: null, $default_lang); 1820 1811 $domain_counts = $this->get_domain_counts(); 1812 $woo_active = class_exists('WooCommerce'); 1821 1813 ?> 1822 1814 <div class="wrap"> 1823 1815 <?php LANGFORGE_Admin_Tabs::render('langforge-strings'); ?> 1824 1816 <?php do_action('langforge/admin_screen_top', 'langforge-strings'); ?> 1825 <h1><?php esc_html_e('String Translation', 'langforge'); ?><?php Forge_Docs_Link::render('langforge', 'translating-theme-text-string-translation', __('String translation', 'langforge'), __('Translate theme & plugin text strings scanned from your code.', 'langforge')); ?></h1> 1826 1817 <h1><?php esc_html_e('String Translation', 'langforge'); ?><?php Forge_Docs_Link::render('langforge', 'translating-theme-text-string-translation', __('String translation', 'langforge'), LANGFORGE_Strings_Screen::help_text()); ?></h1> 1818 1819 <?php 1820 // How a string gets into the list, and (for a shop) the button that lists the WooCommerce ones without a page being shown. 1821 LANGFORGE_Strings_Screen::render_intro($woo_active); 1822 if ($woo_active) { 1823 LANGFORGE_Strings_Screen::render_find_box(); 1824 wp_add_inline_script('lf-admin', LANGFORGE_Strings_Screen::find_script()); 1825 } 1826 ?> 1827 1827 1828 <div class="lf-string-filters"> 1828 1829 <form method="get" action=""> … … 1905 1906 </div> 1906 1907 <?php else: ?> 1907 <p><?php e sc_html_e('No strings found. Add strings using the form above or register them in your theme/plugin code.', 'langforge'); ?></p>1908 <p><?php echo esc_html(LANGFORGE_Strings_Screen::empty_text($woo_active)); ?></p> 1908 1909 <?php endif; ?> 1909 1910 <?php else: … … 2024 2025 <span class="dashicons dashicons-clipboard"></span> 2025 2026 </button> 2027 <?php 2028 // The texts of the emails are listed under keys: show the text behind the key. 2029 $name_excerpt = LANGFORGE_Strings_Screen::source_excerpt( 2030 $string_data['domain'], 2031 isset($string_data['translations'][$string_data['source_lang']]) ? $string_data['translations'][$string_data['source_lang']] : '' 2032 ); 2033 if ($name_excerpt !== '') { 2034 echo '<br><small class="lf-name-excerpt" style="color:#64748b;">' . esc_html($name_excerpt) . '</small>'; 2035 } 2036 LANGFORGE_Strings_Screen::render_other_domains_note(isset($string_data['also_in']) ? $string_data['also_in'] : []); 2037 ?> 2026 2038 </td> 2027 2039 <?php if (!$current_domain): ?> … … 2052 2064 ?> 2053 2065 <td> 2054 <textarea name="strings[<?php echo esc_attr($string_name); ?>][<?php echo esc_attr($code); ?>]" 2055 class="widefat" rows="2" <?php echo $is_source ? 'style="background:#f0f0f0;"' : ''; ?>><?php echo esc_textarea($trans_value); ?></textarea> 2056 <?php if ($is_source): ?> 2057 <small style="color:#666;"><?php esc_html_e('(source)', 'langforge'); ?></small> 2058 <?php endif; ?> 2066 <?php LANGFORGE_Strings_Screen::render_translation_cell($string_name, $code, $string_data['domain'], $is_source, $trans_value); ?> 2059 2067 </td> 2060 2068 <?php endforeach; ?> … … 2477 2485 .lf-domain-badge { background: #f0f0f0; color: #555; padding: 2px 8px; border-radius: 4px; font-size: 14px; } 2478 2486 .lf-add-string-form { background: #f9f9f9; padding: 15px; margin: 20px 0; } 2487 .lf-find-woo { margin: 12px 0; } 2488 .lf-find-woo .lf-find-woo-status { margin-left: 10px; font-size: 14px; color: #475569; } 2489 .lf-find-woo .description { margin-top: 6px; max-width: 820px; } 2479 2490 <?php } finally { $lf_inline_css = (string) ob_get_clean(); } wp_add_inline_style('lf-admin', $lf_inline_css); ?> 2480 2491 <?php … … 2510 2521 foreach ($translations as $lang => $value) { 2511 2522 $lang = sanitize_text_field($lang); 2512 $value = sanitize_textarea_field($value);2523 $value = LANGFORGE_Strings_Screen::sanitize_translation($domain, $value); 2513 2524 2514 2525 if (!empty($value)) { … … 3992 4003 }); 3993 4004 }); 3994 <?php } finally { $lf_inline_js = (string) ob_get_clean(); } wp_add_inline_script('lf-admin', $lf_inline_js); ?> 4005 <?php } finally { $lf_inline_js = (string) ob_get_clean(); } 4006 // This notice is printed on every admin screen (admin_notices), but lf-admin.js is queued only on the Lang Forge 4007 // pages, the post lists/editors and the taxonomy screens (its click handlers are global; see 4008 // enqueue_admin_scripts). An inline script handed to a handle that is not queued is dropped, so on the 4009 // Dashboard, Plugins or Media the buttons were drawn and did nothing. Own handle, jQuery only, and only here: 4010 // the method has returned already when no list is waiting. 4011 wp_register_script('lf-removed-lang-notice', false, ['jquery'], LANGFORGE_VERSION, true); 4012 wp_enqueue_script('lf-removed-lang-notice'); 4013 wp_add_inline_script('lf-removed-lang-notice', $lf_inline_js); ?> 3995 4014 <?php 3996 4015 }
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)