Plugin Support
Darian
(@d0153)
Hi @ecclescake
Thank you for contacting us.
We appreciate you taking the time to bring this issue to our attention. I will make sure to inquire about this matter with the team and gather all the necessary information. Once I have an update, I will get back to you as soon as possible.
I’ve encountered the same issue, thanks in advance for any updates!
Plugin Support
Darian
(@d0153)
Hi @ecclescake @nudel
Are you using a hook to run the snippet? If so, could you provide more details on how we can replicate the issue further on our side.
Looking forward to your reply.
@d0153 I personally use this snipped as part of a custom REST API endpoint, e.g.:
add_action('rest_api_init', function () {
register_rest_route(
'test/v1',
'/events/',
array(
'methods' => 'POST',
'callback' => 'test_create_event',
)
);
});
My event creation is triggered by cron. Here is the relevant portion of my reduced test-case code that doesn’t work:
/**
* Check whether it's time to create this
* year's calendar.
*
* @return void
*/
public static function cron_test() {
$next_execution = get_option( 'prefix_next_execution' );
if ( ( time() >= $next_execution ) && ( gmdate( 'm' ) >= '3' ) ) {
self::test_create_event();
self::set_next_execution_time( strtotime( '+1 year' ) );
}
}
/**
* TEST event creation.
*/
public static function test_create_event() {
$args = array(
'post_title' => 'Test Event',
'post_content' => 'Test description',
'post_status' => 'publish',
'venue' => 61,
'show_map' => true,
'start_date' => gmdate( 'Y-m-d H:i:s' ),
'end_date' => gmdate( 'Y-m-d H:i:s', strtotime( '+2 hours' ) ),
'category' => array( 9 ),
);
$result = tribe_events()->set_args( $args )->create();
}
The cron_test() function is added to a daily cron schedule by my plugin’s Loader class, via:
add_action( 'prefix_cron_hook', $plugin_instance, 'cron_test' );
The event is created with proper time, venue, etc, but no category gets added.
Plugin Support
Darian
(@d0153)
Hi @nudel @ecclescake
Thank you for providing additional details. I’ll make sure to share this with the team, and get back to you once I hear back from them.
Plugin Support
Darian
(@d0153)
Hi @nudel @ecclescake
I’m glad you brought this to our attention, I can see how this issue impacts your ability to add customizations on your website.
I’ve created an internal ticket [BTRIA-2322] to address this issue and I’ve included your specific use case in it to communicate it to our team.
We prioritize bugs by taking into consideration the number of users impacted as well as how the bug impacts one’s ability to run an event/sell tickets. I don’t have a specific timeline as to when this issue will be resolved, but trust that our team is aware. Our team communicates updates and bug fixes in our newsletter and via our changelog.
I’m happy to help if any other questions are coming up around this topic, otherwise I’ll go ahead and close this ticket.
Thanks again for reporting this issue and for using The Events Calendar! Have a great day.
—
Internal Bug Ticket Reference: BTRIA-2322
Plugin Support
Darian
(@d0153)
Hi @ecclescake
We have been investigating this issue and with the help of our wonderful developers, we have more information about what’s happening “under the hood”!
The bottom line is that this comes down to user permissions needed to add a category to an event. The way that a category is added to an event through the ORM is in the taxonomy input ($tax_input) in the post argument array ($postarr). The event category taxonomy is set up here (https://docs.theeventscalendar.com/reference/classes/tribe__events__main/register_taxonomy/), and as you can see, the capabilities defined there requires ‘publish_tribe_events’ and/or ‘edit_tribe_events’.
When using the theme’s function.php to test the ORM creating an event, we had been checking the creation of the event with a category on the frontend as a logged in admin user with these permissions, which is why we were missing this requirement. If you would like to continue using a custom REST endpoint, you will just have to ensure that you are creating the authentication needed – you can use a plugin like this one (https://ww.wp.xz.cn/plugins/jwt-authentication-for-wp-rest-api/) to set that up.
Thanks for the additional info, Darian. I’m not using a custom REST endpoint and don’t want to set one up just to handle event categorization. My code simply runs in a plugin rather than in a theme. (Another commenter on this thread is using the custom endpoint.)
Please consider allowing event categorization from plugin code. WordPress best practices suggest that functionality code like event creation be handled in a plugin rather than the theme, so this is a very common occurrence. I think there are a lot of developers who won’t want to deal with switching over to REST endpoint setup/configuration and just want to continue to be able to do basic event creation tasks in their plugins like always.