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

fix(ia): hide notifications #3563

Merged
merged 9 commits into from
Nov 26, 2024
20 changes: 0 additions & 20 deletions includes/class-newspack.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ public function __construct() {
add_action( 'current_screen', [ $this, 'wizard_redirect' ] );
add_action( 'admin_menu', [ $this, 'handle_resets' ], 1 );
add_action( 'admin_menu', [ $this, 'remove_newspack_suite_plugin_links' ], 1 );
add_action( 'admin_notices', [ $this, 'remove_notifications' ], -9999 );
add_action( 'network_admin_notices', [ $this, 'remove_notifications' ], -9999 );
add_action( 'all_admin_notices', [ $this, 'remove_notifications' ], -9999 );
register_activation_hook( NEWSPACK_PLUGIN_FILE, [ $this, 'activation_hook' ] );
register_deactivation_hook( NEWSPACK_PLUGIN_FILE, [ $this, 'deactivation_hook' ] );
}
Expand Down Expand Up @@ -273,23 +270,6 @@ public function handle_resets() {
}
}

/**
* Remove notifications.
*/
public function remove_notifications() {
$screen = get_current_screen();

$is_newspack_screen = str_contains( $screen->base, 'newspack_page_' );
$is_advertising_screen = str_contains( $screen->base, 'toplevel_page_advertising' );

$is_wizard = $is_newspack_screen || $is_advertising_screen;

if ( ! $screen || ! $is_wizard ) {
return;
}
remove_all_actions( current_action() );
}

/**
* Activation Hook
*/
Expand Down
34 changes: 34 additions & 0 deletions includes/wizards/class-wizard.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ abstract class Wizard {
*/
protected $admin_menu_priority = 10;

/**
* Remove notifications from the wizard screen.
*
* @var bool
*/
protected $remove_notifications = true;

/**
* Initialize.
*
Expand All @@ -86,6 +93,11 @@ public function __construct( $args = [] ) {
$this->load_wizard_sections( $args['sections'] );
}
add_filter( 'admin_body_class', [ $this, 'add_body_class' ] );

// Remove Notices.
add_action( 'admin_notices', [ $this, 'remove_notifications' ], -9999 );
add_action( 'all_admin_notices', [ $this, 'remove_notifications' ], -9999 );
add_action( 'network_admin_notices', [ $this, 'remove_notifications' ], -9999 );
}

/**
Expand Down Expand Up @@ -318,4 +330,26 @@ public function add_body_class( $classes ) {
$classes .= ' newspack-wizard-page';
return $classes;
}

/**
* Remove notifications.
*
* Note: Many of our admin-header-only wizards are CPT list pages where users can do actions such
* as "trash" a post or "bulk actions" like "edit (multiple)" in the dropbown. Keep in mind
* that these actions will still show notices like "1 post was trashed" or "5 posts were
* updated" since WordPress shows these notices outside the actions that the function below
* is removing.
*
* Also "settings saved" notices on post-back of a custom options pages are not removed either. See core
* function 'settings_errors()' here: https://developer.wordpress.org/plugins/settings/custom-settings-page/
*/
public function remove_notifications() {
if ( ! $this->is_wizard_page() ) {
return;
}
if ( ! $this->remove_notifications ) {
return;
}
remove_all_actions( current_action() );
}
}
2 changes: 1 addition & 1 deletion includes/wizards/traits/trait-wizards-admin-header.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function admin_header_init( $args = [] ) {
$this->tabs = $args['tabs'] ?? array();
$this->title = $args['title'] ?? __( 'Newspack Settings', 'newspack-plugin' );
add_action( 'admin_enqueue_scripts', [ $this, 'admin_header_enqueue' ] );
add_action( 'all_admin_notices', [ $this, 'admin_header_render' ] );
add_action( 'in_admin_header', [ $this, 'admin_header_render' ] );
add_filter( 'admin_body_class', [ $this, 'admin_header_body_class' ] );
}

Expand Down
2 changes: 1 addition & 1 deletion src/admin/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ h1 {
box-sizing: border-box;
}
}
.newspack-wizard-page {
.newspack-wizard-page:not(.newspack-admin-header) {
#screen-meta-links {
position: absolute;
right: 0;
Expand Down
31 changes: 23 additions & 8 deletions src/components/src/with-wizard/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
@use "~@wordpress/base-styles/colors" as wp-colors;
@use "../../../shared/scss/colors";

// Reset Padding of the Admin Page for full react pages (ignoring admin-header-only pages).
// Styling for full-page-react Wizards (ignoring admin-header-only wizards).
body.newspack-wizard-page:not(.newspack-admin-header) {

background: white;

// Reset Padding
#wpcontent {
padding-left: 0;
}
Expand All @@ -18,6 +19,13 @@ body.newspack-wizard-page:not(.newspack-admin-header) {
padding-bottom: 220px;
min-height: 100vh;

// For admin notices directly ">" at top of page above the Wizard header.
// PHP code should hide these notices, but just incase add this style.
> .notice {
margin-bottom: 20px;
margin-left: 22px;
}

@media screen and ( min-width: 783px ) {
padding-bottom: 202px;
}
Expand All @@ -28,15 +36,22 @@ body.newspack-wizard-page:not(.newspack-admin-header) {
}
}

// Fix notifications margins for all wizards (full-react and admin-header-only pages).
body.newspack-wizard-page {
// Styling for wizards that are admin-header-only.
body.newspack-wizard-page.newspack-admin-header {

// Only apply when notices are directly ">" at top of page above the header area (ie: not in "wrap" content).
#wpbody-content > .notice {
margin-bottom: 20px;
margin-left: 22px;
}
// For mobile.
@media screen and (max-width: 600px) {

// The header bar (and tabs) need padding.
#newspack-wizards-admin-header {
padding-top: 46px;
}

// Since the padding was added to the header bar, remove from body.
#wpbody {
padding-top: 0;
}
}
}

svg {
Expand Down