Skip to content
Snippets Groups Projects
Commit 283452f6 authored by Erick Hitter's avatar Erick Hitter
Browse files

Allow others to override the priority at which this plugin changes the number of revisions to keep.

parent 207f5a47
No related branches found
No related tags found
No related merge requests found
...@@ -31,6 +31,9 @@ class WP_Revisions_Control { ...@@ -31,6 +31,9 @@ class WP_Revisions_Control {
/** /**
* Class variables * Class variables
*/ */
private static $priority = null; // use $this->plugin_priority()
private $priority_default = 50;
private static $post_types = array(); // use $this->get_post_types() private static $post_types = array(); // use $this->get_post_types()
private static $settings = array(); // use $this->get_settings() private static $settings = array(); // use $this->get_settings()
...@@ -72,20 +75,21 @@ class WP_Revisions_Control { ...@@ -72,20 +75,21 @@ class WP_Revisions_Control {
* Register actions and filters * Register actions and filters
* *
* @uses add_action * @uses add_action
* @uses apply_filters
* @uses add_filter * @uses add_filter
* @uses this::plugin_priority
* @return null * @return null
*/ */
public function action_init() { public function action_init() {
add_action( 'admin_init', array( $this, 'action_admin_init' ) ); add_action( 'admin_init', array( $this, 'action_admin_init' ) );
$plugin_priority = apply_filters( 'wp_revisions_control_priority', 50 ); add_filter( 'wp_revisions_to_keep', array( $this, 'filter_wp_revisions_to_keep' ), $this->plugin_priority(), 2 );
add_filter( 'wp_revisions_to_keep', array( $this, 'filter_wp_revisions_to_keep' ), $plugin_priority, 2 );
} }
/** /**
* Register plugin's settings fields * Register plugin's settings fields
* *
* Plugin title is intentionally not translatable.
*
* @uses register_setting * @uses register_setting
* @uses add_settings_section * @uses add_settings_section
* @uses __ * @uses __
...@@ -108,6 +112,7 @@ class WP_Revisions_Control { ...@@ -108,6 +112,7 @@ class WP_Revisions_Control {
* Display assistive text in settings section * Display assistive text in settings section
* *
* @uses _e * @uses _e
* @uses this::plugin_priority
* @return string * @return string
*/ */
public function settings_section_intro() { public function settings_section_intro() {
...@@ -115,6 +120,12 @@ class WP_Revisions_Control { ...@@ -115,6 +120,12 @@ class WP_Revisions_Control {
<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( '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> <p><?php _e( "If a post type isn't listed, revisions are not enabled for that post type.", 'wp_revisions_control' ); ?></p>
<?php <?php
// Display a note if the plugin priority is other than the default.
// Will be useful when debugging issues later.
if ( $this->plugin_priority() !== $this->priority_default ) : ?>
<p><?php _e( "A local change is causing this plugin's functionality to run at a priority other than the default. If you experience difficulties with the plugin, please unhook any functions from the <code>wp_revisions_control_priority</code> filter.", 'wp_revisions_control' ); ?></p>
<?php endif;
} }
/** /**
...@@ -159,6 +170,22 @@ class WP_Revisions_Control { ...@@ -159,6 +170,22 @@ class WP_Revisions_Control {
return $options_sanitized; return $options_sanitized;
} }
/**
* Allow others to change the priority this plugin's functionality runs at
*
* @uses apply_filters
* @return int
*/
private function plugin_priority() {
if ( is_null( self::$priority ) ) {
$plugin_priority = apply_filters( 'wp_revisions_control_priority', $this->priority_default );
self::$priority = is_numeric( $plugin_priority ) ? (int) $plugin_priority : $this->priority_default;
}
return self::$priority;
}
/** /**
* Override number of revisions to keep using plugin's settings * Override number of revisions to keep using plugin's settings
* *
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment