Skip to content

Commit

Permalink
Configure hosts post type if enabled in Pro
Browse files Browse the repository at this point in the history
  • Loading branch information
joedolson committed Oct 29, 2023
1 parent 25b8dc2 commit 2c26589
Show file tree
Hide file tree
Showing 2 changed files with 194 additions and 83 deletions.
274 changes: 193 additions & 81 deletions src/includes/post-types.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ function mc_load_permalinks() {
$opts = array( 'label_for' => 'mc_location_cpt_base' );
// Add a settings field to the permalink page.
add_settings_field( 'mc_location_cpt_base', __( 'My Calendar Locations base', 'my-calendar' ), 'mc_location_field_callback', 'permalink', 'optional', $opts );

if ( function_exists( 'mcs_submissions' ) && 'true' === get_option( 'mcs_custom_hosts' ) ) {
if ( isset( $_POST['mc_hosts_cpt_base'] ) ) {
mc_update_option( 'hosts_cpt_base', sanitize_key( $_POST['mc_hosts_cpt_base'] ) );
}
$opts = array( 'label_for' => 'mc_cpt_base' );
// Add a settings field to the permalink page.
add_settings_field( 'mc_hosts_cpt_base', __( 'My Calendar Hosts base', 'my-calendar' ), 'mc_field_callback', 'permalink', 'optional', $opts );
}

}
add_action( 'load-options-permalink.php', 'mc_load_permalinks' );

Expand Down Expand Up @@ -112,71 +122,131 @@ function mc_post_type() {
$loc_arguments,
),
);
if ( function_exists( 'mcs_submissions' ) && 'true' === get_option( 'mcs_custom_hosts' ) ) {
$types['mc-hosts'] = array(
__( 'host', 'my-calendar' ),
__( 'hosts', 'my-calendar' ),
__( 'Host', 'my-calendar' ),
__( 'Hosts', 'my-calendar' ),
$loc_arguments,
);
}

return $types;
}

