GMB_Shortcode_Generator

GMB_Shortcode_Generator class.

Defined (1)

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

/includes/admin/class-gmb-shortcode-generator.php  
  1. class GMB_Shortcode_Generator extends Google_Maps_Builder_Core_Shortcode_Generator { 
  2.  
  3. /** 
  4. * Constructor 
  5. */ 
  6. public function __construct() { 
  7. parent::__construct(); 
  8. add_action( 'gmb_after_shortcode_form', array( $this, 'form_upsell') ); 
  9. add_action( 'gmb_shortcode_iframe_style', array( $this, 'upsell_css' ) ); 
  10.  
  11.  
  12.  
  13. /** 
  14. * Renders an HTML Dropdown 
  15. * @since 2.0 
  16. * @param array $args 
  17. * @return string 
  18. */ 
  19. public static function select( $args = array() ) { 
  20.  
  21. $defaults = array( 
  22. 'options' => array(),  
  23. 'name' => null,  
  24. 'class' => '',  
  25. 'id' => '',  
  26. 'selected' => 0,  
  27. 'chosen' => false,  
  28. 'placeholder' => null,  
  29. 'multiple' => false,  
  30. 'show_option_all' => _x( 'All', 'all dropdown items', 'google-maps-builder' ),  
  31. 'show_option_none' => _x( 'None', 'no dropdown items', 'google-maps-builder' ) 
  32. ); 
  33.  
  34. $args = wp_parse_args( $args, $defaults ); 
  35.  
  36. if ( $args['multiple'] ) { 
  37. $multiple = ' MULTIPLE'; 
  38. } else { 
  39. $multiple = ''; 
  40.  
  41. if ( $args['chosen'] ) { 
  42. $args['class'] .= 'gmb-select-chosen'; 
  43.  
  44. if ( $args['placeholder'] ) { 
  45. $placeholder = $args['placeholder']; 
  46. } else { 
  47. $placeholder = ''; 
  48.  
  49. $output = '<select name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( sanitize_key( str_replace( '-', '_', $args['id'] ) ) ) . '" class="gmb-select ' . esc_attr( $args['class'] ) . '"' . $multiple . ' data-placeholder="' . $placeholder . '">'; 
  50.  
  51. if ( $args['show_option_all'] ) { 
  52. if ( $args['multiple'] ) { 
  53. $selected = selected( true, in_array( 0, $args['selected'] ), false ); 
  54. } else { 
  55. $selected = selected( $args['selected'], 0, false ); 
  56. $output .= '<option value="all"' . $selected . '>' . esc_html( $args['show_option_all'] ) . '</option>'; 
  57.  
  58. if ( ! empty( $args['options'] ) ) { 
  59.  
  60. if ( $args['show_option_none'] ) { 
  61. if ( $args['multiple'] ) { 
  62. $selected = selected( true, in_array( - 1, $args['selected'] ), false ); 
  63. } else { 
  64. $selected = selected( $args['selected'], - 1, false ); 
  65. $output .= '<option value="-1"' . $selected . '>' . esc_html( $args['show_option_none'] ) . '</option>'; 
  66.  
  67. foreach ( $args['options'] as $key => $option ) { 
  68.  
  69. if ( $args['multiple'] && is_array( $args['selected'] ) ) { 
  70. $selected = selected( true, in_array( $key, $args['selected'] ), false ); 
  71. } else { 
  72. $selected = selected( $args['selected'], $key, false ); 
  73.  
  74. $output .= '<option value="' . esc_attr( $key ) . '"' . $selected . '>' . esc_html( $option ) . '</option>'; 
  75.  
  76. $output .= '</select>'; 
  77.  
  78. return $output; 
  79.  
  80. /** 
  81. * Add upsell markup to shortcode form 
  82. * @since 2.1.0 
  83. * @uses "gmb_after_shortcode_form" 
  84. */ 
  85. public function form_upsell() {?> 
  86. <a href="https://wordimpress.com/plugins/maps-builder-pro?utm_source=MBF&utm_medium=BANNER&utm_content=SHORTCODE&utm_campaign=MBF%20Shortcode" class="button button-small shortcode-upsell" target="_blank"> 
  87. <?php _e( 'Go Pro', 'google-maps-builder' ); ?> 
  88. <span class="dashicons dashicons-external"></span> 
  89. </a> 
  90. <?php 
  91.  
  92.  
  93. /** 
  94. * Add extra css for upsell 
  95. * @since 2.1.0 
  96. * @uses "gmb_shortcode_iframe_style" action 
  97. */ 
  98. public function upsell_css() { ?> 
  99. .shortcode-upsell { 
  100. position: absolute; 
  101. bottom: 10px; 
  102. right: 10px; 
  103. padding: 5px 10px !important; 
  104. font-size: 13px !important; 
  105.  
  106. .shortcode-upsell span.dashicons { 
  107. font-size: 12px; 
  108. height: 14px; 
  109. position: relative; 
  110. top: 3px; 
  111. opacity: 0.8; 
  112. width: 12px; 
  113. <?php 
  114.  
  115.