WordPress.org

Plugin Directory

Changeset 666993 for jetpack


Ignore:
Timestamp:
02/12/13 18:21:06 (14 months ago)
Author:
tmoorewp
Message:

Subscriptions:

  • Make <form> ids unique for multiple widgets on a page.
  • Add a shortcode to enable placement of a signup form in a post or page.
  • Fix some undefined index notices and other housekeeping.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • jetpack/trunk/modules/subscriptions.php

    r647113 r666993  
    532532 
    533533        $instance               = wp_parse_args( (array) $instance, $this->defaults() ); 
    534         $title                  = stripslashes( $instance['title'] ); 
    535         $subscribe_text         = stripslashes( $instance['subscribe_text'] ); 
    536         $subscribe_button       = stripslashes( $instance['subscribe_button'] ); 
    537         $subscribe_logged_in    = stripslashes( $instance['subscribe_logged_in'] ); 
     534        $title                  = isset( $instance['title'] )               ? stripslashes( $instance['title'] )               : ''; 
     535        $subscribe_text         = isset( $instance['subscribe_text'] )      ? stripslashes( $instance['subscribe_text'] )      : ''; 
     536        $subscribe_button       = isset( $instance['subscribe_button'] )    ? stripslashes( $instance['subscribe_button'] )    : ''; 
     537        $subscribe_logged_in    = isset( $instance['subscribe_logged_in'] ) ? stripslashes( $instance['subscribe_logged_in'] ) : ''; 
    538538        $show_subscribers_total = (bool) $instance['show_subscribers_total']; 
    539539        $subscribers_total      = $this->fetch_subscriber_count(); 
     
    542542            $show_subscribers_total = FALSE; 
    543543 
    544         echo $before_widget; 
    545         echo $before_title . '<label for="subscribe-field">' . esc_attr( $instance['title'] ) . '</label>' . $after_title . "\n"; 
     544        echo $args['before_widget']; 
     545        echo $args['$before_title'] . '<label for="subscribe-field">' . esc_attr( $instance['title'] ) . '</label>' . $args['after_title'] . "\n"; 
    546546 
    547547        $referer = ( is_ssl() ? 'https' : 'http' ) . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; 
    548548 
    549549        // Check for subscription confirmation. 
    550         if ( isset( $_GET['subscribe'] ) && 'success' == $_GET['subscribe'] ) { 
    551             ?> 
     550        if ( isset( $_GET['subscribe'] ) && 'success' == $_GET['subscribe'] ) : ?> 
    552551 
    553552            <div class="success"> 
    554                 <p><?php _e( 'An email was just sent to confirm your subscription. Please find the email now and click activate to start subscribing.', 'jetpack' ); ?></p> 
     553                <p><?php esc_html_e( 'An email was just sent to confirm your subscription. Please find the email now and click activate to start subscribing.', 'jetpack' ); ?></p> 
    555554            </div> 
    556555 
    557             <?php 
    558         } 
     556        <?php endif; 
    559557 
    560558        // Display any errors 
    561559        if ( isset( $_GET['subscribe'] ) ) : 
    562560            switch ( $_GET['subscribe'] ) : 
    563             case 'invalid_email' : ?> 
    564                 <p class="error"><?php _e( 'The email you entered was invalid, please check and try again.', 'jetpack' ); ?></p> 
    565             <?php   break; 
    566             case 'already' : ?> 
    567                 <p class="error"><?php _e( 'You have already subscribed to this site, please check your inbox.', 'jetpack' ); ?></p> 
    568             <?php   break; 
    569             case 'success' : 
    570  
    571                 echo wpautop( $subscribe_text ); 
    572                 break; 
    573             default : ?> 
    574                 <p class="error"><?php _e( 'There was an error when subscribing, please try again.', 'jetpack' ) ?></p> 
    575             <?php   break; 
     561                case 'invalid_email' : ?> 
     562                    <p class="error"><?php esc_html_e( 'The email you entered was invalid, please check and try again.', 'jetpack' ); ?></p> 
     563                <?php break; 
     564                case 'already' : ?> 
     565                    <p class="error"><?php esc_html_e( 'You have already subscribed to this site, please check your inbox.', 'jetpack' ); ?></p> 
     566                <?php break; 
     567                case 'success' : 
     568                    echo wpautop( $subscribe_text ); 
     569                    break; 
     570                default : ?> 
     571                    <p class="error"><?php esc_html_e( 'There was an error when subscribing, please try again.', 'jetpack' ) ?></p> 
     572                <?php break; 
    576573            endswitch; 
    577574        endif; 
    578575 
    579         $email_address = ''; 
    580         if ( ! empty( $current_user->user_email ) ) 
    581             $email_address = $current_user->user_email; 
    582  
    583576        // Display a subscribe form ?> 
    584         <form action="" method="post" accept-charset="utf-8" id="subscribe-blog"> 
     577        <form action="" method="post" accept-charset="utf-8" id="subscribe-blog-<?php echo !empty( $args['widget_id'] ) ? esc_attr( $args['widget_id'] ) : mt_rand( 450, 550 ); ?>"> 
    585578            <?php 
    586579            if ( ! isset ( $_GET['subscribe'] ) ) { 
     
    588581            } 
    589582 
    590             if ( $show_subscribers_total && $subscribers_total['value'] > 0 ) { 
     583            if ( $show_subscribers_total && 0 < $subscribers_total['value'] ) { 
    591584                echo wpautop( sprintf( _n( 'Join %s other subscriber', 'Join %s other subscribers', $subscribers_total['value'], 'jetpack' ), number_format_i18n( $subscribers_total['value'] ) ) ); 
    592585            } 
    593586            ?> 
    594587 
    595             <p><input type="text" name="email" style="width: 95%; padding: 1px 2px" value="<?php if ( !empty( $email_address ) ) { echo $email_address; } else { _e( 'Email Address', 'jetpack' ); } ?>" id="subscribe-field" onclick="if ( this.value == '<?php _e( 'Email Address', 'jetpack' ) ?>' ) { this.value = ''; }" onblur="if ( this.value == '' ) { this.value = '<?php _e( 'Email Address', 'jetpack' ) ?>'; }" /></p> 
     588            <p><input type="text" name="email" style="width: 95%; padding: 1px 2px" value="<?php echo !empty( $current_user->user_email ) ? esc_attr( $current_user->user_email ) : esc_html__( 'Email Address', 'jetpack' ); ?>" id="subscribe-field" onclick="if ( this.value == '<?php esc_html_e( 'Email Address', 'jetpack' ) ?>' ) { this.value = ''; }" onblur="if ( this.value == '' ) { this.value = '<?php esc_html_e( 'Email Address', 'jetpack' ) ?>'; }" /></p> 
    596589 
    597590            <p> 
     
    611604        <?php 
    612605 
    613         echo "\n" . $after_widget; 
     606        echo "\n" . $args['after_widget']; 
    614607    } 
    615608 
     
    657650        $instance = $old_instance; 
    658651 
    659         $instance['title']                  = strip_tags( stripslashes( $new_instance['title'] ) ); 
     652        $instance['title']                  = wp_kses( stripslashes( $new_instance['title'] ), array() ); 
    660653        $instance['subscribe_text']         = wp_filter_post_kses( stripslashes( $new_instance['subscribe_text'] ) ); 
    661654        $instance['subscribe_logged_in']    = wp_filter_post_kses( stripslashes( $new_instance['subscribe_logged_in'] ) ); 
    662         $instance['subscribe_button']       = strip_tags( stripslashes( $new_instance['subscribe_button'] ) ); 
     655        $instance['subscribe_button']       = wp_kses( stripslashes( $new_instance['subscribe_button'] ), array() ); 
    663656        $instance['show_subscribers_total'] = isset( $new_instance['show_subscribers_total'] ) && $new_instance['show_subscribers_total']; 
    664657 
     
    668661    function defaults() { 
    669662        return array( 
    670             'title'                  => __( 'Subscribe to Blog via Email', 'jetpack' ), 
    671             'subscribe_text'         => __( 'Enter your email address to subscribe to this blog and receive notifications of new posts by email.', 'jetpack' ), 
    672             'subscribe_button'       => __( 'Subscribe', 'jetpack' ), 
    673             'subscribe_logged_in'    => __( 'Click to subscribe to this blog and receive notifications of new posts by email.', 'jetpack' ), 
     663            'title'                  => esc_html__( 'Subscribe to Blog via Email', 'jetpack' ), 
     664            'subscribe_text'         => esc_html__( 'Enter your email address to subscribe to this blog and receive notifications of new posts by email.', 'jetpack' ), 
     665            'subscribe_button'       => esc_html__( 'Subscribe', 'jetpack' ), 
     666            'subscribe_logged_in'    => esc_html__( 'Click to subscribe to this blog and receive notifications of new posts by email.', 'jetpack' ), 
    674667            'show_subscribers_total' => true, 
    675668        ); 
     
    679672        $instance = wp_parse_args( (array) $instance, $this->defaults() ); 
    680673 
    681         $title                  = esc_attr( stripslashes( $instance['title'] ) ); 
    682         $subscribe_text         = esc_attr( stripslashes( $instance['subscribe_text'] ) ); 
    683         $subscribe_button       = esc_attr( stripslashes( $instance['subscribe_button'] ) ); 
     674        $title                  = stripslashes( $instance['title'] ); 
     675        $subscribe_text         = stripslashes( $instance['subscribe_text'] ); 
     676        $subscribe_button       = stripslashes( $instance['subscribe_button'] ); 
    684677        $show_subscribers_total = checked( $instance['show_subscribers_total'], true, false ); 
    685678 
     
    721714} 
    722715 
     716add_shortcode( 'jetpack_subscription_form', 'jetpack_do_subscription_form' ); 
     717 
     718function jetpack_do_subscription_form( $args ) { 
     719    $args['show_subscribers_total'] = empty( $args['show_subscribers_total'] ) ? false : true; 
     720    $args = shortcode_atts( Jetpack_Subscriptions_Widget::defaults(), $args ); 
     721    ob_start(); 
     722    the_widget( 'Jetpack_Subscriptions_Widget', $args ); 
     723    $output = ob_get_clean(); 
     724    return $output; 
     725} 
Note: See TracChangeset for help on using the changeset viewer.