Files

114 lines
2.4 KiB
PHP
Raw Permalink Normal View History

2016-03-17 15:09:49 -07:00
<?php
namespace um\widgets;
2016-03-17 15:09:49 -07:00
2018-09-17 08:29:33 +03:00
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;
2018-03-20 13:24:38 +02:00
/**
* Class UM_Search_Widget
* @package um\widgets
*/
class UM_Search_Widget extends \WP_Widget {
2016-03-17 15:09:49 -07:00
2018-03-20 13:24:38 +02:00
/**
* UM_Search_Widget constructor.
*/
2016-03-17 15:09:49 -07:00
function __construct() {
parent::__construct(
// Base ID of your widget
'um_search_widget',
// Widget name will appear in UI
__( 'Ultimate Member - Search', 'ultimate-member' ),
2016-03-17 15:09:49 -07:00
// Widget description
2018-06-30 12:02:12 +08:00
array( 'description' => __( 'Shows the search member form.', 'ultimate-member' ), )
2016-03-17 15:09:49 -07:00
);
}
2018-03-20 13:24:38 +02:00
/**
* Creating widget front-end
*
* @param array $args
* @param array $instance
*/
2016-03-17 15:09:49 -07:00
public function widget( $args, $instance ) {
if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) {
return;
}
if ( ! empty( $_GET['legacy-widget-preview'] ) && defined( 'IFRAME_REQUEST' ) && IFRAME_REQUEST ) {
return;
}
2018-03-02 09:55:49 +02:00
2021-07-08 15:13:13 +03:00
$title = array_key_exists( 'title', $instance ) ? $instance['title'] : '';
$title = apply_filters( 'widget_title', $title );
2016-03-17 15:09:49 -07:00
// before and after widget arguments are defined by themes
echo $args['before_widget'];
if ( ! empty( $title ) ) {
echo $args['before_title'] . $title . $args['after_title'];
}
// display the search form
echo apply_shortcodes( '[ultimatemember_searchform /]' );
2016-03-17 15:09:49 -07:00
echo $args['after_widget'];
}
2018-03-20 13:24:38 +02:00
/**
* Widget Backend
*
* @param array $instance
*/
2016-03-17 15:09:49 -07:00
public function form( $instance ) {
if ( isset( $instance[ 'title' ] ) ) {
$title = $instance[ 'title' ];
} else {
$title = __( 'Search Users', 'ultimate-member' );
2016-03-17 15:09:49 -07:00
}
if ( isset( $instance[ 'max' ] ) ) {
$max = $instance[ 'max' ];
} else {
$max = 11;
}
// Widget admin form
?>
<p>
2019-08-01 14:23:13 +03:00
<label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php _e( 'Title', 'ultimate-member' ); ?>:</label>
<input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"
name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type="text"
value="<?php echo esc_attr( $title ); ?>" />
2016-03-17 15:09:49 -07:00
</p>
<?php
}
2018-03-20 13:24:38 +02:00
/**
* Updating widget replacing old instances with new
*
* @param array $new_instance
* @param array $old_instance
*
* @return array
*/
2016-03-17 15:09:49 -07:00
public function update( $new_instance, $old_instance ) {
$instance = array();
$instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
return $instance;
}
2021-07-08 15:13:13 +03:00
}