berry metal (@erikalleman)

Forum Replies Created

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

  • 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?


    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

    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

    Thanks!


    berry metal
    Participant

    @erikalleman

    I don’t use hand-coded, inline tempolates. I am using Templatera of WPBakery, and I am happy with it as it gives me a graphical overview of the structure, and they are easy to re-make or replace.

    In WPBakery, I have a javascript module, an html module, but there is no PHP module.

    But there is a text module which does accept shortcodes.
    What do you recommend in this scenario?


    berry metal
    Participant

    @erikalleman

    Thank you!
    Should I insert the code above in my functions.php as it is, and use [bbp-single-topic id='.$forum_id.'] in my template?
    The fact that is not tested, can it break my site?


    berry metal
    Participant

    @erikalleman

    The idea is that I just simply want to display a topic with the same title as the post, under each post, as a comments section. Because they are post type, so I can achieve more with them in WordPress, as with comments.


    berry metal
    Participant

    @erikalleman

    Hi Robin,

    no, in my single post template.

    Originally I inserted them separately in my posts, but that of course comes with the lock-in effect, that is, if I want to change the layout of all of my posts, then i will have to edit them one by one – and this is unfeasible.

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