| @@ -1,5 +1,5 @@ | ||
| 1 | -<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName) | |
| 1 | +<?php | |
| 2 | 2 | /** |
| 3 | 3 | * Module Name: Subscriptions |
| 4 | 4 | * Module Description: Let visitors subscribe to new posts and comments via email |
| 5 | 5 | * Sort Order: 9 |
| @@ -12,17 +12,12 @@ | ||
| 12 | 12 | * Feature: Engagement |
| 13 | 13 | * Additional Search Queries: subscriptions, subscription, email, follow, followers, subscribers, signup |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | -// phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed -- TODO: Move classes to appropriately-named class files. | |
| 17 | - | |
| 18 | 16 | use Automattic\Jetpack\Connection\XMLRPC_Async_Call; |
| 19 | 17 | |
| 20 | 18 | add_action( 'jetpack_modules_loaded', 'jetpack_subscriptions_load' ); |
| 21 | 19 | |
| 22 | -/** | |
| 23 | - * Loads the Subscriptions module. | |
| 24 | - */ | |
| 25 | 20 | function jetpack_subscriptions_load() { |
| 26 | 21 | Jetpack::enable_module_configurable( __FILE__ ); |
| 27 | 22 | } |
| 28 | 23 | |
| @@ -48,49 +43,32 @@ | ||
| 48 | 43 | |
| 49 | 44 | return $data; |
| 50 | 45 | } |
| 51 | 46 | |
| 52 | -/** | |
| 53 | - * Main class file for the Subscriptions module. | |
| 54 | - */ | |
| 55 | 47 | class Jetpack_Subscriptions { |
| 56 | - /** | |
| 57 | - * Whether Jetpack has been instantiated or not. | |
| 58 | - * | |
| 59 | - * @var bool | |
| 60 | - */ | |
| 61 | 48 | public $jetpack = false; |
| 62 | 49 | |
| 63 | - /** | |
| 64 | - * Hash of the siteurl option. | |
| 65 | - * | |
| 66 | - * @var string | |
| 67 | - */ | |
| 68 | 50 | public static $hash; |
| 69 | 51 | |
| 70 | 52 | /** |
| 71 | 53 | * Singleton |
| 72 | - * | |
| 73 | 54 | * @static |
| 74 | 55 | */ |
| 75 | - public static function init() { | |
| 56 | + static function init() { | |
| 76 | 57 | static $instance = false; |
| 77 | 58 | |
| 78 | - if ( ! $instance ) { | |
| 79 | - $instance = new Jetpack_Subscriptions(); | |
| 59 | + if ( !$instance ) { | |
| 60 | + $instance = new Jetpack_Subscriptions; | |
| 80 | 61 | } |
| 81 | 62 | |
| 82 | 63 | return $instance; |
| 83 | 64 | } |
| 84 | 65 | |
| 85 | - /** | |
| 86 | - * Jetpack_Subscriptions constructor. | |
| 87 | - */ | |
| 88 | - public function __construct() { | |
| 66 | + function __construct() { | |
| 89 | 67 | $this->jetpack = Jetpack::init(); |
| 90 | 68 | |
| 91 | 69 | // Don't use COOKIEHASH as it could be shared across installs && is non-unique in multisite. |
| 92 | - // @see: https://twitter.com/nacin/status/378246957451333632 . | |
| 70 | + // @see: https://twitter.com/nacin/status/378246957451333632 | |
| 93 | 71 | self::$hash = md5( get_option( 'siteurl' ) ); |
| 94 | 72 | |
| 95 | 73 | add_filter( 'jetpack_xmlrpc_methods', array( $this, 'xmlrpc_methods' ) ); |
| 96 | 74 | |
| @@ -95,23 +73,22 @@ | ||
| 95 | 73 | add_filter( 'jetpack_xmlrpc_methods', array( $this, 'xmlrpc_methods' ) ); |
| 96 | 74 | |
| 97 | 75 | // @todo remove sync from subscriptions and move elsewhere... |
| 98 | 76 | |
| 99 | - // Add Configuration Page. | |
| 77 | + // Add Configuration Page | |
| 100 | 78 | add_action( 'admin_init', array( $this, 'configure' ) ); |
| 101 | 79 | |
| 102 | - // Catch subscription widget submits. | |
| 103 | - if ( isset( $_REQUEST['jetpack_subscriptions_widget'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Nonce checked in widget_submit() for logged in users. | |
| 80 | + // Catch subscription widget submits | |
| 81 | + if ( isset( $_REQUEST['jetpack_subscriptions_widget'] ) ) | |
| 104 | 82 | add_action( 'template_redirect', array( $this, 'widget_submit' ) ); |
| 105 | - } | |
| 106 | 83 | |
| 107 | - // Set up the comment subscription checkboxes. | |
| 84 | + // Set up the comment subscription checkboxes | |
| 108 | 85 | add_filter( 'comment_form_submit_field', array( $this, 'comment_subscribe_init' ), 10, 2 ); |
| 109 | 86 | |
| 110 | 87 | // Catch comment posts and check for subscriptions. |
| 111 | 88 | add_action( 'comment_post', array( $this, 'comment_subscribe_submit' ), 50, 2 ); |
| 112 | 89 | |
| 113 | - // Adds post meta checkbox in the post submit metabox. | |
| 90 | + // Adds post meta checkbox in the post submit metabox | |
| 114 | 91 | add_action( 'post_submitbox_misc_actions', array( $this, 'subscription_post_page_metabox' ) ); |
| 115 | 92 | |
| 116 | 93 | add_action( 'transition_post_status', array( $this, 'maybe_send_subscription_email' ), 10, 3 ); |
| 117 | 94 | |
| @@ -119,13 +96,9 @@ | ||
| 119 | 96 | |
| 120 | 97 | add_filter( 'post_updated_messages', array( $this, 'update_published_message' ), 18, 1 ); |
| 121 | 98 | |
| 122 | 99 | // Set "social_notifications_subscribe" option during the first-time activation. |
| 123 | - add_action( 'jetpack_activate_module_subscriptions', array( $this, 'set_social_notifications_subscribe' ) ); | |
| 124 | - | |
| 125 | - // Hide subscription messaging in Publish panel for posts that were published in the past | |
| 126 | - add_action( 'init', array( $this, 'register_post_meta' ), 20 ); | |
| 127 | - add_action( 'transition_post_status', array( $this, 'maybe_set_first_published_status' ), 10, 3 ); | |
| 100 | + add_action( 'jetpack_activate_module_subscriptions', array( $this, 'set_social_notifications_subscribe' ) ); | |
| 128 | 101 | } |
| 129 | 102 | |
| 130 | 103 | /** |
| 131 | 104 | * Jetpack_Subscriptions::xmlrpc_methods() |
| @@ -130,12 +103,11 @@ | ||
| 130 | 103 | /** |
| 131 | 104 | * Jetpack_Subscriptions::xmlrpc_methods() |
| 132 | 105 | * |
| 133 | 106 | * Register subscriptions methods with the Jetpack XML-RPC server. |
| 134 | - * | |
| 135 | - * @param array $methods Methods being registered. | |
| 107 | + * @param array $methods | |
| 136 | 108 | */ |
| 137 | - public function xmlrpc_methods( $methods ) { | |
| 109 | + function xmlrpc_methods( $methods ) { | |
| 138 | 110 | return array_merge( |
| 139 | 111 | $methods, |
| 140 | 112 | array( |
| 141 | 113 | 'jetpack.subscriptions.subscribe' => array( $this, 'subscribe' ), |
| @@ -142,13 +114,13 @@ | ||
| 142 | 114 | ) |
| 143 | 115 | ); |
| 144 | 116 | } |
| 145 | 117 | |
| 146 | - /** | |
| 118 | + /* | |
| 147 | 119 | * Disable Subscribe on Single Post |
| 148 | 120 | * Register post meta |
| 149 | 121 | */ |
| 150 | - public function subscription_post_page_metabox() { | |
| 122 | + function subscription_post_page_metabox() { | |
| 151 | 123 | if ( |
| 152 | 124 | /** |
| 153 | 125 | * Filter whether or not to show the per-post subscription option. |
| 154 | 126 | * |
| @@ -157,9 +129,10 @@ | ||
| 157 | 129 | * @since 3.7.0 |
| 158 | 130 | * |
| 159 | 131 | * @param bool true = show checkbox option on all new posts | false = hide the option. |
| 160 | 132 | */ |
| 161 | - ! apply_filters( 'jetpack_allow_per_post_subscriptions', false ) ) { | |
| 133 | + ! apply_filters( 'jetpack_allow_per_post_subscriptions', false ) ) | |
| 134 | + { | |
| 162 | 135 | return; |
| 163 | 136 | } |
| 164 | 137 | |
| 165 | 138 | if ( has_filter( 'jetpack_subscriptions_exclude_these_categories' ) || has_filter( 'jetpack_subscriptions_include_only_these_categories' ) ) { |
| @@ -168,19 +141,18 @@ | ||
| 168 | 141 | |
| 169 | 142 | global $post; |
| 170 | 143 | $disable_subscribe_value = get_post_meta( $post->ID, '_jetpack_dont_email_post_to_subs', true ); |
| 171 | 144 | // only show checkbox if post hasn't been published and is a 'post' post type. |
| 172 | - if ( get_post_status( $post->ID ) !== 'publish' && get_post_type( $post->ID ) === 'post' ) : | |
| 173 | - // Nonce it. | |
| 145 | + if ( get_post_status( $post->ID ) !== 'publish' && get_post_type( $post->ID ) == 'post' ) : | |
| 146 | + // Nonce it | |
| 174 | 147 | wp_nonce_field( 'disable_subscribe', 'disable_subscribe_nonce' ); |
| 175 | 148 | ?> |
| 176 | 149 | <div class="misc-pub-section"> |
| 177 | - <label for="_jetpack_dont_email_post_to_subs"><?php esc_html_e( 'Jetpack Subscriptions:', 'jetpack' ); ?></label><br> | |
| 150 | + <label for="_jetpack_dont_email_post_to_subs"><?php _e( 'Jetpack Subscriptions:', 'jetpack' ); ?></label><br> | |
| 178 | 151 | <input type="checkbox" name="_jetpack_dont_email_post_to_subs" id="jetpack-per-post-subscribe" value="1" <?php checked( $disable_subscribe_value, 1, true ); ?> /> |
| 179 | - <?php esc_html_e( 'Don’t send this to subscribers', 'jetpack' ); ?> | |
| 152 | + <?php _e( 'Don’t send this to subscribers', 'jetpack' ); ?> | |
| 180 | 153 | </div> |
| 181 | - <?php | |
| 182 | - endif; | |
| 154 | + <?php endif; | |
| 183 | 155 | } |
| 184 | 156 | |
| 185 | 157 | /** |
| 186 | 158 | * Checks whether or not the post should be emailed to subscribers |
| @@ -191,38 +163,32 @@ | ||
| 191 | 163 | * - Existence of the per-post checkbox option |
| 192 | 164 | * |
| 193 | 165 | * Only one of these can be used at any given time. |
| 194 | 166 | * |
| 195 | - * @param string $new_status Tthe "new" post status of the transition when saved. | |
| 196 | - * @param string $old_status The "old" post status of the transition when saved. | |
| 197 | - * @param object $post obj The post object. | |
| 167 | + * @param $new_status string - the "new" post status of the transition when saved | |
| 168 | + * @param $old_status string - the "old" post status of the transition when saved | |
| 169 | + * @param $post obj - The post object | |
| 198 | 170 | */ |
| 199 | - public function maybe_send_subscription_email( $new_status, $old_status, $post ) { | |
| 171 | + function maybe_send_subscription_email( $new_status, $old_status, $post ) { | |
| 200 | 172 | |
| 201 | 173 | if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { |
| 202 | 174 | return; |
| 203 | 175 | } |
| 204 | 176 | |
| 205 | - // Make sure that the checkbox is preseved. | |
| 206 | - if ( ! empty( $_POST['disable_subscribe_nonce'] ) && wp_verify_nonce( $_POST['disable_subscribe_nonce'], 'disable_subscribe' ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- WP Core doesn't unslash or sanitize nonces either. | |
| 177 | + // Make sure that the checkbox is preseved | |
| 178 | + if ( ! empty( $_POST['disable_subscribe_nonce'] ) && wp_verify_nonce( $_POST['disable_subscribe_nonce'], 'disable_subscribe' ) ) { | |
| 207 | 179 | $set_checkbox = isset( $_POST['_jetpack_dont_email_post_to_subs'] ) ? 1 : 0; |
| 208 | 180 | update_post_meta( $post->ID, '_jetpack_dont_email_post_to_subs', $set_checkbox ); |
| 209 | 181 | } |
| 210 | 182 | } |
| 211 | 183 | |
| 212 | - /** | |
| 213 | - * Message used when publishing a post. | |
| 214 | - * | |
| 215 | - * @param array $messages Message array for a post. | |
| 216 | - */ | |
| 217 | - public function update_published_message( $messages ) { | |
| 184 | + function update_published_message( $messages ) { | |
| 218 | 185 | global $post; |
| 219 | 186 | if ( ! $this->should_email_post_to_subscribers( $post ) ) { |
| 220 | 187 | return $messages; |
| 221 | 188 | } |
| 222 | 189 | |
| 223 | - $view_post_link_html = sprintf( | |
| 224 | - ' <a href="%1$s">%2$s</a>', | |
| 190 | + $view_post_link_html = sprintf( ' <a href="%1$s">%2$s</a>', | |
| 225 | 191 | esc_url( get_permalink( $post ) ), |
| 226 | 192 | __( 'View post', 'jetpack' ) |
| 227 | 193 | ); |
| 228 | 194 | |
| @@ -228,17 +194,12 @@ | ||
| 228 | 194 | |
| 229 | 195 | $messages['post'][6] = sprintf( |
| 230 | 196 | /* translators: Message shown after a post is published */ |
| 231 | 197 | esc_html__( 'Post published and sending emails to subscribers.', 'jetpack' ) |
| 232 | - ) . $view_post_link_html; | |
| 198 | + ) . $view_post_link_html; | |
| 233 | 199 | return $messages; |
| 234 | 200 | } |
| 235 | 201 | |
| 236 | - /** | |
| 237 | - * Determine if a post should notifiy subscribers via email. | |
| 238 | - * | |
| 239 | - * @param object $post The post. | |
| 240 | - */ | |
| 241 | 202 | public function should_email_post_to_subscribers( $post ) { |
| 242 | 203 | $should_email = true; |
| 243 | 204 | if ( get_post_meta( $post->ID, '_jetpack_dont_email_post_to_subs', true ) ) { |
| 244 | 205 | return false; |
| @@ -243,10 +204,10 @@ | ||
| 243 | 204 | if ( get_post_meta( $post->ID, '_jetpack_dont_email_post_to_subs', true ) ) { |
| 244 | 205 | return false; |
| 245 | 206 | } |
| 246 | 207 | |
| 247 | - // Only posts are currently supported. | |
| 248 | - if ( 'post' !== $post->post_type ) { | |
| 208 | + // Only posts are currently supported | |
| 209 | + if ( $post->post_type !== 'post' ) { | |
| 249 | 210 | return false; |
| 250 | 211 | } |
| 251 | 212 | |
| 252 | 213 | // Private posts are not sent to subscribers. |
| @@ -266,9 +227,9 @@ | ||
| 266 | 227 | * @param array $args Array of category slugs or ID's. |
| 267 | 228 | */ |
| 268 | 229 | $excluded_categories = apply_filters( 'jetpack_subscriptions_exclude_these_categories', array() ); |
| 269 | 230 | |
| 270 | - // Never email posts from these categories. | |
| 231 | + // Never email posts from these categories | |
| 271 | 232 | if ( ! empty( $excluded_categories ) && in_category( $excluded_categories, $post->ID ) ) { |
| 272 | 233 | $should_email = false; |
| 273 | 234 | } |
| 274 | 235 | |
| @@ -284,9 +245,9 @@ | ||
| 284 | 245 | * @param array $args Array of category slugs or ID's. |
| 285 | 246 | */ |
| 286 | 247 | $only_these_categories = apply_filters( 'jetpack_subscriptions_exclude_all_categories_except', array() ); |
| 287 | 248 | |
| 288 | - // Only emails posts from these categories. | |
| 249 | + // Only emails posts from these categories | |
| 289 | 250 | if ( ! empty( $only_these_categories ) && ! in_category( $only_these_categories, $post->ID ) ) { |
| 290 | 251 | $should_email = false; |
| 291 | 252 | } |
| 292 | 253 | |
| @@ -292,15 +253,9 @@ | ||
| 292 | 253 | |
| 293 | 254 | return $should_email; |
| 294 | 255 | } |
| 295 | 256 | |
| 296 | - /** | |
| 297 | - * Retrieve which flags should be added to a particular post. | |
| 298 | - * | |
| 299 | - * @param array $flags Flags to be added. | |
| 300 | - * @param object $post A post object. | |
| 301 | - */ | |
| 302 | - public function set_post_flags( $flags, $post ) { | |
| 257 | + function set_post_flags( $flags, $post ) { | |
| 303 | 258 | $flags['send_subscription'] = $this->should_email_post_to_subscribers( $post ); |
| 304 | 259 | return $flags; |
| 305 | 260 | } |
| 306 | 261 | |
| @@ -308,10 +263,10 @@ | ||
| 308 | 263 | * Jetpack_Subscriptions::configure() |
| 309 | 264 | * |
| 310 | 265 | * Jetpack Subscriptions configuration screen. |
| 311 | 266 | */ |
| 312 | - public function configure() { | |
| 313 | - // Create the section. | |
| 267 | + function configure() { | |
| 268 | + // Create the section | |
| 314 | 269 | add_settings_section( |
| 315 | 270 | 'jetpack_subscriptions', |
| 316 | 271 | __( 'Jetpack Subscriptions Settings', 'jetpack' ), |
| 317 | 272 | array( $this, 'subscriptions_settings_section' ), |
| @@ -317,9 +272,9 @@ | ||
| 317 | 272 | array( $this, 'subscriptions_settings_section' ), |
| 318 | 273 | 'discussion' |
| 319 | 274 | ); |
| 320 | 275 | |
| 321 | - /** Subscribe to Posts */ | |
| 276 | + /** Subscribe to Posts ***************************************************/ | |
| 322 | 277 | |
| 323 | 278 | add_settings_field( |
| 324 | 279 | 'jetpack_subscriptions_post_subscribe', |
| 325 | 280 | __( 'Follow Blog', 'jetpack' ), |
| @@ -332,9 +287,9 @@ | ||
| 332 | 287 | 'discussion', |
| 333 | 288 | 'stb_enabled' |
| 334 | 289 | ); |
| 335 | 290 | |
| 336 | - /** Subscribe to Comments */ | |
| 291 | + /** Subscribe to Comments ******************************************************/ | |
| 337 | 292 | |
| 338 | 293 | add_settings_field( |
| 339 | 294 | 'jetpack_subscriptions_comment_subscribe', |
| 340 | 295 | __( 'Follow Comments', 'jetpack' ), |
| @@ -347,9 +302,9 @@ | ||
| 347 | 302 | 'discussion', |
| 348 | 303 | 'stc_enabled' |
| 349 | 304 | ); |
| 350 | 305 | |
| 351 | - /** Email me whenever: Someone follows my blog */ | |
| 306 | + /** Email me whenever: Someone follows my blog ***************************************************/ | |
| 352 | 307 | /* @since 8.1 */ |
| 353 | 308 | |
| 354 | 309 | add_settings_section( |
| 355 | 310 | 'notifications_section', |
| @@ -371,9 +326,9 @@ | ||
| 371 | 326 | 'social_notifications_subscribe', |
| 372 | 327 | array( $this, 'social_notifications_subscribe_validate' ) |
| 373 | 328 | ); |
| 374 | 329 | |
| 375 | - /** Subscription Messaging Options */ | |
| 330 | + /** Subscription Messaging Options ******************************************************/ | |
| 376 | 331 | |
| 377 | 332 | register_setting( |
| 378 | 333 | 'reading', |
| 379 | 334 | 'subscription_options', |
| @@ -404,62 +359,47 @@ | ||
| 404 | 359 | ); |
| 405 | 360 | } |
| 406 | 361 | |
| 407 | 362 | /** |
| 408 | - * Discussions setting section blurb. | |
| 363 | + * Discussions setting section blurb | |
| 364 | + * | |
| 409 | 365 | */ |
| 410 | - public function subscriptions_settings_section() { | |
| 411 | - ?> | |
| 412 | - <p id="jetpack-subscriptions-settings"><?php esc_html_e( 'Change whether your visitors can subscribe to your posts or comments or both.', 'jetpack' ); ?></p> | |
| 366 | + function subscriptions_settings_section() { | |
| 367 | + ?> | |
| 368 | + <p id="jetpack-subscriptions-settings"><?php _e( 'Change whether your visitors can subscribe to your posts or comments or both.', 'jetpack' ); ?></p> | |
| 413 | 369 | |
| 414 | - <?php | |
| 370 | + <?php | |
| 415 | 371 | } |
| 416 | 372 | |
| 417 | 373 | /** |
| 418 | - * Post Subscriptions Toggle. | |
| 374 | + * Post Subscriptions Toggle | |
| 375 | + * | |
| 419 | 376 | */ |
| 420 | - public function subscription_post_subscribe_setting() { | |
| 377 | + function subscription_post_subscribe_setting() { | |
| 421 | 378 | |
| 422 | - $stb_enabled = get_option( 'stb_enabled', 1 ); | |
| 423 | - ?> | |
| 379 | + $stb_enabled = get_option( 'stb_enabled', 1 ); ?> | |
| 424 | 380 | |
| 425 | 381 | <p class="description"> |
| 426 | 382 | <input type="checkbox" name="stb_enabled" id="jetpack-post-subscribe" value="1" <?php checked( $stb_enabled, 1 ); ?> /> |
| 427 | - <?php | |
| 428 | - echo wp_kses( | |
| 429 | - __( | |
| 430 | - "Show a <em>'follow blog'</em> option in the comment form", | |
| 431 | - 'jetpack' | |
| 432 | - ), | |
| 433 | - array( 'em' => array() ) | |
| 434 | - ); | |
| 435 | - ?> | |
| 383 | + <?php _e( "Show a <em>'follow blog'</em> option in the comment form", 'jetpack' ); ?> | |
| 436 | 384 | </p> |
| 437 | - <?php | |
| 385 | + <?php | |
| 438 | 386 | } |
| 439 | 387 | |
| 440 | 388 | /** |
| 441 | - * Comments Subscriptions Toggle. | |
| 389 | + * Comments Subscriptions Toggle | |
| 390 | + * | |
| 442 | 391 | */ |
| 443 | - public function subscription_comment_subscribe_setting() { | |
| 392 | + function subscription_comment_subscribe_setting() { | |
| 444 | 393 | |
| 445 | - $stc_enabled = get_option( 'stc_enabled', 1 ); | |
| 446 | - ?> | |
| 394 | + $stc_enabled = get_option( 'stc_enabled', 1 ); ?> | |
| 447 | 395 | |
| 448 | 396 | <p class="description"> |
| 449 | 397 | <input type="checkbox" name="stc_enabled" id="jetpack-comment-subscribe" value="1" <?php checked( $stc_enabled, 1 ); ?> /> |
| 450 | - <?php | |
| 451 | - echo wp_kses( | |
| 452 | - __( | |
| 453 | - "Show a <em>'follow comments'</em> option in the comment form", | |
| 454 | - 'jetpack' | |
| 455 | - ), | |
| 456 | - array( 'em' => array() ) | |
| 457 | - ); | |
| 458 | - ?> | |
| 398 | + <?php _e( "Show a <em>'follow comments'</em> option in the comment form", 'jetpack' ); ?> | |
| 459 | 399 | </p> |
| 460 | 400 | |
| 461 | - <?php | |
| 401 | + <?php | |
| 462 | 402 | } |
| 463 | 403 | |
| 464 | 404 | /** |
| 465 | 405 | * Someone follows my blog section |
| @@ -466,9 +406,9 @@ | ||
| 466 | 406 | * |
| 467 | 407 | * @since 8.1 |
| 468 | 408 | */ |
| 469 | 409 | public function social_notifications_subscribe_section() { |
| 470 | - // Atypical usage here. We emit jquery to move subscribe notification checkbox to be with the rest of the email notification settings. | |
| 410 | + // Atypical usage here. We emit jquery to move subscribe notification checkbox to be with the rest of the email notification settings | |
| 471 | 411 | ?> |
| 472 | 412 | <script type="text/javascript"> |
| 473 | 413 | jQuery( function( $ ) { |
| 474 | 414 | var table = $( '#social_notifications_subscribe' ).parents( 'table:first' ), |
| @@ -523,79 +463,53 @@ | ||
| 523 | 463 | // Otherwise we return 'on'. |
| 524 | 464 | return 'on'; |
| 525 | 465 | } |
| 526 | 466 | |
| 527 | - /** | |
| 528 | - * Validate settings for the Subscriptions module. | |
| 529 | - * | |
| 530 | - * @param array $settings Settings to be validated. | |
| 531 | - */ | |
| 532 | - public function validate_settings( $settings ) { | |
| 467 | + function validate_settings( $settings ) { | |
| 533 | 468 | global $allowedposttags; |
| 534 | 469 | |
| 535 | 470 | $default = $this->get_default_settings(); |
| 536 | 471 | |
| 537 | - // Blog Follow. | |
| 472 | + // Blog Follow | |
| 538 | 473 | $settings['invitation'] = trim( wp_kses( $settings['invitation'], $allowedposttags ) ); |
| 539 | - if ( empty( $settings['invitation'] ) ) { | |
| 474 | + if ( empty( $settings['invitation'] ) ) | |
| 540 | 475 | $settings['invitation'] = $default['invitation']; |
| 541 | - } | |
| 542 | 476 | |
| 543 | - // Comments Follow (single post). | |
| 477 | + // Comments Follow (single post) | |
| 544 | 478 | $settings['comment_follow'] = trim( wp_kses( $settings['comment_follow'], $allowedposttags ) ); |
| 545 | - if ( empty( $settings['comment_follow'] ) ) { | |
| 479 | + if ( empty( $settings['comment_follow'] ) ) | |
| 546 | 480 | $settings['comment_follow'] = $default['comment_follow']; |
| 547 | - } | |
| 548 | 481 | |
| 549 | 482 | return $settings; |
| 550 | 483 | } |
| 551 | 484 | |
| 552 | - /** | |
| 553 | - * HTML output helper for Reading section. | |
| 554 | - */ | |
| 555 | 485 | public function reading_section() { |
| 556 | 486 | echo '<p id="follower-settings">'; |
| 557 | - esc_html_e( 'These settings change emails sent from your blog to followers.', 'jetpack' ); | |
| 487 | + _e( 'These settings change emails sent from your blog to followers.', 'jetpack' ); | |
| 558 | 488 | echo '</p>'; |
| 559 | 489 | } |
| 560 | 490 | |
| 561 | - /** | |
| 562 | - * HTML output helper for Invitation section. | |
| 563 | - */ | |
| 564 | 491 | public function setting_invitation() { |
| 565 | 492 | $settings = $this->get_settings(); |
| 566 | 493 | echo '<textarea name="subscription_options[invitation]" class="large-text" cols="50" rows="5">' . esc_textarea( $settings['invitation'] ) . '</textarea>'; |
| 567 | - echo '<p><span class="description">' . esc_html__( 'Introduction text sent when someone follows your blog. (Site and confirmation details will be automatically added for you.)', 'jetpack' ) . '</span></p>'; | |
| 494 | + echo '<p><span class="description">'.__( 'Introduction text sent when someone follows your blog. (Site and confirmation details will be automatically added for you.)', 'jetpack' ).'</span></p>'; | |
| 568 | 495 | } |
| 569 | 496 | |
| 570 | - /** | |
| 571 | - * HTML output helper for Comment Follow section. | |
| 572 | - */ | |
| 573 | 497 | public function setting_comment_follow() { |
| 574 | 498 | $settings = $this->get_settings(); |
| 575 | 499 | echo '<textarea name="subscription_options[comment_follow]" class="large-text" cols="50" rows="5">' . esc_textarea( $settings['comment_follow'] ) . '</textarea>'; |
| 576 | - echo '<p><span class="description">' . esc_html__( 'Introduction text sent when someone follows a post on your blog. (Site and confirmation details will be automatically added for you.)', 'jetpack' ) . '</span></p>'; | |
| 500 | + echo '<p><span class="description">'.__( 'Introduction text sent when someone follows a post on your blog. (Site and confirmation details will be automatically added for you.)', 'jetpack' ).'</span></p>'; | |
| 577 | 501 | } |
| 578 | 502 | |
| 579 | - /** | |
| 580 | - * Get default settings for the Subscriptions module. | |
| 581 | - */ | |
| 582 | - public function get_default_settings() { | |
| 583 | - $site_url = get_home_url(); | |
| 584 | - $display_url = preg_replace( '(^https?://)', '', untrailingslashit( $site_url ) ); | |
| 585 | - | |
| 503 | + function get_default_settings() { | |
| 586 | 504 | return array( |
| 587 | - /* translators: Both %1$s and %2$s is site address */ | |
| 588 | - 'invitation' => sprintf( __( "Howdy,\nYou recently subscribed to <a href='%1\$s'>%2\$s</a> and we need to verify the email you provided. Once you confirm below, you'll be able to receive and read new posts.\n\nIf you believe this is an error, ignore this message and nothing more will happen.", 'jetpack' ), $site_url, $display_url ), | |
| 589 | - 'comment_follow' => __( "Howdy.\n\nYou recently followed one of my posts. This means you will receive an email when new comments are posted.\n\nTo activate, click confirm below. If you believe this is an error, ignore this message and we'll never bother you again.", 'jetpack' ), | |
| 505 | + 'invitation' => __( "Howdy.\n\nYou recently followed this blog's posts. This means you will receive each new post by email.\n\nTo activate, click confirm below. If you believe this is an error, ignore this message and we'll never bother you again.", 'jetpack' ), | |
| 506 | + 'comment_follow' => __( "Howdy.\n\nYou recently followed one of my posts. This means you will receive an email when new comments are posted.\n\nTo activate, click confirm below. If you believe this is an error, ignore this message and we'll never bother you again.", 'jetpack' ) | |
| 590 | 507 | ); |
| 591 | 508 | } |
| 592 | 509 | |
| 593 | - /** | |
| 594 | - * Reeturn merged `subscription_options` option with module default settings. | |
| 595 | - */ | |
| 596 | - public function get_settings() { | |
| 597 | - return wp_parse_args( (array) get_option( 'subscription_options' ), $this->get_default_settings() ); | |
| 510 | + function get_settings() { | |
| 511 | + return wp_parse_args( (array) get_option( 'subscription_options', array() ), $this->get_default_settings() ); | |
| 598 | 512 | } |
| 599 | 513 | |
| 600 | 514 | /** |
| 601 | 515 | * Jetpack_Subscriptions::subscribe() |
| @@ -601,30 +515,29 @@ | ||
| 601 | 515 | * Jetpack_Subscriptions::subscribe() |
| 602 | 516 | * |
| 603 | 517 | * Send a synchronous XML-RPC subscribe to blog posts or subscribe to post comments request. |
| 604 | 518 | * |
| 605 | - * @param string $email being subscribed. | |
| 606 | - * @param array $post_ids (optional) defaults to 0 for blog posts only: array of post IDs to subscribe to blog's posts. | |
| 519 | + * @param string $email | |
| 520 | + * @param array $post_ids (optional) defaults to 0 for blog posts only: array of post IDs to subscribe to blog's posts | |
| 607 | 521 | * @param bool $async (optional) Should the subscription be performed asynchronously? Defaults to true. |
| 608 | - * @param array $extra_data Additional data passed to the `jetpack.subscribeToSite` call. | |
| 609 | 522 | * |
| 610 | 523 | * @return true|WP_Error true on success |
| 611 | - * invalid_email : not a valid email address | |
| 612 | - * invalid_post_id : not a valid post ID | |
| 613 | - * unknown_post_id : unknown post | |
| 614 | - * not_subscribed : strange error. Jetpack servers at WordPress.com could subscribe the email. | |
| 615 | - * disabled : Site owner has disabled subscriptions. | |
| 616 | - * active : Already subscribed. | |
| 617 | - * pending : Tried to subscribe before but the confirmation link is never clicked. No confirmation email is sent. | |
| 618 | - * unknown : strange error. Jetpack servers at WordPress.com returned something malformed. | |
| 619 | - * unknown_status : strange error. Jetpack servers at WordPress.com returned something I didn't understand. | |
| 524 | + * invalid_email : not a valid email address | |
| 525 | + * invalid_post_id : not a valid post ID | |
| 526 | + * unknown_post_id : unknown post | |
| 527 | + * not_subscribed : strange error. Jetpack servers at WordPress.com could subscribe the email. | |
| 528 | + * disabled : Site owner has disabled subscriptions. | |
| 529 | + * active : Already subscribed. | |
| 530 | + * pending : Tried to subscribe before but the confirmation link is never clicked. No confirmation email is sent. | |
| 531 | + * unknown : strange error. Jetpack servers at WordPress.com returned something malformed. | |
| 532 | + * unknown_status : strange error. Jetpack servers at WordPress.com returned something I didn't understand. | |
| 620 | 533 | */ |
| 621 | - public function subscribe( $email, $post_ids = 0, $async = true, $extra_data = array() ) { | |
| 622 | - if ( ! is_email( $email ) ) { | |
| 534 | + function subscribe( $email, $post_ids = 0, $async = true, $extra_data = array() ) { | |
| 535 | + if ( !is_email( $email ) ) { | |
| 623 | 536 | return new WP_Error( 'invalid_email' ); |
| 624 | 537 | } |
| 625 | 538 | |
| 626 | - if ( ! $async ) { | |
| 539 | + if ( !$async ) { | |
| 627 | 540 | $xml = new Jetpack_IXR_ClientMulticall(); |
| 628 | 541 | } |
| 629 | 542 | |
| 630 | 543 | foreach ( (array) $post_ids as $post_id ) { |
| @@ -630,9 +543,9 @@ | ||
| 630 | 543 | foreach ( (array) $post_ids as $post_id ) { |
| 631 | 544 | $post_id = (int) $post_id; |
| 632 | 545 | if ( $post_id < 0 ) { |
| 633 | 546 | return new WP_Error( 'invalid_post_id' ); |
| 634 | - } elseif ( $post_id && ! get_post( $post_id ) ) { | |
| 547 | + } else if ( $post_id && !$post = get_post( $post_id ) ) { | |
| 635 | 548 | return new WP_Error( 'unknown_post_id' ); |
| 636 | 549 | } |
| 637 | 550 | |
| 638 | 551 | if ( $async ) { |
| @@ -637,9 +550,9 @@ | ||
| 637 | 550 | |
| 638 | 551 | if ( $async ) { |
| 639 | 552 | XMLRPC_Async_Call::add_call( 'jetpack.subscribeToSite', 0, $email, $post_id, serialize( $extra_data ) ); //phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize |
| 640 | 553 | } else { |
| 641 | - $xml->addCall( 'jetpack.subscribeToSite', $email, $post_id, serialize( $extra_data ) ); //phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize | |
| 554 | + $xml->addCall( 'jetpack.subscribeToSite', $email, $post_id, serialize( $extra_data ) ); | |
| 642 | 555 | } |
| 643 | 556 | } |
| 644 | 557 | |
| 645 | 558 | if ( $async ) { |
| @@ -645,9 +558,9 @@ | ||
| 645 | 558 | if ( $async ) { |
| 646 | 559 | return; |
| 647 | 560 | } |
| 648 | 561 | |
| 649 | - // Call. | |
| 562 | + // Call | |
| 650 | 563 | $xml->query(); |
| 651 | 564 | |
| 652 | 565 | if ( $xml->isError() ) { |
| 653 | 566 | return $xml->get_jetpack_error(); |
| @@ -661,9 +574,9 @@ | ||
| 661 | 574 | $r[] = $xml->get_jetpack_error( $response['faultCode'], $response['faultString'] ); |
| 662 | 575 | continue; |
| 663 | 576 | } |
| 664 | 577 | |
| 665 | - if ( ! is_array( $response[0] ) || empty( $response[0]['status'] ) ) { | |
| 578 | + if ( !is_array( $response[0] ) || empty( $response[0]['status'] ) ) { | |
| 666 | 579 | $r[] = new WP_Error( 'unknown' ); |
| 667 | 580 | continue; |
| 668 | 581 | } |
| 669 | 582 | |
| @@ -696,36 +609,35 @@ | ||
| 696 | 609 | * Jetpack_Subscriptions::widget_submit() |
| 697 | 610 | * |
| 698 | 611 | * When a user submits their email via the blog subscription widget, check the details and call the subsribe() method. |
| 699 | 612 | */ |
| 700 | - public function widget_submit() { | |
| 613 | + function widget_submit() { | |
| 701 | 614 | // Check the nonce. |
| 702 | 615 | if ( is_user_logged_in() ) { |
| 703 | 616 | check_admin_referer( 'blogsub_subscribe_' . get_current_blog_id() ); |
| 704 | 617 | } |
| 705 | 618 | |
| 706 | - if ( empty( $_REQUEST['email'] ) || ! is_string( $_REQUEST['email'] ) ) { | |
| 619 | + if ( empty( $_REQUEST['email'] ) || ! is_string( $_REQUEST['email'] ) ) | |
| 707 | 620 | return false; |
| 708 | - } | |
| 709 | 621 | |
| 710 | 622 | $redirect_fragment = false; |
| 711 | 623 | if ( isset( $_REQUEST['redirect_fragment'] ) ) { |
| 712 | - $redirect_fragment = preg_replace( '/[^a-z0-9_-]/i', '', $_REQUEST['redirect_fragment'] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- This is manually unslashing and sanitizing. | |
| 624 | + $redirect_fragment = preg_replace( '/[^a-z0-9_-]/i', '', $_REQUEST['redirect_fragment'] ); | |
| 713 | 625 | } |
| 714 | - if ( ! $redirect_fragment || ! is_string( $redirect_fragment ) ) { | |
| 626 | + if ( !$redirect_fragment || ! is_string( $redirect_fragment ) ) { | |
| 715 | 627 | $redirect_fragment = 'subscribe-blog'; |
| 716 | 628 | } |
| 717 | 629 | |
| 718 | - $subscribe = self::subscribe( | |
| 719 | - isset( $_REQUEST['email'] ) ? wp_unslash( $_REQUEST['email'] ) : null, // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Validated inside self::subscribe(). | |
| 720 | - 0, | |
| 721 | - false, | |
| 722 | - array( | |
| 723 | - 'source' => 'widget', | |
| 724 | - 'widget-in-use' => is_active_widget( false, false, 'blog_subscription', true ) ? 'yes' : 'no', | |
| 725 | - 'comment_status' => '', | |
| 726 | - 'server_data' => jetpack_subscriptions_cherry_pick_server_data(), | |
| 727 | - ) | |
| 630 | + $subscribe = Jetpack_Subscriptions::subscribe( | |
| 631 | + $_REQUEST['email'], | |
| 632 | + 0, | |
| 633 | + false, | |
| 634 | + array( | |
| 635 | + 'source' => 'widget', | |
| 636 | + 'widget-in-use' => is_active_widget( false, false, 'blog_subscription', true ) ? 'yes' : 'no', | |
| 637 | + 'comment_status' => '', | |
| 638 | + 'server_data' => jetpack_subscriptions_cherry_pick_server_data(), | |
| 639 | + ) | |
| 728 | 640 | ); |
| 729 | 641 | |
| 730 | 642 | if ( is_wp_error( $subscribe ) ) { |
| 731 | 643 | $error = $subscribe->get_error_code(); |
| @@ -785,10 +697,11 @@ | ||
| 785 | 697 | * |
| 786 | 698 | * Set up and add the comment subscription checkbox to the comment form. |
| 787 | 699 | * |
| 788 | 700 | * @param string $submit_button HTML markup for the submit field. |
| 701 | + * @param array $args Arguments passed to `comment_form()`. | |
| 789 | 702 | */ |
| 790 | - public function comment_subscribe_init( $submit_button ) { | |
| 703 | + function comment_subscribe_init( $submit_button, $args ) { | |
| 791 | 704 | global $post; |
| 792 | 705 | |
| 793 | 706 | $comments_checked = ''; |
| 794 | 707 | $blog_checked = ''; |
| @@ -801,20 +714,20 @@ | ||
| 801 | 714 | if ( isset( $_COOKIE[ 'jetpack_blog_subscribe_' . self::$hash ] ) ) { |
| 802 | 715 | $blog_checked = ' checked="checked"'; |
| 803 | 716 | } |
| 804 | 717 | |
| 805 | - // Some themes call this function, don't show the checkbox again. | |
| 718 | + // Some themes call this function, don't show the checkbox again | |
| 806 | 719 | remove_action( 'comment_form', 'subscription_comment_form' ); |
| 807 | 720 | |
| 808 | - // Check if Mark Jaquith's Subscribe to Comments plugin is active - if so, suppress Jetpack checkbox. | |
| 721 | + // Check if Mark Jaquith's Subscribe to Comments plugin is active - if so, suppress Jetpack checkbox | |
| 809 | 722 | |
| 810 | 723 | $str = ''; |
| 811 | 724 | |
| 812 | - if ( false === has_filter( 'comment_form', 'show_subscription_checkbox' ) && 1 === (int) get_option( 'stc_enabled', 1 ) && empty( $post->post_password ) && 'post' === get_post_type() ) { | |
| 813 | - // Subscribe to comments checkbox. | |
| 814 | - $str .= '<p class="comment-subscription-form"><input type="checkbox" name="subscribe_comments" id="subscribe_comments" value="subscribe" style="width: auto; -moz-appearance: checkbox; -webkit-appearance: checkbox;"' . $comments_checked . ' /> '; | |
| 725 | + if ( FALSE === has_filter( 'comment_form', 'show_subscription_checkbox' ) && 1 == get_option( 'stc_enabled', 1 ) && empty( $post->post_password ) && 'post' == get_post_type() ) { | |
| 726 | + // Subscribe to comments checkbox | |
| 727 | + $str .= '<p class="comment-subscription-form"><input type="checkbox" name="subscribe_comments" id="subscribe_comments" value="subscribe" style="width: auto; -moz-appearance: checkbox; -webkit-appearance: checkbox;"' . $comments_checked . ' /> '; | |
| 815 | 728 | $comment_sub_text = __( 'Notify me of follow-up comments by email.', 'jetpack' ); |
| 816 | - $str .= '<label class="subscribe-label" id="subscribe-label" for="subscribe_comments">' . esc_html( | |
| 729 | + $str .= '<label class="subscribe-label" id="subscribe-label" for="subscribe_comments">' . esc_html( | |
| 817 | 730 | /** |
| 818 | 731 | * Filter the Subscribe to comments text appearing below the comment form. |
| 819 | 732 | * |
| 820 | 733 | * @module subscriptions |
| @@ -827,13 +740,13 @@ | ||
| 827 | 740 | ) . '</label>'; |
| 828 | 741 | $str .= '</p>'; |
| 829 | 742 | } |
| 830 | 743 | |
| 831 | - if ( 1 === (int) get_option( 'stb_enabled', 1 ) ) { | |
| 832 | - // Subscribe to blog checkbox. | |
| 833 | - $str .= '<p class="comment-subscription-form"><input type="checkbox" name="subscribe_blog" id="subscribe_blog" value="subscribe" style="width: auto; -moz-appearance: checkbox; -webkit-appearance: checkbox;"' . $blog_checked . ' /> '; | |
| 744 | + if ( 1 == get_option( 'stb_enabled', 1 ) ) { | |
| 745 | + // Subscribe to blog checkbox | |
| 746 | + $str .= '<p class="comment-subscription-form"><input type="checkbox" name="subscribe_blog" id="subscribe_blog" value="subscribe" style="width: auto; -moz-appearance: checkbox; -webkit-appearance: checkbox;"' . $blog_checked . ' /> '; | |
| 834 | 747 | $blog_sub_text = __( 'Notify me of new posts by email.', 'jetpack' ); |
| 835 | - $str .= '<label class="subscribe-label" id="subscribe-blog-label" for="subscribe_blog">' . esc_html( | |
| 748 | + $str .= '<label class="subscribe-label" id="subscribe-blog-label" for="subscribe_blog">' . esc_html( | |
| 836 | 749 | /** |
| 837 | 750 | * Filter the Subscribe to blog text appearing below the comment form. |
| 838 | 751 | * |
| 839 | 752 | * @module subscriptions |
| @@ -864,13 +777,10 @@ | ||
| 864 | 777 | /** |
| 865 | 778 | * Jetpack_Subscriptions::comment_subscribe_init() |
| 866 | 779 | * |
| 867 | 780 | * When a user checks the comment subscribe box and submits a comment, subscribe them to the comment thread. |
| 868 | - * | |
| 869 | - * @param int|string $comment_id Comment thread being subscribed to. | |
| 870 | - * @param string $approved Comment status. | |
| 871 | 781 | */ |
| 872 | - public function comment_subscribe_submit( $comment_id, $approved ) { | |
| 782 | + function comment_subscribe_submit( $comment_id, $approved ) { | |
| 873 | 783 | if ( 'spam' === $approved ) { |
| 874 | 784 | return; |
| 875 | 785 | } |
| 876 | 786 | |
| @@ -878,35 +788,32 @@ | ||
| 878 | 788 | if ( ! $comment ) { |
| 879 | 789 | return; |
| 880 | 790 | } |
| 881 | 791 | |
| 882 | - // Set cookies for this post/comment. | |
| 883 | - $this->set_cookies( isset( $_REQUEST['subscribe_comments'] ), $comment->comment_post_ID, isset( $_REQUEST['subscribe_blog'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 792 | + // Set cookies for this post/comment | |
| 793 | + $this->set_cookies( isset( $_REQUEST['subscribe_comments'] ), $comment->comment_post_ID, isset( $_REQUEST['subscribe_blog'] ) ); | |
| 884 | 794 | |
| 885 | - if ( ! isset( $_REQUEST['subscribe_comments'] ) && ! isset( $_REQUEST['subscribe_blog'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 795 | + if ( !isset( $_REQUEST['subscribe_comments'] ) && !isset( $_REQUEST['subscribe_blog'] ) ) | |
| 886 | 796 | return; |
| 887 | - } | |
| 888 | 797 | |
| 889 | 798 | $post_ids = array(); |
| 890 | 799 | |
| 891 | - if ( isset( $_REQUEST['subscribe_comments'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 800 | + if ( isset( $_REQUEST['subscribe_comments'] ) ) | |
| 892 | 801 | $post_ids[] = $comment->comment_post_ID; |
| 893 | - } | |
| 894 | 802 | |
| 895 | - if ( isset( $_REQUEST['subscribe_blog'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 803 | + if ( isset( $_REQUEST['subscribe_blog'] ) ) | |
| 896 | 804 | $post_ids[] = 0; |
| 897 | - } | |
| 898 | 805 | |
| 899 | - $result = self::subscribe( | |
| 900 | - $comment->comment_author_email, | |
| 901 | - $post_ids, | |
| 902 | - true, | |
| 903 | - array( | |
| 904 | - 'source' => 'comment-form', | |
| 905 | - 'widget-in-use' => is_active_widget( false, false, 'blog_subscription', true ) ? 'yes' : 'no', | |
| 906 | - 'comment_status' => $approved, | |
| 907 | - 'server_data' => jetpack_subscriptions_cherry_pick_server_data(), | |
| 908 | - ) | |
| 806 | + $result = Jetpack_Subscriptions::subscribe( | |
| 807 | + $comment->comment_author_email, | |
| 808 | + $post_ids, | |
| 809 | + true, | |
| 810 | + array( | |
| 811 | + 'source' => 'comment-form', | |
| 812 | + 'widget-in-use' => is_active_widget( false, false, 'blog_subscription', true ) ? 'yes' : 'no', | |
| 813 | + 'comment_status' => $approved, | |
| 814 | + 'server_data' => jetpack_subscriptions_cherry_pick_server_data(), | |
| 815 | + ) | |
| 909 | 816 | ); |
| 910 | 817 | |
| 911 | 818 | /** |
| 912 | 819 | * Fires on each comment subscription form submission. |
| @@ -926,16 +833,16 @@ | ||
| 926 | 833 | * |
| 927 | 834 | * Set a cookie to save state on the comment and post subscription checkboxes. |
| 928 | 835 | * |
| 929 | 836 | * @param bool $subscribe_to_post Whether the user chose to subscribe to subsequent comments on this post. |
| 930 | - * @param int $post_id If $subscribe_to_post is true, the post ID they've subscribed to. | |
| 837 | + * @param int $post_id If $subscribe_to_post is true, the post ID they've subscribed to. | |
| 931 | 838 | * @param bool $subscribe_to_blog Whether the user chose to subscribe to all new posts on the blog. |
| 932 | 839 | */ |
| 933 | - public function set_cookies( $subscribe_to_post = false, $post_id = null, $subscribe_to_blog = false ) { | |
| 840 | + function set_cookies( $subscribe_to_post = false, $post_id = null, $subscribe_to_blog = false ) { | |
| 934 | 841 | $post_id = (int) $post_id; |
| 935 | 842 | |
| 936 | 843 | /** This filter is already documented in core/wp-includes/comment-functions.php */ |
| 937 | - $cookie_lifetime = apply_filters( 'comment_cookie_lifetime', 30000000 ); | |
| 844 | + $cookie_lifetime = apply_filters( 'comment_cookie_lifetime', 30000000 ); | |
| 938 | 845 | |
| 939 | 846 | /** |
| 940 | 847 | * Filter the Jetpack Comment cookie path. |
| 941 | 848 | * |
| @@ -944,9 +851,9 @@ | ||
| 944 | 851 | * @since 2.5.0 |
| 945 | 852 | * |
| 946 | 853 | * @param string COOKIEPATH Cookie path. |
| 947 | 854 | */ |
| 948 | - $cookie_path = apply_filters( 'jetpack_comment_cookie_path', COOKIEPATH ); | |
| 855 | + $cookie_path = apply_filters( 'jetpack_comment_cookie_path', COOKIEPATH ); | |
| 949 | 856 | |
| 950 | 857 | /** |
| 951 | 858 | * Filter the Jetpack Comment cookie domain. |
| 952 | 859 | * |
| @@ -955,20 +862,20 @@ | ||
| 955 | 862 | * @since 2.5.0 |
| 956 | 863 | * |
| 957 | 864 | * @param string COOKIE_DOMAIN Cookie domain. |
| 958 | 865 | */ |
| 959 | - $cookie_domain = apply_filters( 'jetpack_comment_cookie_domain', COOKIE_DOMAIN ); | |
| 866 | + $cookie_domain = apply_filters( 'jetpack_comment_cookie_domain', COOKIE_DOMAIN ); | |
| 960 | 867 | |
| 961 | 868 | if ( $subscribe_to_post && $post_id >= 0 ) { |
| 962 | - setcookie( 'jetpack_comments_subscribe_' . self::$hash . '_' . $post_id, 1, time() + $cookie_lifetime, $cookie_path, $cookie_domain, is_ssl(), true ); | |
| 869 | + setcookie( 'jetpack_comments_subscribe_' . self::$hash . '_' . $post_id, 1, time() + $cookie_lifetime, $cookie_path, $cookie_domain ); | |
| 963 | 870 | } else { |
| 964 | - setcookie( 'jetpack_comments_subscribe_' . self::$hash . '_' . $post_id, '', time() - 3600, $cookie_path, $cookie_domain, is_ssl(), true ); | |
| 871 | + setcookie( 'jetpack_comments_subscribe_' . self::$hash . '_' . $post_id, '', time() - 3600, $cookie_path, $cookie_domain ); | |
| 965 | 872 | } |
| 966 | 873 | |
| 967 | 874 | if ( $subscribe_to_blog ) { |
| 968 | - setcookie( 'jetpack_blog_subscribe_' . self::$hash, 1, time() + $cookie_lifetime, $cookie_path, $cookie_domain, is_ssl(), true ); | |
| 875 | + setcookie( 'jetpack_blog_subscribe_' . self::$hash, 1, time() + $cookie_lifetime, $cookie_path, $cookie_domain ); | |
| 969 | 876 | } else { |
| 970 | - setcookie( 'jetpack_blog_subscribe_' . self::$hash, '', time() - 3600, $cookie_path, $cookie_domain, is_ssl(), true ); | |
| 877 | + setcookie( 'jetpack_blog_subscribe_' . self::$hash, '', time() - 3600, $cookie_path, $cookie_domain ); | |
| 971 | 878 | } |
| 972 | 879 | } |
| 973 | 880 | |
| 974 | 881 | /** |
| @@ -975,64 +882,17 @@ | ||
| 975 | 882 | * Set the social_notifications_subscribe option to `off` when the Subscriptions module is activated in the first time. |
| 976 | 883 | * |
| 977 | 884 | * @since 8.1 |
| 978 | 885 | * |
| 979 | - * @return void | |
| 886 | + * @return null | |
| 980 | 887 | */ |
| 981 | - public function set_social_notifications_subscribe() { | |
| 888 | + function set_social_notifications_subscribe() { | |
| 982 | 889 | if ( false === get_option( 'social_notifications_subscribe' ) ) { |
| 983 | 890 | add_option( 'social_notifications_subscribe', 'off' ); |
| 984 | 891 | } |
| 985 | 892 | } |
| 986 | 893 | |
| 987 | - /** | |
| 988 | - * Save a flag when a post was ever published. | |
| 989 | - * | |
| 990 | - * It saves the post meta when the post was published and becomes a draft. | |
| 991 | - * Then this meta is used to hide subscription messaging in Publish panel. | |
| 992 | - * | |
| 993 | - * @param string $new_status Tthe "new" post status of the transition when saved. | |
| 994 | - * @param string $old_status The "old" post status of the transition when saved. | |
| 995 | - * @param object $post obj The post object. | |
| 996 | - */ | |
| 997 | - public function maybe_set_first_published_status( $new_status, $old_status, $post ) { | |
| 998 | - $was_post_ever_published = get_post_meta( $post->ID, '_jetpack_post_was_ever_published', true ); | |
| 999 | - if ( ! $was_post_ever_published && 'publish' === $old_status && 'draft' === $new_status ) { | |
| 1000 | - update_post_meta( $post->ID, '_jetpack_post_was_ever_published', true ); | |
| 1001 | - } | |
| 1002 | - } | |
| 1003 | - | |
| 1004 | - /** | |
| 1005 | - * Checks if the current user can publish posts. | |
| 1006 | - * | |
| 1007 | - * @return bool | |
| 1008 | - */ | |
| 1009 | - public function first_published_status_meta_auth_callback() { | |
| 1010 | - if ( current_user_can( 'publish_posts' ) ) { | |
| 1011 | - return true; | |
| 1012 | - } | |
| 1013 | - return false; | |
| 1014 | - } | |
| 1015 | - | |
| 1016 | - /** | |
| 1017 | - * Registers the 'post_was_ever_published' post meta for use in the REST API. | |
| 1018 | - */ | |
| 1019 | - public function register_post_meta() { | |
| 1020 | - $jetpack_post_was_ever_published = array( | |
| 1021 | - 'type' => 'boolean', | |
| 1022 | - 'description' => __( 'Whether the post was ever published.', 'jetpack' ), | |
| 1023 | - 'single' => true, | |
| 1024 | - 'default' => false, | |
| 1025 | - 'show_in_rest' => array( | |
| 1026 | - 'name' => 'jetpack_post_was_ever_published', | |
| 1027 | - ), | |
| 1028 | - 'auth_callback' => array( $this, 'first_published_status_meta_auth_callback' ), | |
| 1029 | - ); | |
| 1030 | - | |
| 1031 | - register_meta( 'post', '_jetpack_post_was_ever_published', $jetpack_post_was_ever_published ); | |
| 1032 | - } | |
| 1033 | - | |
| 1034 | 894 | } |
| 1035 | 895 | |
| 1036 | 896 | Jetpack_Subscriptions::init(); |
| 1037 | 897 | |
| 1038 | -require __DIR__ . '/subscriptions/views.php'; | |
| 898 | +include dirname( __FILE__ ) . '/subscriptions/views.php'; | |