Public Post Preview - Version 2.9.0

Version Description

Download this release

Release Info

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

Code changes from version 2.8.0 to 2.9.0

CHANGELOG.md ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Changelog
2
+
3
+ ## 2.9.0 (2019-07-20):
4
+ * Requires WordPress 5.0
5
+ * Requires PHP 5.6
6
+ * Adds notice (as Snackbar if supported) when changing preview status in block editor.
7
+ * Fixes incorrect status message in classic editor.
8
+ * Fixes grammar in expired link notice. Props [@garrett-eclipse](https://github.com/garrett-eclipse).
9
+ * Improves internal checks to be more strict. Props [@PatelUtkarsh](https://github.com/PatelUtkarsh).
10
+ * Removes deprecated i18n compatibility layer from Gutenberg plugin.
11
+
12
+ ## 2.8.0 (2018-11-27):
13
+ * Add support for WordPress 5.0 and the new block editor.
14
+
15
+ ## 2.7.0 (2018-09-14):
16
+ * Initial support for Gutenberg.
17
+ * Block robots for public post previews. Props [@westonruter](https://github.com/westonruter).
18
+
19
+ ## 2.6.0 (2017-04-27):
20
+ * Make `DS_Public_Post_Preview::get_preview_link()` public. Props [@rcstr](https://github.com/rcstr).
21
+ * Send no-cache headers for public post previews.
22
+
23
+ ## 2.5.0 (2016-04-05):
24
+ * Auto select preview link on focus. Props [@JeroenSormani](https://github.com/JeroenSormani).
25
+ * Remove preview status from posts which are trashed or after scheduled posts are published.
26
+ * Add support for paged posts.
27
+
28
+ ## 2.4.1 (2015-10-13):
29
+ * Update text domain to support language packs. Translations are now managed via http://translate.wordpress.org/projects/wp-plugins/public-post-preview.
30
+
31
+ ## 2.4 (2014-08-21):
32
+ * Supports EditFlow and custom statuses
33
+ * Disables comments and pings during public post preview
34
+ * Adds __Public Preview__ to the list of display states used in the Posts list table
35
+ * Prevents flickering of link box on Post edit while loading
36
+
37
+ ## 2.3 (2013-11-18):
38
+ * Introduces a filter `ppp_preview_link`. With the filter you can adjust the preview link.
39
+ * If a post has gone live, redirect to it's proper permalink.
40
+ * Adds the query var `_ppp` to WordPress SEO by Yoast whitelist.
41
+
42
+ ## 2.2 (2013-03-15):
43
+ * Based on user feedback: Removed the extra meta box and added preview link to the main Publish meta box.
44
+ * Only show the checkbox if the post status/post type is good.
45
+ * Requires WordPress 3.5
46
+
47
+ ## 2.1.1 (2012-09-19):
48
+ * 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.
49
+
50
+ ## 2.1 (2012-09-16):
51
+ * 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.
52
+ * 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.
53
+
54
+ ## 2.0.1 (2012-07-25):
55
+ * Makes the preview link copyable again
56
+
57
+ ## 2.0 (2012-07-23):
58
+ * Support for all public post types
59
+ * Saves public preview status via an AJAX request
60
+ * I18n
61
+ * Requires at least WordPress 3.3
62
+
63
+ ## 1.3 (2009-06-30):
64
+ * Hook in earlier in the post selection process to fix PHP notices
65
+ * Add uninstall functionality to remove options from the options table
66
+
67
+ ## 1.2 (2009-03-30):
68
+ * Fix preview URL for scheduled posts on sites with a permalink other than default activated.
69
+
70
+ ## 1.1 (2009-03-11):
71
+ * Don't limit public previews to posts in draft or pending status. Just exclude posts in publish status.
72
+
73
+ ## 1.0 (2009-02-20):
74
+ * Initial Public Release
composer.json ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ }
js/gutenberg-integration.deps.json ADDED
@@ -0,0 +1 @@
 
1
+ ["lodash","wp-components","wp-compose","wp-data","wp-edit-post","wp-element","wp-i18n","wp-plugins","wp-polyfill"]
js/gutenberg-integration.js CHANGED
@@ -1 +1 @@
1
- this.publicPostPreview=this.publicPostPreview||{},this.publicPostPreview.main=function(e){var t={};function r(n){if(t[n])return t[n].exports;var i=t[n]={i:n,l:!1,exports:{}};return e[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)r.d(n,i,function(t){return e[t]}.bind(null,i));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=22)}([function(e,t){!function(){e.exports=this.wp.element}()},function(e,t){e.exports=function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}},function(e,t){!function(){e.exports=this.wp.i18n}()},function(e,t,r){"use strict";(function(e){r.d(t,"a",function(){return c});var n=r(17),i=void 0!==e?e:{},a=Object(n.a)(i),c=(a.flush,a.hydrate,a.cx,a.merge,a.getRegisteredStyles,a.injectGlobal,a.keyframes,a.css);a.sheet,a.caches}).call(this,r(21))},function(e,t){!function(){e.exports=this.wp.components}()},function(e,t){!function(){e.exports=this.wp.compose}()},function(e,t){!function(){e.exports=this.wp.editPost}()},function(e,t){!function(){e.exports=this.wp.plugins}()},function(e,t,r){var n=r(18);e.exports=function(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{},i=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(i=i.concat(Object.getOwnPropertySymbols(r).filter(function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable}))),i.forEach(function(t){n(e,t,r[t])})}return e}},function(e,t){e.exports=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}},function(e,t){function r(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}e.exports=function(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),e}},function(e,t,r){var n=r(19),i=r(1);e.exports=function(e,t){return!t||"object"!==n(t)&&"function"!=typeof t?i(e):t}},function(e,t){function r(t){return e.exports=r=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},r(t)}e.exports=r},function(e,t,r){var n=r(20);e.exports=function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&n(e,t)}},function(e,t){!function(){e.exports=this.lodash}()},function(e,t,r){e.exports=function(){"use strict";return function(e){function t(t){if(t)try{e(t+"}")}catch(e){}}return function(r,n,i,a,c,o,s,u,l,f){switch(r){case 1:if(0===l&&64===n.charCodeAt(0))return e(n+";"),"";break;case 2:if(0===u)return n+"/*|*/";break;case 3:switch(u){case 102:case 112:return e(i[0]+n),"";default:return n+(0===f?"/*|*/":"")}case-2:n.split("/*|*/}").forEach(t)}}}}()},function(e,t){!function(){e.exports=this.wp.data}()},function(e,t,r){"use strict";var n=function(e){var t={};return function(r){return void 0===t[r]&&(t[r]=e(r)),t[r]}},i={animationIterationCount:1,borderImageOutset:1,borderImageSlice:1,borderImageWidth:1,boxFlex:1,boxFlexGroup:1,boxOrdinalGroup:1,columnCount:1,columns:1,flex:1,flexGrow:1,flexPositive:1,flexShrink:1,flexNegative:1,flexOrder:1,gridRow:1,gridRowEnd:1,gridRowSpan:1,gridRowStart:1,gridColumn:1,gridColumnEnd:1,gridColumnSpan:1,gridColumnStart:1,fontWeight:1,lineHeight:1,opacity:1,order:1,orphans:1,tabSize:1,widows:1,zIndex:1,zoom:1,WebkitLineClamp:1,fillOpacity:1,floodOpacity:1,stopOpacity:1,strokeDasharray:1,strokeDashoffset:1,strokeMiterlimit:1,strokeOpacity:1,strokeWidth:1};var a=function(e){for(var t,r=e.length,n=r^r,i=0;r>=4;)t=1540483477*(65535&(t=255&e.charCodeAt(i)|(255&e.charCodeAt(++i))<<8|(255&e.charCodeAt(++i))<<16|(255&e.charCodeAt(++i))<<24))+((1540483477*(t>>>16)&65535)<<16),n=1540483477*(65535&n)+((1540483477*(n>>>16)&65535)<<16)^(t=1540483477*(65535&(t^=t>>>24))+((1540483477*(t>>>16)&65535)<<16)),r-=4,++i;switch(r){case 3:n^=(255&e.charCodeAt(i+2))<<16;case 2:n^=(255&e.charCodeAt(i+1))<<8;case 1:n=1540483477*(65535&(n^=255&e.charCodeAt(i)))+((1540483477*(n>>>16)&65535)<<16)}return n=1540483477*(65535&(n^=n>>>13))+((1540483477*(n>>>16)&65535)<<16),((n^=n>>>15)>>>0).toString(36)};var c=function(e){function t(e,t,n){var i=t.trim().split(d);t=i;var a=i.length,c=e.length;switch(c){case 0:case 1:var o=0;for(e=0===c?"":e[0]+" ";o<a;++o)t[o]=r(e,t[o],n).trim();break;default:var s=o=0;for(t=[];o<a;++o)for(var u=0;u<c;++u)t[s++]=r(e[u]+" ",i[o],n).trim()}return t}function r(e,t,r){var n=t.charCodeAt(0);switch(33>n&&(n=(t=t.trim()).charCodeAt(0)),n){case 38:return t.replace(b,"$1"+e.trim());case 58:return e.trim()+t.replace(b,"$1"+e.trim());default:if(0<1*r&&0<t.indexOf("\f"))return t.replace(b,(58===e.charCodeAt(0)?"":"$1")+e.trim())}return e+t}function n(e,t,r,a){var c=e+";",o=2*t+3*r+4*a;if(944===o){e=c.indexOf(":",9)+1;var s=c.substring(e,c.length-1).trim();return s=c.substring(0,e).trim()+s+";",1===_||2===_&&i(s,1)?"-webkit-"+s+s:s}if(0===_||2===_&&!i(c,1))return c;switch(o){case 1015:return 97===c.charCodeAt(10)?"-webkit-"+c+c:c;case 951:return 116===c.charCodeAt(3)?"-webkit-"+c+c:c;case 963:return 110===c.charCodeAt(5)?"-webkit-"+c+c:c;case 1009:if(100!==c.charCodeAt(4))break;case 969:case 942:return"-webkit-"+c+c;case 978:return"-webkit-"+c+"-moz-"+c+c;case 1019:case 983:return"-webkit-"+c+"-moz-"+c+"-ms-"+c+c;case 883:if(45===c.charCodeAt(8))return"-webkit-"+c+c;if(0<c.indexOf("image-set(",11))return c.replace(A,"$1-webkit-$2")+c;break;case 932:if(45===c.charCodeAt(4))switch(c.charCodeAt(5)){case 103:return"-webkit-box-"+c.replace("-grow","")+"-webkit-"+c+"-ms-"+c.replace("grow","positive")+c;case 115:return"-webkit-"+c+"-ms-"+c.replace("shrink","negative")+c;case 98:return"-webkit-"+c+"-ms-"+c.replace("basis","preferred-size")+c}return"-webkit-"+c+"-ms-"+c+c;case 964:return"-webkit-"+c+"-ms-flex-"+c+c;case 1023:if(99!==c.charCodeAt(8))break;return"-webkit-box-pack"+(s=c.substring(c.indexOf(":",15)).replace("flex-","").replace("space-between","justify"))+"-webkit-"+c+"-ms-flex-pack"+s+c;case 1005:return h.test(c)?c.replace(f,":-webkit-")+c.replace(f,":-moz-")+c:c;case 1e3:switch(t=(s=c.substring(13).trim()).indexOf("-")+1,s.charCodeAt(0)+s.charCodeAt(t)){case 226:s=c.replace(m,"tb");break;case 232:s=c.replace(m,"tb-rl");break;case 220:s=c.replace(m,"lr");break;default:return c}return"-webkit-"+c+"-ms-"+s+c;case 1017:if(-1===c.indexOf("sticky",9))break;case 975:switch(t=(c=e).length-10,o=(s=(33===c.charCodeAt(t)?c.substring(0,t):c).substring(e.indexOf(":",7)+1).trim()).charCodeAt(0)+(0|s.charCodeAt(7))){case 203:if(111>s.charCodeAt(8))break;case 115:c=c.replace(s,"-webkit-"+s)+";"+c;break;case 207:case 102:c=c.replace(s,"-webkit-"+(102<o?"inline-":"")+"box")+";"+c.replace(s,"-webkit-"+s)+";"+c.replace(s,"-ms-"+s+"box")+";"+c}return c+";";case 938:if(45===c.charCodeAt(5))switch(c.charCodeAt(6)){case 105:return s=c.replace("-items",""),"-webkit-"+c+"-webkit-box-"+s+"-ms-flex-"+s+c;case 115:return"-webkit-"+c+"-ms-flex-item-"+c.replace(C,"")+c;default:return"-webkit-"+c+"-ms-flex-line-pack"+c.replace("align-content","").replace(C,"")+c}break;case 973:case 989:if(45!==c.charCodeAt(3)||122===c.charCodeAt(4))break;case 931:case 953:if(!0===O.test(e))return 115===(s=e.substring(e.indexOf(":")+1)).charCodeAt(0)?n(e.replace("stretch","fill-available"),t,r,a).replace(":fill-available",":stretch"):c.replace(s,"-webkit-"+s)+c.replace(s,"-moz-"+s.replace("fill-",""))+c;break;case 962:if(c="-webkit-"+c+(102===c.charCodeAt(5)?"-ms-"+c:"")+c,211===r+a&&105===c.charCodeAt(13)&&0<c.indexOf("transform",10))return c.substring(0,c.indexOf(";",27)+1).replace(p,"$1-webkit-$2")+c}return c}function i(e,t){var r=e.indexOf(1===t?":":"{"),n=e.substring(0,3!==t?r:10);return r=e.substring(r+1,e.length-1),R(2!==t?n:n.replace(x,"$1"),r,t)}function a(e,t){var r=n(t,t.charCodeAt(0),t.charCodeAt(1),t.charCodeAt(2));return r!==t+";"?r.replace(k," or ($1)").substring(4):"("+t+")"}function c(e,t,r,n,i,a,c,o,u,l){for(var f,h=0,p=t;h<z;++h)switch(f=I[h].call(s,e,p,r,n,i,a,c,o,u,l)){case void 0:case!1:case!0:case null:break;default:p=f}if(p!==t)return p}function o(e){return void 0!==(e=e.prefix)&&(R=null,e?"function"!=typeof e?_=1:(_=2,R=e):_=0),o}function s(e,r){var o=e;if(33>o.charCodeAt(0)&&(o=o.trim()),o=[o],0<z){var s=c(-1,r,o,o,S,j,0,0,0,0);void 0!==s&&"string"==typeof s&&(r=s)}var f=function e(r,o,s,f,h){for(var p,d,b,m,k,C=0,x=0,O=0,A=0,I=0,R=0,$=b=p=0,U=0,T=0,M=0,F=0,H=s.length,V=H-1,D="",G="",L="",W="";U<H;){if(d=s.charCodeAt(U),U===V&&0!==x+A+O+C&&(0!==x&&(d=47===x?10:47),A=O=C=0,H++,V++),0===x+A+O+C){if(U===V&&(0<T&&(D=D.replace(l,"")),0<D.trim().length)){switch(d){case 32:case 9:case 59:case 13:case 10:break;default:D+=s.charAt(U)}d=59}switch(d){case 123:for(p=(D=D.trim()).charCodeAt(0),b=1,F=++U;U<H;){switch(d=s.charCodeAt(U)){case 123:b++;break;case 125:b--;break;case 47:switch(d=s.charCodeAt(U+1)){case 42:case 47:e:{for($=U+1;$<V;++$)switch(s.charCodeAt($)){case 47:if(42===d&&42===s.charCodeAt($-1)&&U+2!==$){U=$+1;break e}break;case 10:if(47===d){U=$+1;break e}}U=$}}break;case 91:d++;case 40:d++;case 34:case 39:for(;U++<V&&s.charCodeAt(U)!==d;);}if(0===b)break;U++}switch(b=s.substring(F,U),0===p&&(p=(D=D.replace(u,"").trim()).charCodeAt(0)),p){case 64:switch(0<T&&(D=D.replace(l,"")),d=D.charCodeAt(1)){case 100:case 109:case 115:case 45:T=o;break;default:T=P}if(F=(b=e(o,T,b,d,h+1)).length,0<z&&(k=c(3,b,T=t(P,D,M),o,S,j,F,d,h,f),D=T.join(""),void 0!==k&&0===(F=(b=k.trim()).length)&&(d=0,b="")),0<F)switch(d){case 115:D=D.replace(y,a);case 100:case 109:case 45:b=D+"{"+b+"}";break;case 107:b=(D=D.replace(v,"$1 $2"))+"{"+b+"}",b=1===_||2===_&&i("@"+b,3)?"@-webkit-"+b+"@"+b:"@"+b;break;default:b=D+b,112===f&&(G+=b,b="")}else b="";break;default:b=e(o,t(o,D,M),b,f,h+1)}L+=b,b=M=T=$=p=0,D="",d=s.charCodeAt(++U);break;case 125:case 59:if(1<(F=(D=(0<T?D.replace(l,""):D).trim()).length))switch(0===$&&(p=D.charCodeAt(0),45===p||96<p&&123>p)&&(F=(D=D.replace(" ",":")).length),0<z&&void 0!==(k=c(1,D,o,r,S,j,G.length,f,h,f))&&0===(F=(D=k.trim()).length)&&(D="\0\0"),p=D.charCodeAt(0),d=D.charCodeAt(1),p){case 0:break;case 64:if(105===d||99===d){W+=D+s.charAt(U);break}default:58!==D.charCodeAt(F-1)&&(G+=n(D,p,d,D.charCodeAt(2)))}M=T=$=p=0,D="",d=s.charCodeAt(++U)}}switch(d){case 13:case 10:47===x?x=0:0===1+p&&107!==f&&0<D.length&&(T=1,D+="\0"),0<z*N&&c(0,D,o,r,S,j,G.length,f,h,f),j=1,S++;break;case 59:case 125:if(0===x+A+O+C){j++;break}default:switch(j++,m=s.charAt(U),d){case 9:case 32:if(0===A+C+x)switch(I){case 44:case 58:case 9:case 32:m="";break;default:32!==d&&(m=" ")}break;case 0:m="\\0";break;case 12:m="\\f";break;case 11:m="\\v";break;case 38:0===A+x+C&&(T=M=1,m="\f"+m);break;case 108:if(0===A+x+C+E&&0<$)switch(U-$){case 2:112===I&&58===s.charCodeAt(U-3)&&(E=I);case 8:111===R&&(E=R)}break;case 58:0===A+x+C&&($=U);break;case 44:0===x+O+A+C&&(T=1,m+="\r");break;case 34:case 39:0===x&&(A=A===d?0:0===A?d:A);break;case 91:0===A+x+O&&C++;break;case 93:0===A+x+O&&C--;break;case 41:0===A+x+C&&O--;break;case 40:if(0===A+x+C){if(0===p)switch(2*I+3*R){case 533:break;default:p=1}O++}break;case 64:0===x+O+A+C+$+b&&(b=1);break;case 42:case 47:if(!(0<A+C+O))switch(x){case 0:switch(2*d+3*s.charCodeAt(U+1)){case 235:x=47;break;case 220:F=U,x=42}break;case 42:47===d&&42===I&&F+2!==U&&(33===s.charCodeAt(F+2)&&(G+=s.substring(F,U+1)),m="",x=0)}}0===x&&(D+=m)}R=I,I=d,U++}if(0<(F=G.length)){if(T=o,0<z&&void 0!==(k=c(2,G,T,r,S,j,F,f,h,f))&&0===(G=k).length)return W+G+L;if(G=T.join(",")+"{"+G+"}",0!=_*E){switch(2!==_||i(G,2)||(E=0),E){case 111:G=G.replace(g,":-moz-$1")+G;break;case 112:G=G.replace(w,"::-webkit-input-$1")+G.replace(w,"::-moz-$1")+G.replace(w,":-ms-input-$1")+G}E=0}}return W+G+L}(P,o,r,0,0);return 0<z&&void 0!==(s=c(-2,f,o,o,S,j,f.length,0,0,0))&&(f=s),E=0,j=S=1,f}var u=/^\0+/g,l=/[\0\r\f]/g,f=/: */g,h=/zoo|gra/,p=/([,: ])(transform)/g,d=/,\r+?/g,b=/([\t\r\n ])*\f?&/g,v=/@(k\w+)\s*(\S*)\s*/,w=/::(place)/g,g=/:(read-only)/g,m=/[svh]\w+-[tblr]{2}/,y=/\(\s*(.*)\s*\)/g,k=/([\s\S]*?);/g,C=/-self|flex-/g,x=/[^]*?(:[rp][el]a[\w-]+)[^]*/,O=/stretch|:\s*\w+\-(?:conte|avail)/,A=/([^-])(image-set\()/,j=1,S=1,E=0,_=1,P=[],I=[],z=0,R=null,N=0;return s.use=function e(t){switch(t){case void 0:case null:z=I.length=0;break;default:switch(t.constructor){case Array:for(var r=0,n=t.length;r<n;++r)e(t[r]);break;case Function:I[z++]=t;break;case Boolean:N=0|!!t}}return e},s.set=o,void 0!==e&&o(e),s},o=r(15),s=r.n(o),u=/[A-Z]|^ms/g,l=n(function(e){return e.replace(u,"-$&").toLowerCase()}),f=function(e,t){return null==t||"boolean"==typeof t?"":1===i[e]||45===e.charCodeAt(1)||isNaN(t)||0===t?t:t+"px"},h=function e(t){for(var r=t.length,n=0,i="";n<r;n++){var a=t[n];if(null!=a){var c=void 0;switch(typeof a){case"boolean":break;case"function":0,c=e([a()]);break;case"object":if(Array.isArray(a))c=e(a);else for(var o in c="",a)a[o]&&o&&(c&&(c+=" "),c+=o);break;default:c=a}c&&(i&&(i+=" "),i+=c)}}return i},p="undefined"!=typeof document;function d(e){var t=document.createElement("style");return t.setAttribute("data-emotion",e.key||""),void 0!==e.nonce&&t.setAttribute("nonce",e.nonce),t.appendChild(document.createTextNode("")),(void 0!==e.container?e.container:document.head).appendChild(t),t}var b=function(){function e(e){this.isSpeedy=!0,this.tags=[],this.ctr=0,this.opts=e}var t=e.prototype;return t.inject=function(){if(this.injected)throw new Error("already injected!");this.tags[0]=d(this.opts),this.injected=!0},t.speedy=function(e){if(0!==this.ctr)throw new Error("cannot change speedy now");this.isSpeedy=!!e},t.insert=function(e,t){if(this.isSpeedy){var r=function(e){if(e.sheet)return e.sheet;for(var t=0;t<document.styleSheets.length;t++)if(document.styleSheets[t].ownerNode===e)return document.styleSheets[t]}(this.tags[this.tags.length-1]);try{r.insertRule(e,r.cssRules.length)}catch(e){0}}else{var n=d(this.opts);this.tags.push(n),n.appendChild(document.createTextNode(e+(t||"")))}this.ctr++,this.ctr%65e3==0&&this.tags.push(d(this.opts))},t.flush=function(){this.tags.forEach(function(e){return e.parentNode.removeChild(e)}),this.tags=[],this.ctr=0,this.injected=!1},e}();t.a=function(e,t){if(void 0!==e.__SECRET_EMOTION__)return e.__SECRET_EMOTION__;void 0===t&&(t={});var r,n,i=t.key||"css",o=s()(function(e){r+=e,p&&d.insert(e,w)});void 0!==t.prefix&&(n={prefix:t.prefix});var u={registered:{},inserted:{},nonce:t.nonce,key:i},d=new b(t);p&&d.inject();var v=new c(n);v.use(t.stylisPlugins)(o);var w="";function g(e,t){if(null==e)return"";switch(typeof e){case"boolean":return"";case"function":if(void 0!==e.__emotion_styles){var r=e.toString();return r}return g.call(this,void 0===this?e():e(this.mergedProps,this.context),t);case"object":return function(e){if(k.has(e))return k.get(e);var t="";return Array.isArray(e)?e.forEach(function(e){t+=g.call(this,e,!1)},this):Object.keys(e).forEach(function(r){"object"!=typeof e[r]?void 0!==u.registered[e[r]]?t+=r+"{"+u.registered[e[r]]+"}":t+=l(r)+":"+f(r,e[r])+";":Array.isArray(e[r])&&"string"==typeof e[r][0]&&void 0===u.registered[e[r][0]]?e[r].forEach(function(e){t+=l(r)+":"+f(r,e)+";"}):t+=r+"{"+g.call(this,e[r],!1)+"}"},this),k.set(e,t),t}.call(this,e);default:var n=u.registered[e];return!1===t&&void 0!==n?n:e}}var m,y,k=new WeakMap,C=/label:\s*([^\s;\n{]+)\s*;/g,x=function(e){var t=!0,r="",n="";null==e||void 0===e.raw?(t=!1,r+=g.call(this,e,!1)):r+=e[0];for(var i=arguments.length,c=new Array(i>1?i-1:0),o=1;o<i;o++)c[o-1]=arguments[o];return c.forEach(function(n,i){r+=g.call(this,n,46===r.charCodeAt(r.length-1)),!0===t&&void 0!==e[i+1]&&(r+=e[i+1])},this),y=r,r=r.replace(C,function(e,t){return n+="-"+t,""}),m=function(e,t){return a(e+t)+t}(r,n),r};function O(e,t){void 0===u.inserted[m]&&(r="",v(e,t),u.inserted[m]=r)}var A=function(){var e=x.apply(this,arguments),t=i+"-"+m;return void 0===u.registered[t]&&(u.registered[t]=y),O("."+t,e),t};function j(e,t){var r="";return t.split(" ").forEach(function(t){void 0!==u.registered[t]?e.push(t):r+=t+" "}),r}function S(e,t){var r=[],n=j(r,e);return r.length<2?e:n+A(r,t)}function E(e){u.inserted[e]=!0}if(p){var _=document.querySelectorAll("[data-emotion-"+i+"]");Array.prototype.forEach.call(_,function(e){d.tags[0].parentNode.insertBefore(e,d.tags[0]),e.getAttribute("data-emotion-"+i).split(" ").forEach(E)})}var P={flush:function(){p&&(d.flush(),d.inject()),u.inserted={},u.registered={}},hydrate:function(e){e.forEach(E)},cx:function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];return S(h(t))},merge:S,getRegisteredStyles:j,injectGlobal:function(){O("",x.apply(this,arguments))},keyframes:function(){var e=x.apply(this,arguments),t="animation-"+m;return O("","@keyframes "+t+"{"+e+"}"),t},css:A,sheet:d,caches:u};return e.__SECRET_EMOTION__=P,P}},function(e,t){e.exports=function(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}},function(e,t){function r(e){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function n(t){return"function"==typeof Symbol&&"symbol"===r(Symbol.iterator)?e.exports=n=function(e){return r(e)}:e.exports=n=function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":r(e)},n(t)}e.exports=n},function(e,t){function r(t,n){return e.exports=r=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},r(t,n)}e.exports=r},function(e,t){var r;r=function(){return this}();try{r=r||new Function("return this")()}catch(e){"object"==typeof window&&(r=window)}e.exports=r},function(e,t,r){"use strict";r.r(t);var n=r(7),i=r(8),a=r.n(i),c=r(9),o=r.n(c),s=r(10),u=r.n(s),l=r(11),f=r.n(l),h=r(12),p=r.n(h),d=r(13),b=r.n(d),v=r(1),w=r.n(v),g=r(0),m=r(14),y=r(3),k=r(2),C=r(4),x=r(16),O=r(6),A=r(5),j=window,S=j.ajaxurl,E=j.DSPublicPostPreviewData,_=Object(y.a)("flex-direction:column;align-items:stretch;margin-top:10px;"),P=Object(y.a)("width:100%;margin-right:12px;"),I=Object(y.a)("font-style:italic;color:#666;margin:.2em 0 0 !important;"),z=Object(y.a)("display:flex;justify-content:flex-start;align-items:center;margin:0;"),R=function(e){function t(e){var r;return o()(this,t),(r=f()(this,p()(t).call(this,e))).state={previewEnabled:E.previewEnabled,previewUrl:E.previewUrl,hasCopied:!1},r.previewUrlInput=Object(g.createRef)(),r.onChange=r.onChange.bind(w()(w()(r))),r.onPreviewUrlInputFocus=r.onPreviewUrlInputFocus.bind(w()(w()(r))),r}return b()(t,e),u()(t,[{key:"onChange",value:function(e){var t=this;this.request({checked:e,post_ID:this.props.postId},function(){t.setState({previewEnabled:!t.state.previewEnabled})})}},{key:"onPreviewUrlInputFocus",value:function(){this.previewUrlInput.current.focus(),this.previewUrlInput.current.select()}},{key:"request",value:function(e,t){jQuery.ajax({type:"POST",url:S,data:a()({action:"public-post-preview",_ajax_nonce:E.nonce},e),success:t})}},{key:"render",value:function(){var e=this,t=this.state,r=t.previewEnabled,n=t.previewUrl,i=t.hasCopied,a=i?Object(k.__)("Preview URL copied","public-post-preview"):Object(k.__)("Copy the preview URL","public-post-preview");return Object(g.createElement)(g.Fragment,null,Object(g.createElement)(O.PluginPostStatusInfo,null,Object(g.createElement)(C.CheckboxControl,{label:Object(k.__)("Enable public preview","public-post-preview"),checked:r,onChange:this.onChange})),r&&Object(g.createElement)(O.PluginPostStatusInfo,{className:_},Object(g.createElement)("p",{className:z},Object(g.createElement)("label",{htmlFor:"public-post-preview-url",className:"screen-reader-text"},Object(k.__)("Preview URL","public-post-preview")),Object(g.createElement)("input",{ref:this.previewUrlInput,type:"text",id:"public-post-preview-url",className:P,value:n,readOnly:!0,onFocus:this.onPreviewUrlInputFocus}),Object(g.createElement)(C.ClipboardButton,{text:n,label:a,onCopy:function(){return e.setState({hasCopied:!0})},onFinishCopy:function(){return e.setState({hasCopied:!1})},"aria-disabled":i,icon:Object(g.createElement)(C.SVG,{width:"20",height:"20",viewBox:"0 0 14 16",xmlns:"http://www.w3.org/2000/svg",focusable:"false"},Object(g.createElement)(C.Path,{fillRule:"evenodd",d:"M2 13h4v1H2v-1zm5-6H2v1h5V7zm2 3V8l-3 3 3 3v-2h5v-2H9zM4.5 9H2v1h2.5V9zM2 12h2.5v-1H2v1zm9 1h1v2c-.02.28-.11.52-.3.7-.19.18-.42.28-.7.3H1c-.55 0-1-.45-1-1V4c0-.55.45-1 1-1h3c0-1.11.89-2 2-2 1.11 0 2 .89 2 2h3c.55 0 1 .45 1 1v5h-1V6H1v9h10v-2zM2 5h8c0-.55-.45-1-1-1H8c-.55 0-1-.45-1-1s-.45-1-1-1-1 .45-1 1-.45 1-1 1H3c-.55 0-1 .45-1 1z"}))})),Object(g.createElement)("p",{className:I},Object(k.__)("Copy and share this preview URL.","public-post-preview"))))}}]),t}(g.Component),N=Object(A.compose)([Object(x.withSelect)(function(e){var t=e("core").getPostType,r=e("core/editor"),n=r.getCurrentPostId,i=r.getEditedPostAttribute,a=t(i("type"));return{postId:n(),status:i("status"),isViewable:Object(m.get)(a,["viewable"],!1)}}),Object(A.ifCondition)(function(e){return e.isViewable}),Object(A.ifCondition)(function(e){var t=e.status;return-1===["auto-draft","publish","private"].indexOf(t)})])(R);Object(n.registerPlugin)("public-post-preview",{render:N})}]);
1
+ !function(e){var t={};function r(n){if(t[n])return t[n].exports;var i=t[n]={i:n,l:!1,exports:{}};return e[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)r.d(n,i,function(t){return e[t]}.bind(null,i));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=16)}([function(e,t){!function(){e.exports=this.wp.element}()},function(e,t){!function(){e.exports=this.wp.i18n}()},function(e,t){!function(){e.exports=this.wp.components}()},function(e,t){e.exports=function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}},function(e,t){!function(){e.exports=this.wp.compose}()},function(e,t){!function(){e.exports=this.wp.data}()},function(e,t){!function(){e.exports=this.wp.editPost}()},function(e,t){!function(){e.exports=this.wp.plugins}()},function(e,t){e.exports=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}},function(e,t){function r(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}e.exports=function(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),e}},function(e,t,r){var n=r(14),i=r(3);e.exports=function(e,t){return!t||"object"!==n(t)&&"function"!=typeof t?i(e):t}},function(e,t){function r(t){return e.exports=r=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},r(t)}e.exports=r},function(e,t,r){var n=r(15);e.exports=function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&n(e,t)}},function(e,t){!function(){e.exports=this.lodash}()},function(e,t){function r(e){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function n(t){return"function"==typeof Symbol&&"symbol"===r(Symbol.iterator)?e.exports=n=function(e){return r(e)}:e.exports=n=function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":r(e)},n(t)}e.exports=n},function(e,t){function r(t,n){return e.exports=r=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},r(t,n)}e.exports=r},function(e,t,r){"use strict";r.r(t);var n=r(7),i=r(8),a=r.n(i),c=r(9),o=r.n(c),s=r(10),u=r.n(s),l=r(11),f=r.n(l),p=r(3),h=r.n(p),d=r(12),b=r.n(d);var v=function(){function e(e){this.isSpeedy=void 0===e.speedy||e.speedy,this.tags=[],this.ctr=0,this.nonce=e.nonce,this.key=e.key,this.container=e.container,this.before=null}var t=e.prototype;return t.insert=function(e){if(this.ctr%(this.isSpeedy?65e3:1)==0){var t,r=function(e){var t=document.createElement("style");return t.setAttribute("data-emotion",e.key),void 0!==e.nonce&&t.setAttribute("nonce",e.nonce),t.appendChild(document.createTextNode("")),t}(this);t=0===this.tags.length?this.before:this.tags[this.tags.length-1].nextSibling,this.container.insertBefore(r,t),this.tags.push(r)}var n=this.tags[this.tags.length-1];if(this.isSpeedy){var i=function(e){if(e.sheet)return e.sheet;for(var t=0;t<document.styleSheets.length;t++)if(document.styleSheets[t].ownerNode===e)return document.styleSheets[t]}(n);try{var a=105===e.charCodeAt(1)&&64===e.charCodeAt(0);i.insertRule(e,a?0:i.cssRules.length)}catch(e){0}}else n.appendChild(document.createTextNode(e));this.ctr++},t.flush=function(){this.tags.forEach(function(e){return e.parentNode.removeChild(e)}),this.tags=[],this.ctr=0},e}();var m=function(e){function t(e,t,n){var i=t.trim().split(d);t=i;var a=i.length,c=e.length;switch(c){case 0:case 1:var o=0;for(e=0===c?"":e[0]+" ";o<a;++o)t[o]=r(e,t[o],n).trim();break;default:var s=o=0;for(t=[];o<a;++o)for(var u=0;u<c;++u)t[s++]=r(e[u]+" ",i[o],n).trim()}return t}function r(e,t,r){var n=t.charCodeAt(0);switch(33>n&&(n=(t=t.trim()).charCodeAt(0)),n){case 38:return t.replace(b,"$1"+e.trim());case 58:return e.trim()+t.replace(b,"$1"+e.trim());default:if(0<1*r&&0<t.indexOf("\f"))return t.replace(b,(58===e.charCodeAt(0)?"":"$1")+e.trim())}return e+t}function n(e,t,r,a){var c=e+";",o=2*t+3*r+4*a;if(944===o){e=c.indexOf(":",9)+1;var s=c.substring(e,c.length-1).trim();return s=c.substring(0,e).trim()+s+";",1===P||2===P&&i(s,1)?"-webkit-"+s+s:s}if(0===P||2===P&&!i(c,1))return c;switch(o){case 1015:return 97===c.charCodeAt(10)?"-webkit-"+c+c:c;case 951:return 116===c.charCodeAt(3)?"-webkit-"+c+c:c;case 963:return 110===c.charCodeAt(5)?"-webkit-"+c+c:c;case 1009:if(100!==c.charCodeAt(4))break;case 969:case 942:return"-webkit-"+c+c;case 978:return"-webkit-"+c+"-moz-"+c+c;case 1019:case 983:return"-webkit-"+c+"-moz-"+c+"-ms-"+c+c;case 883:if(45===c.charCodeAt(8))return"-webkit-"+c+c;if(0<c.indexOf("image-set(",11))return c.replace(O,"$1-webkit-$2")+c;break;case 932:if(45===c.charCodeAt(4))switch(c.charCodeAt(5)){case 103:return"-webkit-box-"+c.replace("-grow","")+"-webkit-"+c+"-ms-"+c.replace("grow","positive")+c;case 115:return"-webkit-"+c+"-ms-"+c.replace("shrink","negative")+c;case 98:return"-webkit-"+c+"-ms-"+c.replace("basis","preferred-size")+c}return"-webkit-"+c+"-ms-"+c+c;case 964:return"-webkit-"+c+"-ms-flex-"+c+c;case 1023:if(99!==c.charCodeAt(8))break;return"-webkit-box-pack"+(s=c.substring(c.indexOf(":",15)).replace("flex-","").replace("space-between","justify"))+"-webkit-"+c+"-ms-flex-pack"+s+c;case 1005:return p.test(c)?c.replace(f,":-webkit-")+c.replace(f,":-moz-")+c:c;case 1e3:switch(t=(s=c.substring(13).trim()).indexOf("-")+1,s.charCodeAt(0)+s.charCodeAt(t)){case 226:s=c.replace(g,"tb");break;case 232:s=c.replace(g,"tb-rl");break;case 220:s=c.replace(g,"lr");break;default:return c}return"-webkit-"+c+"-ms-"+s+c;case 1017:if(-1===c.indexOf("sticky",9))break;case 975:switch(t=(c=e).length-10,o=(s=(33===c.charCodeAt(t)?c.substring(0,t):c).substring(e.indexOf(":",7)+1).trim()).charCodeAt(0)+(0|s.charCodeAt(7))){case 203:if(111>s.charCodeAt(8))break;case 115:c=c.replace(s,"-webkit-"+s)+";"+c;break;case 207:case 102:c=c.replace(s,"-webkit-"+(102<o?"inline-":"")+"box")+";"+c.replace(s,"-webkit-"+s)+";"+c.replace(s,"-ms-"+s+"box")+";"+c}return c+";";case 938:if(45===c.charCodeAt(5))switch(c.charCodeAt(6)){case 105:return s=c.replace("-items",""),"-webkit-"+c+"-webkit-box-"+s+"-ms-flex-"+s+c;case 115:return"-webkit-"+c+"-ms-flex-item-"+c.replace(x,"")+c;default:return"-webkit-"+c+"-ms-flex-line-pack"+c.replace("align-content","").replace(x,"")+c}break;case 973:case 989:if(45!==c.charCodeAt(3)||122===c.charCodeAt(4))break;case 931:case 953:if(!0===A.test(e))return 115===(s=e.substring(e.indexOf(":")+1)).charCodeAt(0)?n(e.replace("stretch","fill-available"),t,r,a).replace(":fill-available",":stretch"):c.replace(s,"-webkit-"+s)+c.replace(s,"-moz-"+s.replace("fill-",""))+c;break;case 962:if(c="-webkit-"+c+(102===c.charCodeAt(5)?"-ms-"+c:"")+c,211===r+a&&105===c.charCodeAt(13)&&0<c.indexOf("transform",10))return c.substring(0,c.indexOf(";",27)+1).replace(h,"$1-webkit-$2")+c}return c}function i(e,t){var r=e.indexOf(1===t?":":"{"),n=e.substring(0,3!==t?r:10);return r=e.substring(r+1,e.length-1),z(2!==t?n:n.replace(C,"$1"),r,t)}function a(e,t){var r=n(t,t.charCodeAt(0),t.charCodeAt(1),t.charCodeAt(2));return r!==t+";"?r.replace(k," or ($1)").substring(4):"("+t+")"}function c(e,t,r,n,i,a,c,o,u,l){for(var f,p=0,h=t;p<R;++p)switch(f=I[p].call(s,e,h,r,n,i,a,c,o,u,l)){case void 0:case!1:case!0:case null:break;default:h=f}if(h!==t)return h}function o(e){return void 0!==(e=e.prefix)&&(z=null,e?"function"!=typeof e?P=1:(P=2,z=e):P=0),o}function s(e,r){var o=e;if(33>o.charCodeAt(0)&&(o=o.trim()),o=[o],0<R){var s=c(-1,r,o,o,S,j,0,0,0,0);void 0!==s&&"string"==typeof s&&(r=s)}var f=function e(r,o,s,f,p){for(var h,d,b,g,k,x=0,C=0,A=0,O=0,I=0,z=0,$=b=h=0,U=0,F=0,M=0,G=0,H=s.length,D=H-1,T="",V="",L="",q="";U<H;){if(d=s.charCodeAt(U),U===D&&0!==C+O+A+x&&(0!==C&&(d=47===C?10:47),O=A=x=0,H++,D++),0===C+O+A+x){if(U===D&&(0<F&&(T=T.replace(l,"")),0<T.trim().length)){switch(d){case 32:case 9:case 59:case 13:case 10:break;default:T+=s.charAt(U)}d=59}switch(d){case 123:for(h=(T=T.trim()).charCodeAt(0),b=1,G=++U;U<H;){switch(d=s.charCodeAt(U)){case 123:b++;break;case 125:b--;break;case 47:switch(d=s.charCodeAt(U+1)){case 42:case 47:e:{for($=U+1;$<D;++$)switch(s.charCodeAt($)){case 47:if(42===d&&42===s.charCodeAt($-1)&&U+2!==$){U=$+1;break e}break;case 10:if(47===d){U=$+1;break e}}U=$}}break;case 91:d++;case 40:d++;case 34:case 39:for(;U++<D&&s.charCodeAt(U)!==d;);}if(0===b)break;U++}switch(b=s.substring(G,U),0===h&&(h=(T=T.replace(u,"").trim()).charCodeAt(0)),h){case 64:switch(0<F&&(T=T.replace(l,"")),d=T.charCodeAt(1)){case 100:case 109:case 115:case 45:F=o;break;default:F=E}if(G=(b=e(o,F,b,d,p+1)).length,0<R&&(k=c(3,b,F=t(E,T,M),o,S,j,G,d,p,f),T=F.join(""),void 0!==k&&0===(G=(b=k.trim()).length)&&(d=0,b="")),0<G)switch(d){case 115:T=T.replace(y,a);case 100:case 109:case 45:b=T+"{"+b+"}";break;case 107:b=(T=T.replace(v,"$1 $2"))+"{"+b+"}",b=1===P||2===P&&i("@"+b,3)?"@-webkit-"+b+"@"+b:"@"+b;break;default:b=T+b,112===f&&(V+=b,b="")}else b="";break;default:b=e(o,t(o,T,M),b,f,p+1)}L+=b,b=M=F=$=h=0,T="",d=s.charCodeAt(++U);break;case 125:case 59:if(1<(G=(T=(0<F?T.replace(l,""):T).trim()).length))switch(0===$&&(h=T.charCodeAt(0),45===h||96<h&&123>h)&&(G=(T=T.replace(" ",":")).length),0<R&&void 0!==(k=c(1,T,o,r,S,j,V.length,f,p,f))&&0===(G=(T=k.trim()).length)&&(T="\0\0"),h=T.charCodeAt(0),d=T.charCodeAt(1),h){case 0:break;case 64:if(105===d||99===d){q+=T+s.charAt(U);break}default:58!==T.charCodeAt(G-1)&&(V+=n(T,h,d,T.charCodeAt(2)))}M=F=$=h=0,T="",d=s.charCodeAt(++U)}}switch(d){case 13:case 10:47===C?C=0:0===1+h&&107!==f&&0<T.length&&(F=1,T+="\0"),0<R*N&&c(0,T,o,r,S,j,V.length,f,p,f),j=1,S++;break;case 59:case 125:if(0===C+O+A+x){j++;break}default:switch(j++,g=s.charAt(U),d){case 9:case 32:if(0===O+x+C)switch(I){case 44:case 58:case 9:case 32:g="";break;default:32!==d&&(g=" ")}break;case 0:g="\\0";break;case 12:g="\\f";break;case 11:g="\\v";break;case 38:0===O+C+x&&(F=M=1,g="\f"+g);break;case 108:if(0===O+C+x+_&&0<$)switch(U-$){case 2:112===I&&58===s.charCodeAt(U-3)&&(_=I);case 8:111===z&&(_=z)}break;case 58:0===O+C+x&&($=U);break;case 44:0===C+A+O+x&&(F=1,g+="\r");break;case 34:case 39:0===C&&(O=O===d?0:0===O?d:O);break;case 91:0===O+C+A&&x++;break;case 93:0===O+C+A&&x--;break;case 41:0===O+C+x&&A--;break;case 40:if(0===O+C+x){if(0===h)switch(2*I+3*z){case 533:break;default:h=1}A++}break;case 64:0===C+A+O+x+$+b&&(b=1);break;case 42:case 47:if(!(0<O+x+A))switch(C){case 0:switch(2*d+3*s.charCodeAt(U+1)){case 235:C=47;break;case 220:G=U,C=42}break;case 42:47===d&&42===I&&G+2!==U&&(33===s.charCodeAt(G+2)&&(V+=s.substring(G,U+1)),g="",C=0)}}0===C&&(T+=g)}z=I,I=d,U++}if(0<(G=V.length)){if(F=o,0<R&&void 0!==(k=c(2,V,F,r,S,j,G,f,p,f))&&0===(V=k).length)return q+V+L;if(V=F.join(",")+"{"+V+"}",0!=P*_){switch(2!==P||i(V,2)||(_=0),_){case 111:V=V.replace(w,":-moz-$1")+V;break;case 112:V=V.replace(m,"::-webkit-input-$1")+V.replace(m,"::-moz-$1")+V.replace(m,":-ms-input-$1")+V}_=0}}return q+V+L}(E,o,r,0,0);return 0<R&&void 0!==(s=c(-2,f,o,o,S,j,f.length,0,0,0))&&(f=s),_=0,j=S=1,f}var u=/^\0+/g,l=/[\0\r\f]/g,f=/: */g,p=/zoo|gra/,h=/([,: ])(transform)/g,d=/,\r+?/g,b=/([\t\r\n ])*\f?&/g,v=/@(k\w+)\s*(\S*)\s*/,m=/::(place)/g,w=/:(read-only)/g,g=/[svh]\w+-[tblr]{2}/,y=/\(\s*(.*)\s*\)/g,k=/([\s\S]*?);/g,x=/-self|flex-/g,C=/[^]*?(:[rp][el]a[\w-]+)[^]*/,A=/stretch|:\s*\w+\-(?:conte|avail)/,O=/([^-])(image-set\()/,j=1,S=1,_=0,P=1,E=[],I=[],R=0,z=null,N=0;return s.use=function e(t){switch(t){case void 0:case null:R=I.length=0;break;default:if("function"==typeof t)I[R++]=t;else if("object"==typeof t)for(var r=0,n=t.length;r<n;++r)e(t[r]);else N=0|!!t}return e},s.set=o,void 0!==e&&o(e),s};function w(e){e&&g.current.insert(e+"}")}var g={current:null},y=function(e,t,r,n,i,a,c,o,s,u){switch(e){case 1:switch(t.charCodeAt(0)){case 64:return g.current.insert(t+";"),"";case 108:if(98===t.charCodeAt(2))return""}break;case 2:if(0===o)return t+"/*|*/";break;case 3:switch(o){case 102:case 112:return g.current.insert(r[0]+t),"";default:return t+(0===u?"/*|*/":"")}case-2:t.split("/*|*/}").forEach(w)}},k=function(e){void 0===e&&(e={});var t,r=e.key||"css";void 0!==e.prefix&&(t={prefix:e.prefix});var n=new m(t);var i,a={};i=e.container||document.head;var c,o=document.querySelectorAll("style[data-emotion-"+r+"]");Array.prototype.forEach.call(o,function(e){e.getAttribute("data-emotion-"+r).split(" ").forEach(function(e){a[e]=!0}),e.parentNode!==i&&i.appendChild(e)}),n.use(e.stylisPlugins)(y),c=function(e,t,r,i){var a=t.name;g.current=r,n(e,t.styles),i&&(s.inserted[a]=!0)};var s={key:r,sheet:new v({key:r,container:i,nonce:e.nonce,speedy:e.speedy}),nonce:e.nonce,inserted:a,registered:{},insert:c};return s};var x=function(e){for(var t,r=e.length,n=r^r,i=0;r>=4;)t=1540483477*(65535&(t=255&e.charCodeAt(i)|(255&e.charCodeAt(++i))<<8|(255&e.charCodeAt(++i))<<16|(255&e.charCodeAt(++i))<<24))+((1540483477*(t>>>16)&65535)<<16),n=1540483477*(65535&n)+((1540483477*(n>>>16)&65535)<<16)^(t=1540483477*(65535&(t^=t>>>24))+((1540483477*(t>>>16)&65535)<<16)),r-=4,++i;switch(r){case 3:n^=(255&e.charCodeAt(i+2))<<16;case 2:n^=(255&e.charCodeAt(i+1))<<8;case 1:n=1540483477*(65535&(n^=255&e.charCodeAt(i)))+((1540483477*(n>>>16)&65535)<<16)}return n=1540483477*(65535&(n^=n>>>13))+((1540483477*(n>>>16)&65535)<<16),((n^=n>>>15)>>>0).toString(36)},C={animationIterationCount:1,borderImageOutset:1,borderImageSlice:1,borderImageWidth:1,boxFlex:1,boxFlexGroup:1,boxOrdinalGroup:1,columnCount:1,columns:1,flex:1,flexGrow:1,flexPositive:1,flexShrink:1,flexNegative:1,flexOrder:1,gridRow:1,gridRowEnd:1,gridRowSpan:1,gridRowStart:1,gridColumn:1,gridColumnEnd:1,gridColumnSpan:1,gridColumnStart:1,msGridRow:1,msGridRowSpan:1,msGridColumn:1,msGridColumnSpan:1,fontWeight:1,lineHeight:1,opacity:1,order:1,orphans:1,tabSize:1,widows:1,zIndex:1,zoom:1,WebkitLineClamp:1,fillOpacity:1,floodOpacity:1,stopOpacity:1,strokeDasharray:1,strokeDashoffset:1,strokeMiterlimit:1,strokeOpacity:1,strokeWidth:1};var A=/[A-Z]|^ms/g,O=/_EMO_([^_]+?)_([^]*?)_EMO_/g,j=function(e){return 45===e.charCodeAt(1)},S=function(e){var t={};return function(r){return void 0===t[r]&&(t[r]=e(r)),t[r]}}(function(e){return j(e)?e:e.replace(A,"-$&").toLowerCase()}),_=function(e,t){if(null==t||"boolean"==typeof t)return"";switch(e){case"animation":case"animationName":"string"==typeof t&&(t=t.replace(O,function(e,t,r){return E={name:t,styles:r,next:E},t}))}return 1===C[e]||j(e)||"number"!=typeof t||0===t?t:t+"px"};function P(e,t,r,n){if(null==r)return"";if(void 0!==r.__emotion_styles)return r;switch(typeof r){case"boolean":return"";case"object":if(1===r.anim)return E={name:r.name,styles:r.styles,next:E},r.name;if(void 0!==r.styles){var i=r.next;if(void 0!==i)for(;void 0!==i;)E={name:i.name,styles:i.styles,next:E},i=i.next;return r.styles}return function(e,t,r){var n="";if(Array.isArray(r))for(var i=0;i<r.length;i++)n+=P(e,t,r[i],!1);else for(var a in r){var c=r[a];if("object"!=typeof c)null!=t&&void 0!==t[c]?n+=a+"{"+t[c]+"}":n+=S(a)+":"+_(a,c)+";";else if(!Array.isArray(c)||"string"!=typeof c[0]||null!=t&&void 0!==t[c[0]])n+=a+"{"+P(e,t,c,!1)+"}";else for(var o=0;o<c.length;o++)n+=S(a)+":"+_(a,c[o])+";"}return n}(e,t,r);case"function":if(void 0!==e){var a=E,c=r(e);return E=a,P(e,t,c,n)}default:if(null==t)return r;var o=t[r];return void 0===o||n?r:o}}var E,I=/label:\s*([^\s;\n{]+)\s*;/g;var R=function(e,t,r){if(1===e.length&&"object"==typeof e[0]&&null!==e[0]&&void 0!==e[0].styles)return e[0];var n=!0,i="";E=void 0;var a=e[0];null==a||void 0===a.raw?(n=!1,i+=P(r,t,a,!1)):i+=a[0];for(var c=1;c<e.length;c++)i+=P(r,t,e[c],46===i.charCodeAt(i.length-1)),n&&(i+=a[c]);I.lastIndex=0;for(var o,s="";null!==(o=I.exec(i));)s+="-"+o[1];return{name:x(i)+s,styles:i,next:E}};function z(e,t,r){var n="";return r.split(" ").forEach(function(r){void 0!==e[r]?t.push(e[r]):n+=r+" "}),n}var N=function(e,t,r){var n=e.key+"-"+t.name;if(!1===r&&void 0===e.registered[n]&&(e.registered[n]=t.styles),void 0===e.inserted[t.name]){var i=t;do{e.insert("."+n,i,e.sheet,!0);i=i.next}while(void 0!==i)}};function $(e,t){if(void 0===e.inserted[t.name])return e.insert("",t,e.sheet,!0)}function U(e,t,r){var n=[],i=z(e,n,r);return n.length<2?r:i+t(n)}var F=function e(t){for(var r="",n=0;n<t.length;n++){var i=t[n];if(null!=i){var a=void 0;switch(typeof i){case"boolean":break;case"object":if(Array.isArray(i))a=e(i);else for(var c in a="",i)i[c]&&c&&(a&&(a+=" "),a+=c);break;default:a=i}a&&(r&&(r+=" "),r+=a)}}return r},M=function(e){var t=k(e);t.sheet.speedy=function(e){this.isSpeedy=e},t.compat=!0;var r=function(){for(var e=arguments.length,r=new Array(e),n=0;n<e;n++)r[n]=arguments[n];var i=R(r,t.registered,void 0!==this?this.mergedProps:void 0);return N(t,i,!1),t.key+"-"+i.name};return{css:r,cx:function(){for(var e=arguments.length,n=new Array(e),i=0;i<e;i++)n[i]=arguments[i];return U(t.registered,r,F(n))},injectGlobal:function(){for(var e=arguments.length,r=new Array(e),n=0;n<e;n++)r[n]=arguments[n];var i=R(r,t.registered);$(t,i)},keyframes:function(){for(var e=arguments.length,r=new Array(e),n=0;n<e;n++)r[n]=arguments[n];var i=R(r,t.registered),a="animation-"+i.name;return $(t,{name:i.name,styles:"@keyframes "+a+"{"+i.styles+"}"}),a},hydrate:function(e){e.forEach(function(e){t.inserted[e]=!0})},flush:function(){t.registered={},t.inserted={},t.sheet.flush()},sheet:t.sheet,cache:t,getRegisteredStyles:z.bind(null,t.registered),merge:U.bind(null,t.registered,r)}}(),G=(M.flush,M.hydrate,M.cx,M.merge,M.getRegisteredStyles,M.injectGlobal,M.keyframes,M.css),H=(M.sheet,M.cache,r(0)),D=r(13),T=r(1),V=r(2),L=r(5),q=r(6),W=r(4),B=window,Z=B.ajaxurl,J=B.DSPublicPostPreviewData,K=G({name:"v3x9uo",styles:"flex-direction:column;align-items:stretch;margin-top:10px;"}),Q=G({name:"69ytpn",styles:"width:100%;margin-right:12px;"}),X=G({name:"1gaqufl",styles:"font-style:italic;color:#666;margin:.2em 0 0 !important;"}),Y=G({name:"9vxan6",styles:"display:flex;justify-content:flex-start;align-items:center;margin:0;"}),ee=Object(H.createElement)(V.SVG,{width:"20",height:"20",viewBox:"0 0 14 16",xmlns:"http://www.w3.org/2000/svg"},Object(H.createElement)(V.Path,{fillRule:"evenodd",d:"M2 13h4v1H2v-1zm5-6H2v1h5V7zm2 3V8l-3 3 3 3v-2h5v-2H9zM4.5 9H2v1h2.5V9zM2 12h2.5v-1H2v1zm9 1h1v2c-.02.28-.11.52-.3.7-.19.18-.42.28-.7.3H1c-.55 0-1-.45-1-1V4c0-.55.45-1 1-1h3c0-1.11.89-2 2-2 1.11 0 2 .89 2 2h3c.55 0 1 .45 1 1v5h-1V6H1v9h10v-2zM2 5h8c0-.55-.45-1-1-1H8c-.55 0-1-.45-1-1s-.45-1-1-1-1 .45-1 1-.45 1-1 1H3c-.55 0-1 .45-1 1z"})),te=function(e){function t(e){var r;return a()(this,t),(r=u()(this,f()(t).call(this,e))).state={previewEnabled:J.previewEnabled,previewUrl:J.previewUrl,hasCopied:!1},r.previewUrlInput=Object(H.createRef)(),r.onChange=r.onChange.bind(h()(r)),r.onPreviewUrlInputFocus=r.onPreviewUrlInputFocus.bind(h()(r)),r}return b()(t,e),o()(t,[{key:"onChange",value:function(e){var t=this,r=new window.FormData;r.append("checked",e),r.append("post_ID",this.props.postId),this.sendRequest(r).then(function(e){if(e.status>=200&&e.status<300)return e;throw e}).then(function(e){return e.json()}).then(function(e){if(!e.success)throw e;var r=!t.state.previewEnabled;t.setState({previewEnabled:r}),t.props.createNotice("info",r?Object(T.__)("Public preview enabled.","public-post-preview"):Object(T.__)("Public preview disabled.","public-post-preview"),{id:"public-post-preview",isDismissible:!0,type:"snackbar"})}).catch(function(){t.props.createNotice("error",Object(T.__)("Error while changing the public preview status.","public-post-preview"),{id:"public-post-preview",isDismissible:!0,type:"snackbar"})})}},{key:"onPreviewUrlInputFocus",value:function(){this.previewUrlInput.current.focus(),this.previewUrlInput.current.select()}},{key:"sendRequest",value:function(e){return e.append("action","public-post-preview"),e.append("_ajax_nonce",J.nonce),window.fetch(Z,{method:"POST",body:e})}},{key:"render",value:function(){var e=this,t=this.state,r=t.previewEnabled,n=t.previewUrl,i=t.hasCopied,a=i?Object(T.__)("Preview URL copied","public-post-preview"):Object(T.__)("Copy the preview URL","public-post-preview");return Object(H.createElement)(H.Fragment,null,Object(H.createElement)(q.PluginPostStatusInfo,null,Object(H.createElement)(V.CheckboxControl,{label:Object(T.__)("Enable public preview","public-post-preview"),checked:r,onChange:this.onChange})),r&&Object(H.createElement)(q.PluginPostStatusInfo,{className:K},Object(H.createElement)("p",{className:Y},Object(H.createElement)("label",{htmlFor:"public-post-preview-url",className:"screen-reader-text"},Object(T.__)("Preview URL","public-post-preview")),Object(H.createElement)("input",{ref:this.previewUrlInput,type:"text",id:"public-post-preview-url",className:Q,value:n,readOnly:!0,onFocus:this.onPreviewUrlInputFocus}),Object(H.createElement)(V.ClipboardButton,{text:n,label:a,onCopy:function(){return e.setState({hasCopied:!0})},onFinishCopy:function(){return e.setState({hasCopied:!1})},"aria-disabled":i,icon:ee})),Object(H.createElement)("p",{className:X},Object(T.__)("Copy and share this preview URL.","public-post-preview"))))}}]),t}(H.Component),re=Object(W.compose)([Object(L.withSelect)(function(e){var t=e("core").getPostType,r=e("core/editor"),n=r.getCurrentPostId,i=r.getEditedPostAttribute,a=t(i("type"));return{postId:n(),status:i("status"),isViewable:Object(D.get)(a,["viewable"],!1)}}),Object(W.ifCondition)(function(e){return e.isViewable}),Object(W.ifCondition)(function(e){var t=e.status;return-1===["auto-draft","publish","private"].indexOf(t)}),Object(L.withDispatch)(function(e){return{createNotice:e("core/notices").createNotice}})])(te);Object(n.registerPlugin)("public-post-preview",{render:re})}]);
js/public-post-preview.js CHANGED
@@ -47,9 +47,8 @@
47
  post_ID : $( '#post_ID' ).val()
48
  },
49
  function( data ) {
50
- // data is '1' if it's a successful request
51
- if ( data ) {
52
- if ( checked ) {
53
  t.status.text( DSPublicPostPreviewL10n.enabled );
54
  t._pulsate( t.status, 'green' );
55
  } else {
47
  post_ID : $( '#post_ID' ).val()
48
  },
49
  function( data ) {
50
+ if ( data.success ) {
51
+ if ( 'true' === checked ) {
 
52
  t.status.text( DSPublicPostPreviewL10n.enabled );
53
  t._pulsate( t.status, 'green' );
54
  } else {
js/public-post-preview.min.js CHANGED
@@ -1 +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");b.status=a("#public-post-preview-ajax");b.status.css("opacity",0);b.checkbox.bind("change",function(){b.change();});b.link.find("input").on("focus",function(){a(this).select();});},change:function(){var b=this,c=b.checkbox.prop("checked")?"true":"false";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);
1
+ !function(e){DSPublicPostPreview={initialize:function(){var t=this;t.checkbox=e("#public-post-preview"),t.link=e("#public-post-preview-link"),t.nonce=e("#public_post_preview_wpnonce"),t.status=e("#public-post-preview-ajax"),t.status.css("opacity",0),t.checkbox.bind("change",function(){t.change()}),t.link.find("input").on("focus",function(){e(this).select()})},change:function(){var t=this,i=t.checkbox.prop("checked")?"true":"false";t.link.toggle(),t.checkbox.prop("disabled","disabled"),t.request({_ajax_nonce:t.nonce.val(),checked:i,post_ID:e("#post_ID").val()},function(e){e.success&&("true"===i?(t.status.text(DSPublicPostPreviewL10n.enabled),t._pulsate(t.status,"green")):(t.status.text(DSPublicPostPreviewL10n.disabled),t._pulsate(t.status,"red"))),t.checkbox.prop("disabled","")})},request:function(t,i){e.ajax({type:"POST",url:ajaxurl,data:e.extend(t,{action:"public-post-preview"}),success:i})},_pulsate:function(e,t){e.css("color",t).animate({opacity:1},600,"linear").animate({opacity:0},600,"linear",function(){e.empty()})}},e(DSPublicPostPreview.initialize())}(jQuery);
js/src/components/preview-toggle/index.js CHANGED
@@ -14,9 +14,8 @@ import {
14
  import {
15
  Component,
16
  createRef,
17
- Fragment,
18
  } from '@wordpress/element';
19
- import { withSelect } from '@wordpress/data';
20
  import { PluginPostStatusInfo } from '@wordpress/edit-post';
21
  import { ifCondition, compose } from '@wordpress/compose';
22
 
@@ -49,6 +48,8 @@ const pluginPostStatusInfoPreviewUrlInputWrapper = css`
49
  margin: 0;
50
  `
51
 
 
 
52
  class PreviewToggle extends Component {
53
 
54
  constructor( props ) {
@@ -67,12 +68,48 @@ class PreviewToggle extends Component {
67
  }
68
 
69
  onChange( checked ) {
70
- this.request( {
71
- checked,
72
- post_ID: this.props.postId
73
- }, () => {
74
- this.setState( { previewEnabled: ! this.state.previewEnabled } );
75
- } )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
  }
77
 
78
  onPreviewUrlInputFocus() {
@@ -80,16 +117,12 @@ class PreviewToggle extends Component {
80
  this.previewUrlInput.current.select();
81
  }
82
 
83
- request( data, callback ) {
84
- jQuery.ajax( {
85
- type: 'POST',
86
- url: ajaxurl,
87
- data: {
88
- action: 'public-post-preview',
89
- _ajax_nonce: DSPublicPostPreviewData.nonce,
90
- ...data
91
- },
92
- success: callback,
93
  } );
94
  }
95
 
@@ -103,7 +136,7 @@ class PreviewToggle extends Component {
103
  const ariaCopyLabel = hasCopied ? __( 'Preview URL copied', 'public-post-preview' ) : __( 'Copy the preview URL', 'public-post-preview' );
104
 
105
  return (
106
- <Fragment>
107
  <PluginPostStatusInfo>
108
  <CheckboxControl
109
  label={ __( 'Enable public preview', 'public-post-preview' ) }
@@ -130,7 +163,7 @@ class PreviewToggle extends Component {
130
  onCopy={ () => this.setState( { hasCopied: true } ) }
131
  onFinishCopy={ () => this.setState( { hasCopied: false } ) }
132
  aria-disabled={ hasCopied }
133
- icon={ <SVG width="20" height="20" viewBox="0 0 14 16" xmlns="http://www.w3.org/2000/svg" focusable="false" ><Path fillRule="evenodd" d="M2 13h4v1H2v-1zm5-6H2v1h5V7zm2 3V8l-3 3 3 3v-2h5v-2H9zM4.5 9H2v1h2.5V9zM2 12h2.5v-1H2v1zm9 1h1v2c-.02.28-.11.52-.3.7-.19.18-.42.28-.7.3H1c-.55 0-1-.45-1-1V4c0-.55.45-1 1-1h3c0-1.11.89-2 2-2 1.11 0 2 .89 2 2h3c.55 0 1 .45 1 1v5h-1V6H1v9h10v-2zM2 5h8c0-.55-.45-1-1-1H8c-.55 0-1-.45-1-1s-.45-1-1-1-1 .45-1 1-.45 1-1 1H3c-.55 0-1 .45-1 1z"/></SVG> }
134
  />
135
  </p>
136
  <p className={ pluginPostStatusInfoPreviewDescription }>
@@ -138,7 +171,7 @@ class PreviewToggle extends Component {
138
  </p>
139
  </PluginPostStatusInfo>
140
  }
141
- </Fragment>
142
  );
143
  }
144
  }
@@ -168,4 +201,9 @@ export default compose( [
168
  'private',
169
  ].indexOf( status ) === -1;
170
  } ),
 
 
 
 
 
171
  ] )( PreviewToggle );
14
  import {
15
  Component,
16
  createRef,
 
17
  } from '@wordpress/element';
18
+ import { withSelect, withDispatch } from '@wordpress/data';
19
  import { PluginPostStatusInfo } from '@wordpress/edit-post';
20
  import { ifCondition, compose } from '@wordpress/compose';
21
 
48
  margin: 0;
49
  `
50
 
51
+ const ClipboardIcon = <SVG width="20" height="20" viewBox="0 0 14 16" xmlns="http://www.w3.org/2000/svg"><Path fillRule="evenodd" d="M2 13h4v1H2v-1zm5-6H2v1h5V7zm2 3V8l-3 3 3 3v-2h5v-2H9zM4.5 9H2v1h2.5V9zM2 12h2.5v-1H2v1zm9 1h1v2c-.02.28-.11.52-.3.7-.19.18-.42.28-.7.3H1c-.55 0-1-.45-1-1V4c0-.55.45-1 1-1h3c0-1.11.89-2 2-2 1.11 0 2 .89 2 2h3c.55 0 1 .45 1 1v5h-1V6H1v9h10v-2zM2 5h8c0-.55-.45-1-1-1H8c-.55 0-1-.45-1-1s-.45-1-1-1-1 .45-1 1-.45 1-1 1H3c-.55 0-1 .45-1 1z"/></SVG>
52
+
53
  class PreviewToggle extends Component {
54
 
55
  constructor( props ) {
68
  }
69
 
70
  onChange( checked ) {
71
+ const data = new window.FormData();
72
+ data.append( 'checked', checked );
73
+ data.append( 'post_ID', this.props.postId );
74
+
75
+ this.sendRequest( data)
76
+ .then( ( response ) => {
77
+ if ( response.status >= 200 && response.status < 300 ) {
78
+ return response;
79
+ }
80
+
81
+ throw response;
82
+ } )
83
+ .then( ( response ) => response.json() )
84
+ .then( ( response ) => {
85
+ if ( ! response.success ) {
86
+ throw response;
87
+ }
88
+
89
+ const previewEnabled = ! this.state.previewEnabled;
90
+ this.setState( { previewEnabled: previewEnabled } );
91
+
92
+ this.props.createNotice(
93
+ 'info',
94
+ previewEnabled ? __( 'Public preview enabled.', 'public-post-preview' ) : __( 'Public preview disabled.', 'public-post-preview' ),
95
+ {
96
+ id: 'public-post-preview',
97
+ isDismissible: true,
98
+ type: 'snackbar'
99
+ }
100
+ );
101
+ } )
102
+ .catch( () => {
103
+ this.props.createNotice(
104
+ 'error',
105
+ __( 'Error while changing the public preview status.', 'public-post-preview' ),
106
+ {
107
+ id: 'public-post-preview',
108
+ isDismissible: true,
109
+ type: 'snackbar'
110
+ }
111
+ );
112
+ } );
113
  }
114
 
115
  onPreviewUrlInputFocus() {
117
  this.previewUrlInput.current.select();
118
  }
119
 
120
+ sendRequest( data ) {
121
+ data.append( 'action', 'public-post-preview' );
122
+ data.append( '_ajax_nonce', DSPublicPostPreviewData.nonce );
123
+ return window.fetch( ajaxurl, {
124
+ method: 'POST',
125
+ body: data,
 
 
 
 
126
  } );
127
  }
128
 
136
  const ariaCopyLabel = hasCopied ? __( 'Preview URL copied', 'public-post-preview' ) : __( 'Copy the preview URL', 'public-post-preview' );
137
 
138
  return (
139
+ <>
140
  <PluginPostStatusInfo>
141
  <CheckboxControl
142
  label={ __( 'Enable public preview', 'public-post-preview' ) }
163
  onCopy={ () => this.setState( { hasCopied: true } ) }
164
  onFinishCopy={ () => this.setState( { hasCopied: false } ) }
165
  aria-disabled={ hasCopied }
166
+ icon={ ClipboardIcon }
167
  />
168
  </p>
169
  <p className={ pluginPostStatusInfoPreviewDescription }>
171
  </p>
172
  </PluginPostStatusInfo>
173
  }
174
+ </>
175
  );
176
  }
177
  }
201
  'private',
202
  ].indexOf( status ) === -1;
203
  } ),
204
+ withDispatch( ( dispatch ) => {
205
+ return {
206
+ createNotice: dispatch( 'core/notices' ).createNotice
207
+ };
208
+ } ),
209
  ] )( PreviewToggle );
languages/public-post-preview.php DELETED
@@ -1,19 +0,0 @@
1
- <?php
2
- /* THIS IS A GENERATED FILE. DO NOT EDIT DIRECTLY. */
3
- $generated_i18n_strings = array(
4
- // Reference: js/src/components/preview-toggle/index.js:103
5
- __( 'Preview URL copied', 'public-post-preview' ),
6
-
7
- // Reference: js/src/components/preview-toggle/index.js:103
8
- __( 'Copy the preview URL', 'public-post-preview' ),
9
-
10
- // Reference: js/src/components/preview-toggle/index.js:109
11
- __( 'Enable public preview', 'public-post-preview' ),
12
-
13
- // Reference: js/src/components/preview-toggle/index.js:117
14
- __( 'Preview URL', 'public-post-preview' ),
15
-
16
- // Reference: js/src/components/preview-toggle/index.js:137
17
- __( 'Copy and share this preview URL.', 'public-post-preview' )
18
- );
19
- /* THIS IS THE END OF THE GENERATED FILE */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
languages/public-post-preview.pot DELETED
@@ -1,24 +0,0 @@
1
- msgid ""
2
- msgstr ""
3
- "Content-Type: text/plain; charset=utf-8\n"
4
- "X-Generator: babel-plugin-makepot\n"
5
-
6
- #: js/src/components/preview-toggle/index.js:103
7
- msgid "Preview URL copied"
8
- msgstr ""
9
-
10
- #: js/src/components/preview-toggle/index.js:103
11
- msgid "Copy the preview URL"
12
- msgstr ""
13
-
14
- #: js/src/components/preview-toggle/index.js:109
15
- msgid "Enable public preview"
16
- msgstr ""
17
-
18
- #: js/src/components/preview-toggle/index.js:117
19
- msgid "Preview URL"
20
- msgstr ""
21
-
22
- #: js/src/components/preview-toggle/index.js:137
23
- msgid "Copy and share this preview URL."
24
- msgstr ""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
public-post-preview.php CHANGED
@@ -1,17 +1,17 @@
1
  <?php
2
  /**
3
  * Plugin Name: Public Post Preview
4
- * Version: 2.8.0
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: https://wphelper.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.
13
  *
14
- * Copyright (C) 2012-2018 Dominik Schilling
15
  *
16
  * This program is free software; you can redistribute it and/or
17
  * modify it under the terms of the GNU General Public License
@@ -83,30 +83,23 @@ class DS_Public_Post_Preview {
83
  * @param string $hook_suffix Unique page identifier.
84
  */
85
  public static function enqueue_script( $hook_suffix ) {
86
- if ( ! in_array( $hook_suffix, array( 'post.php', 'post-new.php' ) ) ) {
87
  return;
88
  }
89
 
90
- if (
91
- ( method_exists( get_current_screen(), 'is_block_editor' ) && get_current_screen()->is_block_editor() ) ||
92
- ( function_exists( 'is_gutenberg_page' ) && is_gutenberg_page() )
93
- ) {
94
  wp_enqueue_script(
95
  'public-post-preview-gutenberg',
96
  plugins_url( 'js/gutenberg-integration.js', __FILE__ ),
97
- array(
98
- 'lodash',
99
- 'wp-compose',
100
- 'wp-components',
101
- 'wp-data',
102
- 'wp-edit-post',
103
- 'wp-element',
104
- 'wp-i18n',
105
- ),
106
- '20181127',
107
  true
108
  );
109
 
 
 
110
  $post = get_post();
111
  wp_localize_script(
112
  'public-post-preview-gutenberg',
@@ -117,15 +110,6 @@ class DS_Public_Post_Preview {
117
  'nonce' => wp_create_nonce( 'public-post-preview_' . $post->ID ),
118
  )
119
  );
120
-
121
- if ( function_exists( 'gutenberg_get_jed_locale_data' ) ) {
122
- $locale_data = gutenberg_get_jed_locale_data( 'public-post-preview' );
123
- wp_add_inline_script(
124
- 'public-post-preview-gutenberg',
125
- 'wp.i18n.setLocaleData( ' . wp_json_encode( $locale_data ) . ', "public-post-preview" );',
126
- 'before'
127
- );
128
- }
129
  } else {
130
  $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
131
 
@@ -133,7 +117,7 @@ class DS_Public_Post_Preview {
133
  'public-post-preview',
134
  plugins_url( "js/public-post-preview$suffix.js", __FILE__ ),
135
  array( 'jquery' ),
136
- '20180914',
137
  true
138
  );
139
 
@@ -155,10 +139,10 @@ class DS_Public_Post_Preview {
155
  *
156
  * @param array $post_states An array of post display states.
157
  * @param WP_Post $post The current post object.
158
- * @return Filtered array of post display states.
159
  */
160
  public static function display_preview_state( $post_states, $post ) {
161
- if ( in_array( $post->ID, self::get_preview_post_ids() ) ) {
162
  $post_states['ppp_enabled'] = __( 'Public Preview', 'public-post-preview' );
163
  }
164
 
@@ -166,7 +150,7 @@ class DS_Public_Post_Preview {
166
  }
167
 
168
  /**
169
- * Adds the checkbox to the submit metabox.
170
  *
171
  * @since 2.2.0
172
  */
@@ -179,7 +163,7 @@ class DS_Public_Post_Preview {
179
 
180
  $post = get_post();
181
 
182
- if ( ! in_array( $post->post_type, $post_types ) ) {
183
  return false;
184
  }
185
 
@@ -189,7 +173,7 @@ class DS_Public_Post_Preview {
189
  }
190
 
191
  // Post is already published.
192
- if ( in_array( $post->post_status, self::get_published_statuses() ) ) {
193
  return false;
194
  }
195
 
@@ -269,11 +253,11 @@ class DS_Public_Post_Preview {
269
  * @return string The generated public preview link.
270
  */
271
  public static function get_preview_link( $post ) {
272
- if ( 'page' == $post->post_type ) {
273
  $args = array(
274
  'page_id' => $post->ID,
275
  );
276
- } elseif ( 'post' == $post->post_type ) {
277
  $args = array(
278
  'p' => $post->ID,
279
  );
@@ -317,18 +301,18 @@ class DS_Public_Post_Preview {
317
  }
318
 
319
  $preview_post_ids = self::get_preview_post_ids();
320
- $preview_post_id = $post->ID;
321
 
322
- if ( empty( $_POST['public_post_preview'] ) && in_array( $preview_post_id, $preview_post_ids ) ) {
323
  $preview_post_ids = array_diff( $preview_post_ids, (array) $preview_post_id );
324
  } elseif (
325
  ! empty( $_POST['public_post_preview'] ) &&
326
  ! empty( $_POST['original_post_status'] ) &&
327
- ! in_array( $_POST['original_post_status'], self::get_published_statuses() ) &&
328
- in_array( $post->post_status, self::get_published_statuses() )
329
  ) {
330
  $preview_post_ids = array_diff( $preview_post_ids, (array) $preview_post_id );
331
- } elseif ( ! empty( $_POST['public_post_preview'] ) && ! in_array( $preview_post_id, $preview_post_ids ) ) {
332
  $preview_post_ids = array_merge( $preview_post_ids, (array) $preview_post_id );
333
  } else {
334
  return false; // Nothing has changed.
@@ -352,7 +336,7 @@ class DS_Public_Post_Preview {
352
  $disallowed_status = self::get_published_statuses();
353
  $disallowed_status[] = 'trash';
354
 
355
- if ( in_array( $new_status, $disallowed_status ) ) {
356
  return self::unregister_public_preview( $post->ID );
357
  }
358
 
@@ -372,7 +356,7 @@ class DS_Public_Post_Preview {
372
  $disallowed_status = self::get_published_statuses();
373
  $disallowed_status[] = 'trash';
374
 
375
- if ( in_array( $post->post_status, $disallowed_status ) ) {
376
  return self::unregister_public_preview( $post_id );
377
  }
378
 
@@ -388,9 +372,10 @@ class DS_Public_Post_Preview {
388
  * @return bool Returns false on a failure, true on a success.
389
  */
390
  private static function unregister_public_preview( $post_id ) {
 
391
  $preview_post_ids = self::get_preview_post_ids();
392
 
393
- if ( ! in_array( $post_id, $preview_post_ids ) ) {
394
  return false;
395
  }
396
 
@@ -402,8 +387,6 @@ class DS_Public_Post_Preview {
402
  /**
403
  * (Un)Registers a post for a public preview for an AJAX request.
404
  *
405
- * Returns '0' on a failure, '1' on success.
406
- *
407
  * @since 2.0.0
408
  */
409
  public static function ajax_register_public_preview() {
@@ -417,15 +400,15 @@ class DS_Public_Post_Preview {
417
  wp_send_json_error( 'cannot_edit' );
418
  }
419
 
420
- if ( in_array( $post->post_status, self::get_published_statuses() ) ) {
421
  wp_send_json_error( 'invalid_post_status' );
422
  }
423
 
424
  $preview_post_ids = self::get_preview_post_ids();
425
 
426
- if ( 'false' === $_POST['checked'] && in_array( $preview_post_id, $preview_post_ids ) ) {
427
  $preview_post_ids = array_diff( $preview_post_ids, (array) $preview_post_id );
428
- } elseif ( 'true' === $_POST['checked'] && ! in_array( $preview_post_id, $preview_post_ids ) ) {
429
  $preview_post_ids = array_merge( $preview_post_ids, (array) $preview_post_id );
430
  } else {
431
  wp_send_json_error( 'unknown_status' );
@@ -498,10 +481,10 @@ class DS_Public_Post_Preview {
498
  }
499
 
500
  if ( ! self::verify_nonce( get_query_var( '_ppp' ), 'public_post_preview_' . $post_id ) ) {
501
- wp_die( __( 'The link has been expired!', 'public-post-preview' ) );
502
  }
503
 
504
- if ( ! in_array( $post_id, self::get_preview_post_ids() ) ) {
505
  wp_die( __( 'No public preview available!', 'public-post-preview' ) );
506
  }
507
 
@@ -544,10 +527,10 @@ class DS_Public_Post_Preview {
544
  remove_filter( 'posts_results', array( __CLASS__, 'set_post_to_publish' ), 10 );
545
 
546
  if ( empty( $posts ) ) {
547
- return;
548
  }
549
 
550
- $post_id = $posts[0]->ID;
551
 
552
  // If the post has gone live, redirect to it's proper permalink.
553
  self::maybe_redirect_to_published_post( $post_id );
@@ -574,11 +557,11 @@ class DS_Public_Post_Preview {
574
  * @return false False of post status is not a published status.
575
  */
576
  private static function maybe_redirect_to_published_post( $post_id ) {
577
- if ( ! in_array( get_post_status( $post_id ), self::get_published_statuses() ) ) {
578
  return false;
579
  }
580
 
581
- wp_redirect( get_permalink( $post_id ), 301 );
582
  exit;
583
  }
584
 
@@ -628,12 +611,12 @@ class DS_Public_Post_Preview {
628
  $i = self::nonce_tick();
629
 
630
  // Nonce generated 0-12 hours ago.
631
- if ( substr( wp_hash( $i . $action, 'nonce' ), -12, 10 ) == $nonce ) {
632
  return 1;
633
  }
634
 
635
  // Nonce generated 12-24 hours ago.
636
- if ( substr( wp_hash( ( $i - 1 ) . $action, 'nonce' ), -12, 10 ) == $nonce ) {
637
  return 2;
638
  }
639
 
@@ -642,25 +625,32 @@ class DS_Public_Post_Preview {
642
  }
643
 
644
  /**
645
- * Returns the post ids which are registered for a public preview.
646
  *
647
  * @since 2.0.0
648
  *
649
- * @return array The post ids. (Empty array if no ids are registered.)
650
  */
651
  private static function get_preview_post_ids() {
652
- return get_option( 'public_post_preview', array() );
 
 
 
653
  }
654
 
655
  /**
656
- * Saves the post ids which are registered for a public preview.
657
  *
658
  * @since 2.0.0
659
  *
660
  * @param array $post_ids List of post IDs that have a preview.
661
- * @return array The post ids. (Empty array if no ids are registered.)
662
  */
663
  private static function set_preview_post_ids( $post_ids = array() ) {
 
 
 
 
664
  return update_option( 'public_post_preview', $post_ids );
665
  }
666
 
1
  <?php
2
  /**
3
  * Plugin Name: Public Post Preview
4
+ * Version: 2.9.0
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.
13
  *
14
+ * Copyright (C) 2012-2019 Dominik Schilling
15
  *
16
  * This program is free software; you can redistribute it and/or
17
  * modify it under the terms of the GNU General Public License
83
  * @param string $hook_suffix Unique page identifier.
84
  */
85
  public static function enqueue_script( $hook_suffix ) {
86
+ if ( ! in_array( $hook_suffix, array( 'post.php', 'post-new.php' ), true ) ) {
87
  return;
88
  }
89
 
90
+ if ( get_current_screen()->is_block_editor() ) {
91
+ $script_dependencies_path = plugin_dir_path( __FILE__ ) . 'js/gutenberg-integration.deps.json';
92
+ $script_dependencies = file_exists( $script_dependencies_path ) ? json_decode( file_get_contents( $script_dependencies_path ) ) : array();
 
93
  wp_enqueue_script(
94
  'public-post-preview-gutenberg',
95
  plugins_url( 'js/gutenberg-integration.js', __FILE__ ),
96
+ $script_dependencies,
97
+ '20190720',
 
 
 
 
 
 
 
 
98
  true
99
  );
100
 
101
+ wp_set_script_translations( 'public-post-preview-gutenberg', 'public-post-preview' );
102
+
103
  $post = get_post();
104
  wp_localize_script(
105
  'public-post-preview-gutenberg',
110
  'nonce' => wp_create_nonce( 'public-post-preview_' . $post->ID ),
111
  )
112
  );
 
 
 
 
 
 
 
 
 
113
  } else {
114
  $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
115
 
117
  'public-post-preview',
118
  plugins_url( "js/public-post-preview$suffix.js", __FILE__ ),
119
  array( 'jquery' ),
120
+ '20190713',
121
  true
122
  );
123
 
139
  *
140
  * @param array $post_states An array of post display states.
141
  * @param WP_Post $post The current post object.
142
+ * @return array Filtered array of post display states.
143
  */
144
  public static function display_preview_state( $post_states, $post ) {
145
+ if ( in_array( (int) $post->ID, self::get_preview_post_ids(), true ) ) {
146
  $post_states['ppp_enabled'] = __( 'Public Preview', 'public-post-preview' );
147
  }
148
 
150
  }
151
 
152
  /**
153
+ * Adds the checkbox to the submit meta box.
154
  *
155
  * @since 2.2.0
156
  */
163
 
164
  $post = get_post();
165
 
166
+ if ( ! in_array( $post->post_type, $post_types, true ) ) {
167
  return false;
168
  }
169
 
173
  }
174
 
175
  // Post is already published.
176
+ if ( in_array( $post->post_status, self::get_published_statuses(), true ) ) {
177
  return false;
178
  }
179
 
253
  * @return string The generated public preview link.
254
  */
255
  public static function get_preview_link( $post ) {
256
+ if ( 'page' === $post->post_type ) {
257
  $args = array(
258
  'page_id' => $post->ID,
259
  );
260
+ } elseif ( 'post' === $post->post_type ) {
261
  $args = array(
262
  'p' => $post->ID,
263
  );
301
  }
302
 
303
  $preview_post_ids = self::get_preview_post_ids();
304
+ $preview_post_id = (int) $post->ID;
305
 
306
+ if ( empty( $_POST['public_post_preview'] ) && in_array( $preview_post_id, $preview_post_ids, true ) ) {
307
  $preview_post_ids = array_diff( $preview_post_ids, (array) $preview_post_id );
308
  } elseif (
309
  ! empty( $_POST['public_post_preview'] ) &&
310
  ! empty( $_POST['original_post_status'] ) &&
311
+ ! in_array( $_POST['original_post_status'], self::get_published_statuses(), true ) &&
312
+ in_array( $post->post_status, self::get_published_statuses(), true )
313
  ) {
314
  $preview_post_ids = array_diff( $preview_post_ids, (array) $preview_post_id );
315
+ } elseif ( ! empty( $_POST['public_post_preview'] ) && ! in_array( $preview_post_id, $preview_post_ids, true ) ) {
316
  $preview_post_ids = array_merge( $preview_post_ids, (array) $preview_post_id );
317
  } else {
318
  return false; // Nothing has changed.
336
  $disallowed_status = self::get_published_statuses();
337
  $disallowed_status[] = 'trash';
338
 
339
+ if ( in_array( $new_status, $disallowed_status, true ) ) {
340
  return self::unregister_public_preview( $post->ID );
341
  }
342
 
356
  $disallowed_status = self::get_published_statuses();
357
  $disallowed_status[] = 'trash';
358
 
359
+ if ( in_array( $post->post_status, $disallowed_status, true ) ) {
360
  return self::unregister_public_preview( $post_id );
361
  }
362
 
372
  * @return bool Returns false on a failure, true on a success.
373
  */
374
  private static function unregister_public_preview( $post_id ) {
375
+ $post_id = (int) $post_id;
376
  $preview_post_ids = self::get_preview_post_ids();
377
 
378
+ if ( ! in_array( $post_id, $preview_post_ids, true ) ) {
379
  return false;
380
  }
381
 
387
  /**
388
  * (Un)Registers a post for a public preview for an AJAX request.
389
  *
 
 
390
  * @since 2.0.0
391
  */
392
  public static function ajax_register_public_preview() {
400
  wp_send_json_error( 'cannot_edit' );
401
  }
402
 
403
+ if ( in_array( $post->post_status, self::get_published_statuses(), true ) ) {
404
  wp_send_json_error( 'invalid_post_status' );
405
  }
406
 
407
  $preview_post_ids = self::get_preview_post_ids();
408
 
409
+ if ( 'false' === $_POST['checked'] && in_array( $preview_post_id, $preview_post_ids, true ) ) {
410
  $preview_post_ids = array_diff( $preview_post_ids, (array) $preview_post_id );
411
+ } elseif ( 'true' === $_POST['checked'] && ! in_array( $preview_post_id, $preview_post_ids, true ) ) {
412
  $preview_post_ids = array_merge( $preview_post_ids, (array) $preview_post_id );
413
  } else {
414
  wp_send_json_error( 'unknown_status' );
481
  }
482
 
483
  if ( ! self::verify_nonce( get_query_var( '_ppp' ), 'public_post_preview_' . $post_id ) ) {
484
+ wp_die( __( 'This link has expired!', 'public-post-preview' ) );
485
  }
486
 
487
+ if ( ! in_array( $post_id, self::get_preview_post_ids(), true ) ) {
488
  wp_die( __( 'No public preview available!', 'public-post-preview' ) );
489
  }
490
 
527
  remove_filter( 'posts_results', array( __CLASS__, 'set_post_to_publish' ), 10 );
528
 
529
  if ( empty( $posts ) ) {
530
+ return $posts;
531
  }
532
 
533
+ $post_id = (int) $posts[0]->ID;
534
 
535
  // If the post has gone live, redirect to it's proper permalink.
536
  self::maybe_redirect_to_published_post( $post_id );
557
  * @return false False of post status is not a published status.
558
  */
559
  private static function maybe_redirect_to_published_post( $post_id ) {
560
+ if ( ! in_array( get_post_status( $post_id ), self::get_published_statuses(), true ) ) {
561
  return false;
562
  }
563
 
564
+ wp_safe_redirect( get_permalink( $post_id ), 301 );
565
  exit;
566
  }
567
 
611
  $i = self::nonce_tick();
612
 
613
  // Nonce generated 0-12 hours ago.
614
+ if ( substr( wp_hash( $i . $action, 'nonce' ), -12, 10 ) === $nonce ) {
615
  return 1;
616
  }
617
 
618
  // Nonce generated 12-24 hours ago.
619
+ if ( substr( wp_hash( ( $i - 1 ) . $action, 'nonce' ), -12, 10 ) === $nonce ) {
620
  return 2;
621
  }
622
 
625
  }
626
 
627
  /**
628
+ * Returns the post IDs which are registered for a public preview.
629
  *
630
  * @since 2.0.0
631
  *
632
+ * @return array The post IDs. (Empty array if no IDs are registered.)
633
  */
634
  private static function get_preview_post_ids() {
635
+ $post_ids = get_option( 'public_post_preview', array() );
636
+ $post_ids = array_map( 'intval', $post_ids );
637
+
638
+ return $post_ids;
639
  }
640
 
641
  /**
642
+ * Saves the post IDs which are registered for a public preview.
643
  *
644
  * @since 2.0.0
645
  *
646
  * @param array $post_ids List of post IDs that have a preview.
647
+ * @return array The post IDs. (Empty array if no IDs are registered.)
648
  */
649
  private static function set_preview_post_ids( $post_ids = array() ) {
650
+ $post_ids = array_map( 'absint', $post_ids );
651
+ $post_ids = array_filter( $post_ids );
652
+ $post_ids = array_unique( $post_ids );
653
+
654
  return update_option( 'public_post_preview', $post_ids );
655
  }
656
 
readme.txt CHANGED
@@ -1,19 +1,20 @@
1
  === Public Post Preview ===
2
  Contributors: ocean90
3
- Tags: public, post, preview, posts, custom post types, draft
4
- Requires at least: 4.6
5
- Tested up to: 5.0
6
- Stable tag: 2.8.0
 
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
10
- Enables you to give a link to anonymous users for public preview of a post before it is published.
11
 
12
  == Description ==
13
 
14
- Enables you to give a link to anonymous users for public preview of a post (or any other public post type) before it is published.
15
 
16
- Have you ever been writing a post with the help of someone who does not have access to your blog and needed to give them the ability to preview it before publishing? This plugin takes care of that by generating an URL with an expiring nonce that can be given out for public preview.
17
 
18
  *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/). Thanks to Hans Dinkelberg for his [photo](http://www.flickr.com/photos/uitdragerij/7516234430/).*
19
 
@@ -40,8 +41,7 @@ To upload the plugin through WordPress, instead of FTP:
40
 
41
  == Screenshots ==
42
 
43
- 1. Setting in block editor
44
- 2. Setting in classic editor
45
 
46
  == Usage ==
47
  * To enable a public post preview check the box below the edit post box.
@@ -73,6 +73,15 @@ Or use the [Public Post Preview Configurator](https://wordpress.org/plugins/publ
73
 
74
  == Change Log ==
75
 
 
 
 
 
 
 
 
 
 
76
  = 2.8.0 (2018-11-27): =
77
  * Add support for WordPress 5.0 and the new block editor.
78
 
@@ -80,59 +89,4 @@ Or use the [Public Post Preview Configurator](https://wordpress.org/plugins/publ
80
  * Initial support for Gutenberg.
81
  * Block robots for public post previews. Props [@westonruter](https://github.com/westonruter).
82
 
83
- = 2.6.0 (2017-04-27): =
84
- * Make `DS_Public_Post_Preview::get_preview_link()` public. Props [@rcstr](https://github.com/rcstr).
85
- * Send no-cache headers for public post previews.
86
-
87
- = 2.5.0 (2016-04-05): =
88
- * Auto select preview link on focus. Props [@JeroenSormani](https://github.com/JeroenSormani).
89
- * Remove preview status from posts which are trashed or after scheduled posts are published.
90
- * Add support for paged posts.
91
-
92
- = 2.4.1 (2015-10-13): =
93
- * Update text domain to support language packs. Translations are now managed via http://translate.wordpress.org/projects/wp-plugins/public-post-preview.
94
-
95
- = 2.4 (2014-08-21): =
96
- * Supports EditFlow and custom statuses
97
- * Disables comments and pings during public post preview
98
- * Adds **Public Preview** to the list of display states used in the Posts list table
99
- * Prevents flickering of link box on Post edit while loading
100
-
101
- = 2.3 (2013-11-18): =
102
- * Introduces a filter `ppp_preview_link`. With the filter you can adjust the preview link.
103
- * If a post has gone live, redirect to it's proper permalink.
104
- * Adds the query var `_ppp` to WordPress SEO by Yoast whitelist.
105
-
106
- = 2.2 (2013-03-15): =
107
- * Based on feedback I have removed the extra metabox and added the preview link to the main Publish metabox.
108
- * Only show the checkbox if the post status/post type is good.
109
- * Requires WordPress 3.5.
110
-
111
- = 2.1.1 (2012-09-19): =
112
- * 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.
113
-
114
- = 2.1 (2012-09-16): =
115
- * 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.
116
- * 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.
117
-
118
- = 2.0.1 (2012-07-25): =
119
- * Makes the preview link copyable again
120
-
121
- = 2.0 (2012-07-23): =
122
- * Support for all public post types
123
- * Saves public preview status via an AJAX request
124
- * I18n
125
- * Requires at least WordPress 3.3
126
-
127
- = 1.3 (2009-06-30): =
128
- * Hook in earlier in the post selection process to fix PHP notices
129
- * Add uninstall functionality to remove options from the options table
130
-
131
- = 1.2 (2009-03-30): =
132
- * Fix preview URL for scheduled posts on sites with a permalink other than default activated.
133
-
134
- = 1.1 (2009-03-11): =
135
- * Don't limit public previews to posts in draft or pending status. Just exclude posts in publish status.
136
-
137
- = 1.0 (2009-02-20): =
138
- * Initial Public Release
1
  === Public Post Preview ===
2
  Contributors: ocean90
3
+ Tags: public, preview, posts, anonymous, drafts
4
+ Requires at least: 5.0
5
+ Tested up to: 5.2
6
+ Requires PHP: 5.6
7
+ Stable tag: 2.9.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
11
+ Allow anonymous users to preview a draft of a post before it is published.
12
 
13
  == Description ==
14
 
15
+ Share a link to anonymous users to preview a draft of a post (or any other public post type) before it is published.
16
 
17
+ Have you ever been writing a post with the help of someone who does not have access to your site and needed to give them the ability to preview it before publishing? This plugin takes care of that by generating an URL with an expiring nonce that can be given out for public preview.
18
 
19
  *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/). Thanks to Hans Dinkelberg for his [photo](http://www.flickr.com/photos/uitdragerij/7516234430/).*
20
 
41
 
42
  == Screenshots ==
43
 
44
+ 1. Edit Posts Page
 
45
 
46
  == Usage ==
47
  * To enable a public post preview check the box below the edit post box.
73
 
74
  == Change Log ==
75
 
76
+ = 2.9.0 (2019-07-20): =
77
+ * Requires WordPress 5.0
78
+ * Requires PHP 5.6
79
+ * Adds notice (as Snackbar if supported) when changing preview status in block editor.
80
+ * Fixes incorrect status message in classic editor.
81
+ * Fixes grammar in expired link notice. Props [@garrett-eclipse](https://github.com/garrett-eclipse).
82
+ * Improves internal checks to be more strict. Props [@PatelUtkarsh](https://github.com/PatelUtkarsh).
83
+ * Removes deprecated i18n compatibility layer from Gutenberg plugin.
84
+
85
  = 2.8.0 (2018-11-27): =
86
  * Add support for WordPress 5.0 and the new block editor.
87
 
89
  * Initial support for Gutenberg.
90
  * Block robots for public post previews. Props [@westonruter](https://github.com/westonruter).
91
 
92
+ For more see [CHANGELOG.md](https://github.com/ocean90/public-post-preview/blob/master/CHANGELOG.md).