Making WordPress.org

Changeset 5657


Ignore:
Timestamp:
07/12/2017 02:43:36 AM (7 years ago)
Author:
SergeyBiryukov
Message:

Support Forums: Add "Always notify me via email of follow-up posts in any topics I reply to" checkbox to user profile.

Fixes #6.

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-hooks.php

    r5639 r5657  
    5151
    5252    /**
    53      * Check "Notify me of follow-up replies via email" checkbox for new topics by default.
     53     * Check "Notify me of follow-up replies via email" box for new topics by default.
     54     *
     55     * If the user has enabled "Always notify me via email of follow-up posts" option
     56     * in their profile, check the box for new replies as well.
    5457     *
    5558     * @param string $checked Checked value of topic subscription.
     
    5760     */
    5861    public function check_topic_subscription_checkbox( $checked ) {
    59         if ( bbp_is_single_forum() || bbp_is_single_view() ) {
     62        if (
     63            bbp_is_single_forum() || bbp_is_single_view()
     64        ||
     65            get_user_option( 'auto_topic_subscription' )
     66        ) {
    6067            $checked = checked( true, true, false );
    6168        }
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-users.php

    r5636 r5657  
    66
    77    public function __construct() {
    8         // Add a Custom Title input to user's profile.
    9         add_action( 'bbp_user_edit_after_name', array( $this, 'add_custom_title_input' ) );
    10 
    11         // Save Custom Title input value.
    12         add_action( 'personal_options_update', array( $this, 'save_custom_title' ), 10, 2 );
    13         add_action( 'edit_user_profile_update', array( $this, 'save_custom_title' ), 10, 2 );
     8        // Add custom fields to user's profile.
     9        add_action( 'bbp_user_edit_after_name',        array( $this, 'add_custom_title_input' ) );
     10        add_action( 'bbp_user_edit_after',             array( $this, 'add_auto_topic_subscription_checkbox' ) );
     11
     12        // Save custom field values.
     13        add_action( 'personal_options_update',         array( $this, 'save_custom_fields' ), 10, 2 );
     14        add_action( 'edit_user_profile_update',        array( $this, 'save_custom_fields' ), 10, 2 );
    1415
    1516        // Custom user contact methods.
    16         add_filter( 'user_contactmethods', array( $this, 'custom_contact_methods' ) );
     17        add_filter( 'user_contactmethods',             array( $this, 'custom_contact_methods' ) );
    1718
    1819        // Only allow 3 published topics from a user in the first 24 hours.
    19         add_action( 'bbp_new_topic_pre_insert', array( $this, 'limit_new_user_topics' ) );
     20        add_action( 'bbp_new_topic_pre_insert',        array( $this, 'limit_new_user_topics' ) );
    2021
    2122        // Add query vars and rewrite rules for user's topic and review queries.
    22         add_filter( 'query_vars',            array( $this, 'add_query_vars' ) );
    23         add_action( 'bbp_add_rewrite_rules', array( $this, 'add_rewrite_rules' ) );
     23        add_filter( 'query_vars',                      array( $this, 'add_query_vars' ) );
     24        add_action( 'bbp_add_rewrite_rules',           array( $this, 'add_rewrite_rules' ) );
    2425
    2526        // Parse user's topic and review queries.
     
    5758        }
    5859       
     60        $title = get_user_option( 'title', bbp_get_displayed_user_id() );
    5961        ?>
    6062        <div>
    6163            <label for="title"><?php esc_html_e( 'Custom Title', 'wporg-forums' ); ?></label>
    62             <input type="text" name="title" id="title" value="<?php echo esc_attr( get_user_option( 'title', bbpress()->displayed_user->ID ) ); ?>" class="regular-text" />
     64            <input type="text" name="title" id="title" value="<?php echo esc_attr( $title ); ?>" class="regular-text" />
    6365        </div>
    64     <?php
    65     }
    66 
    67     /**
    68      * Save Custom Title input value.
     66        <?php
     67    }
     68
     69    /**
     70     * Add an auto topic subscription checkbox to user's profile.
     71     */
     72    public function add_auto_topic_subscription_checkbox() {
     73        $auto_topic_subscription = get_user_option( 'auto_topic_subscription', bbp_get_displayed_user_id() );
     74        ?>
     75        <p>
     76            <input name="auto_topic_subscription" id="auto_topic_subscription" type="checkbox" value="yes" <?php checked( $auto_topic_subscription ); ?> />
     77            <label for="auto_topic_subscription"><?php esc_html_e( 'Always notify me via email of follow-up posts in any topics I reply to', 'wporg-forums' ); ?></label>
     78        </p>
     79        <?php
     80    }
     81
     82    /**
     83     * Save custom field values.
    6984     *
    7085     * @param int $user_id The user ID.
    7186     */
    72     public function save_custom_title( $user_id ) {
    73         if ( ! current_user_can( 'moderate' ) || ! isset( $_POST['title'] ) ) {
    74             return;
    75         }
    76 
    77         update_user_option( $user_id, 'title', sanitize_text_field( $_POST['title'] ) );
     87    public function save_custom_fields( $user_id ) {
     88        if ( current_user_can( 'moderate' ) && isset( $_POST['title'] ) ) {
     89            update_user_option( $user_id, 'title', sanitize_text_field( $_POST['title'] ) );
     90        }
     91
     92        $auto_topic_subscription = isset( $_POST['auto_topic_subscription'] );
     93        update_user_option( $user_id, 'auto_topic_subscription', $auto_topic_subscription );
    7894    }
    7995
Note: See TracChangeset for help on using the changeset viewer.