Skip to content

Commit

Permalink
Code reorganization / Deprecate FeedWordPress::diagnostic_on, FeedWor…
Browse files Browse the repository at this point in the history
…dPress::critical_bug, and FeedWordPress::noncritical_bug, in favor of putting these into FeedWordPressDiagnostic::is_on, FeedWordPressDiagnostic::critical_bug, and FeedWordPressDiagnostic::noncritical_bug
  • Loading branch information
Rad Geek committed Nov 12, 2017
1 parent 83e1def commit 61d242e
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 46 deletions.
60 changes: 21 additions & 39 deletions feedwordpress.php
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ function debug_out_human_readable_bytes ($quantity) {
}

function debug_out_feedwordpress_footer () {
if (FeedWordPress::diagnostic_on('memory_usage')) :
if (FeedWordPressDiagnostic::is_on('memory_usage')) :
if (function_exists('memory_get_usage')) :
FeedWordPress::diagnostic ('memory_usage', "Memory: Current usage: ".debug_out_human_readable_bytes(memory_get_usage()));
endif;
Expand Down Expand Up @@ -679,7 +679,7 @@ function feedwordpress_add_post_edit_controls () {

add_filter('user_can_richedit', array($feedwordpress, 'user_can_richedit'), 1000, 1);

if (FeedWordPress::diagnostic_on('syndicated_posts:static_meta_data')) :
if (FeedWordPressDiagnostic::is_on('syndicated_posts:static_meta_data')) :
$inspectPostMeta = new InspectPostMeta;
endif;
} // function feedwordpress_add_post_edit_controls ()
Expand Down Expand Up @@ -1312,7 +1312,7 @@ public function stale () {

// This should never happen.
else :
FeedWordPress::critical_bug('FeedWordPress::stale::last', $last, __LINE__, __FILE__);
FeedWordPressDiagnostic::critical_bug('FeedWordPress::stale::last', $last, __LINE__, __FILE__);
endif;

else :
Expand Down Expand Up @@ -2335,36 +2335,6 @@ static function affirmative ($f, $setting) {
} /* FeedWordPress::affirmative () */

# Internal debugging functions
static function critical_bug ($varname, $var, $line, $file = NULL) {
global $wp_version;

if (!is_null($file)) :
$location = "line # ${line} of ".basename($file);
else :
$location = "line # ${line}";
endif;

print '<p><strong>Critical error:</strong> There may be a bug in FeedWordPress. Please <a href="'.FEEDWORDPRESS_AUTHOR_CONTACT.'">contact the author</a> and paste the following information into your e-mail:</p>';
print "\n<plaintext>";
print "Triggered at ${location}\n";
print "FeedWordPress: ".FEEDWORDPRESS_VERSION."\n";
print "WordPress: {$wp_version}\n";
print "PHP: ".phpversion()."\n";
print "Error data: ";
print $varname.": "; var_dump($var); echo "\n";
die;
} /* FeedWordPress::critical_bug () */

static function noncritical_bug ($varname, $var, $line, $file = NULL) {
if (FEEDWORDPRESS_DEBUG) : // halt only when we are doing debugging
FeedWordPress::critical_bug($varname, $var, $line, $file);
endif;
} /* FeedWordPress::noncritical_bug () */

static function diagnostic_on ($level) {
$show = get_option('feedwordpress_diagnostics_show', array());
return (in_array($level, $show));
} /* FeedWordPress::diagnostic_on () */

static function diagnostic ($level, $out, $persist = NULL, $since = NULL, $mostRecent = NULL) {
global $feedwordpress_admin_footer;
Expand All @@ -2374,7 +2344,7 @@ static function diagnostic ($level, $out, $persist = NULL, $since = NULL, $mostR

$diagnostic_nesting = count(explode(":", $level));

if (self::diagnostic_on($level)) :
if (FeedWordPressDiagnostic::is_on($level)) :
foreach ($output as $method) :
switch ($method) :
case 'echo' :
Expand Down Expand Up @@ -2607,12 +2577,13 @@ static function path ($filename = '') {
return $path;
} /* FeedWordPress::path () */

// DEPRCATED UTILITY FUNCTIONS
// -- DEPRCATED UTILITY FUNCTIONS -------------------------------------
// These are superceded by later code re-organization, (for example
// MyPHP::param/post/get/request), but for the last several versions
// have been kept here for backward compatibility with add-ons, older
// code, etc. Maybe someday they will go away.

// MyPHP::param/post/get/request, or FeedWordPressDiagnostic methods),
// but for the last several versions have been kept here for backward
// compatibility with add-ons, older code, etc. Maybe someday they
// will go away.
// -------------------------------------------------------------------
static function param ($key, $type = 'REQUEST', $default = NULL) {
return MyPHP::param($key, $default, $type);
} /* FeedWordPress::param () */
Expand All @@ -2625,6 +2596,17 @@ static function val ($v, $no_newlines = false) {
return MyPHP::val($v, $no_newlines);
} /* FeedWordPress::val () */

static function critical_bug ($varname, $var, $line, $file = NULL) {
FeedWordPressDiagnostic::critical_bug($varname, $var, $line, $file);
} /* FeedWordPress::critical_bug () */

static function noncritical_bug ($varname, $var, $line, $file = NULL) {
FeedWordPressDiagnostic::noncritical_bug($varname, $var, $line, $file);
} /* FeedWordPress::noncritical_bug () */

static function diagnostic_on ($level) {
return FeedWordPressDiagnostic::is_on($level);
} /* FeedWordPress::diagnostic_on () */

} /* class FeedWordPress */

Expand Down
32 changes: 32 additions & 0 deletions feedwordpressdiagnostic.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,36 @@ public static function admin_emails ($id = '') {
endforeach;
return $recipients;
}

public static function noncritical_bug ($varname, $var, $line, $file = NULL) {
if (FEEDWORDPRESS_DEBUG) : // halt only when we are doing debugging
self::critical_bug($varname, $var, $line, $file);
endif;
} /* FeedWordPressDiagnostic::noncritical_bug () */

public static function critical_bug ($varname, $var, $line, $file = NULL) {
global $wp_version;

if (!is_null($file)) :
$location = "line # ${line} of ".basename($file);
else :
$location = "line # ${line}";
endif;

print '<p><strong>Critical error:</strong> There may be a bug in FeedWordPress. Please <a href="'.FEEDWORDPRESS_AUTHOR_CONTACT.'">contact the author</a> and paste the following information into your e-mail:</p>';
print "\n<plaintext>";
print "Triggered at ${location}\n";
print "FeedWordPress: ".FEEDWORDPRESS_VERSION."\n";
print "WordPress: {$wp_version}\n";
print "PHP: ".phpversion()."\n";
print "Error data: ";
print $varname.": "; var_dump($var); echo "\n";
die;
} /* FeedWordPressDiagnostic::critical_bug () */

public static function is_on ($level) {
$show = get_option('feedwordpress_diagnostics_show', array());
return (in_array($level, $show));
} /* FeedWordPressDiagnostic::is_on () */

} /* class FeedWordPressDiagnostic */
2 changes: 1 addition & 1 deletion feedwordpresssyndicationpage.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ function updates_requested () {
$update_set[] = $target->link_rss;
endforeach;
else : // This should never happen
FeedWordPress::critical_bug('fwp_syndication_manage_page::targets', $targets, __LINE__, __FILE__);
FeedWordPressDiagnostic::critical_bug('fwp_syndication_manage_page::targets', $targets, __LINE__, __FILE__);
endif;
elseif (!is_null(MyPHP::post('update_uri'))) :
$targets = MyPHP::post('update_uri');
Expand Down
10 changes: 5 additions & 5 deletions syndicatedpost.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1228,7 +1228,7 @@ function freshness ($format = 'number') {
global $wpdb;

if ($this->filtered()) : // This should never happen.
FeedWordPress::critical_bug('SyndicatedPost', $this, __LINE__, __FILE__);
FeedWordPressDiagnostic::critical_bug('SyndicatedPost', $this, __LINE__, __FILE__);
endif;

if (is_null($this->_freshness)) : // Not yet checked and cached.
Expand Down Expand Up @@ -1305,7 +1305,7 @@ function freshness ($format = 'number') {
$updated = true; // Can't find syndication meta-data
endif;

if ($updated and FeedWordPress::diagnostic_on('feed_items:freshness:reasons')) :
if ($updated and FeedWordPressDiagnostic::is_on('feed_items:freshness:reasons')) :
// In the absence of definitive
// timestamp information, we
// just have to assume that a
Expand Down Expand Up @@ -1451,7 +1451,7 @@ function fresh_storage_hook () {

function wp_id () {
if ($this->filtered()) : // This should never happen.
FeedWordPress::critical_bug('SyndicatedPost', $this, __LINE__, __FILE__);
FeedWordPressDiagnostic::critical_bug('SyndicatedPost', $this, __LINE__, __FILE__);
endif;

if (is_null($this->_wp_id) and is_null($this->_freshness)) :
Expand Down Expand Up @@ -1607,7 +1607,7 @@ public function store () {
global $wpdb;

if ($this->filtered()) : // This should never happen.
FeedWordPress::critical_bug('SyndicatedPost', $this, __LINE__, __FILE__);
FeedWordPressDiagnostic::critical_bug('SyndicatedPost', $this, __LINE__, __FILE__);
endif;

$freshness = $this->freshness();
Expand Down Expand Up @@ -1989,7 +1989,7 @@ function validate_post_id ($dbpost, $is_update, $ns) {
$ns::_wp_id
EOM;
FeedWordPress::noncritical_bug(
FeedWordPressDiagnostic::noncritical_bug(
/*message=*/ $mesg,
/*var =*/ array(
"\$this->_wp_id" => $this->_wp_id,
Expand Down
2 changes: 1 addition & 1 deletion syndicatedpostterm.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public function insert ($tax = NULL) {
if (is_wp_error($aTerm)) :

// If debug mode is ON, this will halt us here.
FeedWordPress::noncritical_bug(
FeedWordPressDiagnostic::noncritical_bug(
'term insertion problem', array(
'term' => $this->term,
'result' => $aTerm,
Expand Down

0 comments on commit 61d242e

Please sign in to comment.