This is working for editor role vrs admin user.
Updating so the field is hidden if non admin user.
Uses default value in a define.
'type' => 'number'
),
);
-
+
foreach ($fieldNames as $field) {
-
+
$this->glmsimplemessageboardAddSettingField(
$field['name'],
$field['label'],
wp_enqueue_style('messageboard-admin-css',plugins_url('glm-simple-messageboard/css/admin/admin.css' , $this->pluginDirName));
}
public function load_script()
- {
+ {
wp_register_script(
'simple-messageboard-admin-js',
plugins_url('glm-simple-messageboard/js/admin/admin.js' , $this->pluginDirName),
*/
/*
- * USAGE:
- *
+ * USAGE:
+ *
This part goes into your functions.php
<?php
// This part will be placed into your functions.php
if ( !function_exists( 'glm_get_simplemessageboard_option' ) ) {
- function glm_get_simplemessageboard_option( $option_name )
+ function glm_get_simplemessageboard_option( $option_name )
{
$settings = get_option( 'glmsimplemessageboard_settings' );
if ($settings && array_key_exists( $option_name, $settings ) ) {
}
}
?>
- *
+ *
This part goes where you want to display the data
<div>
- <?php
+ <?php
// This part will be placed wherever you want to display the data
if (function_exists( 'glm_get_simplemessageboard_option' ) ) {?>
<?php if ( glm_get_simplemessageboard_option( 'active' ) ) { ?>
*/
-define('GLM_SIMPLEMESSAGEBOARD_SETTINGS', 'glmsimplemessageboard_settings');
-define('GLM_SIMPLEMESSAGEBOARD_NEW_CAPABILITY', 'glmsimplemessageboard_edit_messageboard');
-define('GLM_SIMPLEMESSAGEBOARD_BUILT_IN_CAPABILITY', 'edit_posts');
+define( 'GLM_SIMPLEMESSAGEBOARD_SETTINGS', 'glmsimplemessageboard_settings' );
+define( 'GLM_SIMPLEMESSAGEBOARD_NEW_CAPABILITY', 'glmsimplemessageboard_edit_messageboard' );
+define( 'GLM_SIMPLEMESSAGEBOARD_BUILT_IN_CAPABILITY', 'edit_posts' );
+define( 'GLM_SIMPLEMESSAGEBOARD_TEXTAREA_LIMIT_DEFAULT', '250' );
register_activation_hook(__FILE__, array('Glmsimplemessageboard_Admin_Controller', 'activate_plugin'));
register_deactivation_hook(__FILE__, array('Glmsimplemessageboard_Admin_Controller', 'deactivate_plugin'));
-<?php
+<?php
// This does not seem to restrct on privileges properly
// e.g. current_user_can("bluriglurp") also passes as true
if ( current_user_can( "manage_options" ) ) { ?>
<input type="number" min="0" step="1" max="99999" name="glmsimplemessageboard_settings[<?php echo $fieldName;?>]"
- value="<?php echo str_replace( '"', '"e;', $options[$fieldName] ); ?>">
+ value="<?php echo ($options[$fieldName]) ? $options[$fieldName]: GLM_SIMPLEMESSAGEBOARD_TEXTAREA_LIMIT_DEFAULT; ?>" />
+<?php } else { ?>
+ <input type="hidden" name="glmsimplemessageboard_settings[<?php echo $fieldName;?>]" value="<?php echo ($options[$fieldName]) ? $options[$fieldName]: GLM_SIMPLEMESSAGEBOARD_TEXTAREA_LIMIT_DEFAULT; ?>" />
+ <?php echo ($options[$fieldName]) ? $options[$fieldName]: GLM_SIMPLEMESSAGEBOARD_TEXTAREA_LIMIT_DEFAULT;?>
<?php } ?>
if ($options && array_key_exists( 'characterlimit', $options ) ) {
$characterLimit = $options['characterlimit'];
} else {
- $characterLimit = "250";
+ $characterLimit = GLM_SIMPLEMESSAGEBOARD_TEXTAREA_LIMIT_DEFAULT;
}
?>
<textarea class='message' cols="40" maxlength="<?php echo $characterLimit ?>" rows="5" name="glmsimplemessageboard_settings[<?php echo $fieldName;?>]"><?php echo htmlspecialchars($options[$fieldName]); ?></textarea>
<br><span class="countdown"></span>
<script type="text/javascript">
-
+
var characterLimit = <?php echo $characterLimit ?>;
-
+
function updateCountdown() {
var remaining = characterLimit - jQuery('.message').val().length;
jQuery('.countdown').text(remaining + ' characters remaining.');
$('.message').change(updateCountdown);
$('.message').keyup(updateCountdown);
});
-</script>
\ No newline at end of file
+</script>