Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
/*
Plugin Name: Jeero ❤️ Cinema Paimpol
Version: 1.4
Description: Custom functionality for use with the Theater for WordPress plugin
Author: Jeroen Schmit
Author URI: https://slimndap.com
Plugin URI: https://gist.github.com/slimndap/53a2572b1ea7b5a932b9d9221572444f
*/
namespace WPT\Paimpol;
function translate_texts( $translation, $text, $context, $domain ) {
if ( 'theatre' != $domain ) {
return $translation;
}
if ( 'production dates' != $context ) {
return $translation;
}
if ( '%s to %s' == $text ) {
$translation = '%s jusqu\'au %s';
}
if ( 'until %s' == $text ) {
$translation = 'au %s';
}
return $translation;
}
add_filter( 'gettext_with_context', __NAMESPACE__.'\translate_texts', 10, 4 );
function import_custom_fields( $result, $data, $raw, $theater, $subscription ) {
$importer = new \WPT_Importer();
$importer->set( 'slug', 'ticketingcine' );
if ( !empty( $data[ 'production' ][ 'ref' ] ) ) {
$ref = $data[ 'production' ][ 'ref' ];
} else {
$ref = 'e'.$data[ 'ref' ];
}
if ( $wpt_production = $importer->get_production_by_ref( $ref ) ) {
error_log( sprintf( '[%s] Updating custom fields of %s item started.', 'Cinema Paimpol', $theater ) );
if ( !empty( $raw[ 'event' ][ 'director' ] ) ) {
\update_post_meta( $wpt_production->ID, 'realise', $raw[ 'event' ][ 'director' ] );
}
if ( !empty( $raw[ 'event' ][ 'actors' ] ) ) {
\update_post_meta( $wpt_production->ID, 'avec', $raw[ 'event' ][ 'actors' ] );
}
if ( !empty( $raw[ 'event' ][ 'trailer_url' ] ) ) {
\update_post_meta( $wpt_production->ID, 'trailer_url', $raw[ 'event' ][ 'trailer_url' ] );
}
if ( !empty( $raw[ 'event' ][ 'duration' ] ) ) {
$duration_in_minutes = $raw[ 'event' ][ 'duration' ];
$duration = sprintf( '%dh %02d', floor( $duration_in_minutes / 60 ), ( $duration_in_minutes % 60 ) );
\update_post_meta( $wpt_production->ID, 'duree', $duration );
}
}
return $result;
}
add_filter( 'jeero/inbox/process/item/import/calendar=Theater_For_WordPress', __NAMESPACE__.'\import_custom_fields', 11, 5 );
function update_venue( $result, $data, $raw, $theater, $subscription ) {
$importer = new \WPT_Importer();
$importer->set( 'slug', $theater );
if ( $wpt_event = $importer->get_event_by_ref( $data[ 'ref' ] ) ) {
error_log( sprintf( '[%s] Updating venue of %s item started.', 'Cinema Paimpol', $theater ) );
if ( 'VO' == $raw[ 'version' ] ) {
\update_post_meta( $wpt_event->ID, 'venue', 'VOST' );
}
if ( 'VF' == $raw[ 'version' ] ) {
\update_post_meta( $wpt_event->ID, 'venue', 'VF' );
}
}
}
add_filter( 'jeero/inbox/process/item/import/calendar=Theater_For_WordPress', __NAMESPACE__.'\update_venue', 11, 5 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment