0.2.1, see readme.txt
Peter Molnar hello@petermolnar.eu
Tue, 01 Mar 2016 21:24:17 +0000
2 files changed,
50 insertions(+),
12 deletions(-)
M
readme.txt
→
readme.txt
@@ -4,7 +4,7 @@ Donate link: https://paypal.me/petermolnar/3
Tags: linkrot, archive, hyperlink, url Requires at least: 3.0 Tested up to: 4.4.1 -Stable tag: 0.2 +Stable tag: 0.2.1 License: GPLv3 License URI: http://www.gnu.org/licenses/gpl-3.0.html Required minimum PHP version: 5.3@@ -35,6 +35,11 @@
* every A. indicates BIG changes. * every .B version indicates new features. * every ..C indicates bugfixes for A.B version. + += 0.2.1 = +* 2016-03-01* + +* better logging, added filter for urls = 0.2 = *2016-01-07*
M
wp-url2snapshot.php
→
wp-url2snapshot.php
@@ -3,7 +3,7 @@ /*
Plugin Name: wp-url2snapshot Plugin URI: https://github.com/petermolnar/wp-url2snapshot Description: reversible automatic short slug based on post pubdate epoch for WordPress -Version: 0.2 +Version: 0.2.1 Author: Peter Molnar <hello@petermolnar.eu> Author URI: http://petermolnar.eu/ License: GPLv3@@ -119,6 +119,8 @@
static::debug(" processing post #{$post->ID}"); $content = static::get_the_content($post); $urls = static::extract_urls($content); + $urls = apply_filters ( 'wp_url2snapshot_urls', $urls, $post ); + $urls = array_unique ( $urls ); foreach ($urls as $url) { $url = esc_url_raw($url);@@ -427,23 +429,54 @@ * or if the level is LOG_ERR, but that will kill the process
* * @param string $message * @param int $level + * + * @output log to syslog | wp_die on high level + * @return false on not taking action, true on log sent */ public static function debug( $message, $level = LOG_NOTICE ) { + if ( empty( $message ) ) + return false; + if ( @is_array( $message ) || @is_object ( $message ) ) $message = json_encode($message); + $levels = array ( + LOG_EMERG => 0, // system is unusable + LOG_ALERT => 1, // Alert action must be taken immediately + LOG_CRIT => 2, // Critical critical conditions + LOG_ERR => 3, // Error error conditions + LOG_WARNING => 4, // Warning warning conditions + LOG_NOTICE => 5, // Notice normal but significant condition + LOG_INFO => 6, // Informational informational messages + LOG_DEBUG => 7, // Debug debug-level messages + ); - switch ( $level ) { - case LOG_ERR : - wp_die( '<h1>Error:</h1>' . '<p>' . $message . '</p>' ); - exit; - default: - if ( !defined( 'WP_DEBUG' ) || WP_DEBUG != true ) - return; - break; + // number for number based comparison + // should work with the defines only, this is just a make-it-sure step + $level_ = $levels [ $level ]; + + // in case WordPress debug log has a minimum level + if ( defined ( 'WP_DEBUG_LEVEL' ) ) { + $wp_level = $levels [ WP_DEBUG_LEVEL ]; + if ( $level_ < $wp_level ) { + return false; + } + } + + // ERR, CRIT, ALERT and EMERG + if ( 3 >= $level_ ) { + wp_die( '<h1>Error:</h1>' . '<p>' . $message . '</p>' ); + exit; } - error_log( __CLASS__ . ": " . $message ); + $trace = debug_backtrace(); + $caller = $trace[1]; + $parent = $caller['function']; + + if (isset($caller['class'])) + $parent = $caller['class'] . '::' . $parent; + + return error_log( "{$parent}: {$message}" ); } /**@@ -471,4 +504,4 @@ }
$WP_URL2SNAPSHOT = new WP_URL2SNAPSHOT(); -endif;+endif;