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

Change version reconciliation #33

Closed
wants to merge 2 commits into from
Closed
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
2 changes: 1 addition & 1 deletion src/Whip_MessagesManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function __construct()
* @param Whip_Message $message The message to add.
*/
public function addMessage( Whip_Message $message ) {
$whipVersion = require dirname( __FILE__ ) . '/version.php';
$whipVersion = require dirname( __FILE__ ) . '/configs/version.php';

$GLOBALS[ 'whip_messages' ][$whipVersion] = $message;
}
Expand Down
3 changes: 3 additions & 0 deletions src/configs/version.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

return '1.0.0';
29 changes: 27 additions & 2 deletions src/presenters/Whip_WPMessagePresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,39 @@ public function __construct( Whip_Message $message ) {
* control when the hooks are registered.
*/
public function register_hooks() {
add_action( 'admin_notices', array( $this, 'renderMessage' ) );
add_action( 'admin_notices', array( $this, 'renderMessage' ), $this->getHookPriority() );
}

/**
* Renders the messages present in the global to notices.
*/
public function renderMessage() {
printf( '<div class="error">%s</div>', $this->kses( $this->message->body() ) );
if ( $this->hasRendered() ) {
return;
}

$GLOBALS['whip_wp_has_rendered'] = true;

printf( '<div class="error">%s</div>', $this->kses( $this->message->body() ) );
}

/**
* Whether any WPMessagePresenter has rendered before.
*/
public function hasRendered() {
return isset( $GLOBALS['whip_wp_has_rendered'] ) && $GLOBALS['whip_wp_has_rendered'];
}

/**
* Gets the hook priority based on the version.
*/
public function getHookPriority() {
$version = include dirname( __FILE__ ) . '/../configs/version.php';

$version = (int) str_replace( '.', '', $version );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That won't work, as 1.0.12 => 1012 and 2.0.0 => 200 .

Copy link
Contributor

@schlessera schlessera Mar 8, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try something like 1000 * $major + 100 * $minor + 10 * $patch or something.


// This will work until we hit version 100.
return ( 10000 - $version );
}

/**
Expand Down
7 changes: 0 additions & 7 deletions src/version.php

This file was deleted.