diff options
Diffstat (limited to 'plugins/jetpack/modules/likes/jetpack-likes-settings.php')
-rw-r--r-- | plugins/jetpack/modules/likes/jetpack-likes-settings.php | 82 |
1 files changed, 72 insertions, 10 deletions
diff --git a/plugins/jetpack/modules/likes/jetpack-likes-settings.php b/plugins/jetpack/modules/likes/jetpack-likes-settings.php index b58467a6..8492b92a 100644 --- a/plugins/jetpack/modules/likes/jetpack-likes-settings.php +++ b/plugins/jetpack/modules/likes/jetpack-likes-settings.php @@ -148,7 +148,7 @@ class Jetpack_Likes_Settings { ( $this->is_enabled_sitewide() && ! empty( $_POST['wpl_enable_post_likes'] ) ) ) { // User wants to update the likes button status for an individual post, but the new status - // is the same as if they're asking for the default behaviour according to the current Likes setting. + // is the same as if they're asking for the default behavior according to the current Likes setting. // So we delete the meta. delete_post_meta( $post_id, 'switch_like_status' ); } @@ -164,7 +164,7 @@ class Jetpack_Likes_Settings { $disabled = get_post_meta( $post_id, 'sharing_disabled', true ); ?> <p> <label for="wpl_enable_post_sharing"> - <input type="checkbox" name="wpl_enable_post_sharing" id="wpl_enable_post_sharing" value="1" <?php checked( !$disabled ); ?>> + <input type="checkbox" name="wpl_enable_post_sharing" id="wpl_enable_post_sharing" value="1" <?php checked( ! $disabled ); ?>> <?php _e( 'Show sharing buttons.', 'jetpack' ); ?> </label> <input type="hidden" name="wpl_sharing_status_hidden" value="1" /> @@ -237,14 +237,29 @@ class Jetpack_Likes_Settings { */ function is_post_likeable( $post_id = 0 ) { $post = get_post( $post_id ); - if ( !$post || is_wp_error( $post ) ) { + if ( ! $post || is_wp_error( $post ) ) { return false; } $sitewide_likes_enabled = (bool) $this->is_enabled_sitewide(); $post_likes_switched = get_post_meta( $post->ID, 'switch_like_status', true ); - return $post_likes_switched || ( $sitewide_likes_enabled && $post_likes_switched !== '0' ); + // on WPCOM, we need to look at post edit date so we don't break old posts + // if post edit date predates this code, stick with the former (buggy) behavior + // see: p7DVsv-64H-p2 + $last_modified_time = strtotime( $post->post_modified_gmt ); + + $behavior_was_changed_at = strtotime( "2019-02-22 00:40:42" ); + + if ( $this->in_jetpack || $last_modified_time > $behavior_was_changed_at ) { + // the new and improved behavior on Jetpack and recent WPCOM posts: + // $post_likes_switched is empty to follow site setting, + // 0 if we want likes disabled, 1 if we want likes enabled + return $post_likes_switched || ( $sitewide_likes_enabled && $post_likes_switched !== '0' ); + } + + // implicit else (old behavior): $post_likes_switched simply inverts the global setting + return ( (bool) $post_likes_switched ) xor $sitewide_likes_enabled; } /** @@ -395,7 +410,7 @@ class Jetpack_Likes_Settings { } // Ensure it's always an array (even if not previously empty or scalar) - $setting['show'] = !empty( $sharing['global']['show'] ) ? (array) $sharing['global']['show'] : array(); + $setting['show'] = ! empty( $sharing['global']['show'] ) ? (array) $sharing['global']['show'] : array(); /** * Filters where the Likes are displayed. @@ -507,9 +522,25 @@ class Jetpack_Likes_Settings { <input type="radio" class="code" name="jetpack_reblogs_enabled" value="off" <?php checked( $this->reblogs_enabled_sitewide(), false ); ?> /> <?php esc_html_e( 'Don\'t show the Reblog button on posts', 'jetpack' ); ?> </label> - <div> + </div> </td> </tr> + <!-- WPCOM only: Comment Likes --> + <?php if ( ! $this->in_jetpack ) : ?> + <tr> + <th scope="row"> + <label><?php esc_html_e( 'Comment Likes are', 'jetpack' ); ?></label> + </th> + <td> + <div> + <label> + <input type="checkbox" class="code" name="jetpack_comment_likes_enabled" value="1" <?php checked( $this->is_comments_enabled(), true ); ?> /> + <?php esc_html_e( 'On for all comments', 'jetpack' ); ?> + </label> + </div> + </td> + </tr> + <?php endif; ?> <?php endif; ?> </tbody> <?php // closes the tbody attached to sharing_show_buttons_on_row_start... ?> <?php @@ -534,15 +565,34 @@ class Jetpack_Likes_Settings { } /** + * Used for WPCOM ONLY. Comment likes are in their own module in Jetpack. + * Returns if comment likes are enabled. Defaults to 'off' + * @return boolean true if we should show comment likes, false if not + */ + function is_comments_enabled() { + /** + * Filters whether Comment Likes are enabled. + * true if enabled, false if not. + * + * @module comment-likes + * + * @since 2.2.0 + * + * @param bool $option Are Comment Likes enabled sitewide. + */ + return (bool) apply_filters( 'jetpack_comment_likes_enabled', get_option( 'jetpack_comment_likes_enabled', false ) ); + } + + /** * Saves the setting in the database, bumps a stat on WordPress.com */ function admin_settings_callback() { // We're looking for these, and doing a dance to set some stats and save // them together in array option. - $new_state = !empty( $_POST['wpl_default'] ) ? $_POST['wpl_default'] : 'on'; + $new_state = ! empty( $_POST['wpl_default'] ) ? $_POST['wpl_default'] : 'on'; $db_state = $this->is_enabled_sitewide(); - $reblogs_new_state = !empty( $_POST['jetpack_reblogs_enabled'] ) ? $_POST['jetpack_reblogs_enabled'] : 'on'; + $reblogs_new_state = ! empty( $_POST['jetpack_reblogs_enabled'] ) ? $_POST['jetpack_reblogs_enabled'] : 'on'; $reblogs_db_state = $this->reblogs_enabled_sitewide(); /** Default State *********************************************************/ @@ -578,6 +628,20 @@ class Jetpack_Likes_Settings { delete_option( 'disabled_reblogs' ); break; } + + // WPCOM only: Comment Likes + if ( ! $this->in_jetpack ) { + $new_comments_state = ! empty( $_POST['jetpack_comment_likes_enabled'] ) ? $_POST['jetpack_comment_likes_enabled'] : false; + switch( (bool) $new_comments_state ) { + case true: + update_option( 'jetpack_comment_likes_enabled', 1 ); + break; + case false: + default: + update_option( 'jetpack_comment_likes_enabled', 0 ); + break; + } + } } /** @@ -598,8 +662,6 @@ class Jetpack_Likes_Settings { * If sharedaddy is not loaded, we don't have the "Show buttons on" yet, so we need to add that since it affects likes too. */ function admin_settings_showbuttonon_init() { - ?> - <?php /** This action is documented in modules/sharedaddy/sharing.php */ echo apply_filters( 'sharing_show_buttons_on_row_start', '<tr valign="top">' ); ?> |