Skip to content

Commit

Permalink
Merge pull request #44 from DrewAPicture/no-mo-globals
Browse files Browse the repository at this point in the history
Effectively revert #37 in favor of a hook-based solution for duplicate notices
  • Loading branch information
jcomack authored Aug 8, 2017
2 parents a6823f4 + 3910560 commit a4fa25d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
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

0 comments on commit a4fa25d

Please sign in to comment.