Skip to:
Content
Pages
Categories
Search
Top
Bottom

Synchronize creation Forum to a taxonomy forum


  • kimis
    Participant

    @kimis

    Hello, I have a taxonomy forums that is is linked to the user, how can I do to create a forum on bbpress and when it’s done it also create a forum on my taxonomy

    my code is :

    function create_forum_taxonomy_entry($forum_id, $forum_args) {

    $forum_title = get_the_title($forum_id);
    $forum_slug = sanitize_title($forum_title);

    error_log(“Création du forum : ” . $forum_title);
    error_log(“Slug du forum : ” . $forum_slug);

    // Insertion du forum dans la taxonomie forum
    if (!term_exists($forum_title, ‘forums’)) {
    $result = wp_insert_term($forum_title, ‘forums’, array(
    ‘slug’ => $forum_slug
    ));

    if (is_wp_error($result)) {
    error_log(“Erreur lors de l’insertion du terme : ” . $result->get_error_message());
    } else {
    error_log(“Term créé avec succès : ” . print_r($result, true));
    }
    } else {
    error_log(“Le terme existe déjà : ” . $forum_title);
    }
    }
    add_action(‘bbp_insert_forum’, ‘create_forum_taxonomy_entry’, 10, 2); but this function isn’t called

    the file has another function below and it works so it’s not the calling of the file

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

  • Robin W
    Moderator

    @robin-w

    I think you need to hook to

    do_action( 'bbp_new_forum_post_extras', $forum_id );

    which is in the function bbp_new_forum_handler


    kimis
    Participant

    @kimis

    I did

    add_action('bbp_new_forum_post_extras', 'my_custom_bbp_new_forum_handler');
    
    function my_custom_bbp_new_forum_handler( $action = '' ) {
    error_log('test function');
        if ( 'bbp-new-forum' !== $action ) {
            return;
        }
    
        if ( ! bbp_verify_nonce_request( 'bbp-new-forum' ) ) {
            bbp_add_error( 'bbp_new_forum_nonce', __( '<strong>ERROR</strong>: Are you sure you wanted to do that?', 'bbpress' ) );
            return;
        }
    
        do_action( 'bbp_new_forum_post_extras', $forum_id );
    
        $forum_title = get_the_title($forum_id);
        $forum_slug = sanitize_title($forum_title);
    
        if (!term_exists($forum_title, 'forums')) {
            $result = wp_insert_term($forum_title, 'forums', array(
                'name' => $forum_title,
                'slug' => $forum_slug
            ));
    
            if (is_wp_error($result)) {
                error_log("Erreur lors de l'insertion du terme : " . $result->get_error_message());
            } else {
                error_log("Terme de taxonomie 'forums' créé avec succès : " . print_r($result, true));
            }
        } else {
            error_log("Le terme existe déjà : " . $forum_title);
        }
    
        $redirect_url = bbp_get_forum_permalink( $forum_id );
        bbp_redirect( $redirect_url );
    }

    but it still doesn’t work the first error log doesn’t appear on the debug file


    Robin W
    Moderator

    @robin-w

    so how are you creating the forum on bbpress? ie I go into xx and I click this and then type that


    kimis
    Participant

    @kimis

    I have the plugin BBpress that allow me to create a forum on the admin panel on wordpress, the form is basic I just have to tape a name and pusblished it. Forum > Add new > tape the name > published and my forum is create. I also have a taxonomy forum that is linked to the user for that I do use the plugin User Taxonomy & Directory.


    Robin W
    Moderator

    @robin-w

    ok so from the admin area I think you need to hook to

    do_action( 'bbp_forum_attributes_metabox_save', $forum_id );

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