Skip to content

Commit

Permalink
Merge pull request #4499 from buddyboss/PROD-7938
Browse files Browse the repository at this point in the history
PROD-7938 - Add upgrade notice for platform pro - when platform pro is not installed/enable/not valid license
  • Loading branch information
KartikSuthar authored Oct 2, 2024
2 parents 5e51f2b + 9fb5de6 commit 7d54b71
Show file tree
Hide file tree
Showing 9 changed files with 364 additions and 3 deletions.
83 changes: 83 additions & 0 deletions src/bp-core/admin/bp-core-admin-actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -454,3 +454,86 @@ function bb_core_settings_saved_notice() {
}

add_action( 'bp_admin_notices', 'bb_core_settings_saved_notice', 1010 );

/**
* Display an upgrade notice for free users on BuddyBoss screens.
*
* @since BuddyBoss [BBVERSION]
*
* @return void
*/
function bb_pro_upgrade_notice() {
// If a user is not on a relevant screen, don't show the notice.
$current_screen = get_current_screen();
if (
! $current_screen ||
(
false === strpos( $current_screen->parent_base, 'buddyboss' ) &&
false === strpos( $current_screen->id, 'edit-bpm_category' ) &&
false === strpos( $current_screen->id, 'buddyboss_fonts' )
)
) {
unset( $current_screen );

return;
}

// If a user has dismissed the notice, has a valid Pro license, don't show the notice.
$dismissed = get_transient( 'bb_pro_upgrade_notice_dismissed' );
$is_pro_license_valid = function_exists( 'bb_platform_pro' ) && bbp_pro_is_license_valid();
if ( $dismissed || $is_pro_license_valid ) {
unset( $current_screen, $dismissed, $is_pro_license_valid );

return;
}

unset( $current_screen, $dismissed, $is_pro_license_valid );
?>
<div class="bb-upgrade-notice bb-is-dismissible" data-nonce="<?php echo esc_attr( wp_create_nonce( 'bb-upgrade-notice-nonce' ) ); ?>">
<span class="bb-upgrade-point">
<i class="bb-icon-f bb-icon-brand-buddyboss"></i>
<?php
echo sprintf(
/* translators: %1$s is the main text, %2$s is the URL, %3$s is the link text */
'%1$s <a href="%2$s" class="bb-upgrade-notice__link" target="_blank">%3$s</a>',
__( 'Upgrade to pro and unlock more exciting community features!', 'buddyboss' ),
esc_url( 'https://www.buddyboss.com/bbwebupgrade' ),
__( 'Upgrade to Pro', 'buddyboss' )
);
?>
</span>
<button type="button" class="bb-dismiss-upgrade-notice">
<span class="screen-reader-text">
<?php esc_html_e( 'Dismiss this notice.', 'buddyboss' ); ?>
</span>
</button>
</div>
<?php
}

add_action( 'admin_notices', 'bb_pro_upgrade_notice', 1 );

/**
* Handles the dismissal of the "Upgrade to Pro" notice.
*
* @since BuddyBoss [BBVERSION]
*
* @return void
*/
function bb_upgrade_dismiss_notice() {
$bb_upgrade_nonce = bb_filter_input_string( INPUT_POST, 'nonce' );

// Nonce check!
if ( empty( $bb_upgrade_nonce ) || ! wp_verify_nonce( $bb_upgrade_nonce, 'bb-upgrade-notice-nonce' ) ) {
wp_send_json_error( array( 'error' => __( 'Sorry, something goes wrong please try again.', 'buddyboss' ) ) );
unset( $bb_upgrade_nonce );

}

set_transient( "bb_pro_upgrade_notice_dismissed", true, DAY_IN_SECONDS );

wp_send_json_success();
unset( $bb_upgrade_nonce );
}

add_action( 'wp_ajax_bb_upgrade_dismiss_notice', 'bb_upgrade_dismiss_notice' );
76 changes: 76 additions & 0 deletions src/bp-core/admin/css/common-rtl.css
Original file line number Diff line number Diff line change
Expand Up @@ -4792,6 +4792,82 @@ h1.bb-advance-heading {
color: #e0613c;
}

