diff --git a/includes/class-newspack.php b/includes/class-newspack.php index e626ff304e..1824a7d106 100644 --- a/includes/class-newspack.php +++ b/includes/class-newspack.php @@ -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' ] ); } @@ -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 */ diff --git a/includes/wizards/class-wizard.php b/includes/wizards/class-wizard.php index 91786cdcc4..026f83fd0a 100644 --- a/includes/wizards/class-wizard.php +++ b/includes/wizards/class-wizard.php @@ -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. * @@ -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 ); } /** @@ -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() ); + } } \ No newline at end of file diff --git a/includes/wizards/traits/trait-wizards-admin-header.php b/includes/wizards/traits/trait-wizards-admin-header.php index fa885699cd..a0be4305c3 100644 --- a/includes/wizards/traits/trait-wizards-admin-header.php +++ b/includes/wizards/traits/trait-wizards-admin-header.php @@ -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' ] ); } diff --git a/src/admin/style.scss b/src/admin/style.scss index 1f6376d06f..346df276c5 100644 --- a/src/admin/style.scss +++ b/src/admin/style.scss @@ -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; diff --git a/src/components/src/with-wizard/style.scss b/src/components/src/with-wizard/style.scss index bcc6946c2d..15f64b71d6 100644 --- a/src/components/src/with-wizard/style.scss +++ b/src/components/src/with-wizard/style.scss @@ -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; } @@ -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; } @@ -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 {