/**
* Register custom post types for events
* Labels for My Calendar post types.
*
* @param $type Post type key.
* @param $value Array of post type name variations.
*
* @return array
*/
function mc_posttypes() {
$types = mc_post_type();
$enabled = array( 'mc-events', 'mc-locations' );
if ( is_array( $enabled ) ) {
foreach ( $enabled as $key ) {
$value =& $types[ $key ];
function mc_post_type_labels( $type, $value ) {
$labels = array();
switch ( $type ) {
case 'mc-events':
$labels = array(
'name' => $value[3],
'singular_name' => $value[2],
'add_new' => _x( 'Add New', 'Add new event', 'my-calendar' ),
'add_new' => __( 'Add New Event', 'my-calendar' ),
'add_new_item' => __( 'Create New Event', 'my-calendar' ),
'edit_item' => __( 'Modify Event', 'my-calendar' ),
'new_item' => __( 'New Event', 'my-calendar' ),
'view_item' => __( 'View Event', 'my-calendar' ),
'search_items' => __( 'Search Events', 'my-calendar' ),
'not_found' => __( 'No event found', 'my-calendar' ),
'not_found_in_trash' => __( 'No events found in Trash', 'my-calendar' ),
'not_found' => __( 'No Event found', 'my-calendar' ),
'not_found_in_trash' => __( 'No Events found in Trash', 'my-calendar' ),
'parent_item_colon' => '',
);
$raw = $value[4];
$args = array(
'labels' => $labels,
'public' => $raw['public'],
'publicly_queryable' => $raw['publicly_queryable'],
'exclude_from_search' => $raw['exclude_from_search'],
'show_ui' => $raw['show_ui'],
'show_in_menu' => $raw['show_in_menu'],
'menu_icon' => ( null === $raw['menu_icon'] ) ? plugins_url( 'images', __FILE__ ) . '/icon.png' : $raw['menu_icon'],
'query_var' => true,
'rewrite' => array(
'with_front' => false,
/**
* Filter default calendar post type slugs. Default 'mc-events' for events and 'mc-locations' for locations.
*
* @hook mc_event_slug
*
* @param {string} $key Slug.
*
* @return {string}
*/
'slug' => apply_filters( 'mc_event_slug', $key ),
/**
* Enable feeds for My Calendar post types.
*
* @hook mc_has_feeds
*
* @param {bool} $enabled Default false.
* @param {string} $key Post type name.
*
* @return {bool}
*/
'feeds' => apply_filters( 'mc_has_feeds', false, $key ),
),
'hierarchical' => false,
'menu_position' => 20,
'supports' => $raw['supports'],
break;
case 'mc-locations':
$labels = array(
'name' => $value[3],
'singular_name' => $value[2],
'add_new' => __( 'Add New Location', 'my-calendar' ),
'add_new_item' => __( 'Create New Location', 'my-calendar' ),
'edit_item' => __( 'Modify Location', 'my-calendar' ),
'new_item' => __( 'New Location', 'my-calendar' ),
'view_item' => __( 'View Location', 'my-calendar' ),
'search_items' => __( 'Search Locations', 'my-calendar' ),
'not_found' => __( 'No Location found', 'my-calendar' ),
'not_found_in_trash' => __( 'No Locations found in Trash', 'my-calendar' ),
'parent_item_colon' => '',
);
register_post_type( $key, $args );
}
break;
case 'mc-hosts':
$labels = array(
'name' => $value[3],
'singular_name' => $value[2],
'add_new' => __( 'Add New Host', 'my-calendar' ),
'add_new_item' => __( 'Create New Host', 'my-calendar' ),
'edit_item' => __( 'Modify Host', 'my-calendar' ),
'new_item' => __( 'New Host', 'my-calendar' ),
'view_item' => __( 'View Host', 'my-calendar' ),
'search_items' => __( 'Search Hosts', 'my-calendar' ),
'not_found' => __( 'No Host found', 'my-calendar' ),
'not_found_in_trash' => __( 'No Hosts found in Trash', 'my-calendar' ),
'parent_item_colon' => '',
);
break;
}

return $labels;
}

/**
* Register custom post types for events
*/
function mc_posttypes() {
$types = mc_post_type();
$enabled = array( 'mc-events', 'mc-locations' );
if ( function_exists( 'mcs_submissions' ) && 'true' === get_option( 'mcs_custom_hosts' ) ) {
$enabled[] = 'mc-hosts';
}
foreach ( $enabled as $key ) {
$value =& $types[ $key ];
$labels = mc_post_type_labels( $key, $value );
$raw = $value[4];
$args = array(
'labels' => $labels,
'public' => $raw['public'],
'publicly_queryable' => $raw['publicly_queryable'],
'exclude_from_search' => $raw['exclude_from_search'],
'show_ui' => $raw['show_ui'],
'show_in_menu' => $raw['show_in_menu'],
'menu_icon' => ( null === $raw['menu_icon'] ) ? plugins_url( 'images', __FILE__ ) . '/icon.png' : $raw['menu_icon'],
'query_var' => true,
'rewrite' => array(
'with_front' => false,
/**
* Filter default calendar post type slugs. Default 'mc-events' for events and 'mc-locations' for locations.
*
* @hook mc_event_slug
*
* @param {string} $key Slug.
*
* @return {string}
*/
'slug' => apply_filters( 'mc_event_slug', $key ),
/**
* Enable feeds for My Calendar post types.
*
* @hook mc_has_feeds
*
* @param {bool} $enabled Default false.
* @param {string} $key Post type name.
*
* @return {bool}
*/
'feeds' => apply_filters( 'mc_has_feeds', false, $key ),
),
'hierarchical' => false,
'menu_position' => 20,
'supports' => $raw['supports'],
);
register_post_type( $key, $args );
}
}

Expand All @@ -194,6 +264,9 @@ function mc_filter_posttype_slug( $slug ) {
if ( 'mc-locations' === $slug ) {
$slug = ( '' !== mc_get_option( 'location_cpt_base' ) ) ? mc_get_option( 'location_cpt_base' ) : $slug;
}
if ( 'mc-hosts' === $slug ) {
$slug = ( '' !== mc_get_option( 'hosts_cpt_base' ) ) ? mc_get_option( 'hosts_cpt_base' ) : $slug;
}

return $slug;
}
Expand Down Expand Up @@ -257,33 +330,29 @@ function mc_posttypes_defaults( $post_content, $post ) {
* Register taxonomies on My Calendar custom post types
*/
function mc_taxonomies() {
$types = mc_post_type();
$enabled = array( 'mc-events' );
if ( is_array( $enabled ) ) {
foreach ( $enabled as $key ) {
$value = $types[ $key ];
/**
* Filter event category taxonomy slug. Default 'mc-event-category'.
*
* @hook mc_event_category_slug
*
* @param {string} $slug Default slug.
*
* @return {string}
*/
$slug = apply_filters( 'mc_event_category_slug', 'mc-event-category' );
register_taxonomy(
'mc-event-category',
// Internal name = machine-readable taxonomy name.
array( $key ),
array(
'hierarchical' => true,
'label' => __( 'Event Categories', 'my-calendar' ),
'query_var' => true,
'rewrite' => array( 'slug' => $slug ),
)
);
}
foreach ( $enabled as $key ) {
/**
* Filter event category taxonomy slug. Default 'mc-event-category'.
*
* @hook mc_event_category_slug
*
* @param {string} $slug Default slug.
*
* @return {string}
*/
$slug = apply_filters( 'mc_event_category_slug', 'mc-event-category' );
register_taxonomy(
'mc-event-category',
// Internal name = machine-readable taxonomy name.
array( $key ),
array(
'hierarchical' => true,
'label' => __( 'Event Categories', 'my-calendar' ),
'query_var' => true,
'rewrite' => array( 'slug' => $slug ),
)
);
}
}

Expand All @@ -296,11 +365,12 @@ function mc_taxonomies() {
*/
function mc_posttypes_messages( $messages ) {
global $post, $post_ID;
$types = mc_post_type();
$enabled = array( 'mc-events', 'mc-locations' );
if ( is_array( $enabled ) ) {
foreach ( $enabled as $key ) {
$value = $types[ $key ];
if ( function_exists( 'mcs_submissions' ) && 'true' === get_option( 'mcs_custom_hosts' ) ) {
$enabled[] = 'mc-hosts';
}
foreach ( $enabled as $key ) {
if ( 'mc-events' === $key ) {
$messages[ $key ] = array(
0 => '', // Unused. Messages start at index 1.
// Translators: URL to view event.
Expand All @@ -314,11 +384,53 @@ function mc_posttypes_messages( $messages ) {
6 => sprintf( __( 'Event published. <a href="%s">View event</a>', 'my-calendar' ), esc_url( get_permalink( $post_ID ) ) ),
7 => sprintf( __( 'Event saved.', 'my-calendar' ) ),
// Translators: URL to preview event.
8 => sprintf( __( 'Event submitted. <a target="_blank" href="%s">Preview event</a>', 'my-calendar' ), esc_url( add_query_arg( 'preview', 'true', get_permalink( $post_ID ) ) ) ),
8 => sprintf( __( 'Event submitted. <a target="_blank" href="%s">Preview Event</a>', 'my-calendar' ), esc_url( add_query_arg( 'preview', 'true', get_permalink( $post_ID ) ) ) ),
// Translators: Date event scheduled to be published, URL to preview event.
9 => sprintf( __( 'Event scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview event</a>', 'my-calendar' ), date_i18n( __( 'M j, Y @ G:i', 'my-calendar' ), strtotime( $post->post_date ) ), esc_url( get_permalink( $post_ID ) ) ),
// Translators: URL to preview event.
10 => sprintf( __( 'Event draft updated. <a target="_blank" href="%s">Preview event</a>', 'my-calendar' ), esc_url( add_query_arg( 'preview', 'true', get_permalink( $post_ID ) ) ) ),
10 => sprintf( __( 'Event draft updated. <a target="_blank" href="%s">Preview Event</a>', 'my-calendar' ), esc_url( add_query_arg( 'preview', 'true', get_permalink( $post_ID ) ) ) ),
);
}
if ( 'mc-locations' === $key ) {
$messages[ $key ] = array(
0 => '', // Unused. Messages start at index 1.
// Translators: URL to view event.
1 => sprintf( __( 'Location updated. <a href="%s">View Location</a>', 'my-calendar' ), esc_url( get_permalink( $post_ID ) ) ),
2 => __( 'Custom field updated.', 'my-calendar' ),
3 => __( 'Custom field deleted.', 'my-calendar' ),
4 => __( 'Location updated.', 'my-calendar' ),
// Translators: %s: date and time of the revision.
5 => isset( $_GET['revision'] ) ? sprintf( __( 'Location restored to revision from %s', 'my-calendar' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
// Translators: URL to view event.
6 => sprintf( __( 'Location published. <a href="%s">View event</a>', 'my-calendar' ), esc_url( get_permalink( $post_ID ) ) ),
7 => sprintf( __( 'Location saved.', 'my-calendar' ) ),
// Translators: URL to preview event.
8 => sprintf( __( 'Location submitted. <a target="_blank" href="%s">Preview Location</a>', 'my-calendar' ), esc_url( add_query_arg( 'preview', 'true', get_permalink( $post_ID ) ) ) ),
// Translators: Date event scheduled to be published, URL to preview event.
9 => sprintf( __( 'Location scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview event</a>', 'my-calendar' ), date_i18n( __( 'M j, Y @ G:i', 'my-calendar' ), strtotime( $post->post_date ) ), esc_url( get_permalink( $post_ID ) ) ),
// Translators: URL to preview event.
10 => sprintf( __( 'Location draft updated. <a target="_blank" href="%s">Preview Location</a>', 'my-calendar' ), esc_url( add_query_arg( 'preview', 'true', get_permalink( $post_ID ) ) ) ),
);
}
if ( 'mc-hosts' === $key ) {
$messages[ $key ] = array(
0 => '', // Unused. Messages start at index 1.
// Translators: URL to view event.
1 => sprintf( __( 'Host updated. <a href="%s">View Host</a>', 'my-calendar' ), esc_url( get_permalink( $post_ID ) ) ),
2 => __( 'Custom field updated.', 'my-calendar' ),
3 => __( 'Custom field deleted.', 'my-calendar' ),
4 => __( 'Host updated.', 'my-calendar' ),
// Translators: %s: date and time of the revision.
5 => isset( $_GET['revision'] ) ? sprintf( __( 'Host restored to revision from %s', 'my-calendar' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
// Translators: URL to view event.
6 => sprintf( __( 'Host published. <a href="%s">View event</a>', 'my-calendar' ), esc_url( get_permalink( $post_ID ) ) ),
7 => sprintf( __( 'Host saved.', 'my-calendar' ) ),
// Translators: URL to preview event.
8 => sprintf( __( 'Host submitted. <a target="_blank" href="%s">Preview host</a>', 'my-calendar' ), esc_url( add_query_arg( 'preview', 'true', get_permalink( $post_ID ) ) ) ),
// Translators: Date event scheduled to be published, URL to preview event.
9 => sprintf( __( 'Host scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview event</a>', 'my-calendar' ), date_i18n( __( 'M j, Y @ G:i', 'my-calendar' ), strtotime( $post->post_date ) ), esc_url( get_permalink( $post_ID ) ) ),
// Translators: URL to preview event.
10 => sprintf( __( 'Host draft updated. <a target="_blank" href="%s">Preview Host</a>', 'my-calendar' ), esc_url( add_query_arg( 'preview', 'true', get_permalink( $post_ID ) ) ) ),
);
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/my-calendar-import.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,7 @@ function mc_format_tribe_event_for_import( $event ) {
'event_author' => $event->post_author,
'event_approved' => mc_convert_post_status_to_approval( $event->post_status ),
'event_category' => $category_ids,
// Can I map the organizer info somehow? Don't want to add new users, for sure...
// Maybe add a new table for organizers?
// Event organizers are only supported in My Calendar Pro.
'event_host' => $event->post_author,
// meta data.
'event_added' => $event->post_date,
Expand Down

0 comments on commit 2c26589

Please sign in to comment.