Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change local #170

Merged
merged 7 commits into from
Jul 2, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions plugins/bcc-login/includes/class-bcc-notifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@ function __construct( BCC_Login_Settings $settings, BCC_Coreapi_Client $core_api

}

// NB: This does not run if a post is published without first being saved as a draft.
//wpml plugin
$active_plugins = get_option('active_plugins');
$wpml_plugin = 'sitepress-multilingual-cms/sitepress.php';


// NB: This does not run if a post is published without first being saved as a draft, and the wpml plugin is installed
public function on_post_status_transition( $new_status, $old_status, $post ) {
if ('publish' === $new_status && 'publish' !== $old_status && in_array( $post->post_type, $this->settings->notification_post_types )) {
if ('publish' === $new_status && 'publish' !== $old_status && in_array( $post->post_type, $this->settings->notification_post_types ) && in_array($wpml_plugin, $active_plugins)) {
Oz-Okun marked this conversation as resolved.
Show resolved Hide resolved
if ($this->settings->notification_delay > 0) {
wp_schedule_single_event( time() + $this->settings->notification_delay, 'bcc_send_scheduled_notification', array( $post->ID ) );
} else {
Expand Down Expand Up @@ -90,12 +95,13 @@ public function send_notification( $post_id ) {

if ($is_orginal) {
foreach ( $translations as $lang => $details ) {
$default_local = apply_filters('wpml_current_language', null);
$translation = get_post($details->element_id);
$language_details = apply_filters( 'wpml_post_language_details', NULL, $translation->ID );
$locale = $language_details["locale"];
$language_code = str_replace('_', '-', $locale);
$excerpt = get_the_excerpt($translation);
switch_to_locale($locale);
do_action('wpml_switch_language', $language_details["language_code"]);
Oz-Okun marked this conversation as resolved.
Show resolved Hide resolved
if ($translation->post_status == 'publish') {
$payload[] = [
'post' => $translation,
Expand All @@ -107,7 +113,7 @@ public function send_notification( $post_id ) {
'date' => str_replace(' ','T',$translation->post_date_gmt) . 'Z'
];
}
restore_previous_locale();
do_action('wpml_switch_language', $default_local);
Oz-Okun marked this conversation as resolved.
Show resolved Hide resolved
}
} else {
// Don't process non-default languages of posts that have translations
Expand Down
Loading