Version Description
(2013-11-18): =
* Introduces a filter ppp_preview_link
. With the filter you can adjust the preview link.
* If a post has gone live, redirect to it's proper permalink.
* Adds the query var _ppp
to WordPress SEO by Yoast whitelist.
Download this release
Release Info
Developer | ocean90 |
Plugin | Public Post Preview |
Version | 2.3 |
Comparing to | |
See all releases |
Code changes from version 2.2 to 2.3
- public-post-preview.php +32 -5
- readme.txt +18 -18
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/
|
@@ -71,6 +71,9 @@ class DS_Public_Post_Preview {
|
|
71 |
add_filter( 'pre_get_posts', array( __CLASS__, 'show_public_preview' ) );
|
72 |
|
73 |
add_filter( 'query_vars', array( __CLASS__, 'add_query_var' ) );
|
|
|
|
|
|
|
74 |
} else {
|
75 |
add_action( 'post_submitbox_misc_actions', array( __CLASS__, 'post_submitbox_misc_actions' ) );
|
76 |
|
@@ -189,13 +192,15 @@ class DS_Public_Post_Preview {
|
|
189 |
* @return string The generated public preview link.
|
190 |
*/
|
191 |
private static function get_preview_link( $post_id ) {
|
192 |
-
|
193 |
array(
|
194 |
'preview' => true,
|
195 |
'_ppp' => self::create_nonce( 'public_post_preview_' . $post_id ),
|
196 |
),
|
197 |
get_permalink( $post_id )
|
198 |
);
|
|
|
|
|
199 |
}
|
200 |
|
201 |
/**
|
@@ -325,10 +330,10 @@ class DS_Public_Post_Preview {
|
|
325 |
if ( empty( $post_id ) )
|
326 |
return false;
|
327 |
|
328 |
-
if( ! self::verify_nonce( get_query_var( '_ppp' ), 'public_post_preview_' . $post_id ) )
|
329 |
wp_die( __( 'The link has been expired!', 'ds-public-post-preview' ) );
|
330 |
|
331 |
-
if ( ! in_array( $post_id,
|
332 |
wp_die( __( 'No Public Preview available!', 'ds-public-post-preview' ) );
|
333 |
|
334 |
return true;
|
@@ -349,12 +354,34 @@ class DS_Public_Post_Preview {
|
|
349 |
if ( empty( $posts ) )
|
350 |
return;
|
351 |
|
352 |
-
|
|
|
|
|
|
|
|
|
|
|
353 |
$posts[0]->post_status = 'publish';
|
354 |
|
355 |
return $posts;
|
356 |
}
|
357 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
358 |
/**
|
359 |
* Get the time-dependent variable for nonce creation.
|
360 |
*
|
1 |
<?php
|
2 |
/**
|
3 |
* Plugin Name: Public Post Preview
|
4 |
+
* Version: 2.3
|
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/
|
71 |
add_filter( 'pre_get_posts', array( __CLASS__, 'show_public_preview' ) );
|
72 |
|
73 |
add_filter( 'query_vars', array( __CLASS__, 'add_query_var' ) );
|
74 |
+
|
75 |
+
// Add the query var to WordPress SEO by Yoast whitelist.
|
76 |
+
add_filter( 'wpseo_whitelist_permalink_vars', array( __CLASS__, 'add_query_var' ) );
|
77 |
} else {
|
78 |
add_action( 'post_submitbox_misc_actions', array( __CLASS__, 'post_submitbox_misc_actions' ) );
|
79 |
|
192 |
* @return string The generated public preview link.
|
193 |
*/
|
194 |
private static function get_preview_link( $post_id ) {
|
195 |
+
$link = add_query_arg(
|
196 |
array(
|
197 |
'preview' => true,
|
198 |
'_ppp' => self::create_nonce( 'public_post_preview_' . $post_id ),
|
199 |
),
|
200 |
get_permalink( $post_id )
|
201 |
);
|
202 |
+
|
203 |
+
return apply_filters( 'ppp_preview_link', $link, $post_id );
|
204 |
}
|
205 |
|
206 |
/**
|
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;
|
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::public_preview_available( $post_id ) )
|
363 |
$posts[0]->post_status = 'publish';
|
364 |
|
365 |
return $posts;
|
366 |
}
|
367 |
|
368 |
+
/**
|
369 |
+
* Sets the post status of the first post to publish, so we don't have to do anything
|
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 ( 'publish' != get_post_status( $post_id ) )
|
379 |
+
return false;
|
380 |
+
|
381 |
+
wp_redirect( get_permalink( $post_id ), 301 );
|
382 |
+
exit;
|
383 |
+
}
|
384 |
+
|
385 |
/**
|
386 |
* Get the time-dependent variable for nonce creation.
|
387 |
*
|
readme.txt
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
=== Public Post Preview ===
|
2 |
Contributors: ocean90
|
3 |
-
Tags: public, post, preview, posts, custom post types
|
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: 3.
|
7 |
-
Stable tag: 2.
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -21,7 +21,7 @@ Have you ever been writing a post with the help of someone who does not have acc
|
|
21 |
*Previously this plugin was maintained by [Matt Martz](http://profiles.wordpress.org/sivel/) and was an idea of [Jonathan Dingman](http://profiles.wordpress.org/jdingman/).*
|
22 |
|
23 |
= Feedback =
|
24 |
-
If you want, you can drop me a line @[ocean90](http://twitter.com/ocean90) on Twitter or @[Dominik Schilling](https://plus.google.com/
|
25 |
|
26 |
= More =
|
27 |
Try also some of my [other plugins](http://profiles.wordpress.org/users/ocean90) or visit my site [wpGrafie.de](http://wpgrafie.de/).
|
@@ -66,16 +66,11 @@ New plugin maintainer, supports now all public post types, saves preview status
|
|
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
|
70 |
* To disable a preview just uncheck the box.
|
71 |
|
72 |
== Frequently Asked Questions ==
|
73 |
|
74 |
-
**I have activated the "WordPress SEO by Yoast" plugin and enabled the option "Redirect ugly URL's to clean permalinks.". The public preview doesn't work. What can I do?**
|
75 |
-
|
76 |
-
Please add <strong>_ppp</strong> to the input field "Other variables not to clean:" on SEO -> Permalinks screen.
|
77 |
-
|
78 |
-
|
79 |
**After some time the preview link returns the message "The link has been expired!". Why?**
|
80 |
|
81 |
The plugin generates an URL with an expiring nonce. By default a link "lives" 48 hours. After 48 hours the link is expired and you need to copy and share a new link which is automatically generated on the same place under the editor.
|
@@ -91,22 +86,27 @@ function my_nonce_life() {
|
|
91 |
}`
|
92 |
|
93 |
== Change Log ==
|
94 |
-
= 2.
|
95 |
-
*
|
96 |
-
*
|
97 |
-
*
|
|
|
|
|
|
|
|
|
|
|
98 |
|
99 |
-
= 2.1.1 (
|
100 |
* Sorry for the new update. Through a change in 2.1 a filter was applied to each query. The misplaced "The link has been expired!" message is now gone. Props Aki Björklund and Jonathan Channon.
|
101 |
|
102 |
-
= 2.1 (
|
103 |
* Introduces a filter `ppp_nonce_life`. With the filter you can adjust the expiration of a link. By default a link has a lifetime of 48 hours.
|
104 |
* In some situations (still not sure when) the preview link is rewritten as a permalink which results in an error. The plugin now works in this situations too.
|
105 |
|
106 |
-
= 2.0.1 (
|
107 |
* Makes the preview link copyable again
|
108 |
|
109 |
-
= 2.0 (
|
110 |
* Support for all public post types
|
111 |
* Saves public preview status via an AJAX request
|
112 |
* I18n
|
1 |
=== Public Post Preview ===
|
2 |
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: 3.9
|
7 |
+
Stable tag: 2.3
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
21 |
*Previously this plugin was maintained by [Matt Martz](http://profiles.wordpress.org/sivel/) and was an idea of [Jonathan Dingman](http://profiles.wordpress.org/jdingman/).*
|
22 |
|
23 |
= Feedback =
|
24 |
+
If you want, you can drop me a line @[ocean90](http://twitter.com/ocean90) on Twitter or @[Dominik Schilling](https://plus.google.com/+DominikSchilling/) on Google+.
|
25 |
|
26 |
= More =
|
27 |
Try also some of my [other plugins](http://profiles.wordpress.org/users/ocean90) or visit my site [wpGrafie.de](http://wpgrafie.de/).
|
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.
|
70 |
* To disable a preview just uncheck the box.
|
71 |
|
72 |
== Frequently Asked Questions ==
|
73 |
|
|
|
|
|
|
|
|
|
|
|
74 |
**After some time the preview link returns the message "The link has been expired!". Why?**
|
75 |
|
76 |
The plugin generates an URL with an expiring nonce. By default a link "lives" 48 hours. After 48 hours the link is expired and you need to copy and share a new link which is automatically generated on the same place under the editor.
|
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.
|
92 |
+
* Adds the query var `_ppp` to WordPress SEO by Yoast whitelist.
|
93 |
+
|
94 |
+
= 2.2 (2013-03-15): =
|
95 |
+
* Based on feedback I have removed the extra metabox and added the preview link to the main Publish metabox.
|
96 |
+
* Only show the checkbox if the post status/post type is good.
|
97 |
+
* Requires WordPress 3.5.
|
98 |
|
99 |
+
= 2.1.1 (2012-09-19): =
|
100 |
* Sorry for the new update. Through a change in 2.1 a filter was applied to each query. The misplaced "The link has been expired!" message is now gone. Props Aki Björklund and Jonathan Channon.
|
101 |
|
102 |
+
= 2.1 (2012-09-16): =
|
103 |
* Introduces a filter `ppp_nonce_life`. With the filter you can adjust the expiration of a link. By default a link has a lifetime of 48 hours.
|
104 |
* In some situations (still not sure when) the preview link is rewritten as a permalink which results in an error. The plugin now works in this situations too.
|
105 |
|
106 |
+
= 2.0.1 (2012-07-25): =
|
107 |
* Makes the preview link copyable again
|
108 |
|
109 |
+
= 2.0 (2012-07-23): =
|
110 |
* Support for all public post types
|
111 |
* Saves public preview status via an AJAX request
|
112 |
* I18n
|