5 if ( ! defined(
'GRAVITYVIEW_DIR' ) ) {
20 protected $widget_label =
'';
26 protected $widget_description =
'';
33 protected $widget_subtitle =
'';
39 protected $widget_id =
'';
45 protected $defaults = array();
63 private $widget_options = array();
71 public $position =
'';
113 public function __construct(
$label, $id, $defaults = array(),
$settings = array() ) {
118 $this->shortcode_name = empty( $this->shortcode_name ) ? strtolower( get_called_class() ) : $this->shortcode_name;
121 $this->widget_id = $id;
124 $this->widget_label =
$label;
125 $this->defaults = array_merge( array(
'header' => 0,
'footer' => 0 ), $defaults );
128 $this->settings = wp_parse_args(
$settings, $this->get_default_settings() );
131 if ( $this->is_registered() ) {
136 add_filter(
'gravityview_template_widget_options', array( $this,
'assign_widget_options' ), 10, 3 );
139 add_action( sprintf(
'gravityview/widgets/%s/render', $this->get_widget_id() ), array( $this,
'render_frontend' ), 10, 3 );
142 add_action(
'wp', array( $this,
'add_shortcode' ) );
145 add_filter(
'widget_text', array( $this,
'maybe_do_shortcode' ) );
149 add_filter(
'gravityview/widgets/register', array( $this,
'register_widget' ) );
165 $enable_custom_class = apply_filters(
'gravityview/widget/enable_custom_class',
false, $this );
167 if ( $enable_custom_class ) {
170 'label' => __(
'Custom CSS Class:',
'gk-gravityview' ),
171 'desc' => __(
'This class will be added to the widget container',
'gk-gravityview' ),
173 'merge_tags' =>
true,
174 'class' =>
'widefat code',
187 return $this->widget_id;
209 return Utils::get( $this->settings, $key, null );
221 $default_areas = array(
226 'title' => __(
'Top',
'gk-gravityview' ) ,
235 'title' => __(
'Left',
'gk-gravityview' ) ,
242 'title' => __(
'Right',
'gk-gravityview' ) ,
254 $default_areas = apply_filters(
'gravityview_widget_active_areas', $default_areas );
261 return apply_filters(
'gravityview/widget/active_areas', $default_areas );
272 if ( ! is_array( $widgets ) ) {
276 $widgets[ $this->get_widget_id() ] = array(
277 'label' => $this->widget_label ,
278 'description' => $this->widget_description,
279 'subtitle' => $this->widget_subtitle,
280 'icon' => $this->icon,
281 'class' => get_called_class(),
298 if ( $this->get_widget_id() === $widget ) {
299 if(
$settings = $this->get_settings() ) {
300 $options = array_merge( $options,
$settings );
315 if ( ! empty( $this->shortcode_name ) && has_shortcode( $text, $this->shortcode_name ) ) {
316 return do_shortcode( $text );
327 if ( empty( $this->shortcode_name ) ) {
340 if ( empty( $this->show_on_single ) &&
gravityview()->request->is_entry() ) {
341 gravityview()->log->debug(
'Skipping; set to not run on single entry.' );
342 add_shortcode( $this->shortcode_name,
'__return_null' );
348 if ( ! is_object( $post ) || empty( $post->post_content ) || ! Shortcode::parse( $post->post_content ) ) {
349 add_shortcode( $this->shortcode_name,
'__return_null' );
353 add_shortcode( $this->shortcode_name, array( $this,
'render_shortcode') );
389 $allowlist = apply_filters_deprecated(
'gravityview/widget/hide_until_searched/whitelist', array( $allowlist ),
'2.14',
'gravityview/widget/hide_until_searched/allowlist' );
396 $allowlist = apply_filters(
'gravityview/widget/hide_until_searched/allowlist', $allowlist );
398 if ( ( $view =
gravityview()->views->get() ) && ! in_array( $this->get_widget_id(), $allowlist ) ) {
399 $hide_until_searched = $view->settings->get(
'hide_until_searched' );
401 $hide_until_searched =
false;
409 $hide_until_searched = apply_filters(
'gravityview/widget/hide_until_searched', $hide_until_searched, $this );
411 if ( $hide_until_searched && !
gravityview()->request->is_search() ) {
412 gravityview()->log->debug(
'Hide View data until search is performed' );
430 $this->render_frontend( $atts,
$content, $context );
431 return ob_get_clean();
445 $registered_widgets = self::registered();
447 if ( ! $id = Utils::get( $configuration,
'id' ) ) {
451 if ( ! $widget = Utils::get( $registered_widgets, $id ) ) {
455 if ( ! class_exists(
$class = Utils::get( $widget,
'class' ) ) ) {
459 $w =
new $class( Utils::get( $widget,
'label' ), $id );
460 $w->configuration =
new Settings( $configuration );
477 return array_merge( array(
478 'id' => $this->get_widget_id(),
479 ), $this->configuration->all() );
496 $registered_widgets = apply_filters(
'gravityview_register_directory_widgets', array() );
502 return apply_filters(
'gravityview/widgets/register', $registered_widgets );
514 if ( ! $widget_id = $this->get_widget_id() ) {
515 gravityview()->log->warning(
'Widget ID not set before calling Widget::is_registered', array(
'data' => $this ) );
518 return in_array( $widget_id, array_keys( self::registered() ),
true );
If this file is called directly, abort.
if(! isset( $gravityview)||empty( $gravityview->template)) $template
The entry loop for the list output.
if(empty( $field_settings['content'])) $content
gravityview()
The main GravityView wrapper function.