Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
WP Plugins
WP Revisions Control
Commits
cbd0da5d
Commit
cbd0da5d
authored
Jul 06, 2013
by
Erick Hitter
Browse files
Start of Ajax handling to purge a post's revisions on demand.
See
#1
.
parent
3c397043
Changes
2
Hide whitespace changes
Inline
Side-by-side
js/post.js
0 → 100644
View file @
cbd0da5d
(
function
(
$
)
{
$
(
document
).
ready
(
function
()
{
var
purge_button
=
$
(
'
#wp_revisions_control .button.purge
'
),
post_id
=
null
,
nonce
=
null
,
button_text
=
null
;
$
(
purge_button
).
on
(
'
click
'
,
click_handler_purge
);
/**
*
*/
function
click_handler_purge
()
{
post_id
=
parseInt
(
$
(
this
).
data
(
'
postid
'
)
);
button_text
=
$
(
purge_button
).
text
();
$
(
purge_button
).
text
(
wp_revisions_control
.
processing_text
);
var
confirmed
=
confirm
(
wp_revisions_control
.
ays
);
if
(
confirmed
&&
post_id
)
{
$
.
ajax
({
url
:
ajaxurl
,
cache
:
false
,
data
:
{
action
:
wp_revisions_control
.
processing_text
+
'
_purge
'
,
post_id
:
post_id
,
nonce
:
$
(
this
).
data
(
'
nonce
'
)
},
type
:
'
post
'
,
success
:
ajax_request_success
,
error
:
ajax_request_error
});
}
else
{
$
(
purge_button
).
text
(
button_text
);
}
}
/**
*
*/
function
ajax_request_success
()
{
console
.
log
(
'
Yippee
'
);
$
(
purge_button
).
text
(
button_text
);
}
/**
*
*/
function
ajax_request_error
()
{
console
.
log
(
'
Sad panda
'
);
}
}
);
}
)(
jQuery
);
\ No newline at end of file
wp-revisions-control.php
View file @
cbd0da5d
...
...
@@ -232,8 +232,17 @@ class WP_Revisions_Control {
public
function
action_add_meta_boxes
(
$post_type
,
$post
)
{
remove_meta_box
(
'revisionsdiv'
,
null
,
'normal'
);
if
(
post_type_supports
(
$post_type
,
'revisions'
)
&&
'auto-draft'
!=
get_post_status
()
&&
count
(
wp_get_post_revisions
(
$post
)
)
>
1
)
if
(
post_type_supports
(
$post_type
,
'revisions'
)
&&
'auto-draft'
!=
get_post_status
()
&&
count
(
wp_get_post_revisions
(
$post
)
)
>
1
)
{
add_meta_box
(
'revisionsdiv-wp-rev-ctl'
,
__
(
'Revisions'
),
array
(
$this
,
'revisions_meta_box'
),
null
,
'normal'
,
'core'
);
$handle
=
'wp-revisions-control-post'
;
wp_enqueue_script
(
$handle
,
plugins_url
(
'js/post.js'
,
__FILE__
),
array
(
'jquery'
),
'20130706'
,
true
);
wp_localize_script
(
$handle
,
$this
->
settings_section
,
array
(
'action_base'
=>
$this
->
settings_section
,
'processing_text'
=>
__
(
'Processing…'
,
'wp_revisions_control'
),
'ays'
=>
__
(
'Are you sure?'
,
'wp_revisions_control'
)
)
);
}
}
/**
...
...
@@ -245,6 +254,8 @@ class WP_Revisions_Control {
?>
<div
id=
"
<?php
echo
esc_attr
(
$this
->
settings_section
);
?>
"
>
<h4>
WP Revisions Control
</h4>
<span
class=
"button purge"
data-postid=
"
<?php
the_ID
();
?>
"
data-nonce=
"
<?php
echo
esc_attr
(
wp_create_nonce
(
$this
->
settings_section
.
'_purge'
)
);
?>
_purge"
>
<?php
_e
(
'Purge these revisions'
,
'wp_revisions_control'
);
?>
</span>
</div>
<!-- #
<?php
echo
esc_attr
(
$this
->
settings_section
);
?>
-->
<?php
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment