From 172504813ff6d4b478d8fc42631d0535ed33f485 Mon Sep 17 00:00:00 2001 From: Peter Molnar Date: Tue, 1 Mar 2016 21:24:17 +0000 Subject: [PATCH] 0.2.1, see readme.txt --- readme.txt | 7 +++++- wp-url2snapshot.php | 55 ++++++++++++++++++++++++++++++++++++--------- 2 files changed, 50 insertions(+), 12 deletions(-) diff --git a/readme.txt b/readme.txt index 796ab47..6c388da 100644 --- a/readme.txt +++ b/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 @@ -36,6 +36,11 @@ Version numbering logic: * 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* diff --git a/wp-url2snapshot.php b/wp-url2snapshot.php index 7757043..1e51f74 100644 --- a/wp-url2snapshot.php +++ b/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 Author URI: http://petermolnar.eu/ License: GPLv3 @@ -119,6 +119,8 @@ class WP_URL2SNAPSHOT { 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 @@ class WP_URL2SNAPSHOT { * * @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( '

Error:

' . '

' . $message . '

' ); - 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; + } } - error_log( __CLASS__ . ": " . $message ); + // ERR, CRIT, ALERT and EMERG + if ( 3 >= $level_ ) { + wp_die( '

Error:

' . '

' . $message . '

' ); + exit; + } + + $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 @@ class WP_URL2SNAPSHOT { $WP_URL2SNAPSHOT = new WP_URL2SNAPSHOT(); -endif; \ No newline at end of file +endif;