gravityview /
GravityView
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * Renders field/widget options and view settings |
||
| 4 | * |
||
| 5 | * @package GravityView |
||
| 6 | * @license GPL2+ |
||
| 7 | * @author Katz Web Services, Inc. |
||
| 8 | * @link http://gravityview.co |
||
| 9 | * @copyright Copyright 2014, Katz Web Services, Inc. |
||
| 10 | * |
||
| 11 | * @since 1.2 |
||
| 12 | */ |
||
| 13 | |||
| 14 | class GravityView_Render_Settings { |
||
| 15 | |||
| 16 | /** |
||
| 17 | * Get the default options for a standard field. |
||
| 18 | * |
||
| 19 | * @param string $field_type Type of field options to render (`field` or `widget`) |
||
| 20 | * @param string $template_id Table slug |
||
| 21 | * @param float $field_id GF Field ID - Example: `3`, `5.2`, `entry_link`, `created_by` |
||
| 22 | * @param string $context What context are we in? Example: `single` or `directory` |
||
| 23 | * @param string $input_type (textarea, list, select, etc.) |
||
| 24 | * @return array Array of field options with `label`, `value`, `type`, `default` keys |
||
| 25 | */ |
||
| 26 | public static function get_default_field_options( $field_type, $template_id, $field_id, $context, $input_type ) { |
||
| 27 | |||
| 28 | $field_options = array(); |
||
| 29 | |||
| 30 | if( 'field' === $field_type ) { |
||
| 31 | |||
| 32 | // Default options - fields |
||
| 33 | $field_options = array( |
||
| 34 | 'show_label' => array( |
||
| 35 | 'type' => 'checkbox', |
||
| 36 | 'label' => __( 'Show Label', 'gravityview' ), |
||
| 37 | 'value' => true, |
||
| 38 | ), |
||
| 39 | 'custom_label' => array( |
||
| 40 | 'type' => 'text', |
||
| 41 | 'label' => __( 'Custom Label:', 'gravityview' ), |
||
| 42 | 'value' => '', |
||
| 43 | 'merge_tags' => true, |
||
| 44 | ), |
||
| 45 | 'custom_class' => array( |
||
| 46 | 'type' => 'text', |
||
| 47 | 'label' => __( 'Custom CSS Class:', 'gravityview' ), |
||
| 48 | 'desc' => __( 'This class will be added to the field container', 'gravityview'), |
||
| 49 | 'value' => '', |
||
| 50 | 'merge_tags' => true, |
||
| 51 | 'tooltip' => 'gv_css_merge_tags', |
||
| 52 | ), |
||
| 53 | 'only_loggedin' => array( |
||
| 54 | 'type' => 'checkbox', |
||
| 55 | 'label' => __( 'Make visible only to logged-in users?', 'gravityview' ), |
||
| 56 | 'value' => '' |
||
| 57 | ), |
||
| 58 | 'only_loggedin_cap' => array( |
||
| 59 | 'type' => 'select', |
||
| 60 | 'label' => __( 'Make visible for:', 'gravityview' ), |
||
| 61 | 'options' => self::get_cap_choices( $template_id, $field_id, $context, $input_type ), |
||
| 62 | 'class' => 'widefat', |
||
| 63 | 'value' => 'read', |
||
| 64 | ), |
||
| 65 | ); |
||
| 66 | |||
| 67 | // Match Table as well as DataTables |
||
| 68 | if( preg_match( '/table/ism', $template_id ) && 'directory' === $context ) { |
||
| 69 | $field_options['width'] = array( |
||
| 70 | 'type' => 'number', |
||
| 71 | 'label' => __('Percent Width', 'gravityview'), |
||
| 72 | 'desc' => __( 'Leave blank for column width to be based on the field content.', 'gravityview'), |
||
| 73 | 'class' => 'code widefat', |
||
| 74 | 'value' => '', |
||
| 75 | ); |
||
| 76 | } |
||
| 77 | |||
| 78 | } |
||
| 79 | |||
| 80 | /** |
||
| 81 | * @filter `gravityview_template_{$field_type}_options` Filter the field options by field type. Filter names: `gravityview_template_field_options` and `gravityview_template_widget_options` |
||
| 82 | * @param[in,out] array Array of field options with `label`, `value`, `type`, `default` keys |
||
| 83 | * @param[in] string $template_id Table slug |
||
| 84 | * @param[in] float $field_id GF Field ID - Example: `3`, `5.2`, `entry_link`, `created_by` |
||
| 85 | * @param[in] string $context What context are we in? Example: `single` or `directory` |
||
| 86 | * @param[in] string $input_type (textarea, list, select, etc.) |
||
| 87 | */ |
||
| 88 | $field_options = apply_filters( "gravityview_template_{$field_type}_options", $field_options, $template_id, $field_id, $context, $input_type ); |
||
| 89 | |||
| 90 | /** |
||
| 91 | * @filter `gravityview_template_{$input_type}_options` Filter the field options by input type (`$input_type` examples: `textarea`, `list`, `select`, etc.) |
||
| 92 | * @param[in,out] array Array of field options with `label`, `value`, `type`, `default` keys |
||
| 93 | * @param[in] string $template_id Table slug |
||
| 94 | * @param[in] float $field_id GF Field ID - Example: `3`, `5.2`, `entry_link`, `created_by` |
||
| 95 | * @param[in] string $context What context are we in? Example: `single` or `directory` |
||
| 96 | * @param[in] string $input_type (textarea, list, select, etc.) |
||
| 97 | */ |
||
| 98 | $field_options = apply_filters( "gravityview_template_{$input_type}_options", $field_options, $template_id, $field_id, $context, $input_type ); |
||
| 99 | |||
| 100 | return $field_options; |
||
| 101 | } |
||
| 102 | |||
| 103 | /** |
||
| 104 | * Get capabilities options for GravityView |
||
| 105 | * |
||
| 106 | * Parameters are only to pass to the filter. |
||
| 107 | * |
||
| 108 | * @param string $template_id Optional. View slug |
||
| 109 | * @param string $field_id Optional. GF Field ID - Example: `3`, `5.2`, `entry_link`, `created_by` |
||
| 110 | * @param string $context Optional. What context are we in? Example: `single` or `directory` |
||
| 111 | * @param string $input_type Optional. (textarea, list, select, etc.) |
||
| 112 | * @return array Associative array, with the key being the capability and the value being the label shown. |
||
| 113 | */ |
||
| 114 | static public function get_cap_choices( $template_id = '', $field_id = '', $context = '', $input_type = '' ) { |
||
| 115 | |||
| 116 | $select_cap_choices = array( |
||
| 117 | 'read' => __( 'Any Logged-In User', 'gravityview' ), |
||
| 118 | 'publish_posts' => __( 'Author Or Higher', 'gravityview' ), |
||
| 119 | 'gravityforms_view_entries' => __( 'Can View Gravity Forms Entries', 'gravityview' ), |
||
| 120 | 'delete_others_posts' => __( 'Editor Or Higher', 'gravityview' ), |
||
| 121 | 'gravityforms_edit_entries' => __( 'Can Edit Gravity Forms Entries', 'gravityview' ), |
||
| 122 | 'manage_options' => __( 'Administrator', 'gravityview' ), |
||
| 123 | ); |
||
| 124 | |||
| 125 | if( is_multisite() ) { |
||
| 126 | $select_cap_choices['manage_network'] = __('Multisite Super Admin', 'gravityview' ); |
||
| 127 | } |
||
| 128 | |||
| 129 | /** |
||
| 130 | * @filter `gravityview_field_visibility_caps` Modify the capabilities shown in the field dropdown |
||
| 131 | * @see http://docs.gravityview.co/article/96-how-to-modify-capabilities-shown-in-the-field-only-visible-to-dropdown |
||
| 132 | * @since 1.0.1 |
||
| 133 | * @param array $select_cap_choices Associative rray of role slugs with labels ( `manage_options` => `Administrator` ) |
||
| 134 | * @param string $template_id Optional. View slug |
||
| 135 | * @param string $field_id Optional. GF Field ID - Example: `3`, `5.2`, `entry_link`, `created_by` |
||
| 136 | * @param string $context Optional. What context are we in? Example: `single` or `directory` |
||
| 137 | * @param string $input_type Optional. (textarea, list, select, etc.) |
||
| 138 | */ |
||
| 139 | $select_cap_choices = apply_filters('gravityview_field_visibility_caps', $select_cap_choices, $template_id, $field_id, $context, $input_type ); |
||
| 140 | |||
| 141 | return $select_cap_choices; |
||
| 142 | } |
||
| 143 | |||
| 144 | |||
| 145 | /** |
||
| 146 | * Render Field Options html (shown through a dialog box) |
||
| 147 | * |
||
| 148 | * @see GravityView_Ajax::get_field_options |
||
| 149 | * @see GravityView_Admin_Views::render_active_areas |
||
| 150 | * |
||
| 151 | * @access public |
||
| 152 | * @param string $field_type field / widget |
||
| 153 | * @param string $template_id |
||
| 154 | * @param string $field_id |
||
| 155 | * @param string $field_label |
||
| 156 | * @param string $area |
||
| 157 | * @param string $uniqid (default: '') |
||
| 158 | * @param string $current (default: '') |
||
| 159 | * @param string $context (default: 'single') |
||
| 160 | * @param array $item Field or widget array that's being rendered |
||
| 161 | * |
||
| 162 | * @return string HTML of dialog box |
||
| 163 | */ |
||
| 164 | public static function render_field_options( $field_type, $template_id, $field_id, $field_label, $area, $input_type = NULL, $uniqid = '', $current = '', $context = 'single', $item = array() ) { |
||
| 165 | |||
| 166 | if( empty( $uniqid ) ) { |
||
| 167 | //generate a unique field id |
||
| 168 | $uniqid = uniqid('', false); |
||
| 169 | } |
||
| 170 | |||
| 171 | // get field/widget options |
||
| 172 | $options = self::get_default_field_options( $field_type, $template_id, $field_id, $context, $input_type ); |
||
| 173 | |||
| 174 | // two different post arrays, depending of the field type |
||
| 175 | $name_prefix = $field_type .'s' .'['. $area .']['. $uniqid .']'; |
||
| 176 | |||
| 177 | // build output |
||
| 178 | $output = ''; |
||
| 179 | $output .= '<input type="hidden" class="field-key" name="'. $name_prefix .'[id]" value="'. esc_attr( $field_id ) .'">'; |
||
| 180 | $output .= '<input type="hidden" class="field-label" name="'. $name_prefix .'[label]" value="'. esc_attr( $field_label ) .'">'; |
||
| 181 | |||
| 182 | // If there are no options, return what we got. |
||
| 183 | if(empty($options)) { |
||
| 184 | |||
| 185 | // This is here for checking if the output is empty in render_label() |
||
| 186 | $output .= '<!-- No Options -->'; |
||
| 187 | |||
| 188 | return $output; |
||
| 189 | } |
||
| 190 | |||
| 191 | $output .= '<div class="gv-dialog-options" title="'. esc_attr( sprintf( __( 'Options: %s', 'gravityview' ) , strip_tags( html_entity_decode( $field_label ) ) ) ) .'">'; |
||
| 192 | |||
| 193 | /** |
||
| 194 | * @since 1.8 |
||
| 195 | */ |
||
| 196 | if( !empty( $item['subtitle'] ) ) { |
||
| 197 | $output .= '<div class="subtitle">' . $item['subtitle'] . '</div>'; |
||
| 198 | } |
||
| 199 | |||
| 200 | foreach( $options as $key => $option ) { |
||
| 201 | |||
| 202 | $value = isset( $current[ $key ] ) ? $current[ $key ] : NULL; |
||
| 203 | |||
| 204 | $field_output = self::render_field_option( $name_prefix . '['. $key .']' , $option, $value); |
||
| 205 | |||
| 206 | // The setting is empty |
||
| 207 | if( empty( $field_output ) ) { |
||
| 208 | continue; |
||
| 209 | } |
||
| 210 | |||
| 211 | switch( $option['type'] ) { |
||
| 212 | // Hide hidden fields |
||
| 213 | case 'hidden': |
||
| 214 | $output .= '<div class="gv-setting-container gv-setting-container-'. esc_attr( $key ) . ' screen-reader-text">'. $field_output . '</div>'; |
||
| 215 | break; |
||
| 216 | default: |
||
| 217 | $output .= '<div class="gv-setting-container gv-setting-container-'. esc_attr( $key ) . '">'. $field_output .'</div>'; |
||
| 218 | } |
||
| 219 | } |
||
| 220 | |||
| 221 | // close options window |
||
| 222 | $output .= '</div>'; |
||
| 223 | |||
| 224 | return $output; |
||
| 225 | |||
| 226 | } |
||
| 227 | |||
| 228 | |||
| 229 | |||
| 230 | /** |
||
| 231 | * Handle rendering a field option form element |
||
| 232 | * |
||
| 233 | * @param string $name Input `name` attribute |
||
| 234 | * @param array $option Associative array of options. See the $defaults variable for available keys. |
||
| 235 | * @param mixed $curr_value Current value of option |
||
| 236 | * @return string HTML output of option |
||
| 237 | */ |
||
| 238 | public static function render_field_option( $name = '', $option, $curr_value = NULL ) { |
||
| 239 | |||
| 240 | $output = ''; |
||
| 241 | |||
| 242 | /** |
||
| 243 | * @deprecated setting index 'default' was replaced by 'value' |
||
| 244 | * @see GravityView_FieldType::get_field_defaults |
||
| 245 | */ |
||
| 246 | if( !empty( $option['default'] ) && empty( $option['value'] ) ) { |
||
| 247 | $option['value'] = $option['default']; |
||
| 248 | _deprecated_function( 'GravityView_FieldType::get_field_defaults', '1.1.7', '[value] instead of [default] when defining the setting '. $name .' details' ); |
||
| 249 | } |
||
| 250 | |||
| 251 | // prepare to render option field type |
||
| 252 | if( isset( $option['type'] ) ) { |
||
| 253 | |||
| 254 | $type_class = self::load_type_class( $option ); |
||
| 255 | |||
| 256 | if( class_exists( $type_class ) ) { |
||
| 257 | |||
| 258 | $render_type = new $type_class( $name, $option, $curr_value ); |
||
| 259 | |||
| 260 | ob_start(); |
||
| 261 | |||
| 262 | $render_type->render_option(); |
||
| 263 | |||
| 264 | $output = ob_get_clean(); |
||
| 265 | |||
| 266 | /** |
||
| 267 | * @filter `gravityview/option/output/{option_type}` Modify the output for a GravityView setting.\n |
||
| 268 | * `$option_type` is the type of setting (`radio`, `text`, etc.) |
||
| 269 | * @param[in,out] string $output field class name |
||
| 270 | * @param[in] array $option option field data |
||
| 271 | */ |
||
| 272 | $output = apply_filters( "gravityview/option/output/{$option['type']}" , $output, $option ); |
||
| 273 | } |
||
| 274 | |||
| 275 | } // isset option[type] |
||
|
0 ignored issues
–
show
|
|||
| 276 | |||
| 277 | return $output; |
||
| 278 | } |
||
| 279 | |||
| 280 | |||
| 281 | |||
| 282 | |||
| 283 | |||
| 284 | |||
| 285 | /** |
||
| 286 | * Output a table row for view settings |
||
| 287 | * @param string $key The key of the input |
||
| 288 | * @param array $current_settings Associative array of current settings to use as input values, if set. If not set, the defaults are used. |
||
| 289 | * @param string $override_input [description] |
||
| 290 | * @param string $name [description] |
||
| 291 | * @param string $id [description] |
||
| 292 | * @return void [description] |
||
| 293 | */ |
||
| 294 | public static function render_setting_row( $key = '', $current_settings = array(), $override_input = null, $name = 'template_settings[%s]', $id = 'gravityview_se_%s' ) { |
||
| 295 | |||
| 296 | $setting = GravityView_View_Data::get_default_arg( $key, true ); |
||
| 297 | |||
| 298 | // If the key doesn't exist, there's something wrong. |
||
| 299 | if( empty( $setting ) ) { return; } |
||
| 300 | |||
| 301 | /** |
||
| 302 | * @deprecated setting index 'name' was replaced by 'label' |
||
| 303 | * @see GravityView_FieldType::get_field_defaults |
||
| 304 | */ |
||
| 305 | if( isset( $setting['name'] ) && empty( $setting['label'] ) ) { |
||
| 306 | $setting['label'] = $setting['name']; |
||
| 307 | _deprecated_function( 'GravityView_FieldType::get_field_defaults', '1.1.7', '[label] instead of [name] when defining the setting '. $key .' details' ); |
||
| 308 | } |
||
| 309 | |||
| 310 | $name = esc_attr( sprintf( $name, $key ) ); |
||
| 311 | $setting['id'] = esc_attr( sprintf( $id, $key ) ); |
||
| 312 | $setting['tooltip'] = 'gv_' . $key; |
||
| 313 | |||
| 314 | // Use default if current setting isn't set. |
||
| 315 | $curr_value = isset( $current_settings[ $key ] ) ? $current_settings[ $key ] : $setting['value']; |
||
| 316 | |||
| 317 | // default setting type = text |
||
| 318 | $setting['type'] = empty( $setting['type'] ) ? 'text' : $setting['type']; |
||
| 319 | |||
| 320 | // merge tags |
||
| 321 | if( !isset( $setting['merge_tags'] ) ) { |
||
| 322 | if( $setting['type'] === 'text' ) { |
||
| 323 | $setting['merge_tags'] = true; |
||
| 324 | } else { |
||
| 325 | $setting['merge_tags'] = false; |
||
| 326 | } |
||
| 327 | } |
||
| 328 | |||
| 329 | $output = ''; |
||
| 330 | |||
| 331 | // render the setting |
||
| 332 | $type_class = self::load_type_class( $setting ); |
||
| 333 | if( class_exists( $type_class ) ) { |
||
| 334 | /** @var GravityView_FieldType $render_type */ |
||
| 335 | $render_type = new $type_class( $name, $setting, $curr_value ); |
||
| 336 | ob_start(); |
||
| 337 | $render_type->render_setting( $override_input ); |
||
| 338 | $output = ob_get_clean(); |
||
| 339 | } |
||
| 340 | |||
| 341 | // Check if setting is specific for a template |
||
| 342 | if( !empty( $setting['show_in_template'] ) ) { |
||
| 343 | if( !is_array( $setting['show_in_template'] ) ) { |
||
| 344 | $setting['show_in_template'] = array( $setting['show_in_template'] ); |
||
| 345 | } |
||
| 346 | $show_if = ' data-show-if="'. implode( ' ', $setting['show_in_template'] ).'"'; |
||
| 347 | } else { |
||
| 348 | $show_if = ''; |
||
| 349 | } |
||
| 350 | |||
| 351 | // output |
||
| 352 | echo '<tr valign="top" '. $show_if .'>' . $output . '</tr>'; |
||
| 353 | |||
| 354 | } |
||
| 355 | |||
| 356 | |||
| 357 | /** |
||
| 358 | * Given a field type calculates the php class. If not found try to load it. |
||
| 359 | * @param array $field |
||
| 360 | * @return string type class name |
||
| 361 | */ |
||
| 362 | public static function load_type_class( $field = NULL ) { |
||
| 363 | |||
| 364 | if( empty( $field['type'] ) ) { |
||
| 365 | return NULL; |
||
| 366 | } |
||
| 367 | |||
| 368 | /** |
||
| 369 | * @filter `gravityview/setting/class/{field_type}` |
||
| 370 | * @param string $class_suffix field class suffix; `GravityView_FieldType_{$class_suffix}` |
||
| 371 | * @param array $field field data |
||
| 372 | */ |
||
| 373 | $type_class = apply_filters( "gravityview/setting/class/{$field['type']}", 'GravityView_FieldType_' . $field['type'], $field ); |
||
| 374 | |||
| 375 | if( !class_exists( $type_class ) ) { |
||
| 376 | |||
| 377 | /** |
||
| 378 | * @filter `gravityview/setting/class_file/{field_type}` |
||
| 379 | * @param string $field_type_include_path field class file path |
||
| 380 | * @param array $field field data |
||
| 381 | */ |
||
| 382 | $class_file = apply_filters( "gravityview/setting/class_file/{$field['type']}", GRAVITYVIEW_DIR . "includes/admin/field-types/type_{$field['type']}.php", $field ); |
||
| 383 | |||
| 384 | if( $class_file ) { |
||
| 385 | if( file_exists( $class_file ) ) { |
||
| 386 | require_once( $class_file ); |
||
| 387 | } |
||
| 388 | } |
||
| 389 | |||
| 390 | } |
||
| 391 | |||
| 392 | return $type_class; |
||
| 393 | } |
||
| 394 | |||
| 395 | |||
| 396 | |||
| 397 | |||
| 398 | |||
| 399 | /** |
||
| 400 | * @deprecated 1.2 |
||
| 401 | * Render the HTML for a checkbox input to be used on the field & widgets options |
||
| 402 | * @param string $name , name attribute |
||
| 403 | * @param string $current current value |
||
| 404 | * @return string html tags |
||
| 405 | */ |
||
| 406 | public static function render_checkbox_option( $name = '', $id = '', $current = '' ) { |
||
| 407 | |||
| 408 | $output = '<input name="'. esc_attr( $name ) .'" type="hidden" value="0">'; |
||
| 409 | $output .= '<input name="'. esc_attr( $name ) .'" id="'. esc_attr( $id ) .'" type="checkbox" value="1" '. checked( $current, '1', false ) .' >'; |
||
| 410 | |||
| 411 | return $output; |
||
| 412 | } |
||
| 413 | |||
| 414 | |||
| 415 | /** |
||
| 416 | * @deprecated 1.2 |
||
| 417 | * Render the HTML for an input text to be used on the field & widgets options |
||
| 418 | * @param string $name Unique name of the field. Exampe: `fields[directory_list-title][5374ff6ab128b][custom_label]` |
||
| 419 | * @param string $current [current value] |
||
| 420 | * @param string $add_merge_tags Add merge tags to the input? |
||
| 421 | * @param array $args Field settings, including `class` key for CSS class |
||
| 422 | * @return string [html tags] |
||
| 423 | */ |
||
| 424 | public static function render_text_option( $name = '', $id = '', $current = '', $add_merge_tags = NULL, $args = array() ) { |
||
| 425 | |||
| 426 | // Show the merge tags if the field is a list view |
||
| 427 | $is_list = ( preg_match( '/_list-/ism', $name )); |
||
| 428 | |||
| 429 | // Or is a single entry view |
||
| 430 | $is_single = ( preg_match( '/single_/ism', $name )); |
||
| 431 | $show = ( $is_single || $is_list ); |
||
| 432 | |||
| 433 | $class = ''; |
||
| 434 | // and $add_merge_tags is not false |
||
| 435 | if( $show && $add_merge_tags !== false || $add_merge_tags === 'force' ) { |
||
| 436 | $class = 'merge-tag-support mt-position-right mt-hide_all_fields '; |
||
| 437 | } |
||
| 438 | |||
| 439 | $class .= !empty( $args['class'] ) ? $args['class'] : 'widefat'; |
||
| 440 | $type = !empty( $args['type'] ) ? $args['type'] : 'text'; |
||
| 441 | |||
| 442 | return '<input name="'. esc_attr( $name ) .'" id="'. esc_attr( $id ) .'" type="'.esc_attr($type).'" value="'. esc_attr( $current ) .'" class="'.esc_attr( $class ).'">'; |
||
| 443 | } |
||
| 444 | |||
| 445 | /** |
||
| 446 | * @deprecated 1.2 |
||
| 447 | * Render the HTML for an textarea input to be used on the field & widgets options |
||
| 448 | * @param string $name Unique name of the field. Exampe: `fields[directory_list-title][5374ff6ab128b][custom_label]` |
||
| 449 | * @param string $current [current value] |
||
| 450 | * @param string|boolean $add_merge_tags Add merge tags to the input? |
||
| 451 | * @param array $args Field settings, including `class` key for CSS class |
||
| 452 | * @return string [html tags] |
||
| 453 | */ |
||
| 454 | public static function render_textarea_option( $name = '', $id = '', $current = '', $add_merge_tags = NULL, $args = array() ) { |
||
| 455 | |||
| 456 | // Show the merge tags if the field is a list view |
||
| 457 | $is_list = ( preg_match( '/_list-/ism', $name )); |
||
| 458 | |||
| 459 | // Or is a single entry view |
||
| 460 | $is_single = ( preg_match( '/single_/ism', $name )); |
||
| 461 | $show = ( $is_single || $is_list ); |
||
| 462 | |||
| 463 | $class = ''; |
||
| 464 | // and $add_merge_tags is not false |
||
| 465 | if( $show && $add_merge_tags !== false || $add_merge_tags === 'force' ) { |
||
| 466 | $class = 'merge-tag-support mt-position-right mt-hide_all_fields '; |
||
| 467 | } |
||
| 468 | |||
| 469 | $class .= !empty( $args['class'] ) ? 'widefat '.$args['class'] : 'widefat'; |
||
| 470 | |||
| 471 | return '<textarea name="'. esc_attr( $name ) .'" id="'. esc_attr( $id ) .'" class="'.esc_attr( $class ).'">'. esc_textarea( $current ) .'</textarea>'; |
||
| 472 | } |
||
| 473 | |||
| 474 | /** |
||
| 475 | * |
||
| 476 | * Render the HTML for a select box to be used on the field & widgets options |
||
| 477 | * @deprecated 1.2 |
||
| 478 | * @param string $name [name attribute] |
||
| 479 | * @param array $choices [select options] |
||
| 480 | * @param string $current [current value] |
||
| 481 | * @return string [html tags] |
||
| 482 | */ |
||
| 483 | public static function render_select_option( $name = '', $id = '', $choices, $current = '' ) { |
||
| 484 | |||
| 485 | $output = '<select name="'. $name .'" id="'. $id .'">'; |
||
| 486 | foreach( $choices as $value => $label ) { |
||
| 487 | $output .= '<option value="'. esc_attr( $value ) .'" '. selected( $value, $current, false ) .'>'. esc_html( $label ) .'</option>'; |
||
| 488 | } |
||
| 489 | $output .= '</select>'; |
||
| 490 | |||
| 491 | return $output; |
||
| 492 | } |
||
| 493 | |||
| 494 | |||
| 495 | } |
||
| 496 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.