Last active
September 9, 2020 14:36
-
-
Save slimndap/e813d03998119e7775025f0a8c004953 to your computer and use it in GitHub Desktop.
A custom WordPress plugin for Rebecca that import RTS shows into a custom post type.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Rebecca RTS Film Import | |
Version: 1.1 | |
Description: A custom WordPress plugin for Rebecca that imports RTS shows into a custom post type. | |
Author: Jeroen Schmit | |
Author URI: https://slimndap.com | |
Plugin URI: https://gist.github.com/slimndap/e813d03998119e7775025f0a8c004953 | |
*/ | |
const REBECCA_POST_TYPE = 'films'; | |
const REBECCA_REF_KEY = 'rebecca_ref_key'; | |
function rebecca_import_films( $result, $data, $raw ) { | |
if ( is_wp_error( $result ) ) { | |
return $result; | |
} | |
$ref = $data[ 'ref' ]; | |
$args = array( | |
'post_status' => 'any', | |
'post_type' => REBECCA_POST_TYPE, | |
'meta_query' => array( | |
array( | |
'key' => REBECCA_REF_KEY, | |
'value' => $ref, | |
), | |
), | |
); | |
$films = get_posts( $args ); | |
$post = array( | |
'post_type' => REBECCA_POST_TYPE, | |
'post_title' => $data[ 'production' ][ 'title' ], | |
'post_content' => '', | |
'post_status' => 'draft', | |
); | |
if ( empty( $films ) ) { | |
$post[ 'post_status' ] = 'draft'; | |
} else { | |
$post[ 'ID' ] = $films[ 0 ]->ID; | |
} | |
$post_id = wp_insert_post( $post, true ); | |
if ( is_wp_error( $post_id ) ) { | |
return $post_id; | |
} | |
update_post_meta( $post_id, REBECCA_REF_KEY, $ref ); | |
update_post_meta( $post_id, 'ticket_url', $data[ 'tickets_url' ] ); | |
update_post_meta( $post_id, 'start', $data[ 'start' ] ); | |
update_post_meta( $post_id, 'end', $data[ 'end' ] ); | |
update_post_meta( $post_id, 'venue', $data[ 'venue' ][ 'title' ] ); | |
return $result; | |
} | |
add_filter( 'jeero/inbox/process/item/import/theater=rts', 'rebecca_import_films', 10, 3 ); | |
function rebecca_register_post_type() { | |
if ( post_type_exists( REBECCA_POST_TYPE ) ) { | |
return; | |
} | |
register_post_type( REBECCA_POST_TYPE, array( | |
'public' => true, | |
'supports' => array( | |
'title', 'editor', 'custom-fields', | |
), | |
) ); | |
} | |
add_action( 'init', 'rebecca_register_post_type' ); | |
function rebecca_get_tickets_url( ) { | |
if ( !is_singular( REBECCA_POST_TYPE ) ) { | |
return; | |
} | |
$tickets_url = get_post_meta( get_the_id(), 'ticket_url', true ); | |
if ( empty( $tickets_url ) ) { | |
return; | |
} | |
ob_start(); | |
?><a href="<?php echo $tickets_url; ?>" class="tickets_url">Tickets</a><?php | |
return ob_get_clean(); | |
} | |
add_shortcode( 'tickets_url', 'rebecca_get_tickets_url' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment