@@ -119,16 +119,23 @@ public static function save_post_queue(int $queue_id, \WP_Post $post, bool $upda
119119 )
120120 );
121121
122- $ site_id = wp_insert_post (array (
123- 'post_type ' => 'site ' ,
124- 'post_title ' => esc_html ($ company_name ),
125- 'post_name ' => $ space_name ,
126- 'post_status ' => 'publish ' ,
127- 'post_author ' => $ site_owner ->ID ,
128- ));
129-
130- app_log ("Site entry for {$ company_name } created with ID {$ site_id }" );
122+ $ site_exists = get_page_by_path ($ space_name , OBJECT , 'site ' );
123+ if (!$ site_exists ) {
124+ $ site_id = wp_insert_post (array (
125+ 'post_type ' => 'site ' ,
126+ 'post_title ' => esc_html ($ company_name ),
127+ 'post_name ' => $ space_name ,
128+ 'post_status ' => 'publish ' ,
129+ 'post_author ' => $ site_owner ->ID ,
130+ ));
131+
132+ app_log ("Site entry for {$ company_name } created with ID {$ site_id }" );
133+ } else {
134+ $ site_id = $ site_exists ->ID ;
135+ }
136+
131137 update_field ('site_uri ' , $ wp_home , $ site_id );
138+
132139 foreach ($ variables as $ key => $ variable ) {
133140 app_log ("Updating {$ key } for site {$ company_name }" );
134141 update_field ($ key , $ variable , $ site_id );
0 commit comments