@@ -417,13 +417,7 @@ function my_calendar_edit() {
417
417
echo wp_kses_post ( $ response ['message ' ] );
418
418
}
419
419
for ( $ i = 0 ; $ i < $ count ; $ i ++ ) {
420
- $ mc_output = mc_check_data ( $ action , $ post , $ i );
421
- if ( 'add ' === $ action || 'copy ' === $ action ) {
422
- $ response = my_calendar_save ( $ action , $ mc_output );
423
- $ action = 'add ' ; // After saving, reset action to default.
424
- } else {
425
- $ response = my_calendar_save ( $ action , $ mc_output , (int ) $ post ['event_id ' ] );
426
- }
420
+ $ response = mc_insert_event ( $ action , $ post , $ i );
427
421
echo wp_kses_post ( $ response ['message ' ] );
428
422
}
429
423
if ( isset ( $ post ['ref ' ] ) ) {
@@ -2123,6 +2117,36 @@ function mc_event_accessibility( $form, $data, $label ) {
2123
2117
return $ form ;
2124
2118
}
2125
2119
2120
+ /**
2121
+ * Insert an event. Checks data and saves event to the data, returning a response array.
2122
+ *
2123
+ * @param string $action Type of action being performed.
2124
+ * @param array $post Post data.
2125
+ * @param int $i If multiple events submitted, which index this is.
2126
+ * @param bool $ignore_required Pass 'true' to ignore required fields.
2127
+ *
2128
+ * @return array Modified data and information about approval.
2129
+ */
2130
+ function mc_insert_event ( $ action , $ post , $ i , $ ignore_required = false ) {
2131
+ $ mc_output = mc_check_data ( $ action , $ post , $ i , $ ignore_required );
2132
+ if ( $ mc_output [0 ] ) {
2133
+ if ( 'add ' === $ action || 'copy ' === $ action ) {
2134
+ $ response = my_calendar_save ( $ action , $ mc_output );
2135
+ $ action = 'add ' ; // After saving, reset action to default.
2136
+ } else {
2137
+ $ response = my_calendar_save ( $ action , $ mc_output , (int ) $ post ['event_id ' ] );
2138
+ }
2139
+ } else {
2140
+ $ response = array (
2141
+ 'event_id ' => false ,
2142
+ 'event_post ' => false ,
2143
+ 'message ' => $ mc_output [3 ],
2144
+ );
2145
+ }
2146
+
2147
+ return $ response ;
2148
+ }
2149
+
2126
2150
/**
2127
2151
* Review data submitted and verify.
2128
2152
*
0 commit comments