monsterinsights_select_callback

Select Callback.

Description

monsterinsights_select_callback( (array) $args ); 

Renders select fields.

Parameters (1)

0. $args (array)
Arguments passed by the setting

Usage

  1. if ( !function_exists( 'monsterinsights_select_callback' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'google-analytics-for-wordpress-by-monsterinsights/includes/admin/settings/settings-api.php'; 
  3.  
  4. // Arguments passed by the setting 
  5. $args = array(); 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = monsterinsights_select_callback($args); 
  9.  

Defined (1)

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

/includes/admin/settings/settings-api.php  
  1. function monsterinsights_select_callback($args) { 
  2. $monsterinsights_option = monsterinsights_get_option( $args['id'] ); 
  3.  
  4. if ( $monsterinsights_option ) { 
  5. $value = $monsterinsights_option; 
  6. } else { 
  7. $value = isset( $args['std'] ) ? $args['std'] : ''; 
  8.  
  9. if ( isset( $args['placeholder'] ) ) { 
  10. $placeholder = $args['placeholder']; 
  11. } else { 
  12. $placeholder = ''; 
  13.  
  14. $class = monsterinsights_sanitize_html_class( $args['field_class'] ); 
  15.  
  16. if ( isset( $args['select2'] ) ) { 
  17. $class .= ' monsterinsights-select300'; 
  18.  
  19. $allowclear = isset( $args['allowclear'] ) ? (bool) $args['allowclear'] : false; 
  20. $multiple = isset( $args['multiple'] ) ? (bool) $args['multiple'] : false; 
  21. $multiple = $multiple ? 'multiple="multiple"' : ''; 
  22. $multiple_arg = $multiple ? '[]' : ''; 
  23.  
  24. $html = '<select id="monsterinsights_settings[' . monsterinsights_sanitize_key( $args['id'] ) . ']" name="monsterinsights_settings[' . esc_attr( $args['id'] ) . ']' . $multiple_arg .'" class="' . $class . '" data-placeholder="' . esc_html( $placeholder ) . '" data-allow-clear="' . $allowclear . '" ' . $multiple . ' />'; 
  25.  
  26. foreach ( $args['options'] as $option => $name ) { 
  27. $selected = ! empty( $value ) && is_array( $value ) ? in_array( $option, $value ) : $value === $option; 
  28. $selected = selected( true, $selected, false ); 
  29. $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>'; 
  30.  
  31. $html .= '</select>'; 
  32. $html .= '<p class="description"> ' . wp_kses_post( $args['desc'] ) . '</p>'; 
  33.  
  34. return apply_filters( 'monsterinsights_after_setting_output', $html, $args );