agile_tix = $agile_tix; $this->version = $version; } static function agile_user_custom_post_creator( $event, $commentStat, $postStat, $isNewEvent, $postID, $comingSoonEventData = null ) { $postType = agile_tix_Options::sanitize_theme_custom_map_post_type( get_option( 'agile_field_theme_custom_map_post_type' ) ); if ( '' === $postType ) { agile_tix::agile_tix_log_event( 'Custom Post Creator: missing post type while processing event ' . ( $event['ID'] ?? 'UNKNOWN_ID' ) ); return; } $thumbnailID = 0; $EventImage = $event['EventImage'] ?? ''; if ( ! empty( $EventImage ) ) { $mediaLibImg = agile_tix_post_creator::add_image_to_media_library_from_uri( $EventImage ); if ( $mediaLibImg && array_key_exists( 'url', $mediaLibImg ) && array_key_exists( 'attachment_id', $mediaLibImg ) ) { $thumbnailID = $mediaLibImg['attachment_id']; } } $meta_input = agile_tix_post_creator::agile_create_universal_meta_fields( $event, $thumbnailID, $comingSoonEventData ); $custom_fields = get_option( 'agile_custom_fields', array() ); $custom_meta_input = array(); foreach ( $custom_fields as $value ) { $metaName = $value[0]; $metaPath = $value[1]; $custom_meta_input[ $metaName ] = self::agile_resolve_mapped_value( $event, $metaPath, 'field', $metaName ); } if ( ! empty( $custom_meta_input ) ) { $meta_input += $custom_meta_input; } $post_data = array( 'ID' => $postID, 'post_title' => $event['Name'], 'post_content' => agile_tix_post_creator::agile_create_universal_content_body( $event ) . '
' . $event['CorpOrgName'] . '
', 'post_status' => $postStat, 'post_type' => $postType, 'comment_status' => $commentStat, 'meta_input' => $meta_input, ); if ( $isNewEvent ) { $postID = wp_insert_post( $post_data ); } else { $postID = wp_update_post( $post_data ); } if ( is_wp_error( $postID ) ) { $error_message = $postID->get_error_message(); agile_tix::agile_tix_log_event( 'Custom Post Creator: wp_insert_post/wp_update_post failed for event ' . ( $event['ID'] ?? 'UNKNOWN_ID' ) . ' - ' . $error_message ); return; } $taxonomies = get_option( 'agile_term_fields', array() ); foreach ( $taxonomies as $value ) { $termName = $value[0]; $termPath = $value[1]; $customResult = self::agile_resolve_mapped_value( $event, $termPath, 'term', $termName ); wp_set_object_terms( $postID, $customResult, $termName ); } if ( $thumbnailID != '' ) { set_post_thumbnail( $postID, $thumbnailID ); } } static function agile_resolve_mapped_value( $event, $path, $mapping_type, $mapping_name ) { $value = self::agile_safe_Array_Transversal( $event, $path ); if ( $mapping_type === 'term' ) { return apply_filters( 'agile_tix_custom_term_value', $value, $event, $mapping_name, $path ); } return apply_filters( 'agile_tix_custom_field_value', $value, $event, $mapping_name, $path ); } static function agile_safe_Array_Transversal( $array, $path ) { if ( ! is_array( $array ) || empty( $path ) ) { return null; } $path = preg_replace( "/\['?([a-zA-Z0-9_]+)'?\]/", '.$1', $path ); $path = ltrim( $path, '.' ); $keys = explode( '.', $path ); foreach ( $keys as $key ) { if ( is_array( $array ) && array_key_exists( $key, $array ) ) { $array = $array[ $key ]; } else { return null; } } return $array; } }