Home › Forums › Calendar Products › Community Events › Call to undefined method Tribe__Events__Community__Main::insert_attachment()
- This topic has 6 replies, 3 voices, and was last updated 9 years, 6 months ago by
Cliff.
-
AuthorPosts
-
October 21, 2016 at 1:29 pm #1180919
Sean Spence
ParticipantI’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 435This 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.
October 24, 2016 at 7:19 am #1181863Cliff
MemberHi 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.
October 25, 2016 at 11:44 am #1182722Sean Spence
ParticipantI 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 );October 25, 2016 at 3:23 pm #1182840Cliff
MemberSean, 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.
October 25, 2016 at 7:59 pm #1182945Sean Spence
ParticipantYep, looks like I used it right. Thanks.
October 26, 2016 at 8:10 am #1183183Cliff
MemberI’m glad to hear that. Thanks for letting me know your issue is resolved.
-
AuthorPosts
- The topic ‘Call to undefined method Tribe__Events__Community__Main::insert_attachment()’ is closed to new replies.
