Skip to content

Commit

Permalink
Merge pull request #13 from eighty20results/bug_fix/PHP_Warning_updates
Browse files Browse the repository at this point in the history
Bug fix/php warning updates
  • Loading branch information
eighty20results authored Nov 11, 2018
2 parents 1f20436 + c36d835 commit 4459248
Show file tree
Hide file tree
Showing 7 changed files with 197 additions and 171 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,19 @@ You can also email you support question(s) to [email protected]

##Changelog

###4.6.12

* BUG FIX: PHP Notice when post ID isn't found
* BUG FIX: Ensure we're not actively looking for post ID 0 (we know there's no post, so nothing to find)
* BUG FIX: PHP Warning in Sequence_Updates class

###4.6.11

* BUG FIX: Didn't show Drip Feed Settings metabox for all post types it was configured for
* BUG FIX: PHP Notice when post ID isn't found
* ENHANCEMENT: Add support for using custom subject and links in notices
* ENHANCEMENT: Didn't apply the e20r-sequence-alert-message-post-title filter to the Email Subject

###4.6.8

* BUG FIX: Logic for testing metadata version was invalid
Expand Down
17 changes: 15 additions & 2 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
Contributors: eighty20results
Tags: sequence, drip feed, serial content, delayed, limited, memberships, paid memberships pro, sequences, pmpro series
Requires at least: 3.9
Tested up to: 4.8
Stable tag: 4.6.8
Tested up to: 4.9.8
Stable tag: 4.6.12

Create a drip feed "Sequence" which are groups of posts/pages/CPTs where the content is revealed to members over time.

Expand Down Expand Up @@ -172,6 +172,19 @@ Or you can email [email protected]

== Changelog ==

== 4.6.12 ==

* BUG FIX: PHP Notice when post ID isn't found
* BUG FIX: Ensure we're not actively looking for post ID 0 (we know there's no post, so nothing to find)
* BUG FIX: PHP Warning in Sequence_Updates class

== 4.6.11 ==

* BUG FIX: Didn't show Drip Feed Settings metabox for all post types it was configured for
* BUG FIX: PHP Notice when post ID isn't found
* ENHANCEMENT: Add support for using custom subject and links in notices
* ENHANCEMENT: Didn't apply the e20r-sequence-alert-message-post-title filter to the Email Subject

== 4.6.8 ==

* BUG FIX: Logic for testing metadata version was invalid
Expand Down
6 changes: 3 additions & 3 deletions build_readmes/current.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
BUG FIX: Logic for testing metadata version was invalid
BUG FIX: Didn't save the Preview offset value correctly
BUG FIX: Element ID collision for offset value vs checkbox for Preview Offset setting
BUG FIX: PHP Notice when post ID isn't found
BUG FIX: Ensure we're not actively looking for post ID 0 (we know there's no post, so nothing to find)
BUG FIX: PHP Warning in Sequence_Updates class
7 changes: 7 additions & 0 deletions classes/class.sequence-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -1499,6 +1499,8 @@ public function save_sequence_post( $sequence_id = null, $post_id = null, $delay
* @param $delay
*
* @return bool
*
* @throws \Exception
*/
private function add_post_to_sequence( $sequence_id, $post_id, $delay ) {

Expand Down Expand Up @@ -1558,6 +1560,11 @@ private function add_post_to_sequence( $sequence_id, $post_id, $delay ) {

DBG::log( "Loaded " . count( $p ) . " posts with WP_Query" );

if ( empty( $p ) && $post_id !== 0 ) {
DBG::log("Didn't locate {$post_id}");
return false;
}

$new_post = new \stdClass();
$new_post->id = $p[0]->ID;

Expand Down
311 changes: 152 additions & 159 deletions classes/tools/class.sequence-updates.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,163 +23,156 @@

use E20R\Tools\DBG;

class Sequence_Updates
{
private $current_version;
private static $_this = null;

public function __construct()
{
DBG::log("Loading the sequence_update class");

if ( null !== self::$_this ) {

DBG::log("Error loading the sequence update class");
$error_message = sprintf(__("Attempted to load a second instance of this singleton class (%s)", "e20r-sequences"),
get_class($this)
);

error_log($error_message);
wp_die( $error_message);

}

self::$_this = $this;
}

public static function init()
{
DBG::log("Getting plugin data for E20R Sequences");

$update_functions = array(
'4.4.0', '4.4.11'
);

if (function_exists('get_plugin_data'))
$plugin_status = get_plugin_data(E20R_SEQUENCE_PLUGIN_DIR . 'e20r-sequences.php', false, false);

$version = ( !empty($plugin_status['Version']) ? $plugin_status['Version'] : E20R_SEQUENCE_VERSION );

$me = self::$_this;
$me->set_version($version);

$is_updated = get_option('e20r-sequence-updated', array() );
$a_versions = array_keys($is_updated);
$a_versions = array_unique(array_merge($update_functions, $a_versions));

if (false === in_array( $version, $a_versions ) ) {

DBG::log("Appending {$version} to list of stuff to upgrade");
$is_updated[$version] = false;
$a_versions[] = $version;
}

foreach($is_updated as $v => $status) {

$upgrade_file = str_replace('.', '_', $v);

if (!empty($v) &&
(file_exists(E20R_SEQUENCE_PLUGIN_DIR . "upgrades/{$upgrade_file}.php") &&
(false == $status) ) ) {

DBG::log("Adding update action for {$v}");
add_action("e20r_sequence_before_update_{$v}", array(self::$_this, 'e20r_sequence_before_update'));
add_action("e20r_sequence_update_{$v}", array(self::$_this, 'e20r_sequence_update'));
add_action("e20r_sequence_after_update_{$v}", array(self::$_this, 'e20r_sequence_after_update'));
}
}

update_option('e20r-sequence-updated', $is_updated, 'no');
}

public function get_version()
{
return isset( $this->current_version ) ? $this->current_version : null;
}

public function set_version( $version )
{
$this->current_version = $version;
}

public static function get_instance()
{
if ( null == self::$_this )
{
DBG::log("Instantiating the " . get_class(self::$_this) . " class");
self::$_this = new self;
}

return self::$_this;
}

static public function update()
{
$su_class = apply_filters('get_sequence_update_class_instance',null);
$version = $su_class->get_version();

if (empty($version)) {
return;
}

$is_updated = get_option('e20r-sequence-updated', array() );

$processed = array_keys($is_updated);

if (!array_key_exists( $version, $is_updated )) {

DBG::log("Appending {$version} to list of stuff to upgrade");
$is_updated[$version] = false;
}

foreach ($is_updated as $v => $status ) {

$upgrade_file = str_replace('.', '_', $v);

if (file_exists(E20R_SEQUENCE_PLUGIN_DIR . "upgrades/{$upgrade_file}.php") && (false == $status) ) {

require_once(E20R_SEQUENCE_PLUGIN_DIR . "upgrades/{$upgrade_file}.php");

DBG::log("Running pre (before) update action for {$v}");
do_action("e20r_sequence_before_update_{$v}");

// FIXME: Will always run, every time the plugin loads (prevent this!)
DBG::log("Running update action for {$v}");
do_action("e20r_sequence_update_{$v}");

DBG::log("Running clean-up (after) update action for {$v}");
do_action("e20r_sequence_after_update_{$v}");

if (array_key_exists($v, $is_updated)) {
$is_updated[$v] = true;
}
}
else {
DBG::log("No updates to do for v{$v}");
}
}

update_option('e20r-sequence-updated', $is_updated, 'no');
}

/**
* Stub function
*/
public function e20r_sequence_before_update() {
return;
}

/**
* Stub function
*/
public function e20r_sequence_after_update() {
return;
}

/**
* Stub function
*/
public function e20r_sequence_update() {
return;
}
class Sequence_Updates {
private static $_this = null;
private $current_version;

public function __construct() {
DBG::log( "Loading the sequence_update class" );

if ( null !== self::$_this ) {

DBG::log( "Error loading the sequence update class" );
$error_message = sprintf( __( "Attempted to load a second instance of this singleton class (%s)", "e20r-sequences" ),
get_class( $this )
);

error_log( $error_message );
wp_die( $error_message );

}

self::$_this = $this;
}

public static function init() {
DBG::log( "Getting plugin data for E20R Sequences" );

$update_functions = array(
'4.4.0',
'4.4.11',
);

if ( function_exists( 'get_plugin_data' ) ) {
$plugin_status = get_plugin_data( E20R_SEQUENCE_PLUGIN_DIR . 'e20r-sequences.php', false, false );
}

$version = ( ! empty( $plugin_status['Version'] ) ? $plugin_status['Version'] : E20R_SEQUENCE_VERSION );

$me = self::$_this;
$me->set_version( $version );

$is_updated = get_option( 'e20r-sequence-updated', array() );
$a_versions = array_keys( $is_updated );
$a_versions = array_unique( array_merge( $update_functions, $a_versions ) );

if ( false === in_array( $version, $a_versions ) ) {

DBG::log( "Appending {$version} to list of stuff to upgrade" );
$is_updated[ $version ] = false;
$a_versions[] = $version;
}

foreach ( $is_updated as $v => $status ) {

$upgrade_file = str_replace( '.', '_', $v );

if ( ! empty( $v ) &&
( file_exists( E20R_SEQUENCE_PLUGIN_DIR . "upgrades/{$upgrade_file}.php" ) &&
( false == $status ) ) ) {

DBG::log( "Adding update action for {$v}" );
add_action( "e20r_sequence_before_update_{$v}", array( self::$_this, 'e20r_sequence_before_update' ) );
add_action( "e20r_sequence_update_{$v}", array( self::$_this, 'e20r_sequence_update' ) );
add_action( "e20r_sequence_after_update_{$v}", array( self::$_this, 'e20r_sequence_after_update' ) );
}
}

update_option( 'e20r-sequence-updated', $is_updated, 'no' );
}

public static function get_instance() {
if ( null == self::$_this ) {
self::$_this = new self;
DBG::log( "Instantiating the " . get_class( self::$_this ) . " class" );
}

return self::$_this;
}

static public function update() {
$su_class = apply_filters( 'get_sequence_update_class_instance', null );
$version = $su_class->get_version();

if ( empty( $version ) ) {
return;
}

$is_updated = get_option( 'e20r-sequence-updated', array() );

$processed = array_keys( $is_updated );

if ( ! array_key_exists( $version, $is_updated ) ) {

DBG::log( "Appending {$version} to list of stuff to upgrade" );
$is_updated[ $version ] = false;
}

foreach ( $is_updated as $v => $status ) {

$upgrade_file = str_replace( '.', '_', $v );

if ( file_exists( E20R_SEQUENCE_PLUGIN_DIR . "upgrades/{$upgrade_file}.php" ) && ( false == $status ) ) {

require_once( E20R_SEQUENCE_PLUGIN_DIR . "upgrades/{$upgrade_file}.php" );

DBG::log( "Running pre (before) update action for {$v}" );
do_action( "e20r_sequence_before_update_{$v}" );

// FIXME: Will always run, every time the plugin loads (prevent this!)
DBG::log( "Running update action for {$v}" );
do_action( "e20r_sequence_update_{$v}" );

DBG::log( "Running clean-up (after) update action for {$v}" );
do_action( "e20r_sequence_after_update_{$v}" );

if ( array_key_exists( $v, $is_updated ) ) {
$is_updated[ $v ] = true;
}
} else {
DBG::log( "No updates to do for v{$v}" );
}
}

update_option( 'e20r-sequence-updated', $is_updated, 'no' );
}

public function get_version() {
return isset( $this->current_version ) ? $this->current_version : null;
}

public function set_version( $version ) {
$this->current_version = $version;
}

/**
* Stub function
*/
public function e20r_sequence_before_update() {
return;
}

/**
* Stub function
*/
public function e20r_sequence_after_update() {
return;
}

/**
* Stub function
*/
public function e20r_sequence_update() {
return;
}
}
Loading

0 comments on commit 4459248

Please sign in to comment.