Skip to content

Commit

Permalink
Update "Install" button text to "Upgrade to install", ensure only but…
Browse files Browse the repository at this point in the history
…ton text is replaced
  • Loading branch information
ryelle committed Feb 4, 2025
1 parent 4fb5586 commit 563f07a
Showing 1 changed file with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ function wpcom_themes_ajax_save_wporg_username() {
*/
function wpcom_themes_api_theme_object( $theme ) {
// If there is no set tier, this is a community theme.
$theme->tier = $theme->tier ?? 'community';
$theme->tier = $theme->tier ?? 'community';

// Use the same "activate" logic for both install and activate URLs.
$theme->activate_url = wpcom_themes_get_activation_url( $theme );
Expand All @@ -262,27 +262,34 @@ function wpcom_themes_api_theme_object( $theme ) {
* @param string $tmpl The mustache template for theme cards.
* @return string Updated template.
*/
function wpcom_themes_tmpl_theme( $tmpl ) {
function wpcom_themes_tmpl_theme_plan_tag( $tmpl ) {
return str_replace(
'<h3 class="theme-name">{{ data.name }}</h3>',
'<h3 class="theme-name">{{ data.name }}</h3> <span>{{ data.tier }}</span>',
$tmpl
);
}
add_filter( 'wpcom_themes_tmpl_theme', 'wpcom_themes_tmpl_theme' );
add_filter( 'wpcom_themes_tmpl_theme', 'wpcom_themes_tmpl_theme_plan_tag' );

/**
* Filter the theme template to set the activate button text conditional on the theme and site tier.
* Filter the theme template to set the activate & install button text based on the user's plan.
*
* @param string $tmpl The mustache template for theme cards.
* @return string Updated template.
*/
function wpcom_themes_tmpl_theme_activate_button( $tmpl ) {
return str_replace(
__( 'Activate', 'jetpack-mu-wpcom' ),
'{{{ data.can_activate_with_current_plan ? "' . __( 'Activate', 'jetpack-mu-wpcom' ) . '" : "' . __( 'Upgrade to activate', 'jetpack-mu-wpcom' ) . '" }}}',
$tmpl
$button_labels = array(
__( 'Activate', 'jetpack-mu-wpcom' ) => '{{{ data.can_activate_with_current_plan ? "' . __( 'Activate', 'jetpack-mu-wpcom' ) . '" : "' . __( 'Upgrade to activate', 'jetpack-mu-wpcom' ) . '" }}}',
// No need to check permissions here, this screen is only on Simple sites.
__( 'Install', 'jetpack-mu-wpcom' ) => __( 'Upgrade to install', 'jetpack-mu-wpcom' ),

Check warning on line 284 in projects/packages/jetpack-mu-wpcom/src/features/wpcom-themes/wpcom-themes.php

View workflow job for this annotation

GitHub Actions / PHP Code Sniffer (non-excluded files only)

Array double arrow not aligned correctly; expected 2 space(s) between ")" and double arrow, but found 1. (WordPress.Arrays.MultipleStatementAlignment.DoubleArrowNotAligned)
);

foreach ( $button_labels as $search => $replace ) {
// Ensure the text is only replaced when in a button (link).
$tmpl = str_replace( '>' . $search . '</a>', '>' . $replace . '</a>', $tmpl );
}

return $tmpl;
}
add_filter( 'wpcom_themes_tmpl_theme', 'wpcom_themes_tmpl_theme_activate_button' );

Expand Down

0 comments on commit 563f07a

Please sign in to comment.