diff --git a/README.txt b/README.txt index 3e7b63f..f9be0a9 100644 --- a/README.txt +++ b/README.txt @@ -3,7 +3,7 @@ Contributors: jaredcobb Tags: ccb, church, api, chms Requires at least: 4.6.0 Tested up to: 4.9.4 -Stable tag: 1.0.3 +Stable tag: 1.0.4 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html @@ -61,6 +61,9 @@ You'll need to ensure your [group settings](https://churchcommunitybuilder.force == Changelog == += 1.0.4 = +* Adds the CCB event id (as post meta) to each instance of a recurring event. This allows individual instances of a recurring event to be associated with each other in WordPress. + = 1.0.3 = * Featured images associated with synchronized posts now also get deleted when the post is deleted * A new filter `ccb_core_synchronizer_delete_attachment` has been created to optionally overwrite the default behavior of deleting attachments when posts are deleted diff --git a/ccb-core.php b/ccb-core.php index 2490392..450ab69 100644 --- a/ccb-core.php +++ b/ccb-core.php @@ -10,7 +10,7 @@ * Plugin Name: Church Community Builder Core API * Plugin URI: https://www.wpccb.com * Description: A plugin to provide a core integration of the Church Community Builder API into WordPress custom post types - * Version: 1.0.3 + * Version: 1.0.4 * Author: Jared Cobb * Author URI: https://www.jaredcobb.com/ * License: GPL-2.0+ @@ -27,7 +27,7 @@ define( 'CCB_CORE_PATH', plugin_dir_path( __FILE__ ) ); define( 'CCB_CORE_URL', plugin_dir_url( __FILE__ ) ); define( 'CCB_CORE_BASENAME', plugin_basename( __FILE__ ) ); -define( 'CCB_CORE_VERSION', '1.0.3' ); +define( 'CCB_CORE_VERSION', '1.0.4' ); // Check minimum requirements before proceeding. require_once CCB_CORE_PATH . 'includes/class-ccb-core-requirements.php'; diff --git a/includes/post-types/class-ccb-core-calendar.php b/includes/post-types/class-ccb-core-calendar.php index 21a23de..43b47a5 100644 --- a/includes/post-types/class-ccb-core-calendar.php +++ b/includes/post-types/class-ccb-core-calendar.php @@ -29,6 +29,9 @@ class CCB_Core_Calendar extends CCB_Core_CPT { * Initialize the class */ public function __construct() { + // Add the CCB event id as post meta onto each instance of the event. + add_action( 'ccb_core_after_insert_update_post', [ $this, 'update_event_id' ], 10, 5 ); + $options = CCB_Core_Helpers::instance()->get_options(); $this->enabled = ! empty( $options['calendar_enabled'] ) ? true : false; parent::__construct(); @@ -297,6 +300,33 @@ public function get_post_api_map( $maps ) { return $maps; } + /** + * Parses the CCB event id from the `name` node and + * saves it as post meta. + * + * @since 1.0.4 + * + * @param SimpleXML $entity The entity object. + * @param array $settings The settings array for the import. + * @param array $args The `wp_insert_post` args. + * @param string $post_type The current post type. + * @param int $post_id The WordPress post id of this post. + * @return bool + */ + public function update_event_id( $entity, $settings, $args, $post_type, $post_id ) { + if ( ! empty( $entity->event_name ) ) { + foreach ( $entity->event_name->attributes() as $key => $value ) { + if ( 'ccb_id' === $key ) { + $event_id = (int) $value; + if ( $event_id ) { + return update_post_meta( $post_id, 'event_id', $event_id ); + } + } + } + } + return false; + } + /** * Returns a standardized configuration array of * start and end dates to be used by the API call.