@@ -61,7 +61,7 @@ public function replace_notification_params($text, $post, $language) {
6161 }
6262
6363 public function send_notification ($ post_id ) {
64- error_log ('DEBUG: ' . __METHOD__ . ' - Sending notification for post ID : ' . $ post_id );
64+ error_log ('DEBUG: ' . __METHOD__ . ' - Sending notification for post: ' . $ post_id );
6565
6666 // Fetch the post object since only the ID is passed through scheduling.
6767 $ post = get_post ($ post_id );
@@ -104,13 +104,13 @@ public function send_notification($post_id) {
104104 // 4. Handle multilingual posts
105105 if ($ wpml_installed ) {
106106 // WPML is installed and active.
107- error_log ('DEBUG: ' . __METHOD__ . ' - WPML is installed. Post ID: ' . $ post_id );
107+ error_log ('DEBUG: ' . __METHOD__ . ' - WPML is installed. ' );
108108
109109 // Check if post has been translated
110110 $ has_translations = apply_filters ('wpml_element_has_translations ' , '' , $ post_id , $ post_type );
111111
112112 if ($ has_translations ) {
113- error_log ('DEBUG: ' . __METHOD__ . ' - Post has translations. Post ID: ' . $ post_id );
113+ error_log ('DEBUG: ' . __METHOD__ . ' - Post has translations. ' );
114114
115115 $ trid = apply_filters ('wpml_element_trid ' , NULL , $ post_id , 'post_ ' . $ post_type );
116116 $ translations = apply_filters ('wpml_get_element_translations ' , NULL , $ trid , 'post_ ' . $ post_type );
@@ -128,7 +128,7 @@ public function send_notification($post_id) {
128128 $ is_multilinguage_post = true ;
129129
130130 if ($ is_original ) {
131- error_log ('DEBUG: ' . __METHOD__ . ' - Post is original. Post ID: ' . $ post_id );
131+ error_log ('DEBUG: ' . __METHOD__ . ' - Post is original. ' );
132132
133133 foreach ($ translations as $ lang => $ details ) {
134134 $ default_local = apply_filters ('wpml_current_language ' , null );
@@ -157,7 +157,7 @@ public function send_notification($post_id) {
157157 do_action ('wpml_switch_language ' , $ default_local );
158158 }
159159 } else {
160- error_log ('DEBUG: ' . __METHOD__ . ' - Post is NOT original. Post ID: ' . $ post_id );
160+ error_log ('DEBUG: ' . __METHOD__ . ' - Post is NOT original. ' );
161161
162162 // Don't process non-default languages of posts that have translations
163163 // This is to avoid sending duplicate notifications
@@ -167,7 +167,7 @@ public function send_notification($post_id) {
167167 }
168168
169169 if (!$ is_multilinguage_post ) {
170- error_log ('DEBUG: ' . __METHOD__ . ' - Post is NOT multilingual. Post ID: ' . $ post_id );
170+ error_log ('DEBUG: ' . __METHOD__ . ' - Post is NOT multilingual. ' );
171171
172172 $ excerpt = get_the_excerpt ($ post );
173173 $ payload [] = [
@@ -205,6 +205,7 @@ public function send_notification($post_id) {
205205
206206 $ inapp_payload [] = [
207207 "language " => $ payload_lang ,
208+ "language_code " => $ item ["language_code " ],
208209 "title " => $ item ["title " ],
209210 "content " => $ item ["excerpt " ] . '<br> [cta text=" ' . __ ('Read more ' , 'bcc-login ' ) . '" link=" ' . $ item ["url " ] . '"] ' ,
210211 "notification " => $ item ["excerpt " ] . '<br> [cta text=" ' . __ ('Read more ' , 'bcc-login ' ) . '" link=" ' . $ item ["url " ] . '"] ' //obsolete
@@ -216,6 +217,7 @@ public function send_notification($post_id) {
216217
217218 $ email_payload [] = apply_filters ('bcc_notification_email_payload ' , array (
218219 "language " => $ payload_lang ,
220+ "language_code " => $ item ["language_code " ],
219221 "subject " => $ email_subject ,
220222 "banner " => $ item ["image_url " ] !== false ? $ item ["image_url " ] : null ,
221223 "title " => $ email_title ,
@@ -231,7 +233,7 @@ public function send_notification($post_id) {
231233 restore_previous_locale ();
232234 }
233235
234- error_log ('DEBUG: ' . __METHOD__ . ' - Sending notifications for ' . count ($ email_payload ) . ' languages. Post ID: ' . $ post_id );
236+ error_log ('DEBUG: ' . __METHOD__ . ' - Sending notifications for ' . count ($ email_payload ) . ' languages. ' );
235237
236238 // Send notifications to target groups
237239 if ($ send_email_to_target_groups ) {
@@ -240,20 +242,20 @@ public function send_notification($post_id) {
240242
241243 // Modify email subject to include "Requires action"
242244 foreach ($ email_payload as $ email_item ) {
243- $ email_item ['subject ' ] = apply_filters ( 'wpml_translate_single_string ' , 'Requires action ' , 'bcc-login ' , 'Requires action ' , $ email_item ["language " ] ) . ': ' . $ email_item ['subject ' ];
245+ $ email_item ['subject ' ] = apply_filters ( 'wpml_translate_single_string ' , 'Requires action ' , 'bcc-login ' , 'Requires action ' , $ email_item ["language_code " ] ) . ': ' . $ email_item ['subject ' ];
244246 $ requires_action_email_payload [] = $ email_item ;
245247 }
246248
247249 // Modify notification title to include "Requires action"
248250 foreach ($ inapp_payload as $ inapp_item ) {
249- $ inapp_item ['title ' ] = apply_filters ( 'wpml_translate_single_string ' , 'Requires action ' , 'bcc-login ' , 'Requires action ' , $ inapp_item ["language " ] ) . ': ' . $ inapp_item ['title ' ];
251+ $ inapp_item ['title ' ] = apply_filters ( 'wpml_translate_single_string ' , 'Requires action ' , 'bcc-login ' , 'Requires action ' , $ inapp_item ["language_code " ] ) . ': ' . $ inapp_item ['title ' ];
250252 $ requires_action_inapp_payload [] = $ inapp_item ;
251253 }
252254
253255 $ this ->core_api ->send_notification ($ post_target_groups , 'email ' , 'simpleemail ' , $ requires_action_email_payload );
254256 $ this ->core_api ->send_notification ($ post_target_groups , 'inapp ' , 'simpleinapp ' , $ requires_action_inapp_payload );
255257
256- error_log ('DEBUG: ' . __METHOD__ . ' - Sent notifications for ' . count ($ post_target_groups ) . ' target groups. Post ID: ' . $ post_id );
258+ error_log ('DEBUG: ' . __METHOD__ . ' - Sent notifications for ' . count ($ post_target_groups ) . ' target groups. ' );
257259 }
258260
259261 // Send notifications to visibility groups
@@ -263,29 +265,29 @@ public function send_notification($post_id) {
263265
264266 // Modify email subject to include "For information"
265267 foreach ($ email_payload as $ email_item ) {
266- $ email_item ['subject ' ] = apply_filters ( 'wpml_translate_single_string ' , 'For information ' , 'bcc-login ' , 'For information ' , $ email_item ["language " ] ) . ': ' . $ email_item ['subject ' ];
268+ $ email_item ['subject ' ] = apply_filters ( 'wpml_translate_single_string ' , 'For information ' , 'bcc-login ' , 'For information ' , $ email_item ["language_code " ] ) . ': ' . $ email_item ['subject ' ];
267269 $ for_information_email_payload [] = $ email_item ;
268270 }
269271
270272 // Modify notification title to include "For information"
271273 foreach ($ inapp_payload as $ inapp_item ) {
272- $ inapp_item ['title ' ] = apply_filters ( 'wpml_translate_single_string ' , 'For information ' , 'bcc-login ' , 'For information ' , $ inapp_item ["language " ] ) . ': ' . $ inapp_item ['title ' ];
274+ $ inapp_item ['title ' ] = apply_filters ( 'wpml_translate_single_string ' , 'For information ' , 'bcc-login ' , 'For information ' , $ inapp_item ["language_code " ] ) . ': ' . $ inapp_item ['title ' ];
273275 $ for_information_inapp_payload [] = $ inapp_item ;
274276 }
275277
276278 $ this ->core_api ->send_notification ($ post_visibility_groups , 'email ' , 'simpleemail ' , $ for_information_email_payload );
277279 $ this ->core_api ->send_notification ($ post_visibility_groups , 'inapp ' , 'simpleinapp ' , $ for_information_inapp_payload );
278280
279- error_log ('DEBUG: ' . __METHOD__ . ' - Sent notifications for ' . count ($ post_visibility_groups ) . ' visibility groups. Post ID: ' . $ post_id );
281+ error_log ('DEBUG: ' . __METHOD__ . ' - Sent notifications for ' . count ($ post_visibility_groups ) . ' visibility groups. ' );
280282 }
281283
282284 // Store sent notification data
283285 $ this ->save_notification_data ($ post_id , $ notification_groups );
284286
285- error_log ('DEBUG: ' . __METHOD__ . ' - Sent notifications for ' . count ($ email_payload ) . ' languages. Post ID: ' . $ post_id );
287+ error_log ('DEBUG: ' . __METHOD__ . ' - Sent notifications for ' . count ($ email_payload ) . ' languages. ' );
286288
287289 } else {
288- error_log ('DEBUG: ' . __METHOD__ . ' - Notification payload is EMPTY. Post ID: ' . $ post_id );
290+ error_log ('DEBUG: ' . __METHOD__ . ' - Notification payload is EMPTY. ' );
289291 }
290292 }
291293 else {
0 commit comments