Version Description
(2014-08-21): * Supports EditFlow and custom statuses * Disables comments and pings during public post preview * Adds Public Preview to the list of display states used in the Posts list table * Prevents flickering of link box on Post edit while loading
Download this release
Release Info
Developer | ocean90 |
Plugin | Public Post Preview |
Version | 2.4 |
Comparing to | |
See all releases |
Code changes from version 2.3 to 2.4
- js/public-post-preview.js +0 -3
- js/public-post-preview.min.js +1 -6
- lang/ds-public-post-preview-nb_NO.mo +0 -0
- lang/ds-public-post-preview-nb_NO.po +73 -0
- public-post-preview.php +139 -61
- readme.txt +10 -13
js/public-post-preview.js
CHANGED
@@ -16,9 +16,6 @@
|
|
16 |
|
17 |
t.status.css( 'opacity', 0 );
|
18 |
|
19 |
-
if ( ! t.checkbox.prop( 'checked' ) )
|
20 |
-
t.link.hide();
|
21 |
-
|
22 |
t.checkbox.bind( 'change', function() {
|
23 |
t.change();
|
24 |
} );
|
16 |
|
17 |
t.status.css( 'opacity', 0 );
|
18 |
|
|
|
|
|
|
|
19 |
t.checkbox.bind( 'change', function() {
|
20 |
t.change();
|
21 |
} );
|
js/public-post-preview.min.js
CHANGED
@@ -1,6 +1 @@
|
|
1 |
-
(function(a){DSPublicPostPreview={initialize:function(){var b=this;b.checkbox=a("#public-post-preview");b.link=a("#public-post-preview-link");b.nonce=a("#public_post_preview_wpnonce");
|
2 |
-
b.status=a("#public-post-preview-ajax");b.status.css("opacity",0);if(!b.checkbox.prop("checked")){b.link.hide();}b.checkbox.bind("change",function(){b.change();
|
3 |
-
});},change:function(){var b=this,c=b.checkbox.prop("checked")?1:0;b.link.toggle();b.checkbox.prop("disabled","disabled");b.request({_ajax_nonce:b.nonce.val(),checked:c,post_ID:a("#post_ID").val()},function(d){if(d){if(c){b.status.text(DSPublicPostPreviewL10n.enabled);
|
4 |
-
b._pulsate(b.status,"green");}else{b.status.text(DSPublicPostPreviewL10n.disabled);b._pulsate(b.status,"red");}}b.checkbox.prop("disabled","");});},request:function(b,c){a.ajax({type:"POST",url:ajaxurl,data:a.extend(b,{action:"public-post-preview"}),success:c});
|
5 |
-
},_pulsate:function(c,b){c.css("color",b).animate({opacity:1},600,"linear").animate({opacity:0},600,"linear",function(){c.empty();});}};a(DSPublicPostPreview.initialize());
|
6 |
-
})(jQuery);
|
1 |
+
(function(a){DSPublicPostPreview={initialize:function(){var b=this;b.checkbox=a("#public-post-preview");b.link=a("#public-post-preview-link");b.nonce=a("#public_post_preview_wpnonce");b.status=a("#public-post-preview-ajax");b.status.css("opacity",0);b.checkbox.bind("change",function(){b.change();});},change:function(){var b=this,c=b.checkbox.prop("checked")?1:0;b.link.toggle();b.checkbox.prop("disabled","disabled");b.request({_ajax_nonce:b.nonce.val(),checked:c,post_ID:a("#post_ID").val()},function(d){if(d){if(c){b.status.text(DSPublicPostPreviewL10n.enabled);b._pulsate(b.status,"green");}else{b.status.text(DSPublicPostPreviewL10n.disabled);b._pulsate(b.status,"red");}}b.checkbox.prop("disabled","");});},request:function(b,c){a.ajax({type:"POST",url:ajaxurl,data:a.extend(b,{action:"public-post-preview"}),success:c});},_pulsate:function(c,b){c.css("color",b).animate({opacity:1},600,"linear").animate({opacity:0},600,"linear",function(){c.empty();});}};a(DSPublicPostPreview.initialize());})(jQuery);
|
|
|
|
|
|
|
|
|
|
lang/ds-public-post-preview-nb_NO.mo
ADDED
Binary file
|
lang/ds-public-post-preview-nb_NO.po
ADDED
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
msgid ""
|
2 |
+
msgstr ""
|
3 |
+
"Project-Id-Version: Public Post Preview\n"
|
4 |
+
"POT-Creation-Date: 2015-06-17 21:22+0100\n"
|
5 |
+
"PO-Revision-Date: 2015-06-17 21:24+0100\n"
|
6 |
+
"Last-Translator: Bjørn Johansen <post@bjornjohansen.no>\n"
|
7 |
+
"Language-Team: Bjørn Johansen <post@bjornjohansen.no>\n"
|
8 |
+
"Language: nb_NO\n"
|
9 |
+
"MIME-Version: 1.0\n"
|
10 |
+
"Content-Type: text/plain; charset=UTF-8\n"
|
11 |
+
"Content-Transfer-Encoding: 8bit\n"
|
12 |
+
"X-Generator: Poedit 1.8.1\n"
|
13 |
+
"X-Poedit-Basepath: ..\n"
|
14 |
+
"X-Poedit-WPHeader: public-post-preview.php\n"
|
15 |
+
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
16 |
+
"X-Poedit-SourceCharset: UTF-8\n"
|
17 |
+
"X-Poedit-KeywordsList: __;_e;_n:1,2;_x:1,2c;_ex:1,2c;_nx:4c,1,2;esc_attr__;"
|
18 |
+
"esc_attr_e;esc_attr_x:1,2c;esc_html__;esc_html_e;esc_html_x:1,2c;_n_noop:1,2;"
|
19 |
+
"_nx_noop:3c,1,2;__ngettext_noop:1,2\n"
|
20 |
+
"X-Poedit-SearchPath-0: .\n"
|
21 |
+
"X-Poedit-SearchPathExcluded-0: *.js\n"
|
22 |
+
|
23 |
+
#: public-post-preview.php:129
|
24 |
+
msgid "Enabled!"
|
25 |
+
msgstr "Aktivert!"
|
26 |
+
|
27 |
+
#: public-post-preview.php:130
|
28 |
+
msgid "Disabled!"
|
29 |
+
msgstr "Deaktivert!"
|
30 |
+
|
31 |
+
#: public-post-preview.php:142
|
32 |
+
msgid "Public Preview"
|
33 |
+
msgstr "Offentlig forhåndsvisning"
|
34 |
+
|
35 |
+
#: public-post-preview.php:215
|
36 |
+
msgid "Enable public preview"
|
37 |
+
msgstr "Aktiver offentlig forhåndsvisning"
|
38 |
+
|
39 |
+
#: public-post-preview.php:220
|
40 |
+
msgid "(Copy and share this link.)"
|
41 |
+
msgstr "(Kopiér og del denne lenken)."
|
42 |
+
|
43 |
+
#: public-post-preview.php:401
|
44 |
+
msgid "The link has been expired!"
|
45 |
+
msgstr "Lenken er utgått!"
|
46 |
+
|
47 |
+
#: public-post-preview.php:405
|
48 |
+
msgid "No Public Preview available!"
|
49 |
+
msgstr "Ingen offentlig forhåndsvisning tilgjengelig!"
|
50 |
+
|
51 |
+
#. Plugin Name of the plugin/theme
|
52 |
+
msgid "Public Post Preview"
|
53 |
+
msgstr "Public Post Preview"
|
54 |
+
|
55 |
+
#. Plugin URI of the plugin/theme
|
56 |
+
msgid "http://wpgrafie.de/wp-plugins/public-post-preview/en/"
|
57 |
+
msgstr "http://wpgrafie.de/wp-plugins/public-post-preview/en/"
|
58 |
+
|
59 |
+
#. Description of the plugin/theme
|
60 |
+
msgid ""
|
61 |
+
"Enables you to give a link to anonymous users for public preview of any post "
|
62 |
+
"type before it is published."
|
63 |
+
msgstr ""
|
64 |
+
"Lar deg dele en lenke med anonyme brukere for offentlig forhåndsvisning av "
|
65 |
+
"hvilken som helst posttype før den er publisert."
|
66 |
+
|
67 |
+
#. Author of the plugin/theme
|
68 |
+
msgid "Dominik Schilling"
|
69 |
+
msgstr "Dominik Schilling"
|
70 |
+
|
71 |
+
#. Author URI of the plugin/theme
|
72 |
+
msgid "http://wphelper.de/"
|
73 |
+
msgstr "http://wphelper.de/"
|
public-post-preview.php
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
* Plugin Name: Public Post Preview
|
4 |
-
* Version: 2.
|
5 |
* Description: Enables you to give a link to anonymous users for public preview of any post type before it is published.
|
6 |
* Author: Dominik Schilling
|
7 |
* Author URI: http://wphelper.de/
|
@@ -14,7 +14,7 @@
|
|
14 |
*
|
15 |
* Previously (2009-2011) maintained by Jonathan Dingman and Matt Martz.
|
16 |
*
|
17 |
-
* Copyright (C) 2012-
|
18 |
*
|
19 |
* This program is free software; you can redistribute it and/or
|
20 |
* modify it under the terms of the GNU General Public License
|
@@ -50,6 +50,8 @@ if ( ! class_exists( 'WP' ) ) {
|
|
50 |
* - posts_results
|
51 |
* - wp_ajax_public-post-preview
|
52 |
* - admin_enqueue_scripts
|
|
|
|
|
53 |
*
|
54 |
* Inits at 'plugins_loaded' hook.
|
55 |
*
|
@@ -82,6 +84,8 @@ class DS_Public_Post_Preview {
|
|
82 |
add_action( 'wp_ajax_public-post-preview', array( __CLASS__, 'ajax_register_public_preview' ) );
|
83 |
|
84 |
add_action( 'admin_enqueue_scripts' , array( __CLASS__, 'enqueue_script' ) );
|
|
|
|
|
85 |
}
|
86 |
}
|
87 |
|
@@ -104,8 +108,9 @@ class DS_Public_Post_Preview {
|
|
104 |
* @since 2.0.0
|
105 |
*/
|
106 |
public static function enqueue_script( $hook_suffix ) {
|
107 |
-
if ( ! in_array( $hook_suffix, array( 'post.php', 'post-new.php' ) ) )
|
108 |
return;
|
|
|
109 |
|
110 |
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
|
111 |
|
@@ -128,7 +133,20 @@ class DS_Public_Post_Preview {
|
|
128 |
}
|
129 |
|
130 |
/**
|
131 |
-
* Adds
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
132 |
*
|
133 |
* @since 2.2.0
|
134 |
*/
|
@@ -141,11 +159,19 @@ class DS_Public_Post_Preview {
|
|
141 |
|
142 |
$post = get_post();
|
143 |
|
144 |
-
if ( ! in_array( $post->post_type, $post_types ) )
|
145 |
return false;
|
|
|
146 |
|
147 |
-
|
|
|
148 |
return false;
|
|
|
|
|
|
|
|
|
|
|
|
|
149 |
|
150 |
?>
|
151 |
<div class="misc-pub-section public-post-preview">
|
@@ -156,23 +182,41 @@ class DS_Public_Post_Preview {
|
|
156 |
}
|
157 |
|
158 |
/**
|
159 |
-
*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
160 |
*
|
|
|
161 |
*/
|
162 |
private static function get_checkbox_html( $post ) {
|
163 |
-
if ( empty( $post ) )
|
164 |
$post = get_post();
|
|
|
165 |
|
166 |
wp_nonce_field( 'public_post_preview', 'public_post_preview_wpnonce' );
|
167 |
|
168 |
$preview_post_ids = self::get_preview_post_ids();
|
|
|
169 |
?>
|
170 |
-
<label><input type="checkbox"<?php checked(
|
171 |
<?php _e( 'Enable public preview', 'ds-public-post-preview' ); ?> <span id="public-post-preview-ajax"></span></label>
|
172 |
|
173 |
-
<div id="public-post-preview-link" style="margin-top:6px"
|
174 |
<label>
|
175 |
-
<input type="text" name="public_post_preview_link" class="regular-text" value="<?php echo esc_attr( self::get_preview_link( $post
|
176 |
<span class="description"><?php _e( '(Copy and share this link.)', 'ds-public-post-preview' ); ?></span>
|
177 |
</label>
|
178 |
</div>
|
@@ -180,27 +224,40 @@ class DS_Public_Post_Preview {
|
|
180 |
}
|
181 |
|
182 |
/**
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
'
|
199 |
-
)
|
200 |
-
|
201 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
202 |
|
203 |
-
|
|
|
|
|
204 |
}
|
205 |
|
206 |
/**
|
@@ -215,32 +272,36 @@ class DS_Public_Post_Preview {
|
|
215 |
* @return bool Returns false on a failure, true on a success.
|
216 |
*/
|
217 |
public static function register_public_preview( $post_id, $post ) {
|
218 |
-
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
|
219 |
return false;
|
|
|
220 |
|
221 |
-
if ( wp_is_post_revision( $post_id ) )
|
222 |
return false;
|
|
|
223 |
|
224 |
-
if ( empty( $_POST['public_post_preview_wpnonce'] ) || ! wp_verify_nonce( $_POST['public_post_preview_wpnonce'], 'public_post_preview' ) )
|
225 |
return false;
|
|
|
226 |
|
227 |
$preview_post_ids = self::get_preview_post_ids();
|
228 |
$preview_post_id = $post->ID;
|
229 |
|
230 |
-
if ( empty( $_POST['public_post_preview'] ) && in_array( $preview_post_id, $preview_post_ids ) )
|
231 |
$preview_post_ids = array_diff( $preview_post_ids, (array) $preview_post_id );
|
232 |
-
elseif (
|
233 |
! empty( $_POST['public_post_preview'] ) &&
|
234 |
! empty( $_POST['original_post_status'] ) &&
|
235 |
'publish' != $_POST['original_post_status'] &&
|
236 |
'publish' == $post->post_status &&
|
237 |
in_array( $preview_post_id, $preview_post_ids )
|
238 |
-
)
|
239 |
$preview_post_ids = array_diff( $preview_post_ids, (array) $preview_post_id );
|
240 |
-
elseif ( ! empty( $_POST['public_post_preview'] ) && ! in_array( $preview_post_id, $preview_post_ids ) )
|
241 |
$preview_post_ids = array_merge( $preview_post_ids, (array) $preview_post_id );
|
242 |
-
else
|
243 |
-
return false; // Nothing changed.
|
|
|
244 |
|
245 |
return self::set_preview_post_ids( $preview_post_ids );
|
246 |
}
|
@@ -258,25 +319,29 @@ class DS_Public_Post_Preview {
|
|
258 |
$preview_post_id = (int) $_POST['post_ID'];
|
259 |
$post = get_post( $preview_post_id );
|
260 |
|
261 |
-
if ( ( 'page' == $post->post_type && ! current_user_can( 'edit_page', $preview_post_id ) ) || ! current_user_can( 'edit_post', $preview_post_id ) )
|
262 |
wp_die( 0 );
|
|
|
263 |
|
264 |
-
if (
|
265 |
wp_die( 0 );
|
|
|
266 |
|
267 |
$preview_post_ids = self::get_preview_post_ids();
|
268 |
|
269 |
-
if ( empty( $_POST['checked'] ) && in_array( $preview_post_id, $preview_post_ids ) )
|
270 |
$preview_post_ids = array_diff( $preview_post_ids, (array) $preview_post_id );
|
271 |
-
elseif ( ! empty( $_POST['checked'] ) && ! in_array( $preview_post_id, $preview_post_ids ) )
|
272 |
$preview_post_ids = array_merge( $preview_post_ids, (array) $preview_post_id );
|
273 |
-
else
|
274 |
wp_die( 0 );
|
|
|
275 |
|
276 |
$ret = self::set_preview_post_ids( $preview_post_ids );
|
277 |
|
278 |
-
if ( ! $ret )
|
279 |
wp_die( 0 );
|
|
|
280 |
|
281 |
wp_die( 1 );
|
282 |
}
|
@@ -284,7 +349,7 @@ class DS_Public_Post_Preview {
|
|
284 |
/**
|
285 |
* Registers the new query var `_ppp`.
|
286 |
*
|
287 |
-
* @since 2.1
|
288 |
*
|
289 |
* @return array List of query variables.
|
290 |
*/
|
@@ -311,8 +376,9 @@ class DS_Public_Post_Preview {
|
|
311 |
$query->is_preview() &&
|
312 |
$query->is_singular() &&
|
313 |
$query->get( '_ppp' )
|
314 |
-
)
|
315 |
add_filter( 'posts_results', array( __CLASS__, 'set_post_to_publish' ), 10, 2 );
|
|
|
316 |
|
317 |
return $query;
|
318 |
}
|
@@ -326,15 +392,18 @@ class DS_Public_Post_Preview {
|
|
326 |
* @param int $post_id The post id.
|
327 |
* @return bool True if a public preview is allowed, false on a failure.
|
328 |
*/
|
329 |
-
private static function
|
330 |
-
if ( empty( $post_id ) )
|
331 |
return false;
|
|
|
332 |
|
333 |
-
if ( ! self::verify_nonce( get_query_var( '_ppp' ), 'public_post_preview_' . $post_id ) )
|
334 |
wp_die( __( 'The link has been expired!', 'ds-public-post-preview' ) );
|
|
|
335 |
|
336 |
-
if ( ! in_array( $post_id, self::get_preview_post_ids() ) )
|
337 |
wp_die( __( 'No Public Preview available!', 'ds-public-post-preview' ) );
|
|
|
338 |
|
339 |
return true;
|
340 |
}
|
@@ -351,32 +420,38 @@ class DS_Public_Post_Preview {
|
|
351 |
// Remove the filter again, otherwise it will be applied to other queries too.
|
352 |
remove_filter( 'posts_results', array( __CLASS__, 'set_post_to_publish' ), 10, 2 );
|
353 |
|
354 |
-
if ( empty( $posts ) )
|
355 |
return;
|
|
|
356 |
|
357 |
$post_id = $posts[0]->ID;
|
358 |
|
359 |
// If the post has gone live, redirect to it's proper permalink
|
360 |
self::maybe_redirect_to_published_post( $post_id );
|
361 |
|
362 |
-
if ( self::
|
|
|
363 |
$posts[0]->post_status = 'publish';
|
364 |
|
|
|
|
|
|
|
|
|
|
|
365 |
return $posts;
|
366 |
}
|
367 |
|
368 |
/**
|
369 |
-
*
|
370 |
-
* *too* hacky to get it to load the preview.
|
371 |
*
|
372 |
* @since 2.0.0
|
373 |
*
|
374 |
* @param int $post_id The post id.
|
375 |
-
* @return boolean False, if post isn't published.
|
376 |
*/
|
377 |
private static function maybe_redirect_to_published_post( $post_id ) {
|
378 |
-
if (
|
379 |
return false;
|
|
|
380 |
|
381 |
wp_redirect( get_permalink( $post_id ), 301 );
|
382 |
exit;
|
@@ -428,12 +503,14 @@ class DS_Public_Post_Preview {
|
|
428 |
$i = self::nonce_tick();
|
429 |
|
430 |
// Nonce generated 0-12 hours ago
|
431 |
-
if ( substr( wp_hash( $i . $action, 'nonce' ), -12, 10 ) == $nonce )
|
432 |
return 1;
|
|
|
433 |
|
434 |
// Nonce generated 12-24 hours ago
|
435 |
-
if ( substr( wp_hash( ( $i - 1 ) . $action, 'nonce' ), -12, 10 ) == $nonce )
|
436 |
return 2;
|
|
|
437 |
|
438 |
// Invalid nonce
|
439 |
return false;
|
@@ -471,8 +548,9 @@ class DS_Public_Post_Preview {
|
|
471 |
*/
|
472 |
private static function get_plugin_info( $key = null ) {
|
473 |
$plugin_data = get_plugin_data( __FILE__);
|
474 |
-
if ( array_key_exists( $key, $plugin_data ) )
|
475 |
return $plugin_data[ $key ];
|
|
|
476 |
|
477 |
return false;
|
478 |
}
|
1 |
<?php
|
2 |
/**
|
3 |
* Plugin Name: Public Post Preview
|
4 |
+
* Version: 2.4
|
5 |
* Description: Enables you to give a link to anonymous users for public preview of any post type before it is published.
|
6 |
* Author: Dominik Schilling
|
7 |
* Author URI: http://wphelper.de/
|
14 |
*
|
15 |
* Previously (2009-2011) maintained by Jonathan Dingman and Matt Martz.
|
16 |
*
|
17 |
+
* Copyright (C) 2012-2014 Dominik Schilling
|
18 |
*
|
19 |
* This program is free software; you can redistribute it and/or
|
20 |
* modify it under the terms of the GNU General Public License
|
50 |
* - posts_results
|
51 |
* - wp_ajax_public-post-preview
|
52 |
* - admin_enqueue_scripts
|
53 |
+
* - comments_open
|
54 |
+
* - pings_open
|
55 |
*
|
56 |
* Inits at 'plugins_loaded' hook.
|
57 |
*
|
84 |
add_action( 'wp_ajax_public-post-preview', array( __CLASS__, 'ajax_register_public_preview' ) );
|
85 |
|
86 |
add_action( 'admin_enqueue_scripts' , array( __CLASS__, 'enqueue_script' ) );
|
87 |
+
|
88 |
+
add_filter( 'display_post_states', array( __CLASS__, 'display_preview_state' ), 20, 2 );
|
89 |
}
|
90 |
}
|
91 |
|
108 |
* @since 2.0.0
|
109 |
*/
|
110 |
public static function enqueue_script( $hook_suffix ) {
|
111 |
+
if ( ! in_array( $hook_suffix, array( 'post.php', 'post-new.php' ) ) ) {
|
112 |
return;
|
113 |
+
}
|
114 |
|
115 |
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
|
116 |
|
133 |
}
|
134 |
|
135 |
/**
|
136 |
+
* Adds "Public Preview" to the list of display states used in the Posts list table.
|
137 |
+
*
|
138 |
+
* @since 2.4.0
|
139 |
+
*/
|
140 |
+
public static function display_preview_state( $post_states, $post ) {
|
141 |
+
if ( in_array( $post->ID, self::get_preview_post_ids() ) ) {
|
142 |
+
$post_states['ppp_enabled'] = __( 'Public Preview', 'ds-public-post-preview' );
|
143 |
+
}
|
144 |
+
|
145 |
+
return $post_states;
|
146 |
+
}
|
147 |
+
|
148 |
+
/**
|
149 |
+
* Adds the checkbox to the submit metabox.
|
150 |
*
|
151 |
* @since 2.2.0
|
152 |
*/
|
159 |
|
160 |
$post = get_post();
|
161 |
|
162 |
+
if ( ! in_array( $post->post_type, $post_types ) ) {
|
163 |
return false;
|
164 |
+
}
|
165 |
|
166 |
+
// Do nothing for auto drafts
|
167 |
+
if ( $post->post_status == 'auto-draft' ) {
|
168 |
return false;
|
169 |
+
}
|
170 |
+
|
171 |
+
// Post is already published
|
172 |
+
if ( in_array( $post->post_status, self::get_published_statuses() ) ) {
|
173 |
+
return false;
|
174 |
+
}
|
175 |
|
176 |
?>
|
177 |
<div class="misc-pub-section public-post-preview">
|
182 |
}
|
183 |
|
184 |
/**
|
185 |
+
* Returns post statuses which represent a published post.
|
186 |
+
*
|
187 |
+
* @since 2.4.0
|
188 |
+
*
|
189 |
+
* @return array List with post statuses.
|
190 |
+
*/
|
191 |
+
private static function get_published_statuses() {
|
192 |
+
$published_statuses = array( 'publish', 'private' );
|
193 |
+
|
194 |
+
return apply_filters( 'ppp_published_statuses', $published_statuses );
|
195 |
+
}
|
196 |
+
|
197 |
+
/**
|
198 |
+
* Prints the checkbox with the input field for the preview link.
|
199 |
+
*
|
200 |
+
* @since 2.0.0
|
201 |
*
|
202 |
+
* @param WP_Post $post The post object.
|
203 |
*/
|
204 |
private static function get_checkbox_html( $post ) {
|
205 |
+
if ( empty( $post ) ) {
|
206 |
$post = get_post();
|
207 |
+
}
|
208 |
|
209 |
wp_nonce_field( 'public_post_preview', 'public_post_preview_wpnonce' );
|
210 |
|
211 |
$preview_post_ids = self::get_preview_post_ids();
|
212 |
+
$enabeld = in_array( $post->ID, $preview_post_ids );
|
213 |
?>
|
214 |
+
<label><input type="checkbox"<?php checked( $enabeld ); ?> name="public_post_preview" id="public-post-preview" value="1" />
|
215 |
<?php _e( 'Enable public preview', 'ds-public-post-preview' ); ?> <span id="public-post-preview-ajax"></span></label>
|
216 |
|
217 |
+
<div id="public-post-preview-link" style="margin-top:6px"<?php echo $enabeld ? '' : ' class="hidden"'; ?>>
|
218 |
<label>
|
219 |
+
<input type="text" name="public_post_preview_link" class="regular-text" value="<?php echo esc_attr( self::get_preview_link( $post ) ); ?>" style="width:99%" readonly />
|
220 |
<span class="description"><?php _e( '(Copy and share this link.)', 'ds-public-post-preview' ); ?></span>
|
221 |
</label>
|
222 |
</div>
|
224 |
}
|
225 |
|
226 |
/**
|
227 |
+
* Returns the public preview link.
|
228 |
+
*
|
229 |
+
* The link is the home link with these parameters:
|
230 |
+
* - preview, always true (query var for core)
|
231 |
+
* - _ppp, a custom nonce, see DS_Public_Post_Preview::create_nonce()
|
232 |
+
* - page_id or p or p and post_type to specify the post.
|
233 |
+
*
|
234 |
+
* @since 2.0.0
|
235 |
+
*
|
236 |
+
* @param WP_Post $post The post object.
|
237 |
+
* @return string The generated public preview link.
|
238 |
+
*/
|
239 |
+
private static function get_preview_link( $post ) {
|
240 |
+
if ( 'page' == $post->post_type ) {
|
241 |
+
$args = array(
|
242 |
+
'page_id' => $post->ID,
|
243 |
+
);
|
244 |
+
} else if ( 'post' == $post->post_type ) {
|
245 |
+
$args = array(
|
246 |
+
'p' => $post->ID,
|
247 |
+
);
|
248 |
+
} else {
|
249 |
+
$args = array(
|
250 |
+
'p' => $post->ID,
|
251 |
+
'post_type' => $post->post_type,
|
252 |
+
);
|
253 |
+
}
|
254 |
+
|
255 |
+
$args['preview'] = true;
|
256 |
+
$args['_ppp'] = self::create_nonce( 'public_post_preview_' . $post->ID );
|
257 |
|
258 |
+
$link = add_query_arg( $args, home_url( '/' ) );
|
259 |
+
|
260 |
+
return apply_filters( 'ppp_preview_link', $link, $post->ID, $post );
|
261 |
}
|
262 |
|
263 |
/**
|
272 |
* @return bool Returns false on a failure, true on a success.
|
273 |
*/
|
274 |
public static function register_public_preview( $post_id, $post ) {
|
275 |
+
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
|
276 |
return false;
|
277 |
+
}
|
278 |
|
279 |
+
if ( wp_is_post_revision( $post_id ) ) {
|
280 |
return false;
|
281 |
+
}
|
282 |
|
283 |
+
if ( empty( $_POST['public_post_preview_wpnonce'] ) || ! wp_verify_nonce( $_POST['public_post_preview_wpnonce'], 'public_post_preview' ) ) {
|
284 |
return false;
|
285 |
+
}
|
286 |
|
287 |
$preview_post_ids = self::get_preview_post_ids();
|
288 |
$preview_post_id = $post->ID;
|
289 |
|
290 |
+
if ( empty( $_POST['public_post_preview'] ) && in_array( $preview_post_id, $preview_post_ids ) ) {
|
291 |
$preview_post_ids = array_diff( $preview_post_ids, (array) $preview_post_id );
|
292 |
+
} elseif (
|
293 |
! empty( $_POST['public_post_preview'] ) &&
|
294 |
! empty( $_POST['original_post_status'] ) &&
|
295 |
'publish' != $_POST['original_post_status'] &&
|
296 |
'publish' == $post->post_status &&
|
297 |
in_array( $preview_post_id, $preview_post_ids )
|
298 |
+
) {
|
299 |
$preview_post_ids = array_diff( $preview_post_ids, (array) $preview_post_id );
|
300 |
+
} elseif ( ! empty( $_POST['public_post_preview'] ) && ! in_array( $preview_post_id, $preview_post_ids ) ) {
|
301 |
$preview_post_ids = array_merge( $preview_post_ids, (array) $preview_post_id );
|
302 |
+
} else {
|
303 |
+
return false; // Nothing has changed.
|
304 |
+
}
|
305 |
|
306 |
return self::set_preview_post_ids( $preview_post_ids );
|
307 |
}
|
319 |
$preview_post_id = (int) $_POST['post_ID'];
|
320 |
$post = get_post( $preview_post_id );
|
321 |
|
322 |
+
if ( ( 'page' == $post->post_type && ! current_user_can( 'edit_page', $preview_post_id ) ) || ! current_user_can( 'edit_post', $preview_post_id ) ) {
|
323 |
wp_die( 0 );
|
324 |
+
}
|
325 |
|
326 |
+
if ( in_array( $post->post_status, self::get_published_statuses() ) ) {
|
327 |
wp_die( 0 );
|
328 |
+
}
|
329 |
|
330 |
$preview_post_ids = self::get_preview_post_ids();
|
331 |
|
332 |
+
if ( empty( $_POST['checked'] ) && in_array( $preview_post_id, $preview_post_ids ) ) {
|
333 |
$preview_post_ids = array_diff( $preview_post_ids, (array) $preview_post_id );
|
334 |
+
} elseif ( ! empty( $_POST['checked'] ) && ! in_array( $preview_post_id, $preview_post_ids ) ) {
|
335 |
$preview_post_ids = array_merge( $preview_post_ids, (array) $preview_post_id );
|
336 |
+
} else {
|
337 |
wp_die( 0 );
|
338 |
+
}
|
339 |
|
340 |
$ret = self::set_preview_post_ids( $preview_post_ids );
|
341 |
|
342 |
+
if ( ! $ret ) {
|
343 |
wp_die( 0 );
|
344 |
+
}
|
345 |
|
346 |
wp_die( 1 );
|
347 |
}
|
349 |
/**
|
350 |
* Registers the new query var `_ppp`.
|
351 |
*
|
352 |
+
* @since 2.1.0
|
353 |
*
|
354 |
* @return array List of query variables.
|
355 |
*/
|
376 |
$query->is_preview() &&
|
377 |
$query->is_singular() &&
|
378 |
$query->get( '_ppp' )
|
379 |
+
) {
|
380 |
add_filter( 'posts_results', array( __CLASS__, 'set_post_to_publish' ), 10, 2 );
|
381 |
+
}
|
382 |
|
383 |
return $query;
|
384 |
}
|
392 |
* @param int $post_id The post id.
|
393 |
* @return bool True if a public preview is allowed, false on a failure.
|
394 |
*/
|
395 |
+
private static function is_public_preview_available( $post_id ) {
|
396 |
+
if ( empty( $post_id ) ) {
|
397 |
return false;
|
398 |
+
}
|
399 |
|
400 |
+
if ( ! self::verify_nonce( get_query_var( '_ppp' ), 'public_post_preview_' . $post_id ) ) {
|
401 |
wp_die( __( 'The link has been expired!', 'ds-public-post-preview' ) );
|
402 |
+
}
|
403 |
|
404 |
+
if ( ! in_array( $post_id, self::get_preview_post_ids() ) ) {
|
405 |
wp_die( __( 'No Public Preview available!', 'ds-public-post-preview' ) );
|
406 |
+
}
|
407 |
|
408 |
return true;
|
409 |
}
|
420 |
// Remove the filter again, otherwise it will be applied to other queries too.
|
421 |
remove_filter( 'posts_results', array( __CLASS__, 'set_post_to_publish' ), 10, 2 );
|
422 |
|
423 |
+
if ( empty( $posts ) ) {
|
424 |
return;
|
425 |
+
}
|
426 |
|
427 |
$post_id = $posts[0]->ID;
|
428 |
|
429 |
// If the post has gone live, redirect to it's proper permalink
|
430 |
self::maybe_redirect_to_published_post( $post_id );
|
431 |
|
432 |
+
if ( self::is_public_preview_available( $post_id ) ) {
|
433 |
+
// Set post status to publish so that it's visible
|
434 |
$posts[0]->post_status = 'publish';
|
435 |
|
436 |
+
// Disable comments and pings for this post
|
437 |
+
add_filter( 'comments_open', '__return_false' );
|
438 |
+
add_filter( 'pings_open', '__return_false' );
|
439 |
+
}
|
440 |
+
|
441 |
return $posts;
|
442 |
}
|
443 |
|
444 |
/**
|
445 |
+
* Redirects to post's proper permalink, if it has gone live.
|
|
|
446 |
*
|
447 |
* @since 2.0.0
|
448 |
*
|
449 |
* @param int $post_id The post id.
|
|
|
450 |
*/
|
451 |
private static function maybe_redirect_to_published_post( $post_id ) {
|
452 |
+
if ( ! in_array( get_post_status( $post_id ), self::get_published_statuses() ) ) {
|
453 |
return false;
|
454 |
+
}
|
455 |
|
456 |
wp_redirect( get_permalink( $post_id ), 301 );
|
457 |
exit;
|
503 |
$i = self::nonce_tick();
|
504 |
|
505 |
// Nonce generated 0-12 hours ago
|
506 |
+
if ( substr( wp_hash( $i . $action, 'nonce' ), -12, 10 ) == $nonce ) {
|
507 |
return 1;
|
508 |
+
}
|
509 |
|
510 |
// Nonce generated 12-24 hours ago
|
511 |
+
if ( substr( wp_hash( ( $i - 1 ) . $action, 'nonce' ), -12, 10 ) == $nonce ) {
|
512 |
return 2;
|
513 |
+
}
|
514 |
|
515 |
// Invalid nonce
|
516 |
return false;
|
548 |
*/
|
549 |
private static function get_plugin_info( $key = null ) {
|
550 |
$plugin_data = get_plugin_data( __FILE__);
|
551 |
+
if ( array_key_exists( $key, $plugin_data ) ) {
|
552 |
return $plugin_data[ $key ];
|
553 |
+
}
|
554 |
|
555 |
return false;
|
556 |
}
|
readme.txt
CHANGED
@@ -3,8 +3,8 @@ Contributors: ocean90
|
|
3 |
Tags: public, post, preview, posts, custom post types, draft
|
4 |
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=VR8YU922B7K46
|
5 |
Requires at least: 3.5
|
6 |
-
Tested up to:
|
7 |
-
Stable tag: 2.
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -53,17 +53,6 @@ To upload the plugin through WordPress, instead of FTP:
|
|
53 |
|
54 |
1. Edit Posts Page
|
55 |
|
56 |
-
== Upgrade Notice ==
|
57 |
-
|
58 |
-
= 2.2 =
|
59 |
-
Based on feedback: Removed the extra metabox and added preview link to the main Publish metabox. Requires now WordPress 3.5
|
60 |
-
|
61 |
-
= 2.1 =
|
62 |
-
The update fixes a rare issue which had created 404 errors.
|
63 |
-
|
64 |
-
= 2.0 =
|
65 |
-
New plugin maintainer, supports now all public post types, saves preview status via an AJAX request, ready for translation, requires at least WordPress 3.3.
|
66 |
-
|
67 |
== Usage ==
|
68 |
* To enable a public post preview check the box below the edit post box.
|
69 |
* The link will be displayed if the checkbox is checked, just copy and share the link with your friends.
|
@@ -85,7 +74,15 @@ function my_nonce_life() {
|
|
85 |
return 60 * 60 * 24 * 5; // 5 days
|
86 |
}`
|
87 |
|
|
|
|
|
88 |
== Change Log ==
|
|
|
|
|
|
|
|
|
|
|
|
|
89 |
= 2.3 (2013-11-18): =
|
90 |
* Introduces a filter `ppp_preview_link`. With the filter you can adjust the preview link.
|
91 |
* If a post has gone live, redirect to it's proper permalink.
|
3 |
Tags: public, post, preview, posts, custom post types, draft
|
4 |
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=VR8YU922B7K46
|
5 |
Requires at least: 3.5
|
6 |
+
Tested up to: 4.0
|
7 |
+
Stable tag: 2.4
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
53 |
|
54 |
1. Edit Posts Page
|
55 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
== Usage ==
|
57 |
* To enable a public post preview check the box below the edit post box.
|
58 |
* The link will be displayed if the checkbox is checked, just copy and share the link with your friends.
|
74 |
return 60 * 60 * 24 * 5; // 5 days
|
75 |
}`
|
76 |
|
77 |
+
Or use the [Public Post Preview Configurator](https://wordpress.org/plugins/public-post-preview-configurator/).
|
78 |
+
|
79 |
== Change Log ==
|
80 |
+
= 2.4 (2014-08-21):
|
81 |
+
* Supports EditFlow and custom statuses
|
82 |
+
* Disables comments and pings during public post preview
|
83 |
+
* Adds **Public Preview** to the list of display states used in the Posts list table
|
84 |
+
* Prevents flickering of link box on Post edit while loading
|
85 |
+
|
86 |
= 2.3 (2013-11-18): =
|
87 |
* Introduces a filter `ppp_preview_link`. With the filter you can adjust the preview link.
|
88 |
* If a post has gone live, redirect to it's proper permalink.
|