Skip to content

Commit

Permalink
Blocks: allow multi-line submit buttons (#11223)
Browse files Browse the repository at this point in the history
* Allows the contact form block and subscription form block to display
multi-line submit buttons on the front end.

* clean-up some bad mark-up

* addressing feedback from @enejb and @jeherve
  • Loading branch information
roccotripaldi authored and lezama committed Feb 11, 2019
1 parent 661d73f commit 91e41df
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 11 deletions.
23 changes: 16 additions & 7 deletions modules/contact-form/grunion-contact-form.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ protected function __construct() {
) {
add_filter( 'widget_text', array( $this, 'widget_shortcode_hack' ), 5 );
}

add_filter( 'jetpack_contact_form_is_spam', array( $this, 'is_spam_blacklist' ), 10, 2 );

// Akismet to the rescue
Expand Down Expand Up @@ -634,7 +634,7 @@ function widget_shortcode_hack( $text ) {

return $text;
}

/**
* Check if a submission matches the Comment Blacklist.
* The Comment Blacklist is a means to moderate discussion, and contact
Expand All @@ -650,11 +650,11 @@ function is_spam_blacklist( $is_spam, $form = array() ) {
if ( $is_spam ) {
return $is_spam;
}

if ( wp_blacklist_check( $form['comment_author'], $form['comment_author_email'], $form['comment_author_url'], $form['comment_content'], $form['user_ip'], $form['user_agent'] ) ) {
return true;
}

return false;
}

Expand Down Expand Up @@ -1802,6 +1802,11 @@ class Grunion_Contact_Form extends Crunion_Contact_Form_Shortcode {
*/
static $style = false;

/**
* @var array When printing the submit button, what tags are allowed
*/
static $allowed_html_tags_for_submit_button = array( 'br' => array() );

function __construct( $attributes, $content = null ) {
global $post;

Expand Down Expand Up @@ -2060,12 +2065,16 @@ static function parse( $attributes, $content ) {
$submit_button_text = $form->get_attribute( 'submit_button_text' );
}

$r .= "\t\t<input type='submit' value='" . esc_attr( $submit_button_text ) . "' class='" . esc_attr( $submit_button_class ) . "'";
$r .= "\t\t<button type='submit' class='" . esc_attr( $submit_button_class ) . "'";
if ( ! empty( $submit_button_styles ) ) {
$r .= " style='" . esc_attr( $submit_button_styles ) . "'";
}
$r .= "/>\n";

$r .= ">";
$r .= wp_kses(
$submit_button_text,
self::$allowed_html_tags_for_submit_button
) . "</button>";

if ( is_user_logged_in() ) {
$r .= "\t\t" . wp_nonce_field( 'contact-form_' . $id, '_wpnonce', true, false ) . "\n"; // nonce and referer
}
Expand Down
25 changes: 21 additions & 4 deletions modules/subscriptions/views.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

class Jetpack_Subscriptions_Widget extends WP_Widget {
static $instance_count = 0;
/**
* @var array When printing the submit button, what tags are allowed
*/
static $allowed_html_tags_for_submit_button = array( 'br' => array() );

function __construct() {
$widget_ops = array(
Expand Down Expand Up @@ -289,14 +293,21 @@ static function render_widget_subscription_form( $args, $instance, $subscribe_em
<input type="hidden" name="sub-type" value="<?php echo esc_attr( $source ); ?>"/>
<input type="hidden" name="redirect_fragment" value="<?php echo esc_attr( $widget_id ); ?>"/>
<?php wp_nonce_field( 'blogsub_subscribe_' . $current_blog->blog_id, '_wpnonce', false ); ?>
<input type="submit" value="<?php echo esc_attr( $subscribe_button ); ?>"
<button type="submit"
<?php if ( ! empty( $submit_button_classes ) ) { ?>
class="<?php echo esc_attr( $submit_button_classes ); ?>"
<?php }; ?>
<?php if ( ! empty( $submit_button_styles ) ) { ?>
style="<?php echo esc_attr( $submit_button_styles ); ?>"
<?php }; ?>
/>
>
<?php
echo wp_kses(
$subscribe_button,
self::$allowed_html_tags_for_submit_button
);
?>
</button>
</p>
</form>
<?php
Expand Down Expand Up @@ -349,15 +360,21 @@ class="screen-reader-text"
wp_nonce_field( 'blogsub_subscribe_' . get_current_blog_id(), '_wpnonce', false );
}
?>
<input type="submit" value="<?php echo esc_attr( $subscribe_button ); ?>"
<button type="submit"
<?php if ( ! empty( $submit_button_classes ) ) { ?>
class="<?php echo esc_attr( $submit_button_classes ); ?>"
<?php }; ?>
<?php if ( ! empty( $submit_button_styles ) ) { ?>
style="<?php echo esc_attr( $submit_button_styles ); ?>"
<?php }; ?>
name="jetpack_subscriptions_widget"
/>
>
<?php
echo wp_kses(
$subscribe_button,
self::$allowed_html_tags_for_submit_button
); ?>
</button>
</p>
<?php } ?>
</form>
Expand Down

0 comments on commit 91e41df

Please sign in to comment.