Skip to content

Commit

Permalink
revised welcome sequence
Browse files Browse the repository at this point in the history
  • Loading branch information
itthinx committed Nov 29, 2024
1 parent 721b0c0 commit 166c83f
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 22 deletions.
2 changes: 1 addition & 1 deletion changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* WordPress 6.7 compatible.
* Adds fixes for "Translation loading for the ... domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. ..." PHP notices raised as of WordPress 6.7.0 in certain scenarios when translations are requested before the init or the after_setup_theme action have fired.
* Avoids a potential infinite recursion when evaluating post counts.
* Make sure to present welcome screen only when Groups is activated alone and not in bulk.
* Restrict the redirect to the welcome screen so it happens only when Groups is activated alone and not in bulk. Updates do not trigger a redirect. A legacy update does not trigger a redirect and now only causes an admin notice to be displayed temporarily.

= 3.3.0 =
* WordPress 6.7 compatible.
Expand Down
61 changes: 41 additions & 20 deletions lib/admin/class-groups-admin-welcome.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public static function init() {
add_action( 'admin_head', array( __CLASS__, 'admin_head' ) );
add_action( 'admin_init', array( __CLASS__, 'admin_init' ) );
add_filter( 'plugin_row_meta', array( __CLASS__, 'plugin_row_meta' ), 10, 2 );
add_action( 'admin_notices', array( __CLASS__, 'admin_notices' ) );
}

/**
Expand All @@ -58,6 +59,40 @@ public static function admin_head() {
remove_submenu_page( 'index.php', 'groups-welcome' );
}

/**
* Output admin notices.
*
* @since 3.3.1
*/
public static function admin_notices() {
$is_updated_legacy = get_transient( 'groups_plugin_updated_legacy' );
if ( $is_updated_legacy ) {
$message = '<p>';
$message .= '<strong>';
$message .= esc_html__( 'Important', 'groups' );
$message .= '</strong>';
$message .= ' ';
$message .= esc_html__( 'It seems that you have updated from Groups 1.x where access restrictions were based on capabilities.', 'groups' );
$message .= '</p>';
$message .= '<p>';
$message .= sprintf(
esc_html__( 'Please make sure to read the %1$sMigration Guide%2$s.', 'groups' ),
'<a href="https://docs.itthinx.com/document/groups/migration-guide/">',
'</a>'
);
$message .= '</p>';
wp_admin_notice(
$message,
array(
'type' => 'info',
'dismissible' => true,
'additional_classes' => array( 'inline', 'notice-alt' ),
'attributes' => array( 'data-slug' => 'plugin-slug' )
)
);
}
}

