Skip to content

Commit

Permalink
Notices: hook into a new vaultpress_notices hook in the VP dash. (#44)
Browse files Browse the repository at this point in the history
* Notices: hook into a new vaultpress_notices hook in the VP dash.

Avoid using the admin_notices hook to display notices in the new VP dashboard,
since that new dashboard expects notices to be displayed inside a custom container.

* Also display the notice on the VP dash when Jetpack is not active

* Code formatting

* Correct comment. notice moved in all VP dashs.
  • Loading branch information
jeherve authored and dereksmart committed Jul 9, 2019
1 parent c572adc commit 110825b
Showing 1 changed file with 42 additions and 8 deletions.
50 changes: 42 additions & 8 deletions class-vaultpress.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,29 +237,53 @@ function admin_init() {
}

function admin_head() {
if ( !current_user_can( 'manage_options' ) )
if ( ! current_user_can( 'manage_options' ) ) {
return;
}

// Array of hooks where we want to hook our notices.
$notice_hooks = array( 'user_admin_notices' );

/*
* In the VaultPress dashboard, move the notices.
*/
$screen = get_current_screen();
if (
! is_null( $screen )
&& in_array(
$screen->id,
array( 'jetpack_page_vaultpress', 'toplevel_page_vaultpress' ),
true
)
) {
$notice_hooks[] = 'vaultpress_notices';
} else {
$notice_hooks[] = 'admin_notices';
}

if ( $activated = $this->get_option( 'activated' ) ) {
if ( 'network' == $activated ) {
add_action( 'network_admin_notices', array( $this, 'activated_notice' ) );
} else {
foreach ( array( 'user_admin_notices', 'admin_notices' ) as $filter )
foreach ( $notice_hooks as $filter ) {
add_action( $filter, array( $this, 'activated_notice' ) );
}
}
}

// ask the user to connect their site w/ VP
if ( !$this->is_registered() ) {
foreach ( array( 'user_admin_notices', 'admin_notices' ) as $filter )
foreach ( $notice_hooks as $filter ) {
add_action( $filter, array( $this, 'connect_notice' ) );
}

// if we have an error make sure to let the user know about it
} else {
$error_code = $this->get_option( 'connection_error_code' );
if ( !empty( $error_code ) ) {
foreach ( array( 'user_admin_notices', 'admin_notices' ) as $filter )
if ( ! empty( $error_code ) ) {
foreach ( $notice_hooks as $filter ) {
add_action( $filter, array( $this, 'error_notice' ) );
}
}
}
}
Expand Down Expand Up @@ -405,6 +429,14 @@ function ui() {
<div id="jp-plugin-container">
<?php $this->ui_masthead( $ui_state[ 'dashboard_link' ] ); ?>
<div class="vp-wrap">
<?php
/**
* Allow the display of custom notices.
*
* @since 2.0.0
*/
do_action( 'vaultpress_notices' );
?>
<?php echo $ui_state[ 'ui' ]; // This content is sanitized when it's produced. ?>
</div>
<?php $this->ui_footer(); ?>
Expand Down Expand Up @@ -720,13 +752,15 @@ function ui_message( $message, $type = 'notice', $heading = '' ) {
}
}

$classes = in_array( get_current_screen()->parent_base, array( 'jetpack', 'vaultpress' ), true )
? ''
: "notice notice-$type";

$this->render_notice(
"<strong>$heading</strong><br/>$message",
$level,
array(),
'jetpack' !== get_current_screen()->parent_base
? "notice notice-$type"
: ''
$classes
);
}

Expand Down

0 comments on commit 110825b

Please sign in to comment.