PageRenderTime 51ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/themes/Transfers/includes/plugins/widgets/widget-hero-unit.php

https://gitlab.com/luyxtran264/myproject
PHP | 190 lines | 118 code | 43 blank | 29 comment | 5 complexity | 2257fadc2c12772eea237e0e3d5e624c MD5 | raw file
  1. <?php
  2. /*-----------------------------------------------------------------------------------
  3. Plugin Name: Transfers Hero Unit Widget
  4. -----------------------------------------------------------------------------------*/
  5. // Add function to widgets_init that'll load our widget.
  6. add_action( 'widgets_init', 'transfers_hero_unit_widgets' );
  7. // Register widget.
  8. function transfers_hero_unit_widgets() {
  9. register_widget( 'transfers_Hero_Unit_Widget' );
  10. add_action('transfers_enqueue_admin_scripts_styles', 'transfers_hero_unit_enqueue');
  11. }
  12. function transfers_hero_unit_enqueue() {
  13. wp_enqueue_script('media-upload');
  14. wp_enqueue_script('thickbox');
  15. wp_enqueue_style('thickbox');
  16. wp_enqueue_script('jquery');
  17. wp_enqueue_script('transfers-hero-unit-widget', transfers_get_file_uri ('/includes/plugins/widgets/widget-hero-unit.js'), array('jquery', 'thickbox'), '1.0', true );
  18. }
  19. // Widget class.
  20. class transfers_hero_unit_widget extends WP_Widget {
  21. /*-----------------------------------------------------------------------------------*/
  22. /* Widget Setup
  23. /*-----------------------------------------------------------------------------------*/
  24. function __construct() {
  25. /* Widget settings. */
  26. $widget_ops = array( 'classname' => 'transfers_hero_unit_widget', 'description' => esc_html__('Transfers: Hero Unit Widget', 'transfers') );
  27. /* Widget control settings. */
  28. $control_ops = array( 'width' => 300, 'height' => 550, 'id_base' => 'transfers_hero_unit_widget' );
  29. /* Create the widget. */
  30. parent::__construct( 'transfers_hero_unit_widget', esc_html__('Transfers: Hero Unit Widget', 'transfers'), $widget_ops, $control_ops );
  31. }
  32. /*-----------------------------------------------------------------------------------*/
  33. /* Display Widget
  34. /*-----------------------------------------------------------------------------------*/
  35. function widget( $args, $instance ) {
  36. extract( $args );
  37. /* Our variables from the widget settings. */
  38. $hero_unit_title = isset($instance['hero_unit_title']) ? $instance['hero_unit_title'] : __("Need a ride?", 'transfers');
  39. $hero_unit_sub_title = isset($instance['hero_unit_sub_title']) ? $instance['hero_unit_sub_title'] : __("You've come to the right place.", 'transfers');
  40. $button_1_url = isset($instance['button_1_url']) ? $instance['button_1_url'] : '#services';
  41. $button_1_text = isset($instance['button_1_text']) ? $instance['button_1_text'] : __('Our services', 'transfers');
  42. $button_2_url = isset($instance['button_2_url']) ? $instance['button_2_url'] : '#booking';
  43. $button_2_text = isset($instance['button_2_text']) ? $instance['button_2_text'] : __('Make a booking', 'transfers');
  44. $hero_unit_image_uri = isset($instance['hero_unit_image_uri']) ? $instance['hero_unit_image_uri'] : '';
  45. $allowedtags = transfers_get_allowed_widgets_tags_array();
  46. /* Before widget (defined by themes). */
  47. echo wp_kses($before_widget, $allowedtags);
  48. /* Display Widget */
  49. $background_style = '';
  50. if (!empty($hero_unit_image_uri)) {
  51. $background_style = 'style="background-image:url(' . esc_url($hero_unit_image_uri) . ');"';
  52. }
  53. ?>
  54. <!-- Intro -->
  55. <div class="intro" <?php echo wp_kses($background_style, array('style' => array())); ?>>
  56. <div class="wrap">
  57. <div class="textwidget">
  58. <h1 class="wow fadeInDown"><?php echo esc_html($hero_unit_title); ?></h1>
  59. <h2 class="wow fadeInUp"><?php echo esc_html($hero_unit_sub_title); ?></h2>
  60. <div class="actions">
  61. <?php if (!(empty($button_1_url) && empty($button_1_text))) { ?>
  62. <a href="<?php echo esc_url($button_1_url); ?>" title="<?php echo esc_attr($button_1_text); ?>" class="btn large white wow fadeInLeft anchor"><?php echo esc_html($button_1_text); ?></a>
  63. <?php } ?>
  64. <?php if (!(empty($button_2_url) && empty($button_2_text))) { ?>
  65. <a href="<?php echo esc_url($button_2_url); ?>" title="<?php echo esc_attr($button_2_text); ?>" class="btn large color wow fadeInRight anchor"><?php echo esc_html($button_2_text); ?></a>
  66. <?php } ?>
  67. </div>
  68. </div>
  69. </div>
  70. </div>
  71. <!-- //Intro -->
  72. <?php
  73. /* After widget (defined by themes). */
  74. echo wp_kses($after_widget, $allowedtags);
  75. }
  76. /*-----------------------------------------------------------------------------------*/
  77. /* Update Widget
  78. /*-----------------------------------------------------------------------------------*/
  79. function update( $new_instance, $old_instance ) {
  80. $instance = $old_instance;
  81. $allowed_tags = array(
  82. 'a' => array(
  83. 'href' => array(),
  84. 'title' => array()
  85. ),
  86. 'br' => array()
  87. );
  88. /* Strip tags to remove HTML (important for text inputs). */
  89. $instance['hero_unit_title'] = wp_kses( $new_instance['hero_unit_title'], $allowed_tags );
  90. $instance['hero_unit_sub_title'] = wp_kses( $new_instance['hero_unit_sub_title'], $allowed_tags );
  91. $instance['button_1_url'] = strip_tags( $new_instance['button_1_url'] );
  92. $instance['button_1_text'] = strip_tags( $new_instance['button_1_text'] );
  93. $instance['button_2_url'] = strip_tags( $new_instance['button_2_url'] );
  94. $instance['button_2_text'] = strip_tags( $new_instance['button_2_text'] );
  95. $instance['hero_unit_image_uri'] = strip_tags( $new_instance['hero_unit_image_uri'] );
  96. return $instance;
  97. }
  98. /*-----------------------------------------------------------------------------------*/
  99. /* Widget Settings
  100. /*-----------------------------------------------------------------------------------*/
  101. function form( $instance ) {
  102. /* Set up some default widget settings. */
  103. $defaults = array(
  104. 'hero_unit_title' => esc_html__("Need a ride?", 'transfers'),
  105. 'hero_unit_sub_title' => esc_html__("You've come to the right place.", 'transfers'),
  106. 'button_1_url' => '#services',
  107. 'button_1_text' => esc_html__('Our services', 'transfers'),
  108. 'button_2_url' => '#booking',
  109. 'button_2_text' => esc_html__('Make a booking', 'transfers'),
  110. 'hero_unit_image_uri' => '',
  111. );
  112. $instance = wp_parse_args( (array) $instance, $defaults ); ?>
  113. <!-- Widget Title: Text Input -->
  114. <p>
  115. <label for="<?php echo esc_attr( $this->get_field_id( 'hero_unit_title' ) ); ?>"><?php esc_html_e('Hero unit title:', 'transfers') ?></label>
  116. <input type="text" class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'hero_unit_title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'hero_unit_title' ) ); ?>" value="<?php echo esc_attr( $instance['hero_unit_title'] ); ?>" />
  117. </p>
  118. <p>
  119. <label for="<?php echo esc_attr($this->get_field_name( 'hero_unit_image_uri' )); ?>"><?php esc_html_e('Hero unit image:', 'transfers') ?></label>
  120. <input name="<?php echo esc_attr($this->get_field_name( 'hero_unit_image_uri' )); ?>" id="<?php echo esc_attr($this->get_field_id( 'hero_unit_image_uri' )); ?>" class="widefat" type="text" size="36" value="<?php echo esc_url( $instance['hero_unit_image_uri'] ); ?>" />
  121. <input class="upload_image_button button button-primary" type="button" value="<?php esc_html_e('Select image', 'transfers') ?>" />
  122. </p>
  123. <p>
  124. <label for="<?php echo esc_attr( $this->get_field_id( 'hero_unit_sub_title' ) ); ?>"><?php esc_html_e('Hero unit sub title:', 'transfers') ?></label>
  125. <input type="text" class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'hero_unit_sub_title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'hero_unit_sub_title' ) ); ?>" value="<?php echo esc_attr( $instance['hero_unit_sub_title'] ); ?>" />
  126. </p>
  127. <p>
  128. <label for="<?php echo esc_attr( $this->get_field_id( 'button_1_url' ) ); ?>"><?php esc_html_e('Button 1 url', 'transfers') ?></label>
  129. <input type="text" placeholder="http://" class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'button_1_url' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'button_1_url' ) ); ?>" value="<?php echo esc_attr( $instance['button_1_url'] ); ?>" />
  130. </p>
  131. <p>
  132. <label for="<?php echo esc_attr( $this->get_field_id( 'button_1_text' ) ); ?>"><?php esc_html_e('Button 1 text', 'transfers') ?></label>
  133. <input type="text" class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'button_1_text' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'button_1_text' ) ); ?>" value="<?php echo esc_attr( $instance['button_1_text'] ); ?>" />
  134. </p>
  135. <p>
  136. <label for="<?php echo esc_attr( $this->get_field_id( 'button_2_url' ) ); ?>"><?php esc_html_e('Button 2 url', 'transfers') ?></label>
  137. <input type="text" placeholder="http://" class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'button_2_url' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'button_2_url' ) ); ?>" value="<?php echo esc_attr( $instance['button_2_url'] ); ?>" />
  138. </p>
  139. <p>
  140. <label for="<?php echo esc_attr( $this->get_field_id( 'button_2_text' ) ); ?>"><?php esc_html_e('Button 2 text', 'transfers') ?></label>
  141. <input type="text" class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'button_2_text' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'button_2_text' ) ); ?>" value="<?php echo esc_attr( $instance['button_2_text'] ); ?>" />
  142. </p>
  143. <?php
  144. }
  145. }