Skip to content

Commit

Permalink
Conditional theme activate button text depending of the user plan
Browse files Browse the repository at this point in the history
  • Loading branch information
matiasbenedetto committed Jan 31, 2025
1 parent 2f7791a commit 32e9c8e
Showing 1 changed file with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,9 @@ function wpcom_themes_api_theme_object( $theme ) {
admin_url( 'themes.php' )
);
// If there is no set tier, this is a community theme.
$theme->tier = $theme->tier ?? 'community';
$theme->tier = $theme->tier ?? 'community';
$theme->can_activate_with_current_plan = \A8C\Lib\Themes\Theme_Tiers::is_theme_allowed_on_site( $theme->slug );

return $theme;
}
add_filter( 'wpcom_themes_api_theme_object', 'wpcom_themes_api_theme_object' );
Expand All @@ -271,3 +273,18 @@ function wpcom_themes_tmpl_theme( $tmpl ) {
);
}
add_filter( 'wpcom_themes_tmpl_theme', 'wpcom_themes_tmpl_theme' );

/**
* Filter the theme template to set the activate button text conditional on the theme and site tier.
*
* @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
);
}
add_filter( 'wpcom_themes_tmpl_theme', 'wpcom_themes_tmpl_theme_activate_button' );

0 comments on commit 32e9c8e

Please sign in to comment.