Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Caldwell committed Sep 10, 2017
1 parent fd4e177 commit cfbe100
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 30 deletions.
30 changes: 30 additions & 0 deletions src/includes/traits/Plugin/InstallUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,36 @@ public function checkVersion()
$this->dismissMainNotice('new-pro-version-available');
}

/**
* Version compare.
*
* @since 17xxxx Version compare.
*
* @param string $one Version one.
* @param string $two Version two.
* @param string $operator Comparison operator.
* @param bool $maybe_strip_dev_state Maybe strip dev-state.
*
* @return bool True or false.
*/
public function versionCompare($one, $two, $operator, $maybe_strip_dev_state = false)
{
$one = (string) $one;
$two = (string) $two;
$operator = (string) $operator;

// NOTE: Stripping dev-state suffix.
// The method must be called with `$maybe_strip_dev_state = true`,
// AND, the site owner must have explicitly enabled beta releases.

if ($maybe_strip_dev_state && !$this->options['pro_update_check_stable']) {
$regex = '/\-(?:dev|rc|alpha|beta|pl).*$/ui';
$one = preg_replace($regex, '', $one);
$two = preg_replace($regex, '', $two);
}
return (bool) version_compare($one, $two, $operator);
}

/**
* Plugin deactivation hook.
*
Expand Down
30 changes: 0 additions & 30 deletions src/includes/traits/Plugin/UpdateUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,35 +191,5 @@ public function maybeAutoUpdateInBackground($update, $item)
return $update; // Unchanged in this case.
}
}

/**
* Version compare.
*
* @since 17xxxx Version compare.
*
* @param string $one Version one.
* @param string $two Version two.
* @param string $operator Comparison operator.
* @param bool $maybe_strip_dev_state Maybe strip dev-state.
*
* @return bool True or false.
*/
public function versionCompare($one, $two, $operator, $maybe_strip_dev_state = false)
{
$one = (string) $one;
$two = (string) $two;
$operator = (string) $operator;

// NOTE: Stripping dev-state suffix.
// The method must be called with `$maybe_strip_dev_state = true`,
// AND, the site owner must have explicitly enabled beta releases.

if ($maybe_strip_dev_state && !$this->options['pro_update_check_stable']) {
$regex = '/\-(?:dev|rc|alpha|beta|pl).*$/ui';
$one = preg_replace($regex, '', $one);
$two = preg_replace($regex, '', $two);
}
return (bool) version_compare($one, $two, $operator);
}
}
/*[/pro]*/

0 comments on commit cfbe100

Please sign in to comment.