Advertisement
verygoodplugins

Untitled

Apr 7th, 2020
356
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.00 KB | None | 0 0
  1. <?php
  2.  
  3. // Runs on any post with post type "event" and updates the "Event" custom object with values Title and EventDate
  4.  
  5. function create_update_event_object( $post_id, $post, $update ) {
  6.  
  7.     if ( $post->post_type != 'event' || ! function_exists( 'wp_fusion' ) ) {
  8.         return;
  9.     }
  10.  
  11.     add_filter( 'wpf_crm_object_type', function() {
  12.         return 10011;
  13.     } );
  14.  
  15.     $event_data = array(
  16.         'Title'     => $post->post_title,
  17.         'EventDate' => get_post_meta( $post_id, 'event_date', true )
  18.     );
  19.  
  20.     if ( $update == false ) {
  21.  
  22.         // New event
  23.  
  24.         $object_id = wp_fusion()->crm->add_contact( $event_data, false );
  25.  
  26.         if ( ! is_wp_error( $object_id ) ) {
  27.             update_post_meta( $post_id, wp_fusion()->crm->slug . '_event_id', $object_id );
  28.         }
  29.  
  30.     } else {
  31.  
  32.         // Existing event
  33.  
  34.         $object_id = get_post_meta( $post_id, wp_fusion()->crm->slug . '_event_id', true );
  35.  
  36.         wp_fusion()->crm->update_contact( $object_id, $event_data, false );
  37.  
  38.     }
  39.  
  40. }
  41.  
  42. add_action( 'wp_insert_post', 'create_update_event_object', 10, 3 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement