Skip to content

Commit

Permalink
Merge pull request #76 from firetreedesign/1.3.13
Browse files Browse the repository at this point in the history
1.3.13
  • Loading branch information
danielmilner committed Aug 21, 2020
2 parents ca819fc + 586a3da commit b1eeeac
Show file tree
Hide file tree
Showing 10 changed files with 263 additions and 154 deletions.
4 changes: 2 additions & 2 deletions ccbpress-core.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: CCBPress Core
* Plugin URI: https://ccbpress.com/
* Description: Display information from Church Community Builder on your WordPress site.
* Version: 1.3.11
* Version: 1.3.13
* Author: CCBPress <info@ccbpress.com>
* Author URI: https://ccbpress.com/
* Text Domain: ccbpress-core
Expand Down Expand Up @@ -66,7 +66,7 @@ class CCBPress_Core {
* @var string
* @since 1.0.0
*/
public $version = '1.3.11';
public $version = '1.3.13';

/**
* Main CCBPress_Core Instance
Expand Down
2 changes: 1 addition & 1 deletion dist/blocks.build.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions includes/class-ccbpress-licenses.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ public function __construct( $_file, $_item_id, $_item_name, $_version, $_author
* @return void
*/
private function includes() {
if ( ! class_exists( 'EDD_SL_Plugin_Updater' ) ) {
require CCBPRESS_CORE_PLUGIN_DIR . 'lib/EDD_SL_Plugin_Updater.php';
if ( ! class_exists( 'CCBPress_EDD_SL_Plugin_Updater' ) ) {
require CCBPRESS_CORE_PLUGIN_DIR . 'lib/CCBPress_EDD_SL_Plugin_Updater.php';
}
}

Expand Down Expand Up @@ -160,7 +160,7 @@ public function auto_updater() {
}

if ( is_numeric( $this->item_id ) ) {
$edd_updater = new EDD_SL_Plugin_Updater(
$edd_updater = new CCBPress_EDD_SL_Plugin_Updater(
$this->api_url,
$this->file,
array(
Expand All @@ -172,7 +172,7 @@ public function auto_updater() {
)
);
} else {
$edd_updater = new EDD_SL_Plugin_Updater(
$edd_updater = new CCBPress_EDD_SL_Plugin_Updater(
$this->api_url,
$this->file,
array(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
* Allows plugins to use their own update API.
*
* @author Easy Digital Downloads
* @version 1.6.17
* @version 1.7.1
*/
class EDD_SL_Plugin_Updater {
class CCBPress_EDD_SL_Plugin_Updater {

private $api_url = '';
private $api_data = array();
Expand Down Expand Up @@ -117,15 +117,33 @@ public function check_update( $_transient_data ) {

if ( false !== $version_info && is_object( $version_info ) && isset( $version_info->new_version ) ) {

$no_update = false;
if ( version_compare( $this->version, $version_info->new_version, '<' ) ) {

$_transient_data->response[ $this->name ] = $version_info;

// Make sure the plugin property is set to the plugin's name/location. See issue 1463 on Software Licensing's GitHub repo.
$_transient_data->response[ $this->name ]->plugin = $this->name;

} else {
$no_update = new stdClass();
$no_update->id = '';
$no_update->slug = $this->slug;
$no_update->plugin = $this->name;
$no_update->new_version = $version_info->new_version;
$no_update->url = $version_info->homepage;
$no_update->package = $version_info->package;
$no_update->icons = $version_info->icons;
$no_update->banners = $version_info->banners;
$no_update->banners_rtl = array();
}

$_transient_data->last_checked = time();
$_transient_data->checked[ $this->name ] = $this->version;

if ( $no_update ) {
$_transient_data->no_update[ $this->name ] = $no_update;
}
}

return $_transient_data;
Expand Down Expand Up @@ -182,21 +200,40 @@ public function show_update_notification( $file, $plugin ) {
$version_info->icons = $this->convert_object_to_array( $version_info->icons );
}

if ( isset( $version_info->contributors ) && ! is_array( $version_info->contributors ) ) {
$version_info->contributors = $this->convert_object_to_array( $version_info->contributors );
}

$this->set_version_info_cache( $version_info );
}

if ( ! is_object( $version_info ) ) {
return;
}

$no_update = false;
if ( version_compare( $this->version, $version_info->new_version, '<' ) ) {

$update_cache->response[ $this->name ] = $version_info;

} else {
$no_update = new stdClass();
$no_update->id = '';
$no_update->slug = $this->slug;
$no_update->plugin = $this->name;
$no_update->new_version = $version_info->new_version;
$no_update->url = $version_info->homepage;
$no_update->package = $version_info->package;
$no_update->icons = $version_info->icons;
$no_update->banners = $version_info->banners;
$no_update->banners_rtl = array();
}

$update_cache->last_checked = time();
$update_cache->last_checked = time();
$update_cache->checked[ $this->name ] = $this->version;
if ( $no_update ) {
$update_cache->no_update[ $this->name ] = $no_update;
}

set_site_transient( 'update_plugins', $update_cache );

Expand Down Expand Up @@ -280,18 +317,16 @@ public function plugins_api_filter( $_data, $_action = '', $_args = null ) {
)
);

$cache_key = 'edd_api_request_' . md5( serialize( $this->slug . $this->api_data['license'] . $this->beta ) );

// Get the transient where we store the api request for this plugin for 24 hours
$edd_api_request_transient = $this->get_cached_version_info( $cache_key );
$edd_api_request_transient = $this->get_cached_version_info();

//If we have no transient-saved value, run the API, set a fresh transient with the API value, and return that value too right now.
if ( empty( $edd_api_request_transient ) ) {

$api_response = $this->api_request( 'plugin_information', $to_send );

// Expires in 3 hours
$this->set_version_info_cache( $api_response, $cache_key );
$this->set_version_info_cache( $api_response );

if ( false !== $api_response ) {
$_data = $api_response;
Expand All @@ -316,6 +351,15 @@ public function plugins_api_filter( $_data, $_action = '', $_args = null ) {
$_data->icons = $this->convert_object_to_array( $_data->icons );
}

// Convert contributors into an associative array, since we're getting an object, but Core expects an array.
if ( isset( $_data->contributors ) && ! is_array( $_data->contributors ) ) {
$_data->contributors = $this->convert_object_to_array( $_data->contributors );
}

if( ! isset( $_data->plugin ) ) {
$_data->plugin = $this->name;
}

return $_data;
}

Expand All @@ -334,7 +378,7 @@ public function plugins_api_filter( $_data, $_action = '', $_args = null ) {
private function convert_object_to_array( $data ) {
$new_data = array();
foreach ( $data as $key => $value ) {
$new_data[ $key ] = $value;
$new_data[ $key ] = is_object( $value ) ? $this->convert_object_to_array( $value ) : $value;
}

return $new_data;
Expand Down Expand Up @@ -372,6 +416,8 @@ private function api_request( $_action, $_data ) {

global $wp_version, $edd_plugin_url_available;

$verify_ssl = $this->verify_ssl();

// Do a quick status check on this domain if we haven't already checked it.
$store_hash = md5( $this->api_url );
if ( ! is_array( $edd_plugin_url_available ) || ! isset( $edd_plugin_url_available[ $store_hash ] ) ) {
Expand All @@ -385,7 +431,7 @@ private function api_request( $_action, $_data ) {
$edd_plugin_url_available[ $store_hash ] = false;
} else {
$test_url = $scheme . '://' . $host . $port;
$response = wp_remote_get( $test_url, array( 'timeout' => $this->health_check_timeout, 'sslverify' => true ) );
$response = wp_remote_get( $test_url, array( 'timeout' => $this->health_check_timeout, 'sslverify' => $verify_ssl ) );
$edd_plugin_url_available[ $store_hash ] = is_wp_error( $response ) ? false : true;
}
}
Expand Down Expand Up @@ -416,7 +462,6 @@ private function api_request( $_action, $_data ) {
'beta' => ! empty( $data['beta'] ),
);

$verify_ssl = $this->verify_ssl();
$request = wp_remote_post( $this->api_url, array( 'timeout' => 15, 'sslverify' => $verify_ssl, 'body' => $api_params ) );

if ( ! is_wp_error( $request ) ) {
Expand Down Expand Up @@ -446,6 +491,9 @@ private function api_request( $_action, $_data ) {
return $request;
}

/**
* If available, show the changelog for sites in a multisite install.
*/
public function show_changelog() {

global $edd_plugin_data;
Expand All @@ -467,9 +515,7 @@ public function show_changelog() {
}

$data = $edd_plugin_data[ $_REQUEST['slug'] ];
$beta = ! empty( $data['beta'] ) ? true : false;
$cache_key = md5( 'edd_plugin_' . sanitize_key( $_REQUEST['plugin'] ) . '_' . $beta . '_version_info' );
$version_info = $this->get_cached_version_info( $cache_key );
$version_info = $this->get_cached_version_info();

if( false === $version_info ) {

Expand All @@ -490,7 +536,6 @@ public function show_changelog() {
$version_info = json_decode( wp_remote_retrieve_body( $request ) );
}


if ( ! empty( $version_info ) && isset( $version_info->sections ) ) {
$version_info->sections = maybe_unserialize( $version_info->sections );
} else {
Expand All @@ -503,17 +548,28 @@ public function show_changelog() {
}
}

$this->set_version_info_cache( $version_info, $cache_key );
$this->set_version_info_cache( $version_info );

// Delete the unneeded option
delete_option( md5( 'edd_plugin_' . sanitize_key( $_REQUEST['plugin'] ) . '_' . $this->beta . '_version_info' ) );
}

if( ! empty( $version_info ) && isset( $version_info->sections['changelog'] ) ) {
echo '<div style="background:#fff;padding:10px;">' . $version_info->sections['changelog'] . '</div>';
if ( isset( $version_info->sections ) ) {
$sections = $this->convert_object_to_array( $version_info->sections );
if ( ! empty( $sections['changelog'] ) ) {
echo '<div style="background:#fff;padding:10px;">' . wp_kses_post( $sections['changelog'] ) . '</div>';
}
}

exit;
}

/**
* Gets the plugin's cached version information from the database.
*
* @param string $cache_key
* @return boolean|string
*/
public function get_cached_version_info( $cache_key = '' ) {

if( empty( $cache_key ) ) {
Expand All @@ -536,6 +592,12 @@ public function get_cached_version_info( $cache_key = '' ) {

}

/**
* Adds the plugin version information to the database.
*
* @param string $value
* @param string $cache_key
*/
public function set_version_info_cache( $value = '', $cache_key = '' ) {

if( empty( $cache_key ) ) {
Expand All @@ -549,6 +611,8 @@ public function set_version_info_cache( $value = '', $cache_key = '' ) {

update_option( $cache_key, $data, 'no' );

// Delete the duplicate option
delete_option( 'edd_api_request_' . md5( serialize( $this->slug . $this->api_data['license'] . $this->beta ) ) );
}

/**
Expand Down
6 changes: 5 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Tags: church, ccb, church community builder, chms, gutenberg
Requires at least: 4.3
Tested up to: 5.5
Requires PHP: 5.3
Stable tag: 1.3.12
Stable tag: 1.3.13
License: GPLv2 or later
License URI: http://ww.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -45,6 +45,10 @@ Extend the capabilities of CCBPress with these add-ons:

== Changelog ==

= 1.3.13 =
* Updated the add-on updater class.
* Migrated block components from wp.editor to wp.blockEditor.

= 1.3.12 =
* Compatibility with WordPress 5.5.

Expand Down
Loading

0 comments on commit b1eeeac

Please sign in to comment.