cleanup + fail in php < 5.3 + log tune
This commit is contained in:
parent
de30748078
commit
9b980e55a3
3 changed files with 35 additions and 9 deletions
|
@ -1,6 +1,6 @@
|
|||
=== wp-shortslug ===
|
||||
Contributors: cadeyrn
|
||||
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=AS8Y2GSMDTJZC
|
||||
Donate link: https://paypal.me/petermolnar/3
|
||||
Tags: shortlink, shorturl, slug
|
||||
Requires at least: 3.0
|
||||
Tested up to: 4.4
|
||||
|
|
|
@ -33,6 +33,8 @@ class WP_SHORTSLUG {
|
|||
const base_camel = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||
|
||||
public function __construct () {
|
||||
register_activation_hook( __FILE__ , array( &$this, 'plugin_activate' ) );
|
||||
|
||||
// init all the things!
|
||||
add_action( 'init', array( &$this, 'init'));
|
||||
|
||||
|
@ -57,6 +59,15 @@ class WP_SHORTSLUG {
|
|||
add_filter( 'get_shortlink', array(&$this, 'shorturl'), 1, 4 );
|
||||
}
|
||||
|
||||
/**
|
||||
* activate hook
|
||||
*/
|
||||
public static function plugin_activate() {
|
||||
if ( version_compare( phpversion(), 5.3, '<' ) ) {
|
||||
die( 'The minimum PHP version required for this plugin is 5.3' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* try to redirect by old slug in case the current result is 404
|
||||
*
|
||||
|
@ -196,6 +207,7 @@ class WP_SHORTSLUG {
|
|||
'post_name' => $url36,
|
||||
);
|
||||
|
||||
$wp_error = false;
|
||||
wp_update_post( $_post, $wp_error );
|
||||
|
||||
if (is_wp_error($wp_error)) {
|
||||
|
@ -203,7 +215,6 @@ class WP_SHORTSLUG {
|
|||
static::debug( $errors );
|
||||
}
|
||||
|
||||
|
||||
$meta = get_post_meta( $post->ID, '_wp_old_slug', false);
|
||||
if (in_array($url36,$meta)) {
|
||||
static::debug('removing slug ' . $url36 . ' from ' . $post->ID );
|
||||
|
@ -282,14 +293,29 @@ class WP_SHORTSLUG {
|
|||
}
|
||||
|
||||
/**
|
||||
* debug log messages, if needed
|
||||
*
|
||||
* debug messages; will only work if WP_DEBUG is on
|
||||
* or if the level is LOG_ERR, but that will kill the process
|
||||
*
|
||||
* @param string $message
|
||||
* @param int $level
|
||||
*/
|
||||
public static function debug( $message) {
|
||||
if (is_object($message) || is_array($message))
|
||||
public static function debug( $message, $level = LOG_NOTICE ) {
|
||||
if ( @is_array( $message ) || @is_object ( $message ) )
|
||||
$message = json_encode($message);
|
||||
|
||||
if ( defined('WP_DEBUG') && WP_DEBUG == true )
|
||||
error_log ( __CLASS__ . ' => ' . $message);
|
||||
|
||||
switch ( $level ) {
|
||||
case LOG_ERR :
|
||||
wp_die( '<h1>Error:</h1>' . '<p>' . $message . '</p>' );
|
||||
exit;
|
||||
default:
|
||||
if ( !defined( 'WP_DEBUG' ) || WP_DEBUG != true )
|
||||
return;
|
||||
break;
|
||||
}
|
||||
|
||||
error_log( __CLASS__ . ": " . $message );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue