Commit a58ba32c by Cyrille37

add options description

parent b3e60090
# Eclipse IDE
.settings/
.project
.buildpath
......@@ -13,8 +13,6 @@ require_once 'Vote_UI.php';
require_once 'Util.php';
require_once 'Settings.php';
define( WP_DEBUG, true );
class CommunityVoice
{
public static $Settings;
......@@ -105,6 +103,7 @@ class CommunityVoice
return $join . " LEFT JOIN {$pre}vote_count ON {$pre}posts.ID = {$pre}vote_count.post_id ";
}
/**
* Group Main Loop by post_id
*
......
......@@ -7,27 +7,27 @@
*/
class Settings
{
const SETTING_NAME = "CommunityVoice_settings";
const SETTING_NAME = 'CommunityVoice_settings';
private $settings;
private $settingsList;
function __construct()
{
$this->settingsList = [
['id' => 'CPT_only', 'label' => 'Custom post type only : ', 'type' => 'text'],
['id' => 'activate_negative_vote', 'label' => 'Activate negative vote : ', 'type' => 'checkbox'],
['id' => 'automatically_display_vote', 'label' => 'Automatically display vote : ', 'type' => 'checkbox'],
['id' => 'CPT_only', 'label' => 'Custom post type only : ', 'type' => 'text', 'description'=>'Vote actif seulement pour les articles de ce type.'],
['id' => 'activate_negative_vote', 'label' => 'Activate negative vote : ', 'type' => 'checkbox', 'description'=>'Activer les votes négatifs.'],
['id' => 'automatically_display_vote', 'label' => 'Automatically display vote : ', 'type' => 'checkbox', 'description'=>'' ],
];
if( get_option( self::SETTING_NAME, "" ) !== "" )
if( get_option( self::SETTING_NAME, '' ) !== '' )
{
$this->settings = get_option( self::SETTING_NAME, "" );
$this->settings = get_option( self::SETTING_NAME, '' );
$this->settings = explode( ";", $this->settings );
}
else
{
$this->settings = [];
add_option( self::SETTING_NAME, "" );
add_option( self::SETTING_NAME, '' );
}
add_action( 'admin_post_save_settings', array( $this, 'post_save_settings' ) );
......@@ -123,7 +123,7 @@ class Settings
*/
function saveSetting( $key, $value )
{
$settingsToSave = "";
$settingsToSave = '';
$arraySettings = $this->getArraySettings();
$arraySettings[$key] = $value;
......
......@@ -3,16 +3,21 @@
<form class="" action="<?php echo esc_url( admin_url('admin-post.php') ); ?>" method="post">
<?php foreach( $this->settingsList as $setting ) :?>
<div class="" style="padding:1rem 0">
<label for="<?= $setting['id']?>" style="display:inline-block;min-width:200px"><?= $setting['label']?></label>
<input type="<?= $setting['type']?>" name="<?= $setting['id'] ?>" id="<?= $setting['id']?>" class="popular-category" value="<?= $this->getSetting( $setting['id'] ) ?>" <?= $this->getSetting( $setting['id'] ) === 'checked' ? 'checked' : '' ?>/>
<label for="<?php echo $setting['id']?>" style="display:inline-block;min-width:200px"><?php echo $setting['label']?></label>
<input type="<?php echo $setting['type'] ?>" name="<?php echo $setting['id'] ?>" id="<?php echo $setting['id']?>" aria-describedby="<?php $setting['id'].'-description' ?>" class="popular-category" value="<?php echo $this->getSetting( $setting['id'] ) ?>" <?php echo $this->getSetting( $setting['id'] ) === 'checked' ? 'checked' : '' ?>/>
<p id="<?php echo $setting['id'].'-description' ?>" class="description">
<?php echo $setting['description'] ?>
</p>
</div>
<?php endforeach;?>
<input type="submit" class="button button-primary button-large" value="Sauvegarder">
<input type="hidden" name="action" value="save_settings">
</form>
<script type="text/javascript">
jQuery(function(){
jQuery("input[type=checkbox]").change(function(){
jQuery(this).prop('checked') ? jQuery(this).val("checked") : jQuery(this).val("no");
});
});
</script>
</div>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment