Making WordPress.org

Changeset 6776


Ignore:
Timestamp:
02/26/2018 10:41:18 PM (9 years ago)
Author:
iandunn
Message:

Email Post Changes Specific Post: Apply coding standards.

Location:
sites/trunk/wordcamp.org/public_html/wp-content/plugins/email-post-changes-specific-post
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/email-post-changes-specific-post/email-post-changes-specific-post.php

    r108 r6776  
    55Description: Extends the Email Post Changes plugin to allow visitors to subscribe to a specific post/page
    66Version:     0.1
    7 Author:      Ian Dunn
     7Author:      WordPress Meta Team
    88*/
    99
    1010class EPCSpecificPost {
    11        
    1211        /**
    1312         * Constructor
     
    2928        /**
    3029         * Override EPC's default options
    31          * 
     30         *
    3231         * @param  array $options
    3332         * @return array
     
    3736                 * EPC assumes you always want to e-mail the admin, and will always include the admin_email in the 'Additional Email Addresses' field,
    3837                 * even if you submit an empty value, so emptying the default value works around that.
    39                  */ 
     38                 */
    4039                $options['emails']     = array();
    4140                $options['post_types'] = array( 'page' );
    42                
     41
    4342                return $options;
    4443        }
     
    4746         * Inserts extra email addresses into the list of recipients
    4847         * When EPC is crafting a new notification, this method adds all of the addresses we've collected to it
    49          * 
    50          * @param  array $emails The list of addresses that EPC has collected
     48         *
     49         * @param  array $emails The list of addresses that EPC has collected.
    5150         * @param  int   $old_post_id
    5251         * @param  int   $new_post_id
     
    5554        public function insert_subscribed_emails( $emails, $old_post_id, $new_post_id ) {
    5655                $subscribed_emails = get_option( 'epcsp_subscribed_addresses', array() );
    57                
     56
    5857                if ( isset( $subscribed_emails[ $old_post_id ] ) && is_array( $subscribed_emails[ $old_post_id ] ) ) {
    5958                        $emails = array_merge( $emails, $subscribed_emails[ $old_post_id ] );
    6059                        $emails = array_unique( $emails );
    6160                }
    62                
     61
    6362                return $emails;
    6463        }
     
    6665
    6766require_once( __DIR__ . '/widget-subscribe.php' );
     67
    6868$GLOBALS['EPCSpecificPost'] = new EPCSpecificPost();
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/email-post-changes-specific-post/widget-subscribe.php

    r757 r6776  
    22
    33/**
    4  * A widget that allows visitors to subscribe to the current post/page
     4 * A widget that allows visitors to subscribe to the current post/page.
     5 *
    56 * A form is presented to the visitor to enter their email address, and then their address is mapped to the current post ID and saved in the database
    6  *
    7  * @package EPCSpecificPost
    87 */
    98class EPCSP_SubscribeWidget extends WP_Widget {
    10        
    119        /**
    1210         * Constructor
    1311         */
    14         function __construct() {
     12        public function __construct() {
    1513                $widget_options  = array(
    1614                        'classname'   => 'epcsp_subscribe',
     
    1816                );
    1917                $control_options = array( 'width' => 300 );
    20                
     18
    2119                parent::__construct( 'epcsp_subscribe', __( 'Subscribe to Specific Post', 'wordcamporg' ), $widget_options, $control_options );
    2220
     
    2624        /**
    2725         * Displays and processes the front-end form that visitors will enter their email address into in order to subscribe to the current post
    28          * 
     26         *
    2927         * @param array $args
    3028         * @param array $instance
    3129         */
    32         function widget( $args, $instance ) {
     30        public function widget( $args, $instance ) {
    3331                $errors  = array();
    3432                $message = '';
    3533                $title   = apply_filters( 'epcsp_subscribe_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
    36                
     34
    3735                if ( ! is_singular() || ! $this->is_supported_epc_post_type( get_post_type() ) ) {
    3836                        return;
     
    5048                        }
    5149                }
    52                
     50
    5351                echo $args['before_widget'];
    54                
     52
    5553                if ( ! empty( $title ) ) {
    5654                        echo $args['before_title'] . $title . $args['after_title'];
     
    6159                        $this->render_subscription_form();
    6260                }
    63                
     61
    6462                echo $args['after_widget'];
    6563        }
     
    6765        /**
    6866         * Determines if the given post type is enabled in EPC's settings
    69          * 
     67         *
    7068         * @param  string $post_type
    7169         * @return bool
    7270         */
    73         function is_supported_epc_post_type( $post_type ) {
     71        protected function is_supported_epc_post_type( $post_type ) {
    7472                $supported = false;
    75                
     73
    7674                if ( class_exists( 'Email_Post_Changes' ) ) {
    7775                        $epc_options = Email_Post_Changes::init()->get_options();
    78                        
     76
    7977                        if ( in_array( $post_type, $epc_options['post_types'] ) ) {
    8078                                $supported = true;
    8179                        }
    8280                }
    83                
     81
    8482                return $supported;
    8583        }
     
    8886         * Renders the form the visitor inputs their email address into
    8987         */
    90         function render_subscription_form() {
     88        protected function render_subscription_form() {
    9189                ?>
    9290
    9391                <form id="epcsp_subscribe" name="epcsp_subscribe" action="" method="POST">
    94                         <label for="epcsp_subscribe_address"><?php _e( 'Email Address:', 'wordcamporg' ); ?></label>
     92                        <label for="epcsp_subscribe_address"><?php esc_html_e( 'Email Address:', 'wordcamporg' ); ?></label>
    9593                        <input id="epcsp_subscribe_address" name="epcsp_subscribe_address" type="text" />
    9694                        <input name="epcsp_subscribe_submit" type="submit" value="Subscribe" />
     
    103101         * Outputs the styles for the widget
    104102         */
    105         function output_css() {
     103        public function output_css() {
    106104                ?>
    107                
     105
    108106                <style type="text/css">
    109107                        #epcsp_subscribe label,
     
    111109                                display: block;
    112110                        }
    113                        
     111
    114112                        #epcsp_subscribe_address {
    115113                                width: 100%;
     
    118116                        }
    119117                </style>
    120                
     118
    121119                <?php
    122120        }
    123        
     121
    124122        /**
    125123         * Subscribes the visitor to the post
    126          * 
     124         *
    127125         * @param  string $email
    128126         * @param  int    $post_id
    129127         * @return array
    130128         */
    131         function subscribe_visitor_to_post( $email, $post_id ) {
     129        protected function subscribe_visitor_to_post( $email, $post_id ) {
    132130                $errors  = array();
    133131                $post_id = absint( $post_id );
    134                
     132
    135133                if ( is_email( $email ) ) {
    136134                        $subscribed_addresses = get_option( 'epcsp_subscribed_addresses', array() );
    137                        
     135
    138136                        if ( isset( $subscribed_addresses[ $post_id ] ) && in_array( $email, $subscribed_addresses[ $post_id ] ) ) {
    139137                                $errors[] = __( 'You are already subscribed to this post.', 'wordcamporg' );
    140138                        } else {
    141139                                $subscribed_addresses[ $post_id ][] = sanitize_email( $email );
    142                                 $subscribed_addresses[ $post_id ] = array_unique( $subscribed_addresses[ $post_id ] );
    143                                
     140                                $subscribed_addresses[ $post_id ]   = array_unique( $subscribed_addresses[ $post_id ] );
     141
    144142                                update_option( 'epcsp_subscribed_addresses', $subscribed_addresses );
    145143                        }
     
    147145                        $errors[] = __( 'The email address you entered was not valid.', 'wordcamporg' );
    148146                }
    149                
     147
    150148                return $errors;
    151149        }
     
    153151        /**
    154152         * Processes the back-end form on the Widgets page
    155          * 
     153         *
    156154         * @param  array $new_instance
    157155         * @param  array $old_instance
    158156         * @return array
    159157         */
    160         function update( $new_instance, $old_instance ) {
     158        public function update( $new_instance, $old_instance ) {
    161159                $instance          = $old_instance;
    162160                $instance['title'] = strip_tags( $new_instance['title'] );
    163                
     161
    164162                return $instance;
    165163        }
     
    167165        /**
    168166         * Generates the back-end form for the Widgets page
    169          * 
     167         *
    170168         * @param array $instance
    171169         */
    172         function form( $instance ) {
     170        public function form( $instance ) {
    173171                $instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );
    174172                $title    = strip_tags( $instance['title'] );
    175                
     173
    176174                ?>
    177                
     175
    178176                <?php if ( ! $this->is_epc_enabled() ) : ?>
    179177                        <div class="error inline">
    180                                 <strong>Warning:</strong> The 'Enable' setting on <a href="<?php echo admin_url( 'options-general.php?page=email_post_changes' ); ?>">the Email Post Changes settings page</a> is disabled. No emails will be sent until it is enabled.
     178                                <strong>Warning:</strong>
     179                                The 'Enable' setting on <a href="<?php echo esc_url( admin_url( 'options-general.php?page=email_post_changes' ) ); ?>">the Email Post Changes settings page</a> is disabled.
     180                                No emails will be sent until it is enabled.
    181181                        </div>
    182182                <?php endif; ?>
    183                
     183
    184184                <p>
    185                         <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
    186                         <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
     185                        <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>">
     186                                <?php esc_html_e( 'Title:' ); ?>
     187                        </label>
     188
     189                        <input
     190                                class="widefat"
     191                                id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"
     192                                name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>"
     193                                type="text"
     194                                value="<?php echo esc_attr( $title ); ?>"
     195                        />
    187196                </p>
    188                
     197
    189198                <?php
    190199        }
     
    192201        /**
    193202         * Determines if the Email Post Changes plugin has the 'Enabled' setting turned on or not
    194          * 
     203         *
    195204         * @return bool
    196205         */
    197         function is_epc_enabled() {
     206        protected function is_epc_enabled() {
    198207                $enabled = false;
    199                
     208
    200209                if ( class_exists( 'Email_Post_Changes' ) ) {
    201210                        $epc_options = Email_Post_Changes::init()->get_options();
     
    205214                        }
    206215                }
    207                
     216
    208217                return $enabled;
    209218        }
Note: See TracChangeset for help on using the changeset viewer.