Skip to:
Content
Pages
Categories
Search
Top
Bottom

Can AJAX be enabled for bbPress?


  • berry metal
    Participant

    @erikalleman

    Is the bbPress favorite and subscribe button AJAX?

    On some forums they confirmed that even posting is not AJAX anymore.
    How do I enable AJAX for my bbPress?

    For me both the favorite and the subscribe button reloads the page.
    I can see that on this site the favorite button works with AJAX, so why isn’t AJAX then in the bbPress plugin?

Viewing 5 replies - 1 through 5 (of 5 total)

  • John James Jacoby
    Keymaster

    @johnjamesjacoby

    Probably an issue with a plugin conflict or theme.

    Standard troubleshooting rules apply. Deactivate one plugin at a time and switch to a WordPress Twenty Something theme until it starts working, then work backward until you identify what’s causing it.


    berry metal
    Participant

    @erikalleman

    Thanks!


    berry metal
    Participant

    @erikalleman

    The reason is hard for me to debug this issue is that I am using this code to output a bbpress topic under each post that has the same name as the current post title:

    add_shortcode( 'bbpresscomments', function() {
        $output     = '';
        $current_id = function_exists( 'vcex_get_the_ID' ) ? vcex_get_the_ID() : get_the_ID();
        $topics = new WP_Query( array(
            'post_type' => 'topic',
            'posts_per_page' => -1,
            'fields' => 'ids',
        ) );
        if ( $topics->have_posts() ) {
            foreach( $topics->posts as $topic ) {
                if ( get_the_title( $topic ) == get_the_title( $current_id ) ) {
                    $output .= do_shortcode( '[bbp-single-topic id="' . intval( $topic ) . '"]' );
                }
            }
        }
        return $output;
    } );

    This code is theme specific, so testing with an other theme doesn’t make sense in this case.
    I will open now a ticket to my theme developer, but if you can see anything in this code that would make AJAX not work, please let me know.

    Thanks.


    berry metal
    Participant

    @erikalleman

    Hi again,

    I added this code:

    if ( function_exists( 'bbp_enqueue_script' ) && function_exists( 'bbp_get_version' ) ) {
        bbp_enqueue_script( 'bbpress-engagements', 'js/engagements.js', array( 'jquery' ), bbp_get_version(), true );
    }

    so now it looks like this:

    add_shortcode( 'bbpresscomments', function() {
        $output     = '';
        $current_id = function_exists( 'vcex_get_the_ID' ) ? vcex_get_the_ID() : get_the_ID();
        $topics = new WP_Query( array(
            'post_type' => 'topic',
            'posts_per_page' => -1,
            'fields' => 'ids',
        ) );
        if ( $topics->have_posts() ) {
            // enqueue scripts on this next line...
            if ( function_exists( 'bbp_enqueue_script' ) && function_exists( 'bbp_get_version' ) ) {
        bbp_enqueue_script( 'bbpress-engagements', 'js/engagements.js', array( 'jquery' ), bbp_get_version(), true );
    }
            foreach( $topics->posts as $topic ) {
                if ( get_the_title( $topic ) == get_the_title( $current_id ) ) {
                    $output .= do_shortcode( '[bbp-single-topic id="' . intval( $topic ) . '"]' );
                }
            }
        }
        return $output;
    } );

    because I can see that code that enables all functionality including AJAX, is only enqueued for bbPress pages:

    https://github.com/bbpress/bbPress/blob/afa6030c3e27c4fe582743074a603d25b5e4de48/src/templates/default/bbpress-functions.php#L151

    And it’s not enabled for bbPress shortcodes.

    Is this right?

    Could you please tell me what is wrong with my code, and why cannot I enqueue the scripts that will enable AJAX for the shortcodes?

    Instead of proper enqueuing, my code makes the buttons not work at all, when I click on them, nothing happens.


    berry metal
    Participant

    @erikalleman

    Oh and I forgot to mention that I did test it by deactivating plugins and changing theme. The issue persists, when the shortcode is used.
    Is AJAX enabled for the buttons if the Subscribe and Favorite buttons are used within the Replies shortcode?

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.
Skip to toolbar