Skip to content

Commit

Permalink
Merge pull request #1274 from ravinderk/issues/1269
Browse files Browse the repository at this point in the history
Issues/1269
  • Loading branch information
Devin Walker committed Nov 22, 2016
2 parents 4fbe6f1 + 4a04f0f commit ec319a0
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 37 deletions.
15 changes: 13 additions & 2 deletions includes/forms/template.php
Original file line number Diff line number Diff line change
Expand Up @@ -1684,8 +1684,19 @@ function give_show_goal_progress( $form_id, $args ) {
function give_get_form_content_placement( $form_id, $args ) {
$show_content = '';

if( isset( $args['show_content'] ) && ! empty( $args['show_content'] ) ) {
$show_content = ( 'none' !== $args['show_content'] ? $args['show_content'] : '' );
if ( isset( $args['show_content'] ) && ! empty( $args['show_content'] ) ) {
// Content positions.
$content_placement = array(
'above' => 'give_pre_form',
'below' => 'give_post_form',
);

// Check if content position already decoded.
if ( in_array( $args['show_content'], $content_placement ) ) {
return $args['show_content'];
}

$show_content = ( 'none' !== $args['show_content'] ? $content_placement[ $args['show_content'] ] : '' );
} elseif ( give_is_setting_enabled( get_post_meta( $form_id, '_give_display_content', true ) ) ) {
$show_content = get_post_meta( $form_id, '_give_content_placement', true );
}
Expand Down
20 changes: 12 additions & 8 deletions includes/forms/widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,6 @@ public function widget( $args, $instance ){
$title = !empty( $instance['title'] ) ? $instance['title'] : '';
$title = apply_filters( 'widget_title', $title, $instance, $this->id_base );


// If user set float labels to global then check global float label setting and update donation form widget accordingly.
if( ( 'global' === $instance['float_labels'] ) ) {
$instance['float_labels'] = give_get_option( 'floatlabels', 'disabled' );
}

echo $args['before_widget'];

/**
Expand Down Expand Up @@ -125,6 +119,7 @@ public function form( $instance ){
'id' => '',
'float_labels' => 'global',
'display_style' => 'modal',
'show_content' => 'none',
);

$instance = wp_parse_args( (array) $instance, $defaults );
Expand Down Expand Up @@ -164,7 +159,7 @@ public function form( $instance ){

<?php // Widget: Display Style ?>
<p>
<label for="<?php echo esc_attr( $this->get_field_id( 'display_style' ) ); ?>"><?php esc_html_e( 'Display style:', 'give' ); ?></label><br>
<label for="<?php echo esc_attr( $this->get_field_id( 'display_style' ) ); ?>"><?php esc_html_e( 'Display Style:', 'give' ); ?></label><br>
<label for="<?php echo $this->get_field_id( 'display_style' ); ?>-onpage"><input type="radio" class="widefat" id="<?php echo $this->get_field_id( 'display_style' ); ?>-onpage" name="<?php echo $this->get_field_name( 'display_style' ); ?>" value="onpage" <?php checked( $instance['display_style'], 'onpage' ); ?>> <?php echo esc_html__( 'All Fields', 'give' ); ?></label>
&nbsp;&nbsp;<label for="<?php echo $this->get_field_id( 'display_style' ); ?>-reveal"><input type="radio" class="widefat" id="<?php echo $this->get_field_id( 'display_style' ); ?>-reveal" name="<?php echo $this->get_field_name( 'display_style' ); ?>" value="reveal" <?php checked( $instance['display_style'], 'reveal' ); ?>> <?php echo esc_html__( 'Reveal', 'give' ); ?></label>
&nbsp;&nbsp;<label for="<?php echo $this->get_field_id( 'display_style' ); ?>-modal"><input type="radio" class="widefat" id="<?php echo $this->get_field_id( 'display_style' ); ?>-modal" name="<?php echo $this->get_field_name( 'display_style' ); ?>" value="modal" <?php checked( $instance['display_style'], 'modal' ); ?>> <?php echo esc_html__( 'Modal', 'give' ); ?></label><br>
Expand All @@ -187,7 +182,16 @@ public function form( $instance ){
esc_url( 'https://givewp.com/documentation/core/give-forms/creating-give-forms/#floating-labels' )
);
?></small>
</p><?php
</p>

<?php // Widget: Display Content ?>
<p>
<label for="<?php echo esc_attr( $this->get_field_id( 'show_content' ) ); ?>"><?php esc_html_e( 'Display Content (optional):', 'give' ); ?></label><br>
<label for="<?php echo $this->get_field_id( 'show_content' ); ?>-none"><input type="radio" class="widefat" id="<?php echo $this->get_field_id( 'show_content' ); ?>-none" name="<?php echo $this->get_field_name( 'show_content' ); ?>" value="none" <?php checked( $instance['show_content'], 'none' ); ?>> <?php echo esc_html__( 'None', 'give' ); ?></label>
&nbsp;&nbsp;<label for="<?php echo $this->get_field_id( 'show_content' ); ?>-above"><input type="radio" class="widefat" id="<?php echo $this->get_field_id( 'show_content' ); ?>-above" name="<?php echo $this->get_field_name( 'show_content' ); ?>" value="above" <?php checked( $instance['show_content'], 'above' ); ?>> <?php echo esc_html__( 'Above', 'give' ); ?></label>
&nbsp;&nbsp;<label for="<?php echo $this->get_field_id( 'show_content' ); ?>-below"><input type="radio" class="widefat" id="<?php echo $this->get_field_id( 'show_content' ); ?>-below" name="<?php echo $this->get_field_name( 'show_content' ); ?>" value="below" <?php checked( $instance['show_content'], 'below' ); ?>> <?php echo esc_html__( 'Below', 'give' ); ?></label><br>
<small class="give-field-description"><?php esc_html_e( 'Override the display content setting for this Give form.', 'give' ); ?></small>
<?php
}

/**
Expand Down
30 changes: 3 additions & 27 deletions includes/shortcodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,33 +78,9 @@ function give_form_shortcode( $atts ) {
'display_style' => '',
), $atts, 'give_form' );

foreach ( $atts as $key => $value ) {
//convert shortcode_atts values to booleans
if ( $key == 'show_title' ) {
$atts[ $key ] = filter_var( $atts[ $key ], FILTER_VALIDATE_BOOLEAN );
} elseif ( $key == 'show_goal' ) {
$atts[ $key ] = filter_var( $atts[ $key ], FILTER_VALIDATE_BOOLEAN );
}

//validate show_content value
if ( $key == 'show_content' ) {
if ( ! in_array( $value, array( 'none', 'above', 'below' ) ) ) {
$atts[ $key ] = '';
} else if ( $value == 'above' ) {
$atts[ $key ] = 'give_pre_form';
} else if ( $value == 'below' ) {
$atts[ $key ] = 'give_post_form';
}
}

//validate display_style and float_labels value
if ( ( $key == 'display_style' && ! in_array( $value, array( 'onpage', 'reveal', 'modal' ) ) )
|| ( $key == 'float_labels' && ! in_array( $value, array( 'enabled', 'disabled' ) ) )
) {

$atts[ $key ] = '';
}
}
// Convert string to bool.
$atts['show_title'] = (bool) $atts['show_title'];
$atts['show_goal'] = (bool) $atts['show_goal'];

//get the Give Form
ob_start();
Expand Down

0 comments on commit ec319a0

Please sign in to comment.