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

feat(ras-acc): update otp email template #3032

Merged
merged 5 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
5 changes: 5 additions & 0 deletions assets/other-scripts/emails/style.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
.editor-post-title {
display: none;
}

.editor-styles-wrapper .block-editor-block-list__layout .wp-block-button {
margin-left: 0 !important;
margin-right: 0 !important;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added these styles to resolve an issue where the button block was forced to be centered in the editor. This overrides the behavior in the editor, but actual emails will still see centered buttons for some reason. (Aside from our updated OTP default template)

36 changes: 33 additions & 3 deletions includes/emails/class-emails.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,20 +170,50 @@ public static function get_email_payload( $config_name, $placeholders = [] ) {
$email_config = self::get_email_config_by_type( $config_name );
$html = $email_config['html_payload'];
$reply_to_email = $email_config['reply_to_email'];
$placeholders = array_merge(

if ( class_exists( 'WC' ) ) {
$base_address = WC()->countries->get_base_address();
$base_city = WC()->countries->get_base_city();
$base_postcode = WC()->countries->get_base_postcode();

$site_address = sprintf(
// translators: formatted store address where 1 is street address, 2 is city, and 3 is postcode.
__( '%1$s, %2$s %3$s', 'newspack' ),
$base_address,
$base_city,
$base_postcode
);
} else {
$site_address = sprintf(
// translators: formatted store address where 1 is street address, 2 is city, and 3 is postcode.
__( '%1$s, %2$s %3$s', 'newspack' ),
get_option( 'woocommerce_store_address', '' ),
get_option( 'woocommerce_store_city', '' ),
get_option( 'woocommerce_store_postcode', '' )
);
}
$placeholders = array_merge(
[
[
'template' => '*CONTACT_EMAIL*',
'value' => sprintf( '<a href="mailto:%s">%s</a>', $reply_to_email, $reply_to_email ),
],
[
'template' => '*SITE_URL*',
'value' => get_site_url(),
'template' => '*SITE_ADDRESS*',
'value' => $site_address,
],
[
'template' => '*SITE_LOGO*',
'value' => esc_url( wp_get_attachment_url( get_theme_mod( 'custom_logo' ) ) ),
],
[
'template' => '*SITE_TITLE*',
'value' => get_bloginfo( 'name' ),
],
[
'template' => '*SITE_URL*',
'value' => get_bloginfo( 'wpurl' ),
],
],
$placeholders
);
Expand Down
76 changes: 52 additions & 24 deletions includes/reader-activation/class-reader-activation-emails.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,63 +39,91 @@ public static function init() {
* Register email type.
*
* @param array $configs Email types.
*
* @return array Email configs.
*/
public static function add_email_configs( $configs ) {
$available_placeholders = [
[
'label' => __( 'the site base address', 'newspack' ),
'template' => '*SITE_ADDRESS*',
],
[
'label' => __( 'the site title', 'newspack' ),
'template' => '*SITE_TITLE*',
],
[
'label' => __( 'the site url', 'newspack' ),
'template' => '*SITE_URL*',
],
];
$configs[ self::EMAIL_TYPES['VERIFICATION'] ] = [
'name' => self::EMAIL_TYPES['VERIFICATION'],
'label' => __( 'Verification', 'newspack' ),
'description' => __( "Email sent to the reader after they've registered.", 'newspack' ),
'template' => dirname( NEWSPACK_PLUGIN_FILE ) . '/includes/templates/reader-activation-emails/verification.php',
'editor_notice' => __( 'This email will be sent to a reader after they\'ve registered.', 'newspack' ),
'available_placeholders' => [
'available_placeholders' => array_merge(
$available_placeholders,
[
'label' => __( 'the verification link', 'newspack' ),
'template' => '*VERIFICATION_URL*',
],
],
[
'label' => __( 'the verification link', 'newspack' ),
'template' => '*VERIFICATION_URL*',
],
]
),
];
$configs[ self::EMAIL_TYPES['MAGIC_LINK'] ] = [
'name' => self::EMAIL_TYPES['MAGIC_LINK'],
'label' => __( 'Login link', 'newspack' ),
'description' => __( 'Email with a login link.', 'newspack' ),
'template' => dirname( NEWSPACK_PLUGIN_FILE ) . '/includes/templates/reader-activation-emails/magic-link.php',
'editor_notice' => __( 'This email will be sent to a reader when they request a login link.', 'newspack' ),
'available_placeholders' => [
'available_placeholders' => array_merge(
$available_placeholders,
[
'label' => __( 'the one-time password', 'newspack' ),
'template' => '*MAGIC_LINK_OTP*',
],
],
[
'label' => __( 'the one-time password', 'newspack' ),
'template' => '*MAGIC_LINK_OTP*',
],
]
),
];
$configs[ self::EMAIL_TYPES['OTP_AUTH'] ] = [
'name' => self::EMAIL_TYPES['OTP_AUTH'],
'label' => __( 'Login one-time password', 'newspack' ),
'description' => __( 'Email with a one-time password and login link.', 'newspack' ),
'template' => dirname( NEWSPACK_PLUGIN_FILE ) . '/includes/templates/reader-activation-emails/otp.php',
'editor_notice' => __( 'This email will be sent to a reader when they request a login link and a one-time password is available.', 'newspack' ),
'available_placeholders' => [
'available_placeholders' => array_merge(
$available_placeholders,
[
'label' => __( 'the one-time password', 'newspack' ),
'template' => '*MAGIC_LINK_OTP*',
],
[
'label' => __( 'the login link', 'newspack' ),
'template' => '*MAGIC_LINK_URL*',
],
],
[
'label' => __( 'the one-time password', 'newspack' ),
'template' => '*MAGIC_LINK_OTP*',
],
[
'label' => __( 'the login link', 'newspack' ),
'template' => '*MAGIC_LINK_URL*',
],
]
),
];
$configs[ self::EMAIL_TYPES['RESET_PASSWORD'] ] = [
'name' => self::EMAIL_TYPES['RESET_PASSWORD'],
'label' => __( 'Set a New Password', 'newspack' ),
'description' => __( 'Email with password reset link.', 'newspack' ),
'template' => dirname( NEWSPACK_PLUGIN_FILE ) . '/includes/templates/reader-activation-emails/password-reset.php',
'editor_notice' => __( 'This email will be sent to a reader when they request a password creation or reset.', 'newspack' ),
'available_placeholders' => [
'available_placeholders' => array_merge(
$available_placeholders,
[
'label' => __( 'the password reset link', 'newspack' ),
'template' => '*PASSWORD_RESET_LINK*',
],
],
[
'label' => __( 'the password reset link', 'newspack' ),
'template' => '*PASSWORD_RESET_LINK*',
],
]
),
];
$configs[ self::EMAIL_TYPES['DELETE_ACCOUNT'] ] = [
'name' => self::EMAIL_TYPES['DELETE_ACCOUNT'],
Expand Down
401 changes: 214 additions & 187 deletions includes/templates/reader-activation-emails/otp.php

Large diffs are not rendered by default.

49 changes: 49 additions & 0 deletions includes/util.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

namespace Newspack;

use Newspack\Configuration_Managers;

defined( 'ABSPATH' ) || exit;

define( 'NEWSPACK_API_NAMESPACE', 'newspack/v1' );
Expand Down Expand Up @@ -492,3 +494,50 @@ function newspack_get_countries() {
}
return $countries_options;
}

/**
* Get block and html markup for social media services.
*
* @return array An array containing block and html markup for social media services.
*/
function newspack_get_social_markup() {
$cm = Configuration_Managers::configuration_manager_class_for_plugin_slug( 'wordpress_seo' );
$social_urls = [];
if ( ! is_wp_error( $cm ) ) {
$social_urls = [
'facebook' => $cm->get_option( 'facebook_site' ),
'twitter' => $cm->get_option( 'twitter_site' ),
'instagram' => $cm->get_option( 'instagram_url' ),
'youtube' => $cm->get_option( 'youtube_url' ),
];
}

$block_markup = '';
$html_markup = '';
foreach ( $social_urls as $service => $url ) {
if ( ! empty( $url ) && ! is_wp_error( $url ) ) {
$block_markup .= '<!-- wp:social-link {"url":"' . esc_url( $url ) . '","service":"' . esc_attr( $service ) . '"} /-->';
$html_markup .= '<td><![endif]--><table align="left" border="0" cellpadding="0" cellspacing="0" role="presentation" style="float:none;display:inline-table;"><tbody><tr class="social-element"><td style="padding:4px;vertical-align:middle;"><table border="0" cellpadding="0" cellspacing="0" role="presentation" style="background:transparent;border-radius:999px;width:24px;"><tbody><tr><td style="padding:7px;font-size:0;height:24px;vertical-align:middle;width:24px;"><a href="' . esc_url( $url ) . '" target="_blank"><img alt="" height="24" src="*SITE_URL*/wp-content/plugins/newspack-newsletters/assets/white-' . $service . '.png" style="border-radius:999px;display:block;" width="24"></a></td></tr></tbody></table></td></tr></tbody></table><!--[if mso | IE]></td>';
}
}

return [
'block_markup' => $block_markup,
'html_markup' => $html_markup,
];
}

/**
* Get theme primary and secondary colors or defaults if none present.
*
* @return array An array containing primary and secondary colors.
*/
function newspack_get_theme_colors() {
$primary_color = get_theme_mod( 'primary_color_hex', '#3366ff' );
$secondary_color = get_theme_mod( 'secondary_color_hex', '#f0f0f0' );
Copy link
Member

Choose a reason for hiding this comment

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

Newspack Theme functions should be used (like here).

Copy link
Contributor Author

@chickenn00dle chickenn00dle Apr 9, 2024

Choose a reason for hiding this comment

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

Nice! I've fixed this in cc2f298


return [
'primary_color' => $primary_color,
'secondary_color' => $secondary_color,
];
}