Making WordPress.org

Changeset 10660


Ignore:
Timestamp:
02/11/2021 05:07:19 AM (3 years ago)
Author:
dd32
Message:

Support Forums: Ajaxify the actions (spam/archive/approve) on views.

Props Clorith, dd32.
Fixes #1965.

Location:
sites/trunk/wordpress.org/public_html/wp-content
Files:
3 edited

Legend:

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

    r10640 r10660  
    487487        $permalink = $this->get_permalink( $post->ID );
    488488
     489        $classes = array();
     490
     491        if ( bbp_is_topic( $r['post_id'] ) ) {
     492            $classes[] = 'bbp-topic-archive-link';
     493        } else {
     494            $classes[] = 'bbp-reply-archive-link';
     495        }
     496
    489497        $url = esc_url( wp_nonce_url( add_query_arg( $query_args, $permalink ), 'toggle-post-archive_' . $user_id . '_' . $post->ID ) );
    490         return sprintf( "<a href='%s'>%s</a>", $url, esc_html( $text ) );
     498        return sprintf( "<a href='%s' class='%s'>%s</a>", $url, esc_attr( implode( ' ', $classes ) ), esc_html( $text ) );
    491499    }
    492500
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-support/functions.php

    r10601 r10660  
    3232
    3333    wp_enqueue_script( 'wporg-support-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '20181209', true );
    34     wp_enqueue_script( 'wporg-support-forums', get_template_directory_uri() . '/js/forums.js', array( 'jquery' ), '20200318', true );
     34    wp_enqueue_script( 'wporg-support-forums', get_template_directory_uri() . '/js/forums.js', array( 'jquery' ), '20210211', true );
     35
     36    wp_localize_script(
     37        'wporg-support-forums',
     38        'wporgSupport',
     39        array(
     40            'strings' => array(
     41                'approve'       => __( 'The approval status of this post has been changed.', 'wporg-forums' ),
     42                'spam'          => __( 'The spam status of this post has been changed.', 'wporg-forums' ),
     43                'archive'       => __( 'The archive status of this post has been changed.', 'wporg-forums' ),
     44                'action_failed' => __( 'Unable to complete the requested action, please try again.', 'wporg-forums' ),
     45            ),
     46        )
     47    );
    3548}
    3649add_action( 'wp_enqueue_scripts', 'wporg_support_scripts' );
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-support/js/forums.js

    r9602 r10660  
    2222        } );
    2323    }
     24
     25    if ( $('body.bbp-is-view' ) ) {
     26        $( '.bbp-body .bbp-admin-links a' ).click( function( e ) {
     27            var $this = $( this ),
     28                $element = $this.closest( '.bbp-body' ),
     29                type;
     30
     31            if ( $this.is( '[class*=approve]' ) ) {
     32                type = 'approve';
     33            } else if ( $this.is( '[class*=spam]' ) ) {
     34                type = 'spam';
     35            } else if ( $this.is( '[class*=archive]' ) ) {
     36                type = 'archive';
     37            } else {
     38                return;
     39            }
     40
     41            e.preventDefault();
     42
     43            $.get( $this.prop( 'href' ) ).done( function() {
     44                $element.fadeOut( 250, function() {
     45                    $element.html(
     46                        '<div class="bbp-template-notice">' + wporgSupport.strings[ type ] + '</div>'
     47                    );
     48                } ).fadeIn( 250 );
     49            } ).error( function() {
     50                $element.fadeOut( 250, function() {
     51                    $element.find( '.bbp-topic-content' ).prepend(
     52                        '<div class="bbp-template-notice">' + wporgSupport.strings.action_failed + '</div>'
     53                    );
     54                } ).fadeIn( 250 );
     55            } );
     56        } );
     57    }
     58
    2459}( window.jQuery ) );
Note: See TracChangeset for help on using the changeset viewer.