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

⚠️ Load later for i18n (Enhance i18n of attendees-email...) #752

Closed
wants to merge 16 commits into from
Closed
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
13 changes: 11 additions & 2 deletions gatherpress.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
* Requires PHP: 7.4
* Requires at least: 6.4
* Text Domain: gatherpress
* Domain Path: /languages
* License: GNU General Public License v2.0 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
*
Expand Down Expand Up @@ -40,5 +39,15 @@
require_once GATHERPRESS_CORE_PATH . '/includes/core/classes/class-autoloader.php';
GatherPress\Core\Autoloader::register();

register_activation_hook( GATHERPRESS_CORE_FILE, array( '\GatherPress\Core\Setup', 'activate_gatherpress_plugin' ) );
register_deactivation_hook( GATHERPRESS_CORE_FILE, array( '\GatherPress\Core\Setup', 'deactivate_gatherpress_plugin' ) );


// Initialize setups.
GatherPress\Core\Setup::get_instance();
add_action(
'plugins_loaded',
array( '\GatherPress\Core\Setup', 'get_instance' )
);


// GatherPress\Core\Setup::get_instance();
43 changes: 29 additions & 14 deletions includes/core/classes/class-rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -448,28 +448,43 @@ public function send_emails( int $post_id, array $send, string $message ): bool
return false;
}

$members = $this->get_members( $send, $post_id );
/* translators: %s: event title. */
$subject = sprintf( __( '📅 %s', 'gatherpress' ), get_the_title( $post_id ) );
$body = Utility::render_template(
sprintf( '%s/includes/templates/admin/emails/event-email.php', GATHERPRESS_CORE_PATH ),
array(
'event_id' => $post_id,
'message' => $message,
),
);
$headers = array( 'Content-Type: text/html; charset=UTF-8' );
$subject = stripslashes_deep( html_entity_decode( $subject, ENT_QUOTES, 'UTF-8' ) );
// Keep the currently logged-in user.
$current_user = wp_get_current_user();

