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', array( $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 we are in * the middle of creating a new event. * * @param null $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) array( '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 * * @var 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 organizer dropdown in the event metabox * Used to be a PRO only feature, but as of 3.0, it is part of Core. * */ public function render_dropdowns() { $post_id = $this->event->ID; $current_linked_posts = get_post_meta( $post_id, $this->linked_posts->get_meta_key( $this->post_type ), false ); 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', array(), $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 ); $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 organizers table * * @param int $organizer_id * */ protected function single_post_dropdown( $linked_post_id ) { $linked_post_type_container = $this->linked_posts->get_post_type_container( $this->post_type ); $linked_post_type_id_field = $this->linked_posts->get_post_type_id_field_index( $this->post_type ); ?> move_handle(); ?> linked_posts->saved_linked_post_dropdown( $this->post_type, $linked_post_id ); $this->edit_post_link( $linked_post_id ); if ( ! empty( $this->linked_posts->linked_post_types[ $this->post_type ]['allow_multiple'] ) ) { $this->delete_handle(); } ?> post_type ); if ( empty( $linked_post_pto->cap->edit_others_posts ) || ! current_user_can( $linked_post_pto->cap->edit_others_posts ) ) { return; } ?>
singular_name ) ); ?>
event->ID ) && get_post_status( $this->event->ID ) != 'auto-draft' ) { return false; // the event has already been saved } if ( is_admin() ) { return Tribe__Admin__Helpers::instance()->is_action( 'add' ); } else { return true; // a front-end submission form (e.g., community) } } /** * Renders the "Add Another Organizer" button * */ protected function render_add_post_button() { if ( empty( $this->linked_posts->linked_post_types[ $this->post_type ]['allow_multiple'] ) ) { return; } ?> singular_name_lowercase ) ); ?> '; } /** * Renders the handle for deleting an organizer * */ protected function delete_handle() { ?> get_post_type_container( $this->post_type ); if ( empty( $_POST[ $container ] ) || ! is_array( $_POST[ $container ] ) ) { return; } foreach ( $_POST[ $container ] as $field => $set_of_values ) { if ( ! is_array( $set_of_values ) ) { continue; } foreach ( $set_of_values as $index => $value ) { if ( ! isset( $submitted_data[ $index ] ) ) { $submitted_data[ $index ] = array(); } $submitted_data[ $index ][ $field ] = esc_attr( $value ); } } wp_localize_script( 'tribe-events-admin', 'tribe_sticky_' . $this->post_type . '_fields', $submitted_data ); } /** * @param $current_linked_posts * * @return mixed */ private function maybe_parse_candidate_linked_posts( array $current_linked_posts = array() ) { $linked_post_type_container = $this->linked_posts->get_post_type_container( $this->post_type ); // filter out any non-truthy values $current_linked_posts = array_filter( $current_linked_posts ); // We don't have any items $has_no_current_linked_posts = empty( $current_linked_posts ); $submitted_data_contains_candidate_linked_posts = ! empty( $_POST[ $linked_post_type_container ] ); if ( $has_no_current_linked_posts && $submitted_data_contains_candidate_linked_posts ) { $candidate_linked_posts = $_POST[ $linked_post_type_container ]; $linked_post_type_id_field = $this->linked_posts->get_post_type_id_field_index( $this->post_type ); if ( ! empty( $candidate_linked_posts[ $linked_post_type_id_field ] ) ) { $candidate_linked_posts = $candidate_linked_posts[ $linked_post_type_id_field ]; return $candidate_linked_posts; } return $current_linked_posts; } return $current_linked_posts; } }