Making WordPress.org

Changeset 4909


Ignore:
Timestamp:
02/15/2017 07:49:38 PM (7 years ago)
Author:
SergeyBiryukov
Message:

Support Forums: Reintroduce "Reply and mark as resolved" and "Reply and close the topic" actions in reply form.

Fixes #2070.

File:
1 edited

Legend:

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

    r4889 r4909  
    3333        // Limit no-replies view to certain number of days.
    3434        add_filter( 'bbp_register_view_no_replies', array( $this, 'limit_no_replies_view' ) );
     35
     36        // Add extra reply actions before Submit button in reply form.
     37        add_action( 'bbp_theme_before_reply_form_submit_wrapper', array( $this, 'add_extra_reply_actions' ) );
     38
     39        // Process extra reply actions.
     40        add_action( 'bbp_new_reply',  array( $this, 'handle_extra_reply_actions' ), 10, 2 );
     41        add_action( 'bbp_edit_reply', array( $this, 'handle_extra_reply_actions' ), 10, 2 );
    3542    }
    3643
     
    174181    }
    175182
     183    /**
     184     * Add extra reply actions before Submit button in reply form.
     185     */
     186    public function add_extra_reply_actions() {
     187        if ( class_exists( 'WordPressdotorg\Forums\Topic_Resolution\Plugin' ) ) :
     188            if ( Topic_Resolution\Plugin::get_instance()->user_can_resolve( get_current_user_id(), bbp_get_topic_id() ) ) : ?>
     189                <p>
     190                    <input name="bbp_reply_mark_resolved" id="bbp_reply_mark_resolved" type="checkbox" value="yes" />
     191                    <label for="bbp_reply_mark_resolved"><?php esc_html_e( 'Reply and mark as resolved', 'wporg-forums' ); ?></label>
     192                </p>
     193                <?php
     194            endif;
     195        endif;
     196
     197        if ( current_user_can( 'moderate', bbp_get_topic_id() ) ) : ?>
     198            <p>
     199                <input name="bbp_reply_close_topic" id="bbp_reply_close_topic" type="checkbox" value="yes" />
     200                <label for="bbp_reply_close_topic"><?php esc_html_e( 'Reply and close the topic', 'wporg-forums' ); ?></label>
     201            </p>
     202            <?php
     203        endif;
     204    }
     205
     206    /**
     207     * Process extra reply actions.
     208     *
     209     * @param int $reply_id Reply ID.
     210     * @param int $topic_id Topic ID.
     211     */
     212    public function handle_extra_reply_actions( $reply_id, $topic_id ) {
     213        // Handle "Reply and mark as resolved" checkbox
     214        if ( isset( $_POST['bbp_reply_mark_resolved'] ) && 'yes' === $_POST['bbp_reply_mark_resolved'] ) {
     215            if ( class_exists( 'WordPressdotorg\Forums\Topic_Resolution\Plugin' ) ) {
     216                $topic_resolution_plugin = Topic_Resolution\Plugin::get_instance();
     217
     218                $plugin_enabled   = $topic_resolution_plugin->is_enabled_on_forum( bbp_get_topic_forum_id( $topic_id ) );
     219                $user_can_resolve = $topic_resolution_plugin->user_can_resolve( get_current_user_id(), $topic_id );
     220
     221                if ( $plugin_enabled && $user_can_resolve ) {
     222                    $topic_resolution_plugin->set_topic_resolution( array(
     223                        'id'         => $topic_id,
     224                        'resolution' => 'yes',
     225                    ) );
     226                }
     227            }
     228        }
     229
     230        // Handle "Reply and close the topic" checkbox
     231        if ( isset( $_POST['bbp_reply_close_topic'] ) && 'yes' === $_POST['bbp_reply_close_topic'] ) {
     232            if ( current_user_can( 'moderate', $topic_id ) && bbp_is_topic_open( $topic_id ) ) {
     233                bbp_close_topic( $topic_id );
     234            }
     235        }
     236    }
     237
    176238}
Note: See TracChangeset for help on using the changeset viewer.