forked from not-only-code/qtranslate-slug
-
Notifications
You must be signed in to change notification settings - Fork 0
/
qtranslate-slug-settings-options.php
139 lines (111 loc) · 3.43 KB
/
qtranslate-slug-settings-options.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<?php
/**
* Define our settings sections
*
* @package Qtranslate Slug
* @subpackage Settings
* @version 1.0
*
* @return array key=$id, array value=$title in: add_settings_section( $id, $title, $callback, $page );
*/
function qts_options_page_sections() {
$sections = array();
$sections['post_types'] = __('Post types', 'qts');
$sections['taxonomies'] = __('Taxonomies', 'qts');
return $sections;
}
/**
* Helper for create arrays of choices
*
* @package Qtranslate Slug
* @subpackage Settings
* @version 1.0
*
* @return array
*/
function get_multi_txt_choices($name = false) {
global $q_config;
if (!$name) return array();
$choices = array();
foreach( $q_config['enabled_languages'] as $key => $lang) {
$label = sprintf( __('Slug (%s)', 'qts'), $q_config['language_name'][$lang] );
$choices[] = "$label|$lang"; // prints: 'Slug (English)|en' ( $name = books )
}
return $choices;
}
/**
* Define our form fields (settings)
*
* @package Qtranslate Slug
* @subpackage Settings
* @version 1.0
*
* @return array
*/
function qts_options_page_fields() {
global $q_config;
$post_types = get_post_types( array('_builtin' => false, 'public' => true ), 'objects');
// each post type
foreach ($post_types as $post_type):
$options[] = array(
"section" => "post_types",
"id" => QTS_PREFIX . "post_type_" . $post_type->name,
"title" => $post_type->labels->singular_name,
"desc" => sprintf( __( '<code>http://example.org/<u>%s</u>/some-%s/</code>', 'qts' ), $post_type->name, $post_type->name),
'class' => 'qts-slug',
"type" => "multi-text",
"choices" => get_multi_txt_choices( $post_type->name),
"std" => ""
);
endforeach;
// end each post type
$options[] = array(
"section" => "taxonomies",
"id" => QTS_PREFIX . "taxonomy_category",
"title" => __('Categories'),
"desc" => __( '<code>http://example.org/<u>category</u>/some-category/</code>', 'qts' ),
"type" => "multi-text",
'class' => 'qts-slug',
"choices" => get_multi_txt_choices('category'),
"std" => ""
);
$options[] = array(
"section" => "taxonomies",
"id" => QTS_PREFIX . "taxonomy_post_tag",
"title" => __('Tags'),
"desc" => __( '<code>http://example.org/<u>tag</u>/some-tag/</code>', 'qts' ),
"type" => "multi-text",
'class' => 'qts-slug',
"choices" => get_multi_txt_choices('post_tag'),
"std" => ""
);
$taxonomies = get_taxonomies( array( 'public' => true, 'show_ui' => true, '_builtin' => false ), 'object' );
// each extra taxonomy
foreach ($taxonomies as $taxonomy):
$options[] = array(
"section" => "taxonomies",
"id" => QTS_PREFIX . "taxonomy_" . $taxonomy->name,
"title" => $taxonomy->labels->singular_name,
"desc" => sprintf( __( '<code>http://example.org/<u>%s</u>/some-%s/</code>', 'qts' ), $taxonomy->name, $taxonomy->name ),
"type" => "multi-text",
'class' => 'qts-slug',
"choices" => get_multi_txt_choices( $taxonomy->name),
"std" => ""
);
endforeach;
// end each extra taxonomy
return $options;
}
/**
* Contextual Help
*
* @package Qtranslate Slug
* @subpackage Settings
* @version 1.0
*
*/
function qts_options_page_contextual_help() {
$text = "<h3>" . __('Qtranslate Settings - Contextual Help','qts') . "</h3>";
$text .= "<p>" . __('Contextual help goes here. You may want to use different html elements to format your text as you want.','qts') . "</p>";
return $text;
}