Changeset 6776
- Timestamp:
- 02/26/2018 10:41:18 PM (8 years ago)
- Location:
- sites/trunk/wordcamp.org/public_html/wp-content/plugins/email-post-changes-specific-post
- Files:
-
- 2 edited
-
email-post-changes-specific-post.php (modified) (6 diffs)
-
widget-subscribe.php (modified) (15 diffs)
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 5 5 Description: Extends the Email Post Changes plugin to allow visitors to subscribe to a specific post/page 6 6 Version: 0.1 7 Author: Ian Dunn7 Author: WordPress Meta Team 8 8 */ 9 9 10 10 class EPCSpecificPost { 11 12 11 /** 13 12 * Constructor … … 29 28 /** 30 29 * Override EPC's default options 31 * 30 * 32 31 * @param array $options 33 32 * @return array … … 37 36 * EPC assumes you always want to e-mail the admin, and will always include the admin_email in the 'Additional Email Addresses' field, 38 37 * even if you submit an empty value, so emptying the default value works around that. 39 */ 38 */ 40 39 $options['emails'] = array(); 41 40 $options['post_types'] = array( 'page' ); 42 41 43 42 return $options; 44 43 } … … 47 46 * Inserts extra email addresses into the list of recipients 48 47 * 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. 51 50 * @param int $old_post_id 52 51 * @param int $new_post_id … … 55 54 public function insert_subscribed_emails( $emails, $old_post_id, $new_post_id ) { 56 55 $subscribed_emails = get_option( 'epcsp_subscribed_addresses', array() ); 57 56 58 57 if ( isset( $subscribed_emails[ $old_post_id ] ) && is_array( $subscribed_emails[ $old_post_id ] ) ) { 59 58 $emails = array_merge( $emails, $subscribed_emails[ $old_post_id ] ); 60 59 $emails = array_unique( $emails ); 61 60 } 62 61 63 62 return $emails; 64 63 } … … 66 65 67 66 require_once( __DIR__ . '/widget-subscribe.php' ); 67 68 68 $GLOBALS['EPCSpecificPost'] = new EPCSpecificPost(); -
sites/trunk/wordcamp.org/public_html/wp-content/plugins/email-post-changes-specific-post/widget-subscribe.php
r757 r6776 2 2 3 3 /** 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 * 5 6 * 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 EPCSpecificPost8 7 */ 9 8 class EPCSP_SubscribeWidget extends WP_Widget { 10 11 9 /** 12 10 * Constructor 13 11 */ 14 function __construct() {12 public function __construct() { 15 13 $widget_options = array( 16 14 'classname' => 'epcsp_subscribe', … … 18 16 ); 19 17 $control_options = array( 'width' => 300 ); 20 18 21 19 parent::__construct( 'epcsp_subscribe', __( 'Subscribe to Specific Post', 'wordcamporg' ), $widget_options, $control_options ); 22 20 … … 26 24 /** 27 25 * 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 * 29 27 * @param array $args 30 28 * @param array $instance 31 29 */ 32 function widget( $args, $instance ) {30 public function widget( $args, $instance ) { 33 31 $errors = array(); 34 32 $message = ''; 35 33 $title = apply_filters( 'epcsp_subscribe_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base ); 36 34 37 35 if ( ! is_singular() || ! $this->is_supported_epc_post_type( get_post_type() ) ) { 38 36 return; … … 50 48 } 51 49 } 52 50 53 51 echo $args['before_widget']; 54 52 55 53 if ( ! empty( $title ) ) { 56 54 echo $args['before_title'] . $title . $args['after_title']; … … 61 59 $this->render_subscription_form(); 62 60 } 63 61 64 62 echo $args['after_widget']; 65 63 } … … 67 65 /** 68 66 * Determines if the given post type is enabled in EPC's settings 69 * 67 * 70 68 * @param string $post_type 71 69 * @return bool 72 70 */ 73 function is_supported_epc_post_type( $post_type ) {71 protected function is_supported_epc_post_type( $post_type ) { 74 72 $supported = false; 75 73 76 74 if ( class_exists( 'Email_Post_Changes' ) ) { 77 75 $epc_options = Email_Post_Changes::init()->get_options(); 78 76 79 77 if ( in_array( $post_type, $epc_options['post_types'] ) ) { 80 78 $supported = true; 81 79 } 82 80 } 83 81 84 82 return $supported; 85 83 } … … 88 86 * Renders the form the visitor inputs their email address into 89 87 */ 90 function render_subscription_form() {88 protected function render_subscription_form() { 91 89 ?> 92 90 93 91 <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> 95 93 <input id="epcsp_subscribe_address" name="epcsp_subscribe_address" type="text" /> 96 94 <input name="epcsp_subscribe_submit" type="submit" value="Subscribe" /> … … 103 101 * Outputs the styles for the widget 104 102 */ 105 function output_css() {103 public function output_css() { 106 104 ?> 107 105 108 106 <style type="text/css"> 109 107 #epcsp_subscribe label, … … 111 109 display: block; 112 110 } 113 111 114 112 #epcsp_subscribe_address { 115 113 width: 100%; … … 118 116 } 119 117 </style> 120 118 121 119 <?php 122 120 } 123 121 124 122 /** 125 123 * Subscribes the visitor to the post 126 * 124 * 127 125 * @param string $email 128 126 * @param int $post_id 129 127 * @return array 130 128 */ 131 function subscribe_visitor_to_post( $email, $post_id ) {129 protected function subscribe_visitor_to_post( $email, $post_id ) { 132 130 $errors = array(); 133 131 $post_id = absint( $post_id ); 134 132 135 133 if ( is_email( $email ) ) { 136 134 $subscribed_addresses = get_option( 'epcsp_subscribed_addresses', array() ); 137 135 138 136 if ( isset( $subscribed_addresses[ $post_id ] ) && in_array( $email, $subscribed_addresses[ $post_id ] ) ) { 139 137 $errors[] = __( 'You are already subscribed to this post.', 'wordcamporg' ); 140 138 } else { 141 139 $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 144 142 update_option( 'epcsp_subscribed_addresses', $subscribed_addresses ); 145 143 } … … 147 145 $errors[] = __( 'The email address you entered was not valid.', 'wordcamporg' ); 148 146 } 149 147 150 148 return $errors; 151 149 } … … 153 151 /** 154 152 * Processes the back-end form on the Widgets page 155 * 153 * 156 154 * @param array $new_instance 157 155 * @param array $old_instance 158 156 * @return array 159 157 */ 160 function update( $new_instance, $old_instance ) {158 public function update( $new_instance, $old_instance ) { 161 159 $instance = $old_instance; 162 160 $instance['title'] = strip_tags( $new_instance['title'] ); 163 161 164 162 return $instance; 165 163 } … … 167 165 /** 168 166 * Generates the back-end form for the Widgets page 169 * 167 * 170 168 * @param array $instance 171 169 */ 172 function form( $instance ) {170 public function form( $instance ) { 173 171 $instance = wp_parse_args( (array) $instance, array( 'title' => '' ) ); 174 172 $title = strip_tags( $instance['title'] ); 175 173 176 174 ?> 177 175 178 176 <?php if ( ! $this->is_epc_enabled() ) : ?> 179 177 <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. 181 181 </div> 182 182 <?php endif; ?> 183 183 184 184 <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 /> 187 196 </p> 188 197 189 198 <?php 190 199 } … … 192 201 /** 193 202 * Determines if the Email Post Changes plugin has the 'Enabled' setting turned on or not 194 * 203 * 195 204 * @return bool 196 205 */ 197 function is_epc_enabled() {206 protected function is_epc_enabled() { 198 207 $enabled = false; 199 208 200 209 if ( class_exists( 'Email_Post_Changes' ) ) { 201 210 $epc_options = Email_Post_Changes::init()->get_options(); … … 205 214 } 206 215 } 207 216 208 217 return $enabled; 209 218 }
Note: See TracChangeset
for help on using the changeset viewer.