From b8edc98bdd1e3b0f07891074fb6c7c7a97f7c261 Mon Sep 17 00:00:00 2001
From: Erick Hitter <ehitter@gmail.com>
Date: Sat, 29 Jun 2013 13:11:49 -0400
Subject: [PATCH] Bug fix with storing `0`, add some help text.

---
 wp-revisions-control.php | 31 ++++++++++++++++---------------
 1 file changed, 16 insertions(+), 15 deletions(-)

diff --git a/wp-revisions-control.php b/wp-revisions-control.php
index 27609a7..fae037e 100644
--- a/wp-revisions-control.php
+++ b/wp-revisions-control.php
@@ -57,19 +57,6 @@ class WP_Revisions_Control {
 		return self::$__instance;
 	}
 
-	/**
-	 * Magic getter to provide access to class variables
-	 *
-	 * @param string $name
-	 * @return mixed
-	 */
-	// public function __get( $name ) {
-	//	if ( property_exists( $this, $name ) )
-	//		return $this->$name;
-	//	else
-	//		return null;
-	// }
-
 	/**
 	 * Register actions and filters
 	 *
@@ -89,13 +76,23 @@ class WP_Revisions_Control {
 	public function action_admin_init() {
 		register_setting( $this->settings_page, $this->settings_section, array( $this, 'sanitize_options' ) );
 
-		add_settings_section( $this->settings_section, __( 'WP Revisions Control', 'wp_revisions_control' ), '__return_false', $this->settings_page );
+		add_settings_section( $this->settings_section, __( 'WP Revisions Control', 'wp_revisions_control' ), array( $this, 'settings_section_intro' ), $this->settings_page );
 
 		foreach ( $this->get_post_types() as $post_type => $name ) {
 			add_settings_field( $this->settings_section . '-' . $post_type, $name, array( $this, 'field_post_type' ), $this->settings_page, $this->settings_section, array( 'post_type' => $post_type ) );
 		}
 	}
 
+	/**
+	 *
+	 */
+	public function settings_section_intro() {
+		?>
+		<p><?php _e( 'Set the number of revisions to save for each post type listed. To retain all revisions for a given post type, leave the field empty.', 'wp_revisions_control' ); ?></p>
+		<p><?php _e( "If a post type isn't listed, revisions are not enabled for that post type.", 'wp_revisions_control' ); ?></p>
+		<?php
+	}
+
 	/**
 	 *
 	 */
@@ -114,11 +111,15 @@ class WP_Revisions_Control {
 
 		if ( is_array( $options ) ) {
 			foreach ( $options as $post_type => $to_keep ) {
-				if ( empty( $to_keep ) )
+				if ( 0 === strlen( $to_keep ) )
 					$to_keep = -1;
 				else
 					$to_keep = intval( $to_keep );
 
+				// Lowest possible value is -1, used to indicate infinite revisions are stored
+				if ( -1 > $to_keep )
+					$to_keep = -1;
+
 				$options_sanitized[ $post_type ] = $to_keep;
 			}
 		}
-- 
GitLab