WordPress.org

Making WordPress.org

Changeset 5329


Ignore:
Timestamp:
04/13/2017 10:04:57 PM (5 years ago)
Author:
SergeyBiryukov
Message:

Support Forums: Convert Close/Open, Stick/Unstick toggle links to explicit actions.

See #2418.

File:
1 edited

Legend:

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

    r5306 r5329  
    4545
    4646        // Convert toggle links to explicit actions.
     47        add_filter( 'bbp_get_topic_close_link',         array( $this, 'convert_toggles_to_actions' ), 10, 3 );
     48        add_filter( 'bbp_get_topic_stick_link',         array( $this, 'convert_toggles_to_actions' ), 10, 3 );
    4749        add_filter( 'bbp_get_topic_spam_link',          array( $this, 'convert_toggles_to_actions' ), 10, 3 );
    4850        add_filter( 'bbp_get_topic_approve_link',       array( $this, 'convert_toggles_to_actions' ), 10, 3 );
     
    440442    public function get_topic_actions( $actions ) {
    441443        $actions = array_merge( $actions, array(
     444            'wporg_bbp_close_topic',
     445            'wporg_bbp_open_topic',
     446            'wporg_bbp_stick_topic',
     447            'wporg_bbp_unstick_topic',
    442448            'wporg_bbp_spam_topic',
    443449            'wporg_bbp_unspam_topic',
     
    614620
    615621        switch ( $r['action'] ) {
     622            case 'wporg_bbp_close_topic':
     623                check_ajax_referer( "close-{$nonce_suffix}" );
     624
     625                if ( bbp_is_topic_open( $r['id'] ) ) {
     626                    $retval['status']  = bbp_close_topic( $r['id'] );
     627                    $retval['message'] = __( '<strong>ERROR</strong>: There was a problem closing the topic.', 'wporg-forums' );
     628                }
     629
     630                break;
     631
     632            case 'wporg_bbp_open_topic':
     633                check_ajax_referer( "close-{$nonce_suffix}" );
     634
     635                if ( ! bbp_is_topic_open( $r['id'] ) ) {
     636                    $retval['status']  = bbp_open_topic( $r['id'] );
     637                    $retval['message'] = __( '<strong>ERROR</strong>: There was a problem opening the topic.', 'wporg-forums' );
     638                }
     639
     640                break;
     641
     642            case 'wporg_bbp_stick_topic':
     643                check_ajax_referer( "stick-{$nonce_suffix}" );
     644
     645                if ( ! bbp_is_topic_sticky( $r['id'] ) ) {
     646                    $retval['status']  = bbp_stick_topic( $r['id'], ! empty( $_GET['super'] ) );
     647                    $retval['message'] = __( '<strong>ERROR</strong>: There was a problem sticking the topic.', 'wporg-forums' );
     648                }
     649
     650                break;
     651
     652            case 'wporg_bbp_unstick_topic':
     653                check_ajax_referer( "stick-{$nonce_suffix}" );
     654
     655                if ( bbp_is_topic_sticky( $r['id'] ) ) {
     656                    $retval['status']  = bbp_unstick_topic( $r['id'] );
     657                    $retval['message'] = __( '<strong>ERROR</strong>: There was a problem unsticking the topic.', 'wporg-forums' );
     658                }
     659
     660                break;
     661
    616662            case 'wporg_bbp_spam_topic':
    617663                check_ajax_referer( "spam-{$nonce_suffix}" );
    618664
    619665                if ( ! bbp_is_topic_spam( $r['id'] ) ) {
    620                     $retval['status']   = bbp_spam_topic( $r['id'] );
    621                     $retval['message']  = __( '<strong>ERROR</strong>: There was a problem marking the topic as spam.', 'wporg-forums' );
     666                    $retval['status']  = bbp_spam_topic( $r['id'] );
     667                    $retval['message'] = __( '<strong>ERROR</strong>: There was a problem marking the topic as spam.', 'wporg-forums' );
    622668                }
    623669                $retval['view_all'] = true;
     
    629675
    630676                if ( bbp_is_topic_spam( $r['id'] ) ) {
    631                     $retval['status']   = bbp_unspam_topic( $r['id'] );
    632                     $retval['message']  = __( '<strong>ERROR</strong>: There was a problem unmarking the topic as spam.', 'wporg-forums' );
     677                    $retval['status']  = bbp_unspam_topic( $r['id'] );
     678                    $retval['message'] = __( '<strong>ERROR</strong>: There was a problem unmarking the topic as spam.', 'wporg-forums' );
    633679                }
    634680                $retval['view_all'] = false;
     
    640686
    641687                if ( ! bbp_is_topic_pending( $r['id'] ) ) {
    642                     $retval['status']   = bbp_unapprove_topic( $r['id'] );
    643                     $retval['message']  = __( '<strong>ERROR</strong>: There was a problem unapproving the topic.', 'wporg-forums' );
     688                    $retval['status']  = bbp_unapprove_topic( $r['id'] );
     689                    $retval['message'] = __( '<strong>ERROR</strong>: There was a problem unapproving the topic.', 'wporg-forums' );
    644690                }
    645691                $retval['view_all'] = true;
     
    651697
    652698                if ( bbp_is_topic_pending( $r['id'] ) ) {
    653                     $retval['status']   = bbp_approve_topic( $r['id'] );
    654                     $retval['message']  = __( '<strong>ERROR</strong>: There was a problem approving the topic.', 'wporg-forums' );
     699                    $retval['status']  = bbp_approve_topic( $r['id'] );
     700                    $retval['message'] = __( '<strong>ERROR</strong>: There was a problem approving the topic.', 'wporg-forums' );
    655701                }
    656702                $retval['view_all'] = false;
     
    749795     */
    750796    public function convert_toggles_to_actions( $link, $r, $args ) {
    751         if ( false !== strpos( $link, 'bbp_toggle_topic_spam' ) ) {
     797        if ( false !== strpos( $link, 'bbp_toggle_topic_close' ) ) {
     798            $action = ( bbp_is_topic_closed( $r['id'] ) ) ? 'wporg_bbp_open_topic' : 'wporg_bbp_close_topic';
     799            $link   = str_replace( 'bbp_toggle_topic_close', $action, $link );
     800
     801        } elseif ( false !== strpos( $link, 'bbp_toggle_topic_stick' ) ) {
     802            $action = ( bbp_is_topic_sticky( $r['id'] ) ) ? 'wporg_bbp_unstick_topic' : 'wporg_bbp_stick_topic';
     803            $link   = str_replace( 'bbp_toggle_topic_stick', $action, $link );
     804
     805        } elseif ( false !== strpos( $link, 'bbp_toggle_topic_spam' ) ) {
    752806            $action = ( bbp_is_topic_spam( $r['id'] ) ) ? 'wporg_bbp_unspam_topic' : 'wporg_bbp_spam_topic';
    753807            $link   = str_replace( 'bbp_toggle_topic_spam', $action, $link );
Note: See TracChangeset for help on using the changeset viewer.