DB_Plugin_WP_Admin_Helper

The DevBuddy Twitter Feed Plugin DB Plugin WP Admin Helper class.

Defined (1)

The class is defined in the following location(s).

/admin/class.wp-admin-helper.php  
  1. class DB_Plugin_WP_Admin_Helper extends DB_Twitter_Feed_Base { 
  2.  
  3.  
  4. /** 
  5. * Take attributes/value pairs and write them to an element 
  6. * @access public 
  7. * @return string the attribute/value pairs as valid HTML 
  8. * @since 2.0.0 
  9. * @param array $attributes An associative array of attribute/value pairs 
  10. */ 
  11. public function write_attr( $attributes ) { 
  12. $data = ''; 
  13.  
  14. if ( is_array($attributes) && count($attributes) !== 0 ) { 
  15. foreach ( $attributes as $attr => $value ) { 
  16. $data .= ' '.$attr.'="'.$value.'"'; 
  17.  
  18. return $data; 
  19.  
  20.  
  21. /** 
  22. * Add a description to the setting 
  23. * @access public 
  24. * @return string The description provided wrapped in a tag that WordPress will use to format appropriately 
  25. * @since 1.0.0 
  26. * @param $desc string The decription to accompany a settings field in the WordPress admin interface 
  27. */ 
  28. public function write_desc( $desc = '' ) { 
  29. if ( $desc != '' ) { 
  30. return '<p class="description">'.$desc.'</p>'; 
  31.  
  32.  
  33. /** 
  34. * Output a basic checkbox field 
  35. * @access public 
  36. * @return void 
  37. * @since 1.0.0 
  38. * @param array $args[option] The name of the option as stored in the database 
  39. * @param array $args[desc] The description to accompany this field in the admin 
  40. * @param array $args[attr] An array of attributes to be included on the input element 
  41. */ 
  42. public function write_checkbox_field( $args ) { 
  43. $stored_value = $this->get_db_plugin_option( $this->options_name_main, $args['option'] ); 
  44.  
  45. echo '<input type="checkbox" id="'.$this->_html_item_id_attr( $args['option'] ).'" name="'.$this->options_name_main.'['.$args['option'].']" value="yes"'; 
  46. if( $stored_value && $stored_value === 'yes') { 
  47. echo ' checked="checked"'; 
  48.  
  49. echo ( isset( $args['attr'] ) ) ? $this->write_attr( $args['attr'] ) : ''; 
  50.  
  51. echo ' />'; 
  52.  
  53. echo ( isset( $args['desc'] ) ) ? $this->write_desc( $args['desc'] ) : ''; 
  54.  
  55.  
  56. /** 
  57. * Output basic radio fields 
  58. * @access public 
  59. * @return void 
  60. * @since 2.0.0 
  61. * @param array $args[option] The name of the option as stored in the database 
  62. * @param array $args[options] An associative array of radio options and their values (keys and values respectively) 
  63. * @param array $args[desc] The description to accompany this field in the admin 
  64. * @param array $args[attr] An array of attributes to be included on the input element 
  65. */ 
  66. public function write_radio_fields( $args ) { 
  67. $stored_value = $this->get_db_plugin_option( $this->options_name_main, $args['option'] ); 
  68.  
  69. foreach ( $args['options'] as $name => $value ) { 
  70. echo '<div class="'.$this->plugin_short_name.'_radio_item">'; 
  71.  
  72. echo '<label for="'.$this->_html_item_id_attr( $args['option'] ).'_'.$value.'">'.$name.'</label>'; 
  73.  
  74. echo '<input type="radio" id="'.$this->_html_item_id_attr( $args['option'] ).'_'.$value.'" name="'.$this->options_name_main.'['.$args['option'].']" value="'.$value.'"'; 
  75.  
  76. if ( $stored_value && $stored_value === $value ) { 
  77. echo ' checked="checked"'; 
  78.  
  79. echo ( isset( $args['attr'] ) ) ? $this->write_attr( $args['attr'] ) : ''; 
  80.  
  81. echo ' />'; 
  82.  
  83. echo '</div>'; 
  84.  
  85. echo ( isset( $args['desc'] ) ) ? $this->write_desc( $args['desc'] ) : ''; 
  86.  
  87.  
  88. /** 
  89. * Output basic dropdown field that supports numbered dropdowns only 
  90. * @access public 
  91. * @return void 
  92. * @since 1.0.0 
  93. * @param array $args[option] The name of the option as stored in the database 
  94. * @param array $args[min] The lowest number that the dropdown should reach 
  95. * @param array $args[max] The highest number that the dropdown should reach 
  96. * @param array $args[desc] The description to accompany this field in the admin 
  97. * @param array $args[attr] An array of attributes to be included on the input element 
  98. */ 
  99. public function write_numeric_dropdown_field( $args ) { 
  100. $stored_value = $this->get_db_plugin_option( $this->options_name_main, $args['option'] ); 
  101.  
  102. echo '<select id="'.$this->_html_item_id_attr( $args['option'] ).'" name="'.$this->options_name_main.'['.$args['option'].']"'; 
  103.  
  104. echo ( isset( $args['attr'] ) ) ? $this->write_attr( $args['attr'] ) : ''; 
  105.  
  106. echo '>'; 
  107.  
  108. for ( $num = $args['min']; $num <= $args['max']; $num++ ) { 
  109. echo '<option value="'.$num.'"'; 
  110.  
  111. if ( $stored_value && (int) $stored_value === $num ) { 
  112. echo ' selected="selected"'; 
  113.  
  114. echo '>'.$num.'</option>'; 
  115. echo '</select>'; 
  116.  
  117. echo ( isset( $args['desc'] ) ) ? $this->write_desc( $args['desc'] ) : ''; 
  118.  
  119.  
  120. /** 
  121. * Output basic text field 
  122. * @access public 
  123. * @return void 
  124. * @since 2.0.0 
  125. * @param array $args[option] The name of the option as stored in the database 
  126. * @param array $args[desc] The description to accompany this field in the admin 
  127. * @param array $args[attr] An array of attributes to be included on the input element 
  128. */ 
  129. public function write_input_text_field( $args ) { 
  130. $stored_value = $this->get_db_plugin_option( $this->options_name_main, $args['option'] ); 
  131.  
  132. echo '<input type="text" id="'.$this->_html_item_id_attr( $args['option'] ).'" name="'.$this->options_name_main.'['.$args['option'].']"'; 
  133.  
  134. echo ' value="'; 
  135. if( $stored_value && $stored_value != '') { 
  136. echo $stored_value; 
  137. echo '"'; 
  138.  
  139. echo ( isset( $args['attr'] ) ) ? $this->write_attr( $args['attr'] ) : ''; 
  140.  
  141. echo ' />'; 
  142.  
  143. echo ( isset( $args['desc'] ) ) ? $this->write_desc( $args['desc'] ) : ''; 
  144.  
  145.  
  146. } // END class