/**
* Checks if the welcome screen should be shown and redirected to.
*/
Expand All @@ -74,7 +109,8 @@ public static function admin_init() {
}
$groups_welcome_dismiss = Groups_Options::get_user_option( 'groups-welcome-dismiss', '' );
if ( version_compare( $groups_version, $groups_welcome_dismiss ) > 0 ) {
if ( get_transient( 'groups_plugin_activated' ) || get_transient( 'groups_plugin_updated_legacy' ) ) {
// @see Groups_Controller::activate()
if ( get_transient( 'groups_plugin_activated' ) ) {
$doing_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX;
$doing_cron = defined( 'DOING_CRON' ) && DOING_CRON;
// we'll delete the transients in the welcome screen handler
Expand All @@ -83,19 +119,14 @@ public static function admin_init() {
!$doing_cron &&
( empty( $_GET['page'] ) || $_GET['page'] !== 'groups-welcome' ) &&
!is_network_admin() &&
isset( $_REQUEST['activate'] ) && // @since 3.3.1 must be single activation
!isset( $_REQUEST['activate-multi'] ) &&
!isset( $_REQUEST['activate-selected'] ) && // @since 3.3.1 must not be multiple activation
!isset( $_REQUEST['update-selected'] ) && // @since 3.3.1 must not be multiple update
Groups_User::current_user_can( GROUPS_ACCESS_GROUPS ) &&
apply_filters( 'groups_welcome_show', true )
) {
wp_safe_redirect( admin_url( 'index.php?page=groups-welcome' ) );
exit;
} else {
// @since 3.3.1 remove transients as we don't want to trigger a redirect in any other case than direct activation of the Groups plugin, also see above
// @since 3.3.1 remove the transient as we don't want to trigger a redirect in any other case than direct activation of the Groups plugin
delete_transient( 'groups_plugin_activated' );
delete_transient( 'groups_plugin_updated_legacy' );
}
}
}
Expand Down Expand Up @@ -133,7 +164,9 @@ public static function groups_welcome() {
wp_enqueue_style( 'groups_admin' );

delete_transient( 'groups_plugin_activated' );
$legacy_update = get_transient( 'groups_plugin_updated_legacy' );
// As of Groups 3.3.1 this transient does not trigger a redirect to the welcome screen.
// Instead, an admin notice pointing to the migration guide is displayed for as long as the transient has not expired.
// We still delete the transient here as we are displaying the welcome screen, and the notice will be visible on top of it.
delete_transient( 'groups_plugin_updated_legacy' );

echo '<div class="groups-welcome-panel">';
Expand All @@ -158,18 +191,6 @@ public static function groups_welcome() {
esc_html_e( 'Thanks for using Groups! We have made it even easier to protect your content and hope you like it :)', 'groups' );
echo '</p>';

if ( $legacy_update ) {
echo '<p class="important">';
echo '<strong>';
esc_html_e( 'Important', 'groups' );
echo '</strong>';
echo '<br/><br/>';
esc_html_e( 'It seems that you have updated from Groups 1.x where access restrictions were based on capabilities.', 'groups' );
echo '<br/>';
printf( wp_kses_post( __( 'Please make sure to read the notes on <strong>Switching to Groups %s</strong> below.', 'groups' ) ), esc_html( $groups_version ) );
echo '</p>';
}

echo '<h2>';
esc_html_e( "What's New?", 'groups' );
echo '</h2>';
Expand Down
46 changes: 45 additions & 1 deletion lib/core/class-groups-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,10 @@ public static function activate( $network_wide = false ) {
}
} else {
self::setup();
set_transient( 'groups_plugin_activated', true, 60 );
// @since 3.3.1 Check here already if it is a single activation of Groups and only then set the transient
if ( self::is_single_activate() ) {
set_transient( 'groups_plugin_activated', true, 60 );
}
}
if ( $sem_id !== false ) {
self::sem_release( $sem_id );
Expand Down Expand Up @@ -523,6 +526,47 @@ private static function cleanup( $drop = false ) {
}
}

/**
* Whether this is an individual activation of the plugin.
*
* @since 3.3.1
*
* @return boolean
*/
private static function is_single_activate() {
$is = false;
$groups_basename = plugin_basename( GROUPS_FILE );
if ( isset( $_REQUEST['action'] ) ) {
switch ( $_REQUEST['action'] ) {
case 'activate':
// Single plugin activation of Groups:
if ( !empty( $_REQUEST['plugin'] ) ) {
$slug = wp_unslash( $_REQUEST['plugin'] );
if ( $slug === $groups_basename ) {
$is = true;
}
}
break;
case 'activate-selected':
// Bulk plugin activation of Groups but it is the only plugin being activated:
if ( !empty( $_REQUEST['checked'] ) ) {
if ( is_array( $_REQUEST['checked'] ) ) {
if ( count( $_REQUEST['checked'] ) === 1 ) {
$slugs = wp_unslash( $_REQUEST['checked'] );
$slug = array_pop( $slugs );
if ( $slug === $groups_basename ) {
$is = true;
break;
}
}
}
}
break;
}
}
return $is;
}

/**
* Determines the default capabilities for the administrator role.
* In lack of an administrator role, these capabilities are assigned
Expand Down

0 comments on commit 166c83f

Please sign in to comment.