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

Effectively revert #37 in favor of a hook-based solution for duplicate notices #44

Merged
merged 1 commit into from
Aug 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/facades/wordpress.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ function whip_wp_check_versions( $requirements ) {
$dismisser = new Whip_MessageDismisser( time(), $dismissThreshold, new Whip_WPDismissOption() );

$presenter = new Whip_WPMessagePresenter( $checker->getMostRecentMessage(), $dismisser, $dismissMessage );
$presenter->register_hooks();

// Prevent duplicate notices across multiple implementing plugins.
if ( ! has_action( 'whip_register_hooks' ) ) {
add_action( 'whip_register_hooks', array( $presenter, 'register_hooks' ) );
}

/**
* Fires during hooks registration for the message presenter.
*
* @param \Whip_WPMessagePresenter $presenter Message presenter instance.
*/
do_action( 'whip_register_hooks', $presenter );

}
}
11 changes: 3 additions & 8 deletions src/presenters/Whip_WPMessagePresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,12 @@ public function __construct( Whip_Message $message, Whip_MessageDismisser $dismi
}

/**
* Registers hooks to WordPress. This is a separate function so you can
* control when the hooks are registered.
* Registers hooks to WordPress.
*
* This is a separate function so you can control when the hooks are registered.
*/
public function register_hooks() {
global $whip_admin_notices_added;

if ( null === $whip_admin_notices_added || ! $whip_admin_notices_added ) {
add_action( 'admin_notices', array( $this, 'renderMessage' ) );
$whip_admin_notices_added = true;
}
add_action( 'admin_notices', array( $this, 'renderMessage' ) );
}

/**
Expand Down