$members = $this->get_members( $send, $post_id );
foreach ( $members as $member ) {
if ( '0' === get_user_meta( $member->ID, 'gatherpress_event_updates_opt_in', true ) ) {
continue;
}

if ( $member->user_email ) {
$to = $member->user_email;
$to = $member->user_email;
$switched_locale = switch_to_user_locale( $member->ID );

// Set the current user to the actual member to mail to,
// to make sure the GatherPress filters for date- and time- format, as well as the users timezone,
// are recognized by the functions inside render_template().
wp_set_current_user( $member->ID );

/* translators: %s: event title. */
$subject = sprintf( __( '📅 %s', 'gatherpress' ), get_the_title( $post_id ) );
carstingaxion marked this conversation as resolved.
Show resolved Hide resolved
$body = Utility::render_template(
sprintf( '%s/includes/templates/admin/emails/event-email.php', GATHERPRESS_CORE_PATH ),
array(
'event_id' => $post_id,
'message' => $message,
),
);
$headers = array( 'Content-Type: text/html; charset=UTF-8' );
$subject = stripslashes_deep( html_entity_decode( $subject, ENT_QUOTES, 'UTF-8' ) );

// Reset the current user to the editor sending the email.
wp_set_current_user( $current_user->ID );

wp_mail( $to, $subject, $body, $headers );

if ( $switched_locale ) {
restore_previous_locale();
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions includes/core/classes/class-setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ protected function instantiate_classes(): void {
* @return void
*/
protected function setup_hooks(): void {
register_activation_hook( GATHERPRESS_CORE_FILE, array( $this, 'activate_gatherpress_plugin' ) );
register_deactivation_hook( GATHERPRESS_CORE_FILE, array( $this, 'deactivate_gatherpress_plugin' ) );
// register_activation_hook( GATHERPRESS_CORE_FILE, array( $this, 'activate_gatherpress_plugin' ) );
// register_deactivation_hook( GATHERPRESS_CORE_FILE, array( $this, 'deactivate_gatherpress_plugin' ) );

add_action( 'init', array( $this, 'maybe_flush_rewrite_rules' ) );
add_action( 'admin_notices', array( $this, 'check_users_can_register' ) );
add_action( 'admin_init', array( $this, 'check_gatherpress_alpha' ) );
add_action( 'admin_notices', array( $this, 'check_gatherpress_alpha' ) );
add_action( 'wp_initialize_site', array( $this, 'on_site_create' ) );

add_filter( 'block_categories_all', array( $this, 'register_gatherpress_block_category' ) );
Expand Down
4 changes: 2 additions & 2 deletions includes/core/classes/class-user.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ public function save_profile_fields( int $user_id ): void {
}

update_user_meta( $user_id, 'gatherpress_event_updates_opt_in', intval( filter_input( INPUT_POST, 'gatherpress_event_updates_opt_in' ) ) );
update_user_meta( $user_id, 'gatherpress_date_format', sanitize_text_field( filter_input( INPUT_POST, 'gatherpress_date_format' ) ) );
update_user_meta( $user_id, 'gatherpress_time_format', sanitize_text_field( filter_input( INPUT_POST, 'gatherpress_time_format' ) ) );
update_user_meta( $user_id, 'gatherpress_date_format', sanitize_text_field( filter_input( INPUT_POST, 'gatherpress_date_format', FILTER_SANITIZE_ADD_SLASHES ) ) );
update_user_meta( $user_id, 'gatherpress_time_format', sanitize_text_field( filter_input( INPUT_POST, 'gatherpress_time_format', FILTER_SANITIZE_ADD_SLASHES ) ) );
update_user_meta( $user_id, 'gatherpress_timezone', sanitize_text_field( filter_input( INPUT_POST, 'gatherpress_timezone' ) ) );
}
}
2 changes: 1 addition & 1 deletion includes/core/classes/class-utility.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public static function unprefix_key( string $key ): string {
* @return array An array of time zones with labels as keys and time zone choices as values.
*/
public static function timezone_choices(): array {
$timezones_raw = explode( PHP_EOL, wp_timezone_choice( 'UTC' ) );
$timezones_raw = explode( PHP_EOL, wp_timezone_choice( 'UTC', get_user_locale() ) );
$timezones_clean = array();
$group = null;

Expand Down
13 changes: 8 additions & 5 deletions includes/templates/admin/emails/event-email.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@
return;
}

$gatherpress_event = new Event( $event_id );
$gatherpress_venue = $gatherpress_event->get_venue_information()['name'];
$gatherpress_event = new Event( $event_id );
$gatherpress_event_image = get_the_post_thumbnail_url( $event_id, 'full' );
$gatherpress_venue = $gatherpress_event->get_venue_information()['name'];

?>

<!DOCTYPE html>
<html lang="en-US">
<html <?php language_attributes(); ?>>
carstingaxion marked this conversation as resolved.
Show resolved Hide resolved
<head>
<title><?php echo wp_kses_post( get_the_title( $event_id ) ); ?></title>
</head>
Expand All @@ -36,8 +37,10 @@
<?php echo wp_kses( nl2br( $message ), array( 'br' => array() ) ); ?>
</p>
<?php endif; ?>
<!-- Feature Image -->
<img src="<?php echo esc_url( get_the_post_thumbnail_url( $event_id, 'full' ) ); ?>" alt="<?php esc_attr_e( 'Event Image', 'gatherpress' ); ?>" style="max-width: 100%;">
<?php if ( $gatherpress_event_image ) : ?>
<!-- Feature Image -->
<img src="<?php echo esc_url( $gatherpress_event_image ); ?>" alt="<?php esc_attr_e( 'Event Image', 'gatherpress' ); ?>" style="max-width: 100%;">
<?php endif; ?>

<!-- Event Title -->
<h1 style="text-align: center;"><?php echo wp_kses_post( get_the_title( $event_id ) ); ?></h1>
Expand Down
3 changes: 2 additions & 1 deletion test/unit/php/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
static function () {
// Manually load our plugin without having to setup the development folder in the correct plugin folder.
require_once __DIR__ . '/../../../gatherpress.php';
}
},
9 // Require file on 9, because the plugin itself is loaded on 10.
);

$gatherpress_bootstrap_instance->start();