Public Post Preview - Version 2.9.2

Version Description

(2020-10-03): = * Fixes saving of preview status without a previous Ajax request.

Download this release

Release Info

Developer ocean90
Plugin Icon 128x128 Public Post Preview
Version 2.9.2
Comparing to
See all releases

Code changes from version 2.9.1 to 2.9.2

Files changed (4) hide show
  1. CHANGELOG.md +3 -0
  2. composer.json +0 -25
  3. public-post-preview.php +15 -9
  4. readme.txt +5 -2
CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
  # Changelog
2
 
 
 
 
3
  ## 2.9.1 (2020-07-25):
4
  * Improve HTTP status codes for expired/invalid preview links.
5
 
1
  # Changelog
2
 
3
+ ## 2.9.2 (2020-10-03):
4
+ * Fixes saving of preview status without a previous Ajax request.
5
+
6
  ## 2.9.1 (2020-07-25):
7
  * Improve HTTP status codes for expired/invalid preview links.
8
 
composer.json DELETED
@@ -1,25 +0,0 @@
1
- {
2
- "name": "ocean90/public-post-preview",
3
- "description": "WordPress plugin to allow anonymous users to preview a post before it is published.",
4
- "homepage": "https://wordpress.org/plugins/public-post-preview/",
5
- "type": "wordpress-plugin",
6
- "license": "GPL-2.0-or-later",
7
- "authors": [
8
- {
9
- "name": "Dominik Schilling",
10
- "homepage": "https://dominikschilling.de/"
11
- }
12
- ],
13
- "support": {
14
- "issues": "https://github.com/ocean90/public-post-preview/issues",
15
- "forum": "https://wordpress.org/support/plugin/public-post-preview",
16
- "source": "https://github.com/ocean90/public-post-preview"
17
- },
18
- "config": {
19
- "sort-packages": true,
20
- "preferred-install": "dist"
21
- },
22
- "require": {
23
- "php": ">=5.6"
24
- }
25
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
public-post-preview.php CHANGED
@@ -1,12 +1,14 @@
1
  <?php
2
  /**
3
  * Plugin Name: Public Post Preview
4
- * Version: 2.9.1
5
  * Description: Allow anonymous users to preview a post before it is published.
6
  * Author: Dominik Schilling
7
  * Author URI: https://dominikschilling.de/
8
  * Plugin URI: https://dominikschilling.de/wp-plugins/public-post-preview/en/
9
  * Text Domain: public-post-preview
 
 
10
  * License: GPLv2 or later
11
  *
12
  * Previously (2009-2011) maintained by Jonathan Dingman and Matt Martz.
@@ -274,13 +276,13 @@ class DS_Public_Post_Preview {
274
  /**
275
  * (Un)Registers a post for a public preview.
276
  *
277
- * Don't runs on an autosave and ignores post revisions.
278
  *
279
  * @since 2.0.0
280
  *
281
  * @param int $post_id The post id.
282
  * @param object $post The post object.
283
- * @return bool Returns false on a failure, true on a success.
284
  */
285
  public static function register_public_preview( $post_id, $post ) {
286
  if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
@@ -291,7 +293,11 @@ class DS_Public_Post_Preview {
291
  return false;
292
  }
293
 
294
- if ( empty( $_POST['public_post_preview_wpnonce'] ) || ! wp_verify_nonce( $_POST['public_post_preview_wpnonce'], 'public_post_preview' ) ) {
 
 
 
 
295
  return false;
296
  }
297
 
@@ -325,7 +331,7 @@ class DS_Public_Post_Preview {
325
  * @param string $new_status New post status.
326
  * @param string $old_status Old post status.
327
  * @param WP_Post $post Post object.
328
- * @return bool Returns false on a failure, true on a success.
329
  */
330
  public static function unregister_public_preview_on_status_change( $new_status, $old_status, $post ) {
331
  $disallowed_status = self::get_published_statuses();
@@ -345,7 +351,7 @@ class DS_Public_Post_Preview {
345
  *
346
  * @param int $post_id Post ID.
347
  * @param WP_Post $post Post object.
348
- * @return bool Returns false on a failure, true on a success.
349
  */
350
  public static function unregister_public_preview_on_edit( $post_id, $post ) {
351
  $disallowed_status = self::get_published_statuses();
@@ -364,7 +370,7 @@ class DS_Public_Post_Preview {
364
  * @since 2.5.0
365
  *
366
  * @param int $post_id Post ID.
367
- * @return bool Returns false on a failure, true on a success.
368
  */
369
  private static function unregister_public_preview( $post_id ) {
370
  $post_id = (int) $post_id;
@@ -571,7 +577,7 @@ class DS_Public_Post_Preview {
571
  * @return int The time-dependent variable.
572
  */
573
  private static function nonce_tick() {
574
- $nonce_life = apply_filters( 'ppp_nonce_life', 60 * 60 * 48 ); // 48 hours
575
 
576
  return ceil( time() / ( $nonce_life / 2 ) );
577
  }
@@ -640,7 +646,7 @@ class DS_Public_Post_Preview {
640
  * @since 2.0.0
641
  *
642
  * @param array $post_ids List of post IDs that have a preview.
643
- * @return array The post IDs. (Empty array if no IDs are registered.)
644
  */
645
  private static function set_preview_post_ids( $post_ids = array() ) {
646
  $post_ids = array_map( 'absint', $post_ids );
1
  <?php
2
  /**
3
  * Plugin Name: Public Post Preview
4
+ * Version: 2.9.2
5
  * Description: Allow anonymous users to preview a post before it is published.
6
  * Author: Dominik Schilling
7
  * Author URI: https://dominikschilling.de/
8
  * Plugin URI: https://dominikschilling.de/wp-plugins/public-post-preview/en/
9
  * Text Domain: public-post-preview
10
+ * Requires at least: 5.0
11
+ * Requires PHP: 5.6
12
  * License: GPLv2 or later
13
  *
14
  * Previously (2009-2011) maintained by Jonathan Dingman and Matt Martz.
276
  /**
277
  * (Un)Registers a post for a public preview.
278
  *
279
+ * Runs when a post is saved, ignores revisions and autosaves.
280
  *
281
  * @since 2.0.0
282
  *
283
  * @param int $post_id The post id.
284
  * @param object $post The post object.
285
+ * @return bool Returns true on a success, false on a failure.
286
  */
287
  public static function register_public_preview( $post_id, $post ) {
288
  if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
293
  return false;
294
  }
295
 
296
+ if ( empty( $_POST['public_post_preview_wpnonce'] ) || ! wp_verify_nonce( $_POST['public_post_preview_wpnonce'], 'public-post-preview_' . $post_id ) ) {
297
+ return false;
298
+ }
299
+
300
+ if ( ! current_user_can( 'edit_post', $post_id ) ) {
301
  return false;
302
  }
303
 
331
  * @param string $new_status New post status.
332
  * @param string $old_status Old post status.
333
  * @param WP_Post $post Post object.
334
+ * @return bool Returns true on a success, false on a failure.
335
  */
336
  public static function unregister_public_preview_on_status_change( $new_status, $old_status, $post ) {
337
  $disallowed_status = self::get_published_statuses();
351
  *
352
  * @param int $post_id Post ID.
353
  * @param WP_Post $post Post object.
354
+ * @return bool Returns true on a success, false on a failure.
355
  */
356
  public static function unregister_public_preview_on_edit( $post_id, $post ) {
357
  $disallowed_status = self::get_published_statuses();
370
  * @since 2.5.0
371
  *
372
  * @param int $post_id Post ID.
373
+ * @return bool Returns true on a success, false on a failure.
374
  */
375
  private static function unregister_public_preview( $post_id ) {
376
  $post_id = (int) $post_id;
577
  * @return int The time-dependent variable.
578
  */
579
  private static function nonce_tick() {
580
+ $nonce_life = apply_filters( 'ppp_nonce_life', 2 * DAY_IN_SECONDS ); // 2 days.
581
 
582
  return ceil( time() / ( $nonce_life / 2 ) );
583
  }
646
  * @since 2.0.0
647
  *
648
  * @param array $post_ids List of post IDs that have a preview.
649
+ * @return bool Returns true on a success, false on a failure.
650
  */
651
  private static function set_preview_post_ids( $post_ids = array() ) {
652
  $post_ids = array_map( 'absint', $post_ids );
readme.txt CHANGED
@@ -2,9 +2,9 @@
2
  Contributors: ocean90
3
  Tags: public, preview, posts, anonymous, drafts
4
  Requires at least: 5.0
5
- Tested up to: 5.4
6
  Requires PHP: 5.6
7
- Stable tag: 2.9.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -73,6 +73,9 @@ Or use the [Public Post Preview Configurator](https://wordpress.org/plugins/publ
73
 
74
  == Change Log ==
75
 
 
 
 
76
  = 2.9.1 (2020-07-25): =
77
  * Improve HTTP status codes for expired/invalid preview links.
78
 
2
  Contributors: ocean90
3
  Tags: public, preview, posts, anonymous, drafts
4
  Requires at least: 5.0
5
+ Tested up to: 5.6
6
  Requires PHP: 5.6
7
+ Stable tag: 2.9.2
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
73
 
74
  == Change Log ==
75
 
76
+ = 2.9.2 (2020-10-03): =
77
+ * Fixes saving of preview status without a previous Ajax request.
78
+
79
  = 2.9.1 (2020-07-25): =
80
  * Improve HTTP status codes for expired/invalid preview links.
81