tribe = Tribe__Events__Main::instance(); $this->linked_posts = Tribe__Events__Linked_Posts::instance(); $this->post_type = $post_type; $this->singular_name = $this->linked_posts->linked_post_types[ $this->post_type ]['singular_name']; $this->singular_name_lowercase = $this->linked_posts->linked_post_types[ $this->post_type ]['singular_name_lowercase']; $this->get_event( $event ); add_action( 'wp', [ $this, 'sticky_form_data' ], 50 ); // Later than events-admin.js itself is enqueued } /** * Work with the specifed event object or else use a placeholder if in the middle of creating a new event. * * @param mixed $event */ protected function get_event( $event = null ) { if ( is_null( $event ) ) { $event = $GLOBALS['post']; } if ( is_numeric( $event ) ) { $event = WP_Post::get_instance( $event ); } if ( $event instanceof stdClass || is_array( $event ) ) { $event = new WP_Post( (object) $event ); } if ( ! $event instanceof WP_Post ) { $event = new WP_Post( (object) [ 'ID' => 0 ] ); } $this->event = $event; } /** * Render the organizer chooser section for the events meta box */ public function render() { $this->render_dropdowns(); $this->render_add_post_button(); /** * Make this Template filterable, used for Community Facing templates. * * @param string $file_path */ include apply_filters( 'tribe_events_multiple_linked_post_template', $this->tribe->pluginPath . 'src/admin-views/linked-post-meta-box.php' ); } /** * Displays the saved linked post dropdown in the event metabox. * * @since 3.0 * @since 4.5.11 Genericized to work for all linked posts, not just organizers like it was originally. */ public function render_dropdowns() { $post_id = $this->event->ID; $current_linked_post_meta_key = $this->linked_posts->get_meta_key( $this->post_type ); $current_linked_posts = get_post_meta( $post_id, $current_linked_post_meta_key, false ); if ( $this->post_type === Tribe__Events__Organizer::POSTTYPE ) { $current_linked_posts = tribe_get_organizer_ids( $post_id ); } /** * Allows for filtering the array of values retrieved for a specific linked post meta field. * * Name of filter is assembled as tribe_events_linked_post_meta_values_{$current_linked_post_meta_key}, where * $current_linked_post_meta_key is just literally the name of the current meta key. So when the _EventOrganizerID * is being filtered, for example, the filter name would be tribe_events_linked_post_meta_values__EventOrganizerID * * @since 4.5.11 * * @param array $current_linked_posts The array of the current meta field's values. * @param int $post_id The current event's post ID. */ $current_linked_posts = apply_filters( "tribe_events_linked_post_meta_values_{$current_linked_post_meta_key}", $current_linked_posts, $post_id ); if ( $this->use_default_post( $current_linked_posts ) ) { /** * Filters the default selected post for the linked post * * @param array $default Default post array * @param string $post_type Linked post post type */ $current_linked_posts = apply_filters( 'tribe_events_linked_post_default', [], $this->post_type ); } /** * Filters the default selected post for the linked post. * * @param array $current_linked_posts Array of currently linked posts * @param string $post_type Linked post post type */ $current_linked_posts = (array) apply_filters( 'tribe_display_event_linked_post_dropdown_id', $current_linked_posts, $this->post_type ); /* if the user can't create organizers, then remove any empty values from the $current_organizers array. This prevents the automatic selection of an organizer every time the event is edited. */ $linked_post_pto = get_post_type_object( $this->post_type ); if ( ! current_user_can( $linked_post_pto->cap->create_posts ) ) { $current_linked_posts = array_filter( $current_linked_posts ); } ?>maybe_parse_candidate_linked_posts( $current_linked_posts ); $current_linked_posts = array_values( $current_linked_posts ); $i = 0; $num_records = count( $current_linked_posts ); do { echo '
'; $this->single_post_dropdown( isset( $current_linked_posts[ $i ] ) ? $current_linked_posts[ $i ] : 0 ); echo ''; $i++; } while ( $i < $num_records ); } /** * Render a single row of the linked post's table * * @since 3.0 * * @param int $linked_post_id */ protected function single_post_dropdown( $linked_post_id ) { $linked_post_type_container = $this->linked_posts->get_post_type_container( $this->post_type ); ?>