Call to undefined method Tribe__Events__Community__Main::insert_attachment()

Home Forums Calendar Products Community Events Call to undefined method Tribe__Events__Community__Main::insert_attachment()

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1180919
    Sean Spence
    Participant

    I’m getting the following error

    PHP Fatal error: Call to undefined method Tribe__Events__Community__Main::insert_attachment()
    in /home/everyeve/staging/1/wp-content/themes/ticketgives_2015/includes/event-management/modules/product/product.php on line 435

    This is the offending line, but there should be nothing wrong with this.

    $upload = Tribe__Events__Community__Main::instance()->insert_attachment( ‘product_image’, $product_id, true );

    I traced the insert_attachment() method to inside: plugins\the-events-calendar-community-events\src\Tribe\Submission_Handler.php

    I also tried to fire a few other the other methods like validate() inside the Tribe__Events__Community__Submission_Handler() class but they didn’t work either.

    #1181863
    Cliff
    Member

    Hi Sean.

    insert_attachment() method was moved to the Tribe__Events__Community__Submission_Handler class (src/Tribe/Submission_Handler.php) in v4.0.4 if I’m not mistaken.

    It’s possible you’ll be able to leverage your custom code if needed, but you’d probably need to create a new object of that class to do so.

    Please let me know if you have any follow-up questions on this topic.

    #1182722
    Sean Spence
    Participant

    I figured out the issue.

    I’m not sure if this is the way I’m supposed to do this, and there is ZERO documentation on this code so if you would confirm for me I would appreciate it.

    I created a new instance of the Class Tribe__Events__Community__Submission_Handler() then used my variable to call the insert_attachment() method inside the Class and this is working.

    Is that a correct way to use this code?

    // Save the product image
    $eeg_submission_handler = new Tribe__Events__Community__Submission_Handler();
    		
    $upload = $eeg_submission_handler->insert_attachment( 'product_image', $product_id, true );
    #1182840
    Cliff
    Member

    Sean, I’d suggest looking in /wp-content/plugins/the-events-calendar-community-events/src/Tribe/Main.php for how Tribe__Events__Community__Submission_Handler is used.

    As far as documentation, this is the DocBlock from the insert_attachment() method:

    /**
    * Insert an attachment.
    *
    * @param string $file_handler The upload.
    * @param int $post_id The post to attach the upload to.
    * @param string $setthumb To set or not to set the thumb.
    * @return int The attachment's ID.
    * @since 4.0.4
    */

    Beyond that, you’ll need to test and verify your own custom coding. If you need some coding help, you may want to ask your developer or reference our documentation and list of known customizers.

    #1182945
    Sean Spence
    Participant

    Yep, looks like I used it right. Thanks.

    #1183183
    Cliff
    Member

    I’m glad to hear that. Thanks for letting me know your issue is resolved.

Viewing 6 posts - 1 through 6 (of 6 total)
  • The topic ‘Call to undefined method Tribe__Events__Community__Main::insert_attachment()’ is closed to new replies.