.bb-upgrade-notice {
background-color: #F6EFE8;
padding: 8px;
text-align: center;
border-bottom: 1px solid #C5BFBA;
margin-right: -20px;
position: relative;
}

.bb-upgrade-notice .bb-upgrade-point {
font-size: 1rem;
font-weight: 500;
color: #000;
display: flex;
align-items: center;
justify-content: center;
}

.bb-upgrade-notice .bb-upgrade-point i {
font-size: 24px;
margin-left: 4px;
}

.bb-upgrade-notice .bb-upgrade-point .bb-upgrade-notice__link {
font-weight: 600;
color: inherit;
margin-right: 16px;
}

.bb-upgrade-notice .bb-upgrade-point .bb-upgrade-notice__link:focus {
box-shadow: none;
}

.bb-upgrade-notice .bb-dismiss-upgrade-notice {
display: inline-block;
width: 20px;
height: 20px;
position: absolute;
color: rgba(0, 0, 0, 0.6);
left: 8px;
top: 50%;
transform: translateY(-50%);
border: 0;
padding: 0;
outline: none;
cursor: pointer;
}

.bb-upgrade-notice .bb-dismiss-upgrade-notice:before {
content: '\e828';
font-family: "bb-icons";
font-style: normal;
display: inline-block;
text-decoration: inherit;
width: 20px;
height: 20px;
font-size: 20px;
text-decoration: none;
}

.bb-upgrade-notice .bb-dismiss-upgrade-notice:hover {
color: black;
}

.bb-upgrade-notice .bb-dismiss-upgrade-notice:focus, .bb-upgrade-notice .bb-dismiss-upgrade-notice:active {
outline: 0;
box-shadow: none;
}

@media screen and (max-width: 768px) {
.bb-upgrade-notice {
margin: 0 -10px 0 0;
padding-left: 35px;
}
}

.wrap.wrap--performance > h2:first-child {
font-weight: 500;
font-size: 24px;
Expand Down
2 changes: 1 addition & 1 deletion src/bp-core/admin/css/common-rtl.min.css

Large diffs are not rendered by default.

76 changes: 76 additions & 0 deletions src/bp-core/admin/css/common.css
Original file line number Diff line number Diff line change
Expand Up @@ -4792,6 +4792,82 @@ h1.bb-advance-heading {
color: #e0613c;
}

.bb-upgrade-notice {
background-color: #F6EFE8;
padding: 8px;
text-align: center;
border-bottom: 1px solid #C5BFBA;
margin-left: -20px;
position: relative;
}

.bb-upgrade-notice .bb-upgrade-point {
font-size: 1rem;
font-weight: 500;
color: #000;
display: flex;
align-items: center;
justify-content: center;
}

.bb-upgrade-notice .bb-upgrade-point i {
font-size: 24px;
margin-right: 4px;
}

.bb-upgrade-notice .bb-upgrade-point .bb-upgrade-notice__link {
font-weight: 600;
color: inherit;
margin-left: 16px;
}

.bb-upgrade-notice .bb-upgrade-point .bb-upgrade-notice__link:focus {
box-shadow: none;
}

.bb-upgrade-notice .bb-dismiss-upgrade-notice {
display: inline-block;
width: 20px;
height: 20px;
position: absolute;
color: rgba(0, 0, 0, 0.6);
right: 8px;
top: 50%;
transform: translateY(-50%);
border: 0;
padding: 0;
outline: none;
cursor: pointer;
}

.bb-upgrade-notice .bb-dismiss-upgrade-notice:before {
content: '\e828';
font-family: "bb-icons";
font-style: normal;
display: inline-block;
text-decoration: inherit;
width: 20px;
height: 20px;
font-size: 20px;
text-decoration: none;
}

.bb-upgrade-notice .bb-dismiss-upgrade-notice:hover {
color: black;
}

.bb-upgrade-notice .bb-dismiss-upgrade-notice:focus, .bb-upgrade-notice .bb-dismiss-upgrade-notice:active {
outline: 0;
box-shadow: none;
}

@media screen and (max-width: 768px) {
.bb-upgrade-notice {
margin: 0 0 0 -10px;
padding-right: 35px;
}
}

.wrap.wrap--performance > h2:first-child {
font-weight: 500;
font-size: 24px;
Expand Down
2 changes: 1 addition & 1 deletion src/bp-core/admin/css/common.min.css

Large diffs are not rendered by default.

31 changes: 31 additions & 0 deletions src/bp-core/admin/js/settings-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -2847,6 +2847,37 @@ window.bp = window.bp || {};
validateDuplicateEmailRuleEntry( e );
} );

