Update the limit field.
authorSteve Sutton <steve@gaslightmedia.com>
Thu, 2 Mar 2017 13:43:01 +0000 (08:43 -0500)
committerSteve Sutton <steve@gaslightmedia.com>
Thu, 2 Mar 2017 13:43:01 +0000 (08:43 -0500)
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.

controllers/Admin.php
glm-simple-messageboard.php
views/number.php
views/textArea.php

index a58b565..f4ee7ff 100644 (file)
@@ -160,9 +160,9 @@ class Glmsimplemessageboard_Admin_Controller
                 'type'  => 'number'
             ),
         );
-        
+
         foreach ($fieldNames as $field) {
-            
+
             $this->glmsimplemessageboardAddSettingField(
                 $field['name'],
                 $field['label'],
@@ -228,7 +228,7 @@ class Glmsimplemessageboard_Admin_Controller
         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),
index f7024d0..2669d56 100644 (file)
@@ -9,13 +9,13 @@
  */
 
 /*
- * 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'));
index 9d565ad..05e7035 100644 (file)
@@ -1,9 +1,12 @@
 
 
-<?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( '"', '&quote;', $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 } ?>
index fdd41e3..3079705 100644 (file)
@@ -2,16 +2,16 @@
     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.');
@@ -21,4 +21,4 @@
         $('.message').change(updateCountdown);
         $('.message').keyup(updateCountdown);
     });
-</script>
\ No newline at end of file
+</script>