Нема описа

class-um-search-widget.php 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. namespace um\widgets;
  3. // Exit if accessed directly
  4. if ( ! defined( 'ABSPATH' ) ) exit;
  5. /**
  6. * Class UM_Search_Widget
  7. * @package um\widgets
  8. */
  9. class UM_Search_Widget extends \WP_Widget {
  10. /**
  11. * UM_Search_Widget constructor.
  12. */
  13. function __construct() {
  14. parent::__construct(
  15. // Base ID of your widget
  16. 'um_search_widget',
  17. // Widget name will appear in UI
  18. __( 'Ultimate Member - Search', 'ultimate-member' ),
  19. // Widget description
  20. array( 'description' => __( 'Shows the search member form.', 'ultimate-member' ), )
  21. );
  22. }
  23. /**
  24. * Creating widget front-end
  25. *
  26. * @param array $args
  27. * @param array $instance
  28. */
  29. public function widget( $args, $instance ) {
  30. if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) {
  31. return;
  32. }
  33. if ( ! empty( $_GET['legacy-widget-preview'] ) && defined( 'IFRAME_REQUEST' ) && IFRAME_REQUEST ) {
  34. return;
  35. }
  36. $title = array_key_exists( 'title', $instance ) ? $instance['title'] : '';
  37. $title = apply_filters( 'widget_title', $title );
  38. // before and after widget arguments are defined by themes
  39. echo $args['before_widget'];
  40. if ( ! empty( $title ) ) {
  41. echo $args['before_title'] . $title . $args['after_title'];
  42. }
  43. // display the search form
  44. if ( version_compare( get_bloginfo('version'),'5.4', '<' ) ) {
  45. echo do_shortcode( '[ultimatemember_searchform /]' );
  46. } else {
  47. echo apply_shortcodes( '[ultimatemember_searchform /]' );
  48. }
  49. echo $args['after_widget'];
  50. }
  51. /**
  52. * Widget Backend
  53. *
  54. * @param array $instance
  55. */
  56. public function form( $instance ) {
  57. if ( isset( $instance[ 'title' ] ) ) {
  58. $title = $instance[ 'title' ];
  59. } else {
  60. $title = __( 'Search Users', 'ultimate-member' );
  61. }
  62. if ( isset( $instance[ 'max' ] ) ) {
  63. $max = $instance[ 'max' ];
  64. } else {
  65. $max = 11;
  66. }
  67. // Widget admin form
  68. ?>
  69. <p>
  70. <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php _e( 'Title', 'ultimate-member' ); ?>:</label>
  71. <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"
  72. name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type="text"
  73. value="<?php echo esc_attr( $title ); ?>" />
  74. </p>
  75. <?php
  76. }
  77. /**
  78. * Updating widget replacing old instances with new
  79. *
  80. * @param array $new_instance
  81. * @param array $old_instance
  82. *
  83. * @return array
  84. */
  85. public function update( $new_instance, $old_instance ) {
  86. $instance = array();
  87. $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
  88. return $instance;
  89. }
  90. }