Barry (@barryhughes-1)

Forum Replies Created

Viewing 11 replies - 51 through 61 (of 61 total)

  • Barry
    Participant

    @barryhughes-1

    What do you know, it worked!

    So getting back to business – thanks for catching that error in my earlier snippet, Robin. I think yours is perfectly fine (also, great links re adding author meta) but just to ‘close the circle’ on my own snippet, here’s a revision:

    function bbpress_enable_rest_api() {
    	$types = array(
    		bbp_get_reply_post_type(),
    		bbp_get_forum_post_type(),
    		bbp_get_topic_post_type(),
    	);
    
    	foreach ( $types as $slug ) {
    		$definition = (array) get_post_type_object( $slug );
    		$definition['show_in_rest'] = true;
    		$definition['rest_controller_class'] = 'WP_REST_Posts_Controller';
    		register_post_type( $slug, $definition );
    	}
    }
    
    add_action( 'bbp_register_post_types', 'bbpress_enable_rest_api', 11 );

    Barry
    Participant

    @barryhughes-1

    My replies seem to keep disappearing into the bbPress void … trying again just to see if this one will show up.


    Barry
    Participant

    @barryhughes-1

    Apologies all and good catch, Robin!

    I don’t think there’s anything wrong with your version of the code, but for the sake of alternatives here’s a fix for what I posted originally:

    function bbpress_enable_rest_api() {
    	$types = array(
    		bbp_get_reply_post_type(),
    		bbp_get_forum_post_type(),
    		bbp_get_topic_post_type(),
    	);
    
    	foreach ( $types as $slug ) {
    		$definition = (array) get_post_type_object( $slug );
    		$definition['show_in_rest'] = true;
    		$definition['rest_controller_class'] = 'WP_REST_Posts_Controller';
    		register_post_type( $slug, $definition );
    	}
    }
    
    add_action( 'bbp_register_post_types', 'bbpress_enable_rest_api', 11 );

    Beyond that, the links you shared (in terms of mixing in extra info such as the author’s details) look solid to me 🙂


    Barry
    Participant

    @barryhughes-1

    …A PHP 5.2-friendly version that also covers the reply and forum post types:

    function bbpress_enable_rest_api_support() {
    	$enable_rest = array( 'show_in_rest' => true );
    	register_post_type( bbp_get_reply_post_type(), $enable_rest );
    	register_post_type( bbp_get_topic_post_type(), $enable_rest );
    	register_post_type( bbp_get_forum_post_type(), $enable_rest );
    }
    
    add_action( 'bbp_register_post_types', 'bbpress_enable_rest_api_support', 11 );

    Barry
    Participant

    @barryhughes-1

    To enable default REST API support for topics you could use a snippet like this one:

    add_action( 'bbp_register_post_types', function() {
    	register_post_type( bbp_get_topic_post_type(), [ 'show_in_rest' => true ] );
    }, 11 );

    This waits until bbPress has registered its post types, then modifies the properties of the topic post type so that it is exposed via the REST API. You could of course extend it to cover forum and reply posts, too. With that in place, you should find URLs like the following work as expected:

    http://bbpress.site/wp-json/wp/v2/topic


    Barry
    Participant

    @barryhughes-1

    Are you still logging email transactions, via Postman or by some other means? Have you uncovered any failures if so?

    Who is your mail provider and have you approached them about this?


    Barry
    Participant

    @barryhughes-1

    On the bbPress side, you’ll probably want to use bbp_insert_topic(). Usage is near-identical to wp_insert_post() – see here if you’re unfamiliar with this:

    wp_insert_post()

    I’ll leave interaction with the Postmark API for you to figure out 😉


    Barry
    Participant

    @barryhughes-1

    However, the onsite Buddypress notification stopped working as well. I guess Buddypress taps into the emails for notification generation.

    That’s a shame.

    I don’t actually find the same problem happens for me, though. If a new reply is posted, then subscribed users still receive a notification via their BuddyPress profiles. Are you describing some other type of notification, or is it possible some other customization/plugin etc is conflicting?


    Barry
    Participant

    @barryhughes-1

    Awesome, happy to hear it 🙂


    Barry
    Participant

    @barryhughes-1

    If you want to take a custom CSS based approach, you could use the body.bbpress selector.

    In your case, an extra selector is needed for the main forum page. It’s not ideal to hardcode page IDs in CSS this way and normally that wouldn’t be required – but you seem to be using a custom page instead of a regular forum archive there.

    Example:

    body.page-id-174,
    body.bbpress {
      background: white url("http://replace.me/with-image.png") repeat top left !important;
    }

    If you add the above to your child theme stylesheet it should get you in the right direction. Please also note if you are able to add it after the existing custom background CSS rule, you can drop the !important modifier.

    Of course, don’t forget to add a legit URL in there!

    Hope that helps 🙂


    Barry
    Participant

    @barryhughes-1

    Would this snippet work for you? You could add to a custom plugin, or to your theme’s functions.php file if that’s how you like to do things.

    function bbpress_unhook_email_notifications() {
    	remove_action( 'bbp_new_reply', 'bbp_notify_topic_subscribers', 11 );
    	remove_action( 'bbp_new_topic', 'bbp_notify_forum_subscribers', 11 );
    }
    
    add_action( 'init', 'bbpress_unhook_email_notifications', 100 );
Viewing 11 replies - 51 through 61 (of 61 total)