installation language construction
This commit is contained in:
parent
ce753acf20
commit
8b270bb1ed
|
@ -111,12 +111,35 @@ class WhatDidTheySayAdmin {
|
|||
}
|
||||
|
||||
function install() {
|
||||
$this->read_language_file();
|
||||
$options = get_option('what-did-they-say-options');
|
||||
if (empty($options)) {
|
||||
$this->default_options['languages'] = $this->build_default_languages();
|
||||
update_option('what-did-they-say-options', $this->default_options);
|
||||
}
|
||||
}
|
||||
|
||||
function build_default_languages() {
|
||||
$full_default_language_info = array();
|
||||
foreach ($this->default_options['languages'] as $info) {
|
||||
$code = null;
|
||||
if (is_string($info)) {
|
||||
$code = $info;
|
||||
$default = false;
|
||||
}
|
||||
if (is_array($info)) {
|
||||
extract($info);
|
||||
}
|
||||
if (isset($this->all_languages[$code])) {
|
||||
$full_default_language_info[$code] = array('name' => $this->all_languages[$code]);
|
||||
if (!empty($default)) {
|
||||
$full_default_language_info[$code]['default'] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $full_default_language_info;
|
||||
}
|
||||
|
||||
function admin_menu() {
|
||||
add_submenu_page(
|
||||
'edit-comments.php',
|
||||
|
|
|
@ -6,16 +6,15 @@
|
|||
<h3>Languages</h3>
|
||||
|
||||
<ul id="language-holder">
|
||||
<?php foreach ($options['languages'] as $language) {
|
||||
$default = false;
|
||||
if (is_array($language)) {
|
||||
$default = $language['default'];
|
||||
$code = $language['code'];
|
||||
}
|
||||
if (is_string($language)) { $code = $language; }
|
||||
<?php foreach ($options['languages'] as $code => $info) {
|
||||
$default = isset($info['default']);
|
||||
$name = $info['name'];
|
||||
?>
|
||||
<li>
|
||||
<strong><?php echo $this->all_languages[$code] ?></strong>
|
||||
<strong>
|
||||
<?php echo $name ?>
|
||||
<?php if ($
|
||||
</strong>
|
||||
| <a class="verify" href="<?php echo add_query_arg(array('wdts[code]' => $code, 'wdts[action]' => 'delete'), $nonce_url) ?>">Delete</a>
|
||||
</li>
|
||||
<?php } ?>
|
||||
|
|
|
@ -76,7 +76,30 @@ class WhatDidTheySayAdminTest extends PHPUnit_Framework_TestCase {
|
|||
|
||||
$options = get_option('what-did-they-say-options');
|
||||
$this->assertTrue($options['only_allowed_users']);
|
||||
}
|
||||
|
||||
function testBuildFullDefaultLanguageInfo() {
|
||||
$admin = new WhatDidTheySayAdmin();
|
||||
$admin->all_languages = array(
|
||||
'en' => 'English',
|
||||
'de' => 'German',
|
||||
'fr' => 'French'
|
||||
);
|
||||
|
||||
$admin->default_options = array(
|
||||
'languages' => array(
|
||||
'en',
|
||||
array('code' => 'de', 'default' => true),
|
||||
'it'
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
array(
|
||||
'en' => array('name' => 'English'),
|
||||
'de' => array('name' => 'German', 'default' => true),
|
||||
), $admin->build_default_languages()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue