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

Fix localised WordCamp logs #1431

Open
wants to merge 2 commits into
base: production
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -256,19 +256,6 @@ public function metabox_status( $post ) {
*/
abstract public static function get_edit_capability();

/**
* Filter: Set the locale to en_US.
*
* For some purposes, such as internal logging, strings that would normally be translated to the
* current user's locale should be in English, so that other users who may not share the same
* locale can read them.
*
* @return string
*/
public function set_locale_to_en_us() {
return 'en_US';
}

/**
* Log when the post status changes
*
Expand All @@ -286,7 +273,7 @@ public function log_status_changes( $new_status, $old_status, $post ) {
}

// Ensure status labels are in English.
add_filter( 'locale', array( $this, 'set_locale_to_en_us' ) );
$locale_switched = switch_to_locale( 'en_US' );

$old_status = get_post_status_object( $old_status );
$new_status = get_post_status_object( $new_status );
Expand All @@ -308,7 +295,9 @@ public function log_status_changes( $new_status, $old_status, $post ) {
}

// Remove the temporary locale change.
remove_filter( 'locale', array( $this, 'set_locale_to_en_us' ) );
if ( $locale_switched ) {
restore_previous_locale();
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public function __construct() {
add_action( 'plugins_loaded', array( $this, 'includes' ) );
add_action( 'init', array( $this, 'register_post_types' ) );
add_action( 'init', array( $this, 'register_post_statuses' ) );
add_action( 'change_locale', array( $this, 'register_post_statuses' ) ); // Re-register them when the locale changes, to have localised statuses.
Comment on lines 18 to +20
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
add_action( 'init', array( $this, 'register_post_types' ) );
add_action( 'init', array( $this, 'register_post_statuses' ) );
add_action( 'change_locale', array( $this, 'register_post_statuses' ) ); // Re-register them when the locale changes, to have localised statuses.
add_action( 'init', array( $this, 'register_post_types' ) );
add_action( 'init', array( $this, 'register_post_statuses' ) );
// Re-register them when the locale changes, to have localised statuses.
add_action( 'change_locale', array( $this, 'register_post_types' ) );
add_action( 'change_locale', array( $this, 'register_post_statuses' ) );

The post types can probably be reloaded too, to ensure they're properly translated, but I don't think they're used anywhere in logs so are likely less problematic.

add_filter( 'pre_get_posts', array( $this, 'query_public_statuses_on_archives' ) );
add_filter( 'cron_schedules', array( $this, 'add_weekly_cron_interval' ) );
}
Expand Down
Loading