Version Description
- Introduce Spanish translation thanks to Maria Ramos at WebHostingHub.
Download this release
Release Info
Developer | ethitter |
Plugin | WP Revisions Control |
Version | 1.2.1 |
Comparing to | |
See all releases |
Code changes from version 1.0 to 1.2.1
- js/post.js +73 -0
- languages/wp-revisions-control.pot +113 -0
- languages/wp_revisions_control-es_ES.mo +0 -0
- languages/wp_revisions_control-es_ES.pot +114 -0
- readme.txt +22 -5
- wp-revisions-control.php +234 -9
js/post.js
ADDED
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
( function( $ ) {
|
2 |
+
$( document ).ready( function() {
|
3 |
+
var purge_button = $( '#' + wp_revisions_control.namespace + ' .button.purge' ),
|
4 |
+
post_id = null,
|
5 |
+
nonce = null,
|
6 |
+
button_text = null;
|
7 |
+
|
8 |
+
button_text = $( purge_button ).text();
|
9 |
+
|
10 |
+
$( purge_button ).on( 'click', click_handler_purge );
|
11 |
+
|
12 |
+
/**
|
13 |
+
* Click handler for purging a post's revisions
|
14 |
+
*/
|
15 |
+
function click_handler_purge() {
|
16 |
+
post_id = parseInt( $( this ).data( 'postid' ) );
|
17 |
+
|
18 |
+
$( purge_button ).text( wp_revisions_control.processing_text );
|
19 |
+
|
20 |
+
var confirmed = confirm( wp_revisions_control.ays );
|
21 |
+
|
22 |
+
if ( confirmed && post_id ) {
|
23 |
+
$.ajax({
|
24 |
+
url: ajaxurl,
|
25 |
+
cache: false,
|
26 |
+
data: {
|
27 |
+
action: wp_revisions_control.action_base + '_purge',
|
28 |
+
post_id: post_id,
|
29 |
+
nonce: $( this ).data( 'nonce' )
|
30 |
+
},
|
31 |
+
type: 'post',
|
32 |
+
dataType: 'json',
|
33 |
+
success: ajax_purge_request_success,
|
34 |
+
error: ajax_purge_request_error
|
35 |
+
});
|
36 |
+
} else {
|
37 |
+
$( purge_button ).text( button_text );
|
38 |
+
}
|
39 |
+
}
|
40 |
+
|
41 |
+
/**
|
42 |
+
* User feedback when Ajax request succeeds
|
43 |
+
* Does not indicate that purge request succeeded
|
44 |
+
*/
|
45 |
+
function ajax_purge_request_success( response ) {
|
46 |
+
if ( response.error ) {
|
47 |
+
alert( response.error );
|
48 |
+
|
49 |
+
$( purge_button ).text( button_text );
|
50 |
+
} else if ( response.success ) {
|
51 |
+
var list_table = $( 'ul.post-revisions > li' );
|
52 |
+
|
53 |
+
$( list_table ).each( function() {
|
54 |
+
var autosave = $( this ).text().match( wp_revisions_control.autosave );
|
55 |
+
|
56 |
+
if ( ! autosave )
|
57 |
+
$( this ).slideUp( 'slow' ).remove();
|
58 |
+
} );
|
59 |
+
|
60 |
+
$( purge_button ).fadeOut( 'slow' ).after( wp_revisions_control.nothing_text );
|
61 |
+
}
|
62 |
+
}
|
63 |
+
|
64 |
+
/**
|
65 |
+
* Return a generic error when the Ajax request fails
|
66 |
+
*/
|
67 |
+
function ajax_purge_request_error() {
|
68 |
+
alert( wp_revisions_control.error );
|
69 |
+
|
70 |
+
$( purge_button ).text( button_text );
|
71 |
+
}
|
72 |
+
} );
|
73 |
+
} )( jQuery );
|
languages/wp-revisions-control.pot
ADDED
@@ -0,0 +1,113 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Copyright (C) 2019 Erick Hitter
|
2 |
+
# This file is distributed under the same license as the WP Revisions Control package.
|
3 |
+
msgid ""
|
4 |
+
msgstr ""
|
5 |
+
"Project-Id-Version: WP Revisions Control 1.2.1\n"
|
6 |
+
"Report-Msgid-Bugs-To: "
|
7 |
+
"https://wordpress.org/support/plugin/wp-revisions-control\n"
|
8 |
+
"POT-Creation-Date: 2019-04-14 04:52:10+00:00\n"
|
9 |
+
"MIME-Version: 1.0\n"
|
10 |
+
"Content-Type: text/plain; charset=utf-8\n"
|
11 |
+
"Content-Transfer-Encoding: 8bit\n"
|
12 |
+
"PO-Revision-Date: 2019-MO-DA HO:MI+ZONE\n"
|
13 |
+
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
14 |
+
"Language-Team: LANGUAGE <LL@li.org>\n"
|
15 |
+
"X-Generator: grunt-wp-i18n 0.5.4\n"
|
16 |
+
"X-Poedit-KeywordsList: "
|
17 |
+
"__;_e;_x:1,2c;_ex:1,2c;_n:1,2;_nx:1,2,4c;_n_noop:1,2;_nx_noop:1,2,3c;esc_"
|
18 |
+
"attr__;esc_html__;esc_attr_e;esc_html_e;esc_attr_x:1,2c;esc_html_x:1,2c;\n"
|
19 |
+
"Language: en\n"
|
20 |
+
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
21 |
+
"X-Poedit-Country: United States\n"
|
22 |
+
"X-Poedit-SourceCharset: UTF-8\n"
|
23 |
+
"X-Poedit-Basepath: ../\n"
|
24 |
+
"X-Poedit-SearchPath-0: .\n"
|
25 |
+
"X-Poedit-Bookmarks: \n"
|
26 |
+
"X-Textdomain-Support: yes\n"
|
27 |
+
|
28 |
+
#: wp-revisions-control.php:148
|
29 |
+
msgid ""
|
30 |
+
"Set the number of revisions to save for each post type listed. To retain "
|
31 |
+
"all revisions for a given post type, leave the field empty."
|
32 |
+
msgstr ""
|
33 |
+
|
34 |
+
#: wp-revisions-control.php:149
|
35 |
+
msgid "If a post type isn't listed, revisions are not enabled for that post type."
|
36 |
+
msgstr ""
|
37 |
+
|
38 |
+
#: wp-revisions-control.php:155
|
39 |
+
msgid ""
|
40 |
+
"A local change is causing this plugin's functionality to run at a priority "
|
41 |
+
"other than the default. If you experience difficulties with the plugin, "
|
42 |
+
"please unhook any functions from the %s filter."
|
43 |
+
msgstr ""
|
44 |
+
|
45 |
+
#: wp-revisions-control.php:274
|
46 |
+
msgid "Revisions"
|
47 |
+
msgstr ""
|
48 |
+
|
49 |
+
#: wp-revisions-control.php:282
|
50 |
+
msgid "Processing…"
|
51 |
+
msgstr ""
|
52 |
+
|
53 |
+
#: wp-revisions-control.php:283
|
54 |
+
msgid "Are you sure you want to remove revisions from this post?"
|
55 |
+
msgstr ""
|
56 |
+
|
57 |
+
#: wp-revisions-control.php:284
|
58 |
+
msgid "Autosave"
|
59 |
+
msgstr ""
|
60 |
+
|
61 |
+
#: wp-revisions-control.php:285
|
62 |
+
msgid "There are no revisions to remove."
|
63 |
+
msgstr ""
|
64 |
+
|
65 |
+
#: wp-revisions-control.php:286
|
66 |
+
msgid "An error occurred. Please refresh the page and try again."
|
67 |
+
msgstr ""
|
68 |
+
|
69 |
+
#: wp-revisions-control.php:312
|
70 |
+
msgid "Purge these revisions"
|
71 |
+
msgstr ""
|
72 |
+
|
73 |
+
#: wp-revisions-control.php:315
|
74 |
+
msgid ""
|
75 |
+
"Limit this post to %s revisions. Leave this field blank for default "
|
76 |
+
"behavior."
|
77 |
+
msgstr ""
|
78 |
+
|
79 |
+
#: wp-revisions-control.php:341
|
80 |
+
msgid "No post ID was provided. Please refresh the page and try again."
|
81 |
+
msgstr ""
|
82 |
+
|
83 |
+
#: wp-revisions-control.php:343
|
84 |
+
msgid "Invalid request. Please refresh the page and try again."
|
85 |
+
msgstr ""
|
86 |
+
|
87 |
+
#: wp-revisions-control.php:345
|
88 |
+
msgid "You are not allowed to edit this post."
|
89 |
+
msgstr ""
|
90 |
+
|
91 |
+
#: wp-revisions-control.php:357
|
92 |
+
msgid "Removed %s revisions associated with this post."
|
93 |
+
msgstr ""
|
94 |
+
|
95 |
+
#. Plugin Name of the plugin/theme
|
96 |
+
msgid "WP Revisions Control"
|
97 |
+
msgstr ""
|
98 |
+
|
99 |
+
#. Plugin URI of the plugin/theme
|
100 |
+
msgid "https://ethitter.com/plugins/wp-revisions-control/"
|
101 |
+
msgstr ""
|
102 |
+
|
103 |
+
#. Description of the plugin/theme
|
104 |
+
msgid "Control how many revisions are stored for each post type"
|
105 |
+
msgstr ""
|
106 |
+
|
107 |
+
#. Author of the plugin/theme
|
108 |
+
msgid "Erick Hitter"
|
109 |
+
msgstr ""
|
110 |
+
|
111 |
+
#. Author URI of the plugin/theme
|
112 |
+
msgid "https://ethitter.com/"
|
113 |
+
msgstr ""
|
languages/wp_revisions_control-es_ES.mo
ADDED
Binary file
|
languages/wp_revisions_control-es_ES.pot
ADDED
@@ -0,0 +1,114 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Copyright (C) 2013 WP Revisions Control
|
2 |
+
# This file is distributed under the same license as the WP Revisions Control package.
|
3 |
+
msgid ""
|
4 |
+
msgstr ""
|
5 |
+
"Project-Id-Version: WP Revisions Control 1.2.1\n"
|
6 |
+
"Report-Msgid-Bugs-To: http://wordpress.org/tag/wp-revisions-control\n"
|
7 |
+
"POT-Creation-Date: 2013-12-05 22:43:04+00:00\n"
|
8 |
+
"MIME-Version: 1.0\n"
|
9 |
+
"Content-Type: text/plain; charset=UTF-8\n"
|
10 |
+
"Content-Transfer-Encoding: 8bit\n"
|
11 |
+
"PO-Revision-Date: 2013-12-10 10:40+0100\n"
|
12 |
+
"Last-Translator: jelena kovacevic <jecajeca260@gmail.com>\n"
|
13 |
+
"Language-Team: LANGUAGE <LL@li.org>\n"
|
14 |
+
"X-Generator: Poedit 1.5.5\n"
|
15 |
+
|
16 |
+
#: wp-revisions-control.php:148
|
17 |
+
msgid ""
|
18 |
+
"Set the number of revisions to save for each post type listed. To retain all "
|
19 |
+
"revisions for a given post type, leave the field empty."
|
20 |
+
msgstr ""
|
21 |
+
"Establecer el número de revisiones a guardar para cada tipo de publicación "
|
22 |
+
"que aparece. Para conservar todas las revisiones para un tipo determinado de "
|
23 |
+
"publicación, deje el campo vacío."
|
24 |
+
|
25 |
+
#: wp-revisions-control.php:149
|
26 |
+
msgid ""
|
27 |
+
"If a post type isn't listed, revisions are not enabled for that post type."
|
28 |
+
msgstr ""
|
29 |
+
"Si un tipo de publicación no aparece en la lista, las revisiones no están "
|
30 |
+
"habilitadas para ese tipo de publicación.."
|
31 |
+
|
32 |
+
#: wp-revisions-control.php:155
|
33 |
+
msgid ""
|
34 |
+
"A local change is causing this plugin's functionality to run at a priority "
|
35 |
+
"other than the default. If you experience difficulties with the plugin, "
|
36 |
+
"please unhook any functions from the %s filter."
|
37 |
+
msgstr ""
|
38 |
+
"Un cambio local está causando que la funcionalidad de este plugin se ejecute "
|
39 |
+
"con una prioridad distinta de la predeterminada . Si tiene alguna dificultad "
|
40 |
+
"con el plugin, por favor desenganchar las funciones del filtro %s."
|
41 |
+
|
42 |
+
#: wp-revisions-control.php:274
|
43 |
+
msgid "Revisions"
|
44 |
+
msgstr "Revisiones"
|
45 |
+
|
46 |
+
#: wp-revisions-control.php:282
|
47 |
+
msgid "Processing…"
|
48 |
+
msgstr "Procesaando…..."
|
49 |
+
|
50 |
+
#: wp-revisions-control.php:283
|
51 |
+
msgid "Are you sure you want to remove revisions from this post?"
|
52 |
+
msgstr "¿Está seguro de que desea eliminar las revisiones de esta publicación?"
|
53 |
+
|
54 |
+
#: wp-revisions-control.php:284
|
55 |
+
msgid "Autosave"
|
56 |
+
msgstr "Autoguardado"
|
57 |
+
|
58 |
+
#: wp-revisions-control.php:285
|
59 |
+
msgid "There are no revisions to remove."
|
60 |
+
msgstr "No hay revisiones para eliminar."
|
61 |
+
|
62 |
+
#: wp-revisions-control.php:286
|
63 |
+
msgid "An error occurred. Please refresh the page and try again."
|
64 |
+
msgstr "Se ha producido un error. Actualice la página y vuelva a intentarlo."
|
65 |
+
|
66 |
+
#: wp-revisions-control.php:312
|
67 |
+
msgid "Purge these revisions"
|
68 |
+
msgstr "Purgar estas revisiones"
|
69 |
+
|
70 |
+
#: wp-revisions-control.php:315
|
71 |
+
msgid ""
|
72 |
+
"Limit this post to %s revisions. Leave this field blank for default behavior."
|
73 |
+
msgstr ""
|
74 |
+
"Limitar esta publicación a %s revisiones. Deje este campo en blanco para el "
|
75 |
+
"comportamiento por defecto."
|
76 |
+
|
77 |
+
#: wp-revisions-control.php:341
|
78 |
+
msgid "No post ID was provided. Please refresh the page and try again."
|
79 |
+
msgstr ""
|
80 |
+
"No se proporcionó un ID de publicación. Actualice la página y vuelva a "
|
81 |
+
"intentarlo."
|
82 |
+
|
83 |
+
#: wp-revisions-control.php:343
|
84 |
+
msgid "Invalid request. Please refresh the page and try again."
|
85 |
+
msgstr "Petición no válida. Actualice la página y vuelva a intentarlo."
|
86 |
+
|
87 |
+
#: wp-revisions-control.php:345
|
88 |
+
msgid "You are not allowed to edit this post."
|
89 |
+
msgstr "Usted no está autorizado a editar esta publicación."
|
90 |
+
|
91 |
+
#: wp-revisions-control.php:357
|
92 |
+
msgid "Removed %s revisions associated with this post."
|
93 |
+
msgstr "Eliminadas %s revisiones asociadas a esta publicación."
|
94 |
+
|
95 |
+
#. Plugin Name of the plugin/theme
|
96 |
+
msgid "WP Revisions Control"
|
97 |
+
msgstr "Control Revisiones WP"
|
98 |
+
|
99 |
+
#. Plugin URI of the plugin/theme
|
100 |
+
msgid "http://www.ethitter.com/plugins/wp-revisions-control/"
|
101 |
+
msgstr "http://www.ethitter.com/plugins/wp-revisions-control/"
|
102 |
+
|
103 |
+
#. Description of the plugin/theme
|
104 |
+
msgid "Control how many revisions are stored for each post type"
|
105 |
+
msgstr ""
|
106 |
+
"Control de cuántas revisiones se almacenan para cada tipo de publicación"
|
107 |
+
|
108 |
+
#. Author of the plugin/theme
|
109 |
+
msgid "Erick Hitter"
|
110 |
+
msgstr "Erick Hitter"
|
111 |
+
|
112 |
+
#. Author URI of the plugin/theme
|
113 |
+
msgid "http://www.ethitter.com/"
|
114 |
+
msgstr "http://www.ethitter.com/"
|
readme.txt
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
=== WP Revisions Control ===
|
2 |
Contributors: ethitter
|
3 |
-
Donate link: https://
|
4 |
Tags: revision, revisions, admin
|
5 |
Requires at least: 3.6
|
6 |
-
Tested up to:
|
7 |
-
Stable tag: 1.
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -18,6 +18,8 @@ With this plugin enabled, simply visit **Settings > Writing** to specify the num
|
|
18 |
|
19 |
Why is this helpful? Revisions are stored in the database, and if many are stored, can cause bloat. This bloat may lead to slower queries, which can have a noticeable performance impact. The value of these revisions also depends on what is being tracked. For example, I may want to store every revision of the posts I write, but only desire to keep the latest five versions of each page on my site. Starting in WordPress 3.6, this control is available. WordPress doesn’t provide a native interface to specify revisions quantities, so I wrote this quick plugin to do so.
|
20 |
|
|
|
|
|
21 |
**Development is over on GitHub: https://github.com/ethitter/WP-Revisions-Control.**
|
22 |
|
23 |
== Installation ==
|
@@ -33,9 +35,24 @@ Navigate to **Settings > Writing** in your WordPress Dashboard, and look for the
|
|
33 |
|
34 |
== Changelog ==
|
35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
= 1.0 =
|
37 |
-
Initial public release
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
== Screenshots ==
|
40 |
|
41 |
-
1. The plugin's settings section, found under **Settings > Writing**.
|
|
1 |
=== WP Revisions Control ===
|
2 |
Contributors: ethitter
|
3 |
+
Donate link: https://ethitter.com/donate/
|
4 |
Tags: revision, revisions, admin
|
5 |
Requires at least: 3.6
|
6 |
+
Tested up to: 5.2
|
7 |
+
Stable tag: 1.2.1
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
18 |
|
19 |
Why is this helpful? Revisions are stored in the database, and if many are stored, can cause bloat. This bloat may lead to slower queries, which can have a noticeable performance impact. The value of these revisions also depends on what is being tracked. For example, I may want to store every revision of the posts I write, but only desire to keep the latest five versions of each page on my site. Starting in WordPress 3.6, this control is available. WordPress doesn’t provide a native interface to specify revisions quantities, so I wrote this quick plugin to do so.
|
20 |
|
21 |
+
Thanks to Maria Ramos at [WebHostingHub](http://www.webhostinghub.com/), the plugin is also available in Spanish. Many thanks to her for her efforts!
|
22 |
+
|
23 |
**Development is over on GitHub: https://github.com/ethitter/WP-Revisions-Control.**
|
24 |
|
25 |
== Installation ==
|
35 |
|
36 |
== Changelog ==
|
37 |
|
38 |
+
= 1.2.1 =
|
39 |
+
* Introduce Spanish translation thanks to Maria Ramos at [WebHostingHub](http://www.webhostinghub.com/).
|
40 |
+
|
41 |
+
= 1.2 =
|
42 |
+
* Add post-level revision purging and limiting. For any post type that supports revisions, you can now limit the number of revisions retained at a post level.
|
43 |
+
|
44 |
= 1.0 =
|
45 |
+
* Initial public release
|
46 |
+
|
47 |
+
== Upgrade Notice ==
|
48 |
+
|
49 |
+
= 1.2.1 =
|
50 |
+
Introduces Spanish translation thanks to Maria Ramos at [WebHostingHub](http://www.webhostinghub.com/).
|
51 |
+
|
52 |
+
= 1.2 =
|
53 |
+
For any post type that supports revisions, you can now limit the number of revisions retained at a post level.
|
54 |
|
55 |
== Screenshots ==
|
56 |
|
57 |
+
1. The plugin's settings section, found under **Settings > Writing**.
|
58 |
+
2. The post-level controls provided in version 1.2.
|
wp-revisions-control.php
CHANGED
@@ -1,11 +1,13 @@
|
|
1 |
<?php
|
2 |
/*
|
3 |
Plugin Name: WP Revisions Control
|
4 |
-
Plugin URI:
|
5 |
Description: Control how many revisions are stored for each post type
|
6 |
Author: Erick Hitter
|
7 |
-
Version: 1.
|
8 |
-
Author URI:
|
|
|
|
|
9 |
|
10 |
This program is free software; you can redistribute it and/or modify
|
11 |
it under the terms of the GNU General Public License as published by
|
@@ -40,6 +42,8 @@ class WP_Revisions_Control {
|
|
40 |
private $settings_page = 'writing';
|
41 |
private $settings_section = 'wp_revisions_control';
|
42 |
|
|
|
|
|
43 |
/**
|
44 |
* Silence is golden!
|
45 |
*/
|
@@ -68,9 +72,22 @@ class WP_Revisions_Control {
|
|
68 |
* @return null
|
69 |
*/
|
70 |
private function setup() {
|
|
|
71 |
add_action( 'init', array( $this, 'action_init' ) );
|
72 |
}
|
73 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
/**
|
75 |
* Register actions and filters
|
76 |
*
|
@@ -86,7 +103,7 @@ class WP_Revisions_Control {
|
|
86 |
}
|
87 |
|
88 |
/**
|
89 |
-
* Register plugin's
|
90 |
*
|
91 |
* Plugin title is intentionally not translatable.
|
92 |
*
|
@@ -99,6 +116,7 @@ class WP_Revisions_Control {
|
|
99 |
* @return null
|
100 |
*/
|
101 |
public function action_admin_init() {
|
|
|
102 |
register_setting( $this->settings_page, $this->settings_section, array( $this, 'sanitize_options' ) );
|
103 |
|
104 |
add_settings_section( $this->settings_section, 'WP Revisions Control', array( $this, 'settings_section_intro' ), $this->settings_page );
|
@@ -106,8 +124,18 @@ class WP_Revisions_Control {
|
|
106 |
foreach ( $this->get_post_types() as $post_type => $name ) {
|
107 |
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 ) );
|
108 |
}
|
|
|
|
|
|
|
|
|
|
|
109 |
}
|
110 |
|
|
|
|
|
|
|
|
|
|
|
111 |
/**
|
112 |
* Display assistive text in settings section
|
113 |
*
|
@@ -124,7 +152,7 @@ class WP_Revisions_Control {
|
|
124 |
// Display a note if the plugin priority is other than the default.
|
125 |
// Will be useful when debugging issues later.
|
126 |
if ( $this->plugin_priority() !== $this->priority_default ) : ?>
|
127 |
-
<p><?php
|
128 |
<?php endif;
|
129 |
}
|
130 |
|
@@ -170,6 +198,10 @@ class WP_Revisions_Control {
|
|
170 |
return $options_sanitized;
|
171 |
}
|
172 |
|
|
|
|
|
|
|
|
|
173 |
/**
|
174 |
* Allow others to change the priority this plugin's functionality runs at
|
175 |
*
|
@@ -189,21 +221,196 @@ class WP_Revisions_Control {
|
|
189 |
/**
|
190 |
* Override number of revisions to keep using plugin's settings
|
191 |
*
|
|
|
|
|
|
|
192 |
* @uses get_post_type
|
193 |
* @uses this::get_settings
|
194 |
* @filter wp_revisions_to_keep
|
195 |
* @return mixed
|
196 |
*/
|
197 |
public function filter_wp_revisions_to_keep( $qty, $post ) {
|
198 |
-
$
|
199 |
-
$settings = $this->get_settings();
|
200 |
|
201 |
-
if (
|
202 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
203 |
|
204 |
return $qty;
|
205 |
}
|
206 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
207 |
/**
|
208 |
* Retrieve plugin settings
|
209 |
*
|
@@ -279,5 +486,23 @@ class WP_Revisions_Control {
|
|
279 |
else
|
280 |
return (int) $to_keep;
|
281 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
282 |
}
|
283 |
WP_Revisions_Control::get_instance();
|
1 |
<?php
|
2 |
/*
|
3 |
Plugin Name: WP Revisions Control
|
4 |
+
Plugin URI: https://ethitter.com/plugins/wp-revisions-control/
|
5 |
Description: Control how many revisions are stored for each post type
|
6 |
Author: Erick Hitter
|
7 |
+
Version: 1.2.1
|
8 |
+
Author URI: https://ethitter.com/
|
9 |
+
Text Domain: wp_revisions_control
|
10 |
+
Domain Path: /languages/
|
11 |
|
12 |
This program is free software; you can redistribute it and/or modify
|
13 |
it under the terms of the GNU General Public License as published by
|
42 |
private $settings_page = 'writing';
|
43 |
private $settings_section = 'wp_revisions_control';
|
44 |
|
45 |
+
private $meta_key_limit = '_wp_rev_ctl_limit';
|
46 |
+
|
47 |
/**
|
48 |
* Silence is golden!
|
49 |
*/
|
72 |
* @return null
|
73 |
*/
|
74 |
private function setup() {
|
75 |
+
add_action( 'plugins_loaded', array( $this, 'action_plugins_loaded' ) );
|
76 |
add_action( 'init', array( $this, 'action_init' ) );
|
77 |
}
|
78 |
|
79 |
+
/**
|
80 |
+
* Load plugin translations
|
81 |
+
*
|
82 |
+
* @uses load_plugin_textdomain
|
83 |
+
* @uses plugin_basename
|
84 |
+
* @action plugins_loaded
|
85 |
+
* @return null
|
86 |
+
*/
|
87 |
+
public function action_plugins_loaded() {
|
88 |
+
load_plugin_textdomain( 'wp_revisions_control', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
|
89 |
+
}
|
90 |
+
|
91 |
/**
|
92 |
* Register actions and filters
|
93 |
*
|
103 |
}
|
104 |
|
105 |
/**
|
106 |
+
* Register plugin's admin-specific elements
|
107 |
*
|
108 |
* Plugin title is intentionally not translatable.
|
109 |
*
|
116 |
* @return null
|
117 |
*/
|
118 |
public function action_admin_init() {
|
119 |
+
// Plugin setting section
|
120 |
register_setting( $this->settings_page, $this->settings_section, array( $this, 'sanitize_options' ) );
|
121 |
|
122 |
add_settings_section( $this->settings_section, 'WP Revisions Control', array( $this, 'settings_section_intro' ), $this->settings_page );
|
124 |
foreach ( $this->get_post_types() as $post_type => $name ) {
|
125 |
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 ) );
|
126 |
}
|
127 |
+
|
128 |
+
// Post-level functionality
|
129 |
+
add_action( 'add_meta_boxes', array( $this, 'action_add_meta_boxes' ), 10, 2 );
|
130 |
+
add_action( 'wp_ajax_' . $this->settings_section . '_purge', array( $this, 'ajax_purge' ) );
|
131 |
+
add_action( 'save_post', array( $this, 'action_save_post' ) );
|
132 |
}
|
133 |
|
134 |
+
/**
|
135 |
+
** PLUGIN SETTINGS SECTION
|
136 |
+
** FOUND UNDER SETTINGS > WRITING
|
137 |
+
**/
|
138 |
+
|
139 |
/**
|
140 |
* Display assistive text in settings section
|
141 |
*
|
152 |
// Display a note if the plugin priority is other than the default.
|
153 |
// Will be useful when debugging issues later.
|
154 |
if ( $this->plugin_priority() !== $this->priority_default ) : ?>
|
155 |
+
<p><?php printf( __( "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 %s filter.", 'wp_revisions_control' ), '<code>wp_revisions_control_priority</code>' ); ?></p>
|
156 |
<?php endif;
|
157 |
}
|
158 |
|
198 |
return $options_sanitized;
|
199 |
}
|
200 |
|
201 |
+
/**
|
202 |
+
** REVISIONS QUANTITY OVERRIDES
|
203 |
+
**/
|
204 |
+
|
205 |
/**
|
206 |
* Allow others to change the priority this plugin's functionality runs at
|
207 |
*
|
221 |
/**
|
222 |
* Override number of revisions to keep using plugin's settings
|
223 |
*
|
224 |
+
* Can either be post-specific or universal
|
225 |
+
*
|
226 |
+
* @uses get_post_meta
|
227 |
* @uses get_post_type
|
228 |
* @uses this::get_settings
|
229 |
* @filter wp_revisions_to_keep
|
230 |
* @return mixed
|
231 |
*/
|
232 |
public function filter_wp_revisions_to_keep( $qty, $post ) {
|
233 |
+
$post_limit = get_post_meta( $post->ID, $this->meta_key_limit, true );
|
|
|
234 |
|
235 |
+
if ( 0 < strlen( $post_limit ) ) {
|
236 |
+
$qty = $post_limit;
|
237 |
+
} else {
|
238 |
+
$post_type = get_post_type( $post ) ? get_post_type( $post ) : $post->post_type;
|
239 |
+
$settings = $this->get_settings();
|
240 |
+
|
241 |
+
if ( array_key_exists( $post_type, $settings ) )
|
242 |
+
$qty = $settings[ $post_type ];
|
243 |
+
}
|
244 |
|
245 |
return $qty;
|
246 |
}
|
247 |
|
248 |
+
/**
|
249 |
+
** POST-LEVEL FUNCTIONALITY
|
250 |
+
**/
|
251 |
+
|
252 |
+
/**
|
253 |
+
* Override Core's revisions metabox
|
254 |
+
*
|
255 |
+
* @param string $post_type
|
256 |
+
* @param object $post
|
257 |
+
* @uses post_type_supports
|
258 |
+
* @uses get_post_status
|
259 |
+
* @uses wp_get_post_revisions
|
260 |
+
* @uses remove_meta_box
|
261 |
+
* @uses add_meta_box
|
262 |
+
* @uses wp_enqueue_script
|
263 |
+
* @uses plugins_url
|
264 |
+
* @uses wp_localize_script
|
265 |
+
* @uses wpautop
|
266 |
+
* @uses add_action
|
267 |
+
* @action add_meta_boxes
|
268 |
+
* @return null
|
269 |
+
*/
|
270 |
+
public function action_add_meta_boxes( $post_type, $post ) {
|
271 |
+
if ( post_type_supports( $post_type, 'revisions' ) && 'auto-draft' != get_post_status() && count( wp_get_post_revisions( $post ) ) > 1 ) {
|
272 |
+
// Replace the metabox
|
273 |
+
remove_meta_box( 'revisionsdiv', null, 'normal' );
|
274 |
+
add_meta_box( 'revisionsdiv-wp-rev-ctl', __('Revisions', 'wp_revisions_control'), array( $this, 'revisions_meta_box' ), null, 'normal', 'core' );
|
275 |
+
|
276 |
+
// A bit of JS for us
|
277 |
+
$handle = 'wp-revisions-control-post';
|
278 |
+
wp_enqueue_script( $handle, plugins_url( 'js/post.js', __FILE__ ), array( 'jquery' ), '20131205', true );
|
279 |
+
wp_localize_script( $handle, $this->settings_section, array(
|
280 |
+
'namespace' => $this->settings_section,
|
281 |
+
'action_base' => $this->settings_section,
|
282 |
+
'processing_text' => __( 'Processing…', 'wp_revisions_control' ),
|
283 |
+
'ays' => __( 'Are you sure you want to remove revisions from this post?', 'wp_revisions_control' ),
|
284 |
+
'autosave' => __( 'Autosave', 'wp_revisions_control' ),
|
285 |
+
'nothing_text' => wpautop( __( 'There are no revisions to remove.', 'wp_revisions_control' ) ),
|
286 |
+
'error' => __( 'An error occurred. Please refresh the page and try again.', 'wp_revisions_control' )
|
287 |
+
) );
|
288 |
+
|
289 |
+
// Add some styling to our metabox additions
|
290 |
+
add_action( 'admin_head', array( $this, 'action_admin_head' ), 999 );
|
291 |
+
}
|
292 |
+
}
|
293 |
+
|
294 |
+
/**
|
295 |
+
* Render Revisions metabox with plugin's additions
|
296 |
+
*
|
297 |
+
* @uses post_revisions_meta_box
|
298 |
+
* @uses the_ID
|
299 |
+
* @uses esc_attr
|
300 |
+
* @uses wp_create_nonce
|
301 |
+
* @uses this::get_post_revisions_to_keep
|
302 |
+
* @uses wp_nonce_field
|
303 |
+
* @return string
|
304 |
+
*/
|
305 |
+
public function revisions_meta_box( $post ) {
|
306 |
+
post_revisions_meta_box( $post );
|
307 |
+
|
308 |
+
?>
|
309 |
+
<div id="<?php echo esc_attr( $this->settings_section ); ?>">
|
310 |
+
<h4>WP Revisions Control</h4>
|
311 |
+
|
312 |
+
<p class="button purge" data-postid="<?php the_ID(); ?>" data-nonce="<?php echo esc_attr( wp_create_nonce( $this->settings_section . '_purge' ) ); ?>"><?php _e( 'Purge these revisions', 'wp_revisions_control' ); ?></p>
|
313 |
+
|
314 |
+
<p>
|
315 |
+
<?php printf( __( 'Limit this post to %s revisions. Leave this field blank for default behavior.', 'wp_revisions_control' ), '<input type="text" name="' . $this->settings_section . '_qty" value="' . $this->get_post_revisions_to_keep( $post->ID ) . '" id="' . $this->settings_section . '_qty" size="2" />' ); ?>
|
316 |
+
|
317 |
+
<?php wp_nonce_field( $this->settings_section . '_limit', $this->settings_section . '_limit_nonce', false ); ?>
|
318 |
+
</p>
|
319 |
+
</div><!-- #<?php echo esc_attr( $this->settings_section ); ?> -->
|
320 |
+
<?php
|
321 |
+
}
|
322 |
+
|
323 |
+
/**
|
324 |
+
* Process a post-specific request to purge revisions
|
325 |
+
*
|
326 |
+
* @uses __
|
327 |
+
* @uses check_ajax_referer
|
328 |
+
* @uses current_user_can
|
329 |
+
* @uses wp_get_post_revisions
|
330 |
+
* @uses number_format_i18n
|
331 |
+
* @return string
|
332 |
+
*/
|
333 |
+
public function ajax_purge() {
|
334 |
+
$post_id = isset( $_REQUEST['post_id'] ) ? (int) $_REQUEST['post_id'] : false;
|
335 |
+
|
336 |
+
// Hold the current state of this Ajax request
|
337 |
+
$response = array();
|
338 |
+
|
339 |
+
// Check for necessary data and capabilities
|
340 |
+
if ( ! $post_id )
|
341 |
+
$response['error'] = __( 'No post ID was provided. Please refresh the page and try again.', 'wp_revisions_control' );
|
342 |
+
elseif ( ! check_ajax_referer( $this->settings_section . '_purge', 'nonce', false ) )
|
343 |
+
$response['error'] = __( 'Invalid request. Please refresh the page and try again.', 'wp_revisions_control' );
|
344 |
+
elseif ( ! current_user_can( 'edit_post', $post_id ) )
|
345 |
+
$response['error'] = __( 'You are not allowed to edit this post.', 'wp_revisions_control' );
|
346 |
+
|
347 |
+
// Request is valid if $response is still empty, as no errors arose above
|
348 |
+
if ( empty( $response ) ) {
|
349 |
+
$revisions = wp_get_post_revisions( $post_id );
|
350 |
+
|
351 |
+
$count = count( $revisions );
|
352 |
+
|
353 |
+
foreach ( $revisions as $revision ) {
|
354 |
+
wp_delete_post_revision( $revision->ID );
|
355 |
+
}
|
356 |
+
|
357 |
+
$response['success'] = sprintf( __( 'Removed %s revisions associated with this post.', 'wp_revisions_control' ), number_format_i18n( $count, 0 ) );
|
358 |
+
$response['count'] = $count;
|
359 |
+
}
|
360 |
+
|
361 |
+
// Pass the response back to JS
|
362 |
+
echo json_encode( $response );
|
363 |
+
exit;
|
364 |
+
}
|
365 |
+
|
366 |
+
/**
|
367 |
+
* Sanitize and store post-specifiy revisions quantity
|
368 |
+
*
|
369 |
+
* @uses wp_verify_nonce
|
370 |
+
* @uses update_post_meta
|
371 |
+
* @action save_post
|
372 |
+
* @return null
|
373 |
+
*/
|
374 |
+
public function action_save_post( $post_id ) {
|
375 |
+
if ( isset( $_POST[ $this->settings_section . '_limit_nonce' ] ) && wp_verify_nonce( $_POST[ $this->settings_section . '_limit_nonce' ], $this->settings_section . '_limit' ) && isset( $_POST[ $this->settings_section . '_qty' ] ) ) {
|
376 |
+
$limit = $_POST[ $this->settings_section . '_qty' ];
|
377 |
+
|
378 |
+
if ( -1 == $limit || empty( $limit ) )
|
379 |
+
delete_post_meta( $post_id, $this->meta_key_limit );
|
380 |
+
else
|
381 |
+
update_post_meta( $post_id, $this->meta_key_limit, absint( $limit ) );
|
382 |
+
}
|
383 |
+
}
|
384 |
+
|
385 |
+
/**
|
386 |
+
* Add a border between the regular revisions list and this plugin's additions
|
387 |
+
*
|
388 |
+
* @uses esc_attr
|
389 |
+
* @action admin_head
|
390 |
+
* @return string
|
391 |
+
*/
|
392 |
+
public function action_admin_head() {
|
393 |
+
?>
|
394 |
+
<style type="text/css">
|
395 |
+
#revisionsdiv-wp-rev-ctl #<?php echo esc_attr( $this->settings_section ); ?> {
|
396 |
+
border-top: 1px solid #dfdfdf;
|
397 |
+
padding-top: 0;
|
398 |
+
margin-top: 20px;
|
399 |
+
}
|
400 |
+
|
401 |
+
#revisionsdiv-wp-rev-ctl #<?php echo esc_attr( $this->settings_section ); ?> h4 {
|
402 |
+
border-top: 1px solid #fff;
|
403 |
+
padding-top: 1.33em;
|
404 |
+
margin-top: 0;
|
405 |
+
}
|
406 |
+
</style>
|
407 |
+
<?php
|
408 |
+
}
|
409 |
+
|
410 |
+
/**
|
411 |
+
** PLUGIN UTILITIES
|
412 |
+
**/
|
413 |
+
|
414 |
/**
|
415 |
* Retrieve plugin settings
|
416 |
*
|
486 |
else
|
487 |
return (int) $to_keep;
|
488 |
}
|
489 |
+
|
490 |
+
/**
|
491 |
+
* Retrieve number of revisions to keep for a give post
|
492 |
+
*
|
493 |
+
* @param int $post_id
|
494 |
+
* @uses get_post_meta
|
495 |
+
* @return mixed
|
496 |
+
*/
|
497 |
+
private function get_post_revisions_to_keep( $post_id ) {
|
498 |
+
$to_keep = get_post_meta( $post_id, $this->meta_key_limit, true );
|
499 |
+
|
500 |
+
if ( -1 == $to_keep || empty( $to_keep ) )
|
501 |
+
$to_keep = '';
|
502 |
+
else
|
503 |
+
$to_keep = (int) $to_keep;
|
504 |
+
|
505 |
+
return $to_keep;
|
506 |
+
}
|
507 |
}
|
508 |
WP_Revisions_Control::get_instance();
|