Leng7881 (@leng7881)

Forum Replies Created

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

  • Leng7881
    Participant

    @leng7881

    Log’s who knew? From further examination due to the log telling me to look I found that I have a gh_ in front of the function name when declaring it. There error is also in your updated code above. Now that I took that out it works great. Here is the code without the minor syntax error and thank you for this.

    function post_published_create_topic( $ID, $post ) {
        $checkduplicate = get_post_meta( $ID, 'gh_topic_created',true);
        if ( empty( $checkduplicate ) ) {
            $author = $post->post_author;
            $name = get_the_author_meta( 'display_name', $author );
            $title = $post->post_title;
            $permalink = get_permalink( $ID );
            $excerpt = $post->post_excerpt;
            $subject = sprintf( '%s: %s', $name, $title );
            $message = sprintf ('[b]%s[/b]' . "\n" . 'By %s' . "\n\n" . '[i]%s[/i]' . "\n\n" . 'View: %s' . "\n\n", $title, $name, $excerpt, $permalink );
            $tags = wp_get_post_tags( $ID, array( 'fields' => 'names' ) );
    
            $new_post = array(
                'post_title'    => $subject,
                'post_content'  => $message,
                'post_parent' => 72,
                'post_status'   => 'publish',
                'post_type' => 'topic'
            );
            $topic_meta = array(
                'forum_id'       => $new_post['post_parent']
            );
            $topic_id = bbp_insert_topic($new_post, $topic_meta);
            if ( !empty( $topic_id ) ) {
                add_post_meta($ID, 'gh_topic_created', 'true', true);
                $term_taxonomy_ids = wp_set_object_terms( $topic_id, $tags, 'topic-tag' );
                bbp_update_forum(array('forum_id' => 72));
            }
        }
    }
    add_action( 'publish_post', 'post_published_create_topic', 10, 2 );

    Leng7881
    Participant

    @leng7881

    I’m getting this error:

    PHP Warning: call_user_func_array() expects parameter 1 to be a valid callback, function ‘post_published_create_topic’ not found or invalid function name in C:\xampp\htdocs\alpa\wp-includes\plugin.php on line 496


    Leng7881
    Participant

    @leng7881

    I got the id from the Reveal ID’s thank you for that. I am trying to get this to work on my website which currently is on a localhost so can’t send you to it. I have put the code in the functions and changed the number to 72 (my forum id), however, when I post it does not create a new topic in that forum. I have been poking around trying to get it to work and have found that some places say the publish_post is deprecated and others that say to ignore that it still works. I’m currently using wordpress version 4.2.4 and here is the code I put in my functions.

    function gh_post_published_create_topic( $ID, $post ) {
        $checkduplicate = get_post_meta( $ID, 'gh_topic_created',true);
        if ( empty( $checkduplicate ) ) {
            $author = $post->post_author;
            $name = get_the_author_meta( 'display_name', $author );
            $title = $post->post_title;
            $permalink = get_permalink( $ID );
            $excerpt = $post->post_excerpt;
            $subject = sprintf( '%s: %s', $name, $title );
            $message = sprintf ('[b]%s[/b]' . "\n" . 'By %s' . "\n\n" . '[i]%s[/i]' . "\n\n" . 'View: %s' . "\n\n", $title, $name, $excerpt, $permalink );
            $tags = wp_get_post_tags( $ID, array( 'fields' => 'names' ) );
    
            $new_post = array(
                'post_title'    => $subject,
                'post_content'  => $message,
                'post_parent' => 72,
                'post_status'   => 'publish',
                'post_type' => 'topic'
            );
            $topic_meta = array(
                'forum_id'       => $new_post['post_parent']
            );
            $topic_id = bbp_insert_topic($new_post, $topic_meta);
            if ( !empty( $topic_id ) ) {
                add_post_meta($ID, 'gh_topic_created', 'true', true);
                $term_taxonomy_ids = wp_set_object_terms( $topic_id, $tags, 'topic-tag' );
                bbp_update_forum(array('forum_id' => 72));
            }
        }
    }
    add_action( 'publish_post', 'post_published_create_topic', 10, 2 );

    Any help on why this wouldn’t work for me would me much appreciated.


    Leng7881
    Participant

    @leng7881

    This is probably a stupid question but where do I get my forum id?

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