/**
* Handles the dismissal of the "Upgrade to Pro" notice via AJAX.
*
* @param {Event} e The click event triggered when the dismiss button is clicked.
*/
$( document ).on( 'click', '.bb-dismiss-upgrade-notice', function ( e ) {
e.preventDefault();

// Retrieve the nonce from the notice element.
var nonce = jQuery( this ).closest( '.bb-upgrade-notice' ).data( 'nonce' );
if ( 'undefined' === typeof nonce ) {
return;
}

$.ajax(
{
type : 'POST',
url : BP_ADMIN.ajax_url,
data : {
'action': 'bb_upgrade_dismiss_notice',
'nonce' : nonce
},
success: function ( response ) {
if ( response.success ) {
jQuery( '.bb-upgrade-notice' ).fadeOut();
}
},
}
);
} );

function bb_unique( array ) {
return $.grep( array, function ( el, index ) {
return index === $.inArray( el, array );
Expand Down
2 changes: 1 addition & 1 deletion src/bp-core/admin/js/settings-page.min.js

Large diffs are not rendered by default.

75 changes: 75 additions & 0 deletions src/bp-core/admin/sass/common.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5129,6 +5129,81 @@ h1.bb-advance-heading {
}
}

.bb-upgrade-notice {
background-color: #F6EFE8;
padding: 8px;
text-align: center;
border-bottom: 1px solid #C5BFBA;
margin-left: -20px;
position: relative;

.bb-upgrade-point {
font-size: 1rem;
font-weight: 500;
color: #000;
display: flex;
align-items: center;
justify-content: center;

i {
font-size: 24px;
margin-right: 4px;
}

.bb-upgrade-notice__link {
font-weight: 600;
color: inherit;
margin-left: 16px;

&:focus {
box-shadow: none;
}
}
}

.bb-dismiss-upgrade-notice {
display: inline-block;
width: 20px;
height: 20px;
position: absolute;
color: rgba(0, 0, 0, 0.6);
right: 8px;
top: 50%;
transform: translateY(-50%);
border: 0;
padding: 0;
outline: none;
cursor: pointer;

&:before {
content: '\e828';
font-family: "bb-icons";
font-style: normal;
display: inline-block;
text-decoration: inherit;
width: 20px;
height: 20px;
font-size: 20px;
text-decoration: none;
}

&:hover {
color: rgba(0, 0, 0, 1);
}

&:focus,
&:active {
outline: 0;
box-shadow: none;
}
}

@media screen and (max-width: 768px) {
margin: 0 0 0 -10px;
padding-right: 35px;
}
}

.wrap.wrap--performance {

> h2:first-child {
Expand Down
20 changes: 20 additions & 0 deletions src/bp-core/bp-core-actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -1205,3 +1205,23 @@ function bb_load_web_performance_tester() {
bb_web_performance_tester();
}
}

/**
* Delete the upgrade notice transient when administrators logout.
*
* @since BuddyBoss [BBVERSION]
*
* @param int $user_id The ID of the user who is logging out.
*
* @return void
*/
function bb_reset_upgrade_notice_on_admin_logut( $user_id ) {
$user = get_userdata( $user_id );
if ( user_can( $user, 'manage_options' ) ) {
delete_transient( 'bb_pro_upgrade_notice_dismissed' );
}

unset( $user );
}

add_action( 'wp_logout', 'bb_reset_upgrade_notice_on_admin_logut' );

0 comments on commit 7d54b71

Please sign in to comment.