Webex_Provider
Class Webex_Provider
Source
File: src/Tribe/Meetings/Webex_Provider.php
class Webex_Provider extends Meeting_Provider { use With_Nonce_Routes; /** * The slug of this provider. * * @since 1.9.0 */ const SLUG = 'webex'; /** * {@inheritDoc} */ public function get_slug() { return self::SLUG; } /** * Registers the bindings, actions and filters required by the Webex API meetings provider to work. * * @since 1.9.0 */ public function register() { // Register this providers in the container to allow calls on it, e.g. to check if enabled. $this->container->singleton( 'events-virtual.meetings.webex', self::class ); $this->container->singleton( self::class, self::class ); if ( ! $this->is_enabled() ) { return; } $this->add_actions(); $this->add_filters(); $this->hook_templates(); $this->route_admin_by_nonce( $this->admin_routes(), 'manage_options' ); } /** * Hooks the actions required for the Webex API integration to work correctly. * * @since 1.9.0 */ protected function add_actions() { // Filter event object properties to add the ones related to Webex meetings for virtual events. add_action( 'tribe_events_virtual_add_event_properties', [ $this, 'add_event_properties' ] ); add_action( 'add_meta_boxes_' . Events_Plugin::POSTTYPE, [ $this, 'check_admin_webex_meeting' ] ); add_action( 'wp', [ $this, 'check_webex_meeting' ], 50 ); add_action( 'tribe_events_virtual_metabox_save', [ $this, 'on_metabox_save' ], 10, 2 ); add_action( 'save_post_tribe_events', [ $this, 'on_post_save' ], 100, 3 ); } /** * Hooks the filters required for the Webex API integration to work correctly. * * @since 1.9.0 */ protected function add_filters() { add_filter( 'tribe_addons_tab_fields', [ $this, 'filter_addons_tab_fields' ] ); add_filter( 'tribe_events_virtual_video_sources', [ $this, 'add_video_source' ], 20, 2 ); add_filter( 'tec_events_virtual_autodetect_video_sources', [ $this, 'add_autodetect_source' ], 20, 3 ); add_filter( 'tec_events_virtual_video_source_autodetect_field_all', [ $this, 'filter_virtual_autodetect_field_accounts' ], 20, 5 ); add_filter( 'tec_events_virtual_video_source_autodetect_field_webex-accounts', [ $this, 'filter_virtual_autodetect_field_accounts' ], 20, 5 ); add_filter( 'tribe_events_virtual_display_embed_video_hidden', [ $this, 'filter_display_embed_video_hidden' ], 10, 2 ); add_filter( 'tec_events_virtual_export_fields', [ $this, 'filter_webex_source_google_calendar_parameters' ], 10, 5 ); add_filter( 'tec_events_virtual_webex_export_fields', [ $this, 'filter_source_google_calendar_webex_password' ], 10, 5 ); add_filter( 'tec_events_virtual_export_fields', [ $this, 'filter_webex_source_ical_feed_items' ], 10, 5 ); add_filter( 'tec_events_virtual_webex_export_fields', [ $this, 'filter_source_ical_webex_password' ], 10, 5 ); } /** * Hooks the template required for the integration to work. * * @since 1.9.0 */ protected function hook_templates() { // Metabox. add_action( 'tribe_template_entry_point:events-virtual/admin-views/virtual-metabox/container/video-source:video_sources', [ $this, 'render_classic_meeting_link_ui' ], 10, 3 ); // Email Templates. add_filter( 'tribe_events_virtual_ticket_email_template', [ $this, 'maybe_change_email_template', ], 10, 2 ); // Event Single. add_action( 'tribe_events_single_event_after_the_content', [ $this, 'action_add_event_single_webex_details' ], 15, 0 ); // Event Single - Blocks. add_action( 'wp', [ $this, 'hook_block_template' ] ); // The location which the template is injected depends on whether or not V2 is enabled. $webex_details_inject_action = tribe_events_single_view_v2_is_enabled() ? 'tribe_events_virtual_block_content' : 'tribe_template_after_include:events/blocks/event-datetime'; add_action( $webex_details_inject_action, [ $this, 'action_add_event_single_webex_details' ], 20, 0 ); } /** * Filters the fields in the Events > Settings > APIs tab to add the ones provided by the extension. * * @since 1.9.0 * * @param array<string,array> $fields The current fields. * * @return array<string,array> The fields, as updated by the settings. */ public function filter_addons_tab_fields( $fields ) { if ( ! is_array( $fields ) ) { return $fields; } return tribe( Webex\Settings::class )->add_fields( $fields ); } /** * Filters the object returned by the `tribe_get_event` function to add to it properties related to Webex meetings. * * @since 1.9.0 * * @param WP_Post $event The events post object to be modified. * * @return WP_Post The original event object decorated with properties related to virtual events. */ public function add_event_properties( $event ) { if ( ! $event instanceof WP_Post ) { // We should only act on event posts, else bail. return $event; } return $this->container->make( Webex_Meta::class )->add_event_properties( $event ); } /** * Check Webex Meeting in the admin. * * @since 1.9.0 * * @param WP_Post $event The event post object. * * @return bool|void Whether the update completed. */ public function check_admin_webex_meeting( $event ) { return $this->container->make( Password::class )->check_admin_webex_meeting( $event ); } /** * Check Webex Meeting on Front End. * * @since 1.9.0 * * @return bool|void Whether the update completed. */ public function check_webex_meeting() { return $this->container->make( Password::class )->check_webex_meeting(); } /** * Handles the save operations of the Classic Editor VE Metabox. * * @since 1.9.0 * * @param int $post_id The post ID of the event currently being saved. * @param array<string,mixed> $data The data currently being saved. */ public function on_metabox_save( $post_id, $data ) { $post = get_post( $post_id ); if ( ! $post instanceof WP_Post && is_array( $data ) ) { return; } $this->container->make( Webex_Meta::class )->save_metabox_data( $post_id, $data ); } /** * Handles updating Webex meetings on post save. * * @since 1.9.0 * * @param int $post_id The post ID. * @param WP_Post $unused_post The post object. * @param bool $update Whether this is an existing post being updated or not. */ public function on_post_save( $post_id, $unused_post, $update ) { if ( ! $update ) { return; } $event = tribe_get_event( $post_id ); if ( ! $event instanceof WP_Post || empty( $event->duration ) ) { // Hook for the Event meta save to try later in the save request, data might be there then. if ( ! doing_action( 'tribe_events_update_meta' ) ) { // But do no re-hook if we're acting on it. add_action( 'tribe_events_update_meta', [ $this, 'on_post_save' ], 100, 3 ); } return; } $meeting_handler = $this->container->make( Meetings::class ); $meeting_handler->update( $event ); } /** * Provides the routes that should be used to handle Webex API requests. * * The map returned by this method will be used by the `Tribe\Events\Virtual\Traits\With_Nonce_Routes` trait. * * @since 1.9.0 * * @return array<string,callable> A map from the nonce actions to the corresponding handlers. */ public function admin_routes() { return [ Api::$authorize_nonce_action => $this->container->callback( Api::class, 'handle_auth_request' ), Api::$status_action => $this->container->callback( Api::class, 'ajax_status' ), Api::$delete_action => $this->container->callback( Api::class, 'ajax_delete' ), Api::$select_action => $this->container->callback( Classic_Editor::class, 'ajax_selection' ), Meetings::$create_action => $this->container->callback( Meetings::class, 'ajax_create' ), Meetings::$remove_action => $this->container->callback( Meetings::class, 'ajax_remove' ), ]; } /** * Add the Webex Video Source. * * @since 1.9.0 * * @param array<string|string> An array of video sources. * @param WP_Post $post The current event post object, as decorated by the `tribe_get_event` function. * * @return array<string|mixed> An array of video sources. */ public function add_video_source( $video_sources, $post ) { $video_sources[] = [ 'text' => _x( 'Webex Account', 'The name of the video source.', 'events-virtual' ), 'id' => Webex_Meta::$key_source_id, 'value' => Webex_Meta::$key_source_id, 'selected' => Webex_Meta::$key_source_id === $post->virtual_video_source, ]; return $video_sources; } /** * Add Webex to Autodetect Source. * * @since 1.9.0 * * @param array<string|string> An array of autodetect sources. * @param string $autodetect_source The ID of the current selected video source. * @param WP_Post $post The current event post object, as decorated by the `tribe_get_event` function. * * @return array<string|string> An array of video sources. */ public function add_autodetect_source( $autodetect_sources, $autodetect_source, $post ) { $autodetect_sources[] = [ 'text' => _x( 'Webex', 'The name of the autodetect source.', 'events-virtual' ), 'id' => Webex_Meta::$key_source_id, 'value' => Webex_Meta::$key_source_id, 'selected' => Webex_Meta::$key_source_id === $autodetect_source, ]; return $autodetect_sources; } /** * Add the Webex accounts dropdown field to the autodetect fields. * * @since 1.9.0 * * @param array<string|mixed> $autodetect An array of the autodetect resukts. * @param string $video_url The url to use to autodetect the video source. * @param string $autodetect_source The optional name of the video source to attempt to autodetect. * @param WP_Post|null $event The event post object, as decorated by the `tribe_get_event` function. * @param array<string|mixed> $ajax_data An array of extra values that were sent by the ajax script. * * @return array<string|mixed> An array of the autodetect results. */ public function filter_virtual_autodetect_field_accounts( $autodetect_fields, $video_url, $autodetect_source, $event, $ajax_data ) { return $this->container->make( Classic_Editor::class ) ->classic_autodetect_video_source_accounts( $autodetect_fields, $video_url, $autodetect_source, $event, $ajax_data ); } /** * Filters whether embed video control is hidden. * * @param boolean $is_hidden Whether the embed video control is hidden. * @param WP_Post $event The event object. * * @return boolean Whether the embed video control is hidden. */ public function filter_display_embed_video_hidden( $is_hidden, $event ) { if ( ! $event->virtual_meeting || tribe( self::class )->get_slug() !== $event->virtual_meeting_provider ) { return $is_hidden; } return true; } /** * Filter the Google Calendar export fields for a Webex source event. * * @since 1.9.0 * * @param array<string|string> $fields The various file format components for this specific event. * @param WP_Post $event The WP_Post of this event. * @param string $key_name The name of the array key to modify. * @param string $type The name of the export type. * @param boolean $should_show Whether to modify the export fields for the current user, default to false. * * @return array<string|string> Google Calendar Link params. */ public function filter_webex_source_google_calendar_parameters( $fields, $event, $key_name, $type, $should_show ) { return $this->container->make( Webex_Event_Export::class )->modify_video_source_export_output( $fields, $event, $key_name, $type, $should_show ); } /** * Filter the Google Calendar export fields for a Webex to add the password. * * @since 1.9.0 * * @param array<string|string> $fields The various file format components for this specific event. * @param WP_Post $event The WP_Post of this event. * @param string $key_name The name of the array key to modify. * @param string $type The name of the export type. * @param boolean $should_show Whether to modify the export fields for the current user, default to false. * * @return array<string|string> Google Calendar Link params. */ public function filter_source_google_calendar_webex_password( $fields, $event, $key_name, $type, $should_show ) { return $this->container->make( Webex_Event_Export::class )->add_password_to_gcal_details( $fields, $event, $key_name, $type, $should_show ); } /** * Filter the iCal export fields for a Webex source event. * * @since 1.9.0 * * @param array<string|string> $fields The various file format components for this specific event. * @param WP_Post $event The WP_Post of this event. * @param string $key_name The name of the array key to modify. * @param string $type The name of the export type. * @param boolean $should_show Whether to modify the export fields for the current user, default to false. * * @return array<string|string> The various iCal file format components of this specific event item. */ public function filter_webex_source_ical_feed_items( $fields, $event, $key_name, $type, $should_show ) { return $this->container->make( Webex_Event_Export::class )->modify_video_source_export_output( $fields, $event, $key_name, $type, $should_show ); } /** * Filter the iCal export fields for Webex to add the password. * * @since 1.9.0 * * @param array<string|string> $fields The various file format components for this specific event. * @param WP_Post $event The WP_Post of this event. * @param string $key_name The name of the array key to modify. * @param string $type The name of the export type. * @param boolean $should_show Whether to modify the export fields for the current user, default to false. * * @return array<string|string> The various iCal file format components of this specific event item. */ public function filter_source_ical_webex_password( $fields, $event, $key_name, $type, $should_show ) { return $this->container->make( Webex_Event_Export::class )->add_password_to_ical_description( $fields, $event, $key_name, $type, $should_show ); } /** * Renders the Webex API link generation UI and controls, depending on the current state. * * @since 1.9.0 * * @param string $file The path to the template file, unused. * @param string $entry_point The name of the template entry point, unused. * @param \Tribe__Template $template The current template instance. */ public function render_classic_meeting_link_ui( $file, $entry_point, \Tribe__Template $template ) { $this->container->make( Webex\Classic_Editor::class ) ->render_initial_setup_options( $template->get( 'post' ) ); } /** * Conditionally inject content into ticket email templates. * * @since 1.9.0 * * @param string $template The template path, relative to src/views. * @param array $args The template arguments. * * @return string */ public function maybe_change_email_template( $template, $args ) { return $this->container->make( Email::class )->maybe_change_email_template( $template, $args ); } /** * Hook block templates - legacy or new VE block. * Has to be postponed to `wp` action or later so global $post is available. * * @since 1.9.0 */ public function hook_block_template() { /* The action/location which the template is injected depends on whether or not V2 is enabled * and whether the virtual event block is present in the post content. */ $embed_inject_action = tribe( 'events-virtual.hooks' )->get_virtual_embed_action(); add_action( $embed_inject_action, [ $this, 'action_add_event_single_webex_details' ], 20, 0 ); } /** * Include the Webex details for event single. * * @since 1.9.0 */ public function action_add_event_single_webex_details() { // Don't show if requires log in and user isn't logged in. $base_modifications = $this->container->make( 'Tribe\Events\Virtual\Template_Modifications' ); $should_show = $base_modifications->should_show_virtual_content( tribe_get_Event( get_the_ID() ) ); if ( ! $should_show ) { return; } $template_modifications = $this->container->make( Template_Modifications::class ); $template_modifications->add_event_single_webex_details(); } }
Changelog
Version | Description |
---|---|
1.9.0 | Introduced. |
Methods
- action_add_event_single_webex_details — Include the Webex details for event single.
- add_autodetect_source — Add Webex to Autodetect Source.
- add_event_properties — Filters the object returned by the `tribe_get_event` function to add to it properties related to Webex meetings.
- add_password_to_outlook_description — Filter the Outlook single event export url for Webex to add the password.
- add_video_source — Add the Webex Video Source.
- admin_routes — Provides the routes that should be used to handle Webex API requests.
- check_admin_webex_meeting — Check Webex Meeting in the admin.
- check_webex_meeting — Check Webex Meeting on Front End.
- filter_addons_tab_fields — Filters the fields in the Events > Settings > APIs tab to add the ones provided by the extension.
- filter_api_error_message — Filters the API error message.
- filter_display_embed_video_hidden — Filters whether embed video control is hidden.
- filter_outlook_single_event_export_url_by_api — Filter the Outlook single event export url for a Webex source event.
- filter_source_google_calendar_webex_password — Filter the Google Calendar export fields for a Webex to add the password.
- filter_source_ical_webex_password — Filter the iCal export fields for Webex to add the password.
- filter_virtual_autodetect_field_accounts — Add the Webex accounts dropdown field to the autodetect fields.
- filter_webex_source_google_calendar_parameters — Filter the Google Calendar export fields for a Webex source event.
- filter_webex_source_ical_feed_items — Filter the iCal export fields for a Webex source event.
- get_slug — {@inheritDoc}
- hook_block_template — Hook block templates - legacy or new VE block.
- maybe_change_email_template — Conditionally inject content into ticket email templates.
- on_metabox_save — Handles the save operations of the Classic Editor VE Metabox.
- on_post_save — Handles updating Webex meetings on post save.
- register — Registers the bindings, actions and filters required by the Webex API meetings provider to work.
- render_classic_meeting_link_ui — Renders the Webex API link generation UI and controls, depending on the current state.