Advertisement
sarahn

Xavier's custom widget

Feb 14th, 2013
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.13 KB | None | 0 0
  1. <?php
  2. class DT_contact_Widget extends WP_Widget {
  3.  
  4. /* Widget setup */
  5. function __construct() {
  6. /* Widget settings. */
  7. $widget_ops = array( 'description' => _x( 'Contact form', 'widget contact form', LANGUAGE_ZONE ) );
  8.  
  9. /* Create the widget. */
  10. parent::__construct(
  11. 'dt-contact-widget',
  12. DT_WIDGET_PREFIX . _x( 'Contact', 'widget contact form', LANGUAGE_ZONE ),
  13. $widget_ops
  14. );
  15. }
  16.  
  17. /* Display the widget */
  18. function widget( $args, $instance ) {
  19. static $widget_counter = 1;
  20. extract( $args );
  21.  
  22. /* Our variables from the widget settings. */
  23. $title = apply_filters( 'widget_title', $instance['title'] );
  24. $en_captcha = isset( $instance['enable_captcha'] ) ? $instance['enable_captcha'] : true;
  25.  
  26. $captcha_id = 'widget_' . $widget_counter++;
  27. echo $before_widget ;
  28.  
  29. // start
  30. echo $before_title . $title . $after_title;
  31.  
  32. if( isset($instance['text']) && $instance['text'] )
  33. echo force_balance_tags('<p>' . icl_t('contact_widget','Text', $instance['text']) . '</p>');
  34. ?>
  35. <form class="uniform get-in-touch ajaxing" method="post" action="/">
  36. <?php wp_nonce_field('dt_contact_' . $captcha_id,'dt_contact_form_nonce'); ?>
  37. <input type="hidden" name="send_message" value="" />
  38. <input type="hidden" name="send_contacts" value="<?php echo $captcha_id; ?>" />
  39.  
  40. <div class="i-i">
  41. <div class="i-h">
  42. <input id="your_name" name="f_name" type="text" value="" class="validate[required]" />
  43. </div>
  44. <div class="i-l"><span><?php _ex( 'Name*', 'widget contact form', LANGUAGE_ZONE ); ?></span></div>
  45. </div>
  46. <div class="i-i">
  47. <div class="i-h">
  48. <input id="email" name="f_email" type="text" value="" class="validate[required,custom[email]" />
  49. </div>
  50. <div class="i-l"><span><?php _ex( 'E-mail*', 'widget contact form', LANGUAGE_ZONE ); ?></span></div>
  51. </div>
  52.  
  53. <div class="t-h">
  54. <textarea type="textarea" id="message" name="f_comment" class="validate[required]"></textarea>
  55. </div>
  56.  
  57. <?php do_action('dt_contact_form_captcha_place', array( 'whoami' => $captcha_id, 'enable' => $en_captcha ) ); ?>
  58.  
  59. <div class="but-wrap"><a href="#" class="button go_submit" title="<?php _ex( 'Submit', 'widget contact form', LANGUAGE_ZONE ); ?>"><span><i class="submit"></i><?php _ex( "Send message", 'widget contact form', LANGUAGE_ZONE ); ?></span></a></div>
  60. <span class="c-clear"><a href="#" class="do-clear"><?php _ex( 'clear form', 'widget contact form', LANGUAGE_ZONE ); ?></a></span>
  61. </form>
  62. <?php
  63. echo $after_widget;
  64. }
  65.  
  66. /* Update the widget settings */
  67. function update( $new_instance, $old_instance ) {
  68. $instance = $old_instance;
  69. $instance['title'] = isset( $new_instance['title'] ) ? strip_tags( $new_instance['title'] ) : '';
  70. $instance['text'] = isset( $new_instance['text'] ) ? esc_html( $new_instance['text'] ) : '';
  71. $instance['enable_captcha'] = isset( $new_instance['enable_captcha'] );
  72.  
  73. icl_register_string('contact_widget', 'Text', $instance['text'] );
  74.  
  75. return $instance;
  76. }
  77.  
  78. /**
  79. * Displays the widget settings controls on the widget panel.
  80. * Make use of the get_field_id() and get_field_name() function
  81. * when creating your form elements. This handles the confusing stuff.
  82. */
  83. function form( $instance ) {
  84.  
  85. /* Set up some default widget settings. */
  86. $defaults = array(
  87. 'text' => '',
  88. 'title' => '',
  89. 'enable_captcha' => true
  90. );
  91.  
  92. $instance = wp_parse_args( (array) $instance, $defaults );
  93. ?>
  94. <p>
  95. <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _ex( 'Title:', 'widget contact form', LANGUAGE_ZONE ); ?></label>
  96. <input type="text" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo esc_attr($instance['title']); ?>" class="widefat" />
  97. </p>
  98. <p>
  99. <label for="<?php echo $this->get_field_id( 'text' ); ?>"><?php _ex( 'Text:', 'widget contact form', LANGUAGE_ZONE ); ?></label>
  100. <textarea class="widefat" id="<?php echo $this->get_field_id( 'text' ); ?>" name="<?php echo $this->get_field_name( 'text' ); ?>"><?php echo $instance['text']; ?></textarea>
  101. </p>
  102. <p>
  103. <label for="<?php echo $this->get_field_id( 'enable_captcha' ); ?>"><?php _ex( 'Enable Captcha:', 'widget contact form', LANGUAGE_ZONE ); ?></label>
  104. <input type="checkbox" id="<?php echo $this->get_field_id( 'enable_captcha' ); ?>" name="<?php echo $this->get_field_name( 'enable_captcha' ); ?>" <?php checked( $instance['enable_captcha'] ); ?> />
  105. </p>
  106. <a href="<?php echo admin_url('admin.php?page=of-captcha-menu'); ?>"><?php _ex( 'Captha options', 'widget contact form', LANGUAGE_ZONE ); ?></a>
  107. <?php
  108.  
  109. }
  110. }
  111.  
  112. /* Register the widget */
  113. function dt_contact_register() {
  114. register_widget( 'DT_contact_Widget' );
  115. }
  116.  
  117. /* Load the widget */
  118. add_action( 'widgets_init', 'dt_contact_register' );
  119. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement