Skip to content

Commit

Permalink
Bump version to 2.0.0-alpha3
Browse files Browse the repository at this point in the history
  • Loading branch information
folbert committed Feb 18, 2020
1 parent 136e438 commit b1a68e6
Show file tree
Hide file tree
Showing 5 changed files with 170 additions and 19 deletions.
7 changes: 4 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# Fewbricks changelog
An incomplete log of changes.

## 1.6 - March 19, 2017
* Added function `get_field_values()`to `brick`
* Added function `get_get_html_arg()` to `brick`
* Added ability to pass $post_id to `have_rows()` in `brick`
* Added ability to pass $post_id to `have_rows()` in `brick`

## 1.5.1 - February 13, 2017
* Changed name on filter for project files base path
Expand All @@ -29,7 +30,7 @@
* Added support for placing fewbricks in child theme

## 1.1.1 - April 24, 2016
* Hotfix for Timber dependency in demo
* Hotfix for Timber dependency in demo

## 1.1.0 - April 23, 2016
* Added autoupdate functionality when viewing the plugin in plugins list.
Expand All @@ -41,4 +42,4 @@
* Updates to the Readme file

## 1.0 - April 22, 2016
* First stable release
* First stable release
11 changes: 9 additions & 2 deletions DEVELOPER-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,16 @@ These are notes to make sure that I don't forget anything when creating a new re

Version numbering follows [Semantic Versioning](http://semver.org/).

1. Describe new version in changelog.md
1. Describe new version in CHANGELOG.md
2. Change version nr in comment in fewbricks.php
3. Change version nr for $plugin_current_version in fewbricks.php
3. Change FEWBRICKS_VERSION in lib/Fewbricks.php
3. Change version nr in readme.txt

Create release locally and push.

After master has been pushed, create release on GitHub.

Start version number with a "v".

Update https://version.fewbricks2.folbert.com/version-info.php with the correct data

34 changes: 21 additions & 13 deletions fewbricks.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Plugin URI: https://github.com/folbert/fewbricks
Description: A module extension to Advanced Custom Fields
Author: Björn Folbert
Version: 2.0-beta1
Version: 2.0.0-alpha2
Author URI: https://folbert.com
License: GPLv3
*/
Expand All @@ -29,7 +29,7 @@
&& $namespaceParts[0] === 'Fewbricks'
) {

// First item will always be "Febwricks" and we don't need that when building the path
// First item will always be "Fewbricks" and we don't need that when building the path
// Yes, by not checking of the file exists, we do get ugly error messages but we save some execution time.
/** @noinspection PhpIncludeInspection */
include __DIR__ . '/src/' . implode('/', array_slice($namespaceParts, 1)) . '.php';
Expand All @@ -40,18 +40,26 @@

}

if(class_exists('Puc_v4_Factory')) {
add_action('acf/init', function () {
\Fewbricks\Fewbricks::run();
});

$update_checker = Puc_v4_Factory::buildUpdateChecker(
'https://github.com/folbert/fewbricks',
__FILE__,
'fewbricks'
);
if(!function_exists('fewbricks_check_version')) {

//dump($update_checker);
add_action('init', 'fewbricks_check_version');

}
function fewbricks_check_version()
{

add_action('acf/init', function () {
\Fewbricks\Fewbricks::run();
});
require_once 'src/WP_AutoUpdate.php';

// set auto-update params
$plugin_current_version = \Fewbricks\Fewbricks::FEWBRICKS_VERSION;
$plugin_remote_path = 'https://version.fewbricks2.folbert.com/version-info.php';
$plugin_slug = plugin_basename(__FILE__);

new WP_AutoUpdate($plugin_current_version, $plugin_remote_path, $plugin_slug);

}

}
2 changes: 1 addition & 1 deletion src/Fewbricks.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Fewbricks
/**
*
*/
const FEWBRICKS_VERSION = '2.0.0-alpha';
const FEWBRICKS_VERSION = '2.0.0-alpha2';

/**
*
Expand Down
135 changes: 135 additions & 0 deletions src/WP_AutoUpdate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
<?php

// Based on https://github.com/omarabid/Self-Hosted-WordPress-Plugin-repository/blob/master/wp_autoupdate.php

class WP_AutoUpdate
{
/**
* The plugin current version
* @var string
*/
private $current_version;

/**
* The plugin remote update path
* @var string
*/
private $update_path;

/**
* Plugin Slug (plugin_directory/plugin_file.php)
* @var string
*/
private $plugin_slug;

/**
* Plugin name (plugin_file)
* @var string
*/
private $slug;

/**
* Initialize a new instance of the WordPress Auto-Update class
* @param string $current_version
* @param string $update_path
* @param string $plugin_slug
*/
public function __construct( $current_version, $update_path, $plugin_slug)
{
// Set the class public variables
$this->current_version = $current_version;
$this->update_path = $update_path;

// Set the Plugin Slug
$this->plugin_slug = $plugin_slug;
list ($t1, $t2) = explode( '/', $plugin_slug );
$this->slug = str_replace( '.php', '', $t2 );

// define the alternative API for updating checking
add_filter( 'pre_set_site_transient_update_plugins', array( &$this, 'check_update' ) );

// Define the alternative response for information checking
add_filter( 'plugins_api', array( &$this, 'check_info' ), 10, 3 );
}

/**
* Add our self-hosted autoupdate plugin to the filter transient
*
* @param $transient
* @return object $ transient
*/
public function check_update( $transient )
{

if (empty($transient) || !isset($transient->checked) || empty( $transient->checked ) ) {
return $transient;
}

// Get the remote version
$remote_version = $this->getRemote('version');

if(empty($remote_version)) {
return $transient;
}

// If a newer version is available, add the update
if ( version_compare( $this->current_version, $remote_version->new_version, '<' ) ) {
$obj = new stdClass();
$obj->slug = $this->slug;
$obj->new_version = $remote_version->new_version;
$obj->url = $remote_version->url;
$obj->plugin = $this->plugin_slug;
//$obj->package = $remote_version->package;

if(isset($remote_version->tested)) {
$obj->tested = $remote_version->tested;
}

$transient->response[$this->plugin_slug] = $obj;
}
return $transient;
}

/**
* Add our self-hosted description to the filter
*
* @param boolean $false
* @param array $action
* @param object $arg
* @return bool|object
*/
public function check_info($obj, $action, $arg)
{
if (($action=='query_plugins' || $action=='plugin_information') &&
isset($arg->slug) && $arg->slug === $this->slug) {
return $this->getRemote('info');
}

return $obj;
}

/**
* Return the remote version
*
* @return string $remote_version
*/
public function getRemote($action = '')
{

$params = array(
'body' => array(
'action' => $action,
),
);

// Make the POST request
$request = wp_remote_post($this->update_path, $params );

// Check if response is valid
if ( !is_wp_error( $request ) || wp_remote_retrieve_response_code( $request ) === 200 ) {
return @unserialize( $request['body'] );
}

return false;
}
}

0 comments on commit b1a68e6

Please sign in to comment.