forked from msaari/relevanssi-premium-snowball-stemmer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadmin-menu.php
92 lines (81 loc) · 3.17 KB
/
admin-menu.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
/**
* Relevanssi Premium Snowball Stemmer
*
* /admin-menu.php
*
* @package Relevanssi Premium Snowball Stemmer
* @author Mikko Saari
* @license https://wordpress.org/about/gpl/ GNU General Public License
* @see https://www.relevanssi.com/snowball-stemmer/
*/
add_filter( 'relevanssi_tabs', 'relevanssi_premium_snowball_stemmer_tab', 20 );
/**
* Adds the stemmer tab to the Relevanssi admin menu.
*
* @param array $tabs The tabs array.
*
* @return array The updated tabs array.
*/
function relevanssi_premium_snowball_stemmer_tab( $tabs ) {
$tabs[] = array(
'slug' => 'snowball-stemmer',
'name' => 'Stemmer',
'require' => false,
'callback' => 'relevanssi_premium_snowball_stemmer_render_tab',
'save' => true,
);
return $tabs;
}
/**
* Renders the options page.
*
* Relevanssi Light doesn't have plenty of options at the moment. That is
* unlikely to change in the future.
*/
function relevanssi_premium_snowball_stemmer_render_tab() {
$languages = array(
'catalá (Catalan)' => 'ca',
'dansk (Danish)' => 'da',
'Deutsch (German)' => 'de',
'English' => 'en',
'español (Spanish)' => 'es',
'français (French)' => 'fr',
'italiano (Italian)' => 'it',
'Nederlands (Dutch)' => 'nl',
'norsk (Norwegian)' => 'no',
'português (Portuguese)' => 'pt',
'românește (Romanian)' => 'ro',
'русский язык (Russian)' => 'ru',
'suomi (Finnish)' => 'fi',
'svensk (Swedish)' => 'sv',
);
if ( ! empty( $_REQUEST ) && isset( $_REQUEST['submit'] ) ) {
check_admin_referer( 'save_options', 'relevanssi_premium_snowball_stemmer' );
$language = $_REQUEST['relevanssi_premium_snowball_language'];
if ( in_array( $language, $languages, true ) ) {
update_option( 'relevanssi_premium_snowball_stemmer_language', $language );
}
}
$selected_language = get_option( 'relevanssi_premium_snowball_stemmer_language', 'en' );
$language_options = array_map(
function( $key, $value ) use ( $selected_language ) {
$selected = $selected_language === $value ? "selected='selected'" : '';
return "<option value='$value' $selected>$key</option>";
},
array_keys( $languages ),
$languages
);
?>
<div class="wrap">
<?php wp_nonce_field( 'save_options', 'relevanssi_premium_snowball_stemmer' ); ?>
<h3 id="stemmer"><?php esc_html_e( 'Snowball Stemmer', 'relevanssi_premium_snowball_stemmer' ); ?></h3>
<p><?php esc_html_e( 'Choose the language here and then rebuild the index on the Indexing tab. Once you do that, all words in the posts and all search terms are stemmed, making it easier to find posts with varying word forms. The search term highlighting does not support stemming at the moment, so highlighting will only work when the search term matches the word form in the post.', 'relevanssi_premium_snowball_stemmer' ); ?></p>
<p><?php esc_html_e( 'Choose the language', 'relevanssi_premium_snowball_stemmer' ); ?>:
<select name="relevanssi_premium_snowball_language" id="relevanssi_premium_snowball_language">
<?php echo implode( "\n", $language_options ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
</select>
</p>
</div>
<?php
}