Changeset 3342923
- Timestamp:
- 08/11/2025 01:55:23 PM (4 months ago)
- Location:
- sharable-password-protected-posts
- Files:
-
- 50 added
- 4 deleted
- 26 edited
- 1 copied
-
tags/2.0.0 (copied) (copied from sharable-password-protected-posts/trunk)
-
tags/2.0.0/CHANGELOG.md (deleted)
-
tags/2.0.0/build/index-rtl.css (added)
-
tags/2.0.0/build/index.asset.php (modified) (1 diff)
-
tags/2.0.0/build/index.css (modified) (1 diff)
-
tags/2.0.0/build/index.js (modified) (1 diff)
-
tags/2.0.0/includes (added)
-
tags/2.0.0/includes/classes (added)
-
tags/2.0.0/includes/editor.php (added)
-
tags/2.0.0/includes/functions.php (added)
-
tags/2.0.0/includes/meta.php (added)
-
tags/2.0.0/includes/posts.php (added)
-
tags/2.0.0/languages/good-slider.pot (deleted)
-
tags/2.0.0/languages/sharable-password-protected-posts-de_DE.l10n.php (modified) (1 diff)
-
tags/2.0.0/languages/sharable-password-protected-posts-de_DE.mo (modified) (previous)
-
tags/2.0.0/languages/sharable-password-protected-posts-de_DE.po (modified) (2 diffs)
-
tags/2.0.0/languages/sharable-password-protected-posts.pot (modified) (2 diffs)
-
tags/2.0.0/sharable-password-protected-posts.php (modified) (2 diffs)
-
tags/2.0.0/src/PostStatusSettings/Check.js (modified) (2 diffs)
-
tags/2.0.0/src/PostStatusSettings/CopyUrl.js (modified) (2 diffs)
-
tags/2.0.0/src/PostStatusSettings/index.js (modified) (4 diffs)
-
tags/2.0.0/src/PostStatusSettings/styles.scss (modified) (3 diffs)
-
tags/2.0.0/src/index.js (modified) (1 diff)
-
tags/2.0.0/templates (added)
-
tags/2.0.0/vendor (added)
-
tags/2.0.0/vendor/autoload.php (added)
-
tags/2.0.0/vendor/composer (added)
-
tags/2.0.0/vendor/composer/ClassLoader.php (added)
-
tags/2.0.0/vendor/composer/InstalledVersions.php (added)
-
tags/2.0.0/vendor/composer/LICENSE (added)
-
tags/2.0.0/vendor/composer/autoload_classmap.php (added)
-
tags/2.0.0/vendor/composer/autoload_namespaces.php (added)
-
tags/2.0.0/vendor/composer/autoload_psr4.php (added)
-
tags/2.0.0/vendor/composer/autoload_real.php (added)
-
tags/2.0.0/vendor/composer/autoload_static.php (added)
-
tags/2.0.0/vendor/composer/installed.json (added)
-
tags/2.0.0/vendor/composer/installed.php (added)
-
tags/2.0.0/vendor/composer/platform_check.php (added)
-
tags/2.0.0/vendor/vendor-prefixed (added)
-
tags/2.0.0/vendor/vendor-prefixed/autoload-classmap.php (added)
-
tags/2.0.0/vendor/vendor-prefixed/autoload.php (added)
-
trunk/CHANGELOG.md (deleted)
-
trunk/build/index-rtl.css (added)
-
trunk/build/index.asset.php (modified) (1 diff)
-
trunk/build/index.css (modified) (1 diff)
-
trunk/build/index.js (modified) (1 diff)
-
trunk/includes (added)
-
trunk/includes/classes (added)
-
trunk/includes/editor.php (added)
-
trunk/includes/functions.php (added)
-
trunk/includes/meta.php (added)
-
trunk/includes/posts.php (added)
-
trunk/languages/good-slider.pot (deleted)
-
trunk/languages/sharable-password-protected-posts-de_DE.l10n.php (modified) (1 diff)
-
trunk/languages/sharable-password-protected-posts-de_DE.mo (modified) (previous)
-
trunk/languages/sharable-password-protected-posts-de_DE.po (modified) (2 diffs)
-
trunk/languages/sharable-password-protected-posts.pot (modified) (2 diffs)
-
trunk/sharable-password-protected-posts.php (modified) (2 diffs)
-
trunk/src/PostStatusSettings/Check.js (modified) (2 diffs)
-
trunk/src/PostStatusSettings/CopyUrl.js (modified) (2 diffs)
-
trunk/src/PostStatusSettings/index.js (modified) (4 diffs)
-
trunk/src/PostStatusSettings/styles.scss (modified) (3 diffs)
-
trunk/src/index.js (modified) (1 diff)
-
trunk/templates (added)
-
trunk/vendor (added)
-
trunk/vendor/autoload.php (added)
-
trunk/vendor/composer (added)
-
trunk/vendor/composer/ClassLoader.php (added)
-
trunk/vendor/composer/InstalledVersions.php (added)
-
trunk/vendor/composer/LICENSE (added)
-
trunk/vendor/composer/autoload_classmap.php (added)
-
trunk/vendor/composer/autoload_namespaces.php (added)
-
trunk/vendor/composer/autoload_psr4.php (added)
-
trunk/vendor/composer/autoload_real.php (added)
-
trunk/vendor/composer/autoload_static.php (added)
-
trunk/vendor/composer/installed.json (added)
-
trunk/vendor/composer/installed.php (added)
-
trunk/vendor/composer/platform_check.php (added)
-
trunk/vendor/vendor-prefixed (added)
-
trunk/vendor/vendor-prefixed/autoload-classmap.php (added)
-
trunk/vendor/vendor-prefixed/autoload.php (added)
Legend:
- Unmodified
- Added
- Removed
-
sharable-password-protected-posts/tags/2.0.0/build/index.asset.php
r3145331 r3342923 1 <?php return array('dependencies' => array('react ', 'wp-components', 'wp-compose', 'wp-core-data', 'wp-data', 'wp-editor', 'wp-element', 'wp-i18n', 'wp-plugins', 'wp-url'), 'version' => 'eb9f3e35316836719bd7');1 <?php return array('dependencies' => array('react-jsx-runtime', 'wp-components', 'wp-compose', 'wp-core-data', 'wp-data', 'wp-editor', 'wp-element', 'wp-i18n', 'wp-plugins', 'wp-url'), 'version' => 'a0338c091bc90438ef14'); -
sharable-password-protected-posts/tags/2.0.0/build/index.css
r2809716 r3342923 1 .components-panel__row. sppp{align-items:flex-start;flex-direction:column}.components-panel__row.sppp .sppp__link-copy{align-items:flex-end;display:flex;margin-bottom:16px 0}.components-panel__row.sppp .sppp__link-copy .components-base-control__field{margin-bottom:0}.components-panel__row.sppp .sppp__link-copy .sppp__link-field{flex:1}.components-panel__row.sppp .sppp__link-copy input[readonly]{background:#ddd;overflow:hidden;padding:10px;text-overflow:ellipsis}.components-panel__row.sppp .sppp__link-copy .sppp__copy-button{flex-shrink:0;height:38px;margin-left:8px}1 .components-panel__row.private-post-share{align-items:flex-start;flex-direction:column}.components-panel__row.private-post-share .private-post-share__link-copy{align-items:flex-end;display:flex;margin-bottom:16px 0}.components-panel__row.private-post-share .private-post-share__link-copy .components-base-control__field{margin-bottom:0}.components-panel__row.private-post-share .private-post-share__link-copy .private-post-share__link-field{flex:1}.components-panel__row.private-post-share .private-post-share__link-copy input[readonly]{background:#ddd;overflow:hidden;padding:10px;text-overflow:ellipsis}.components-panel__row.private-post-share .private-post-share__link-copy .private-post-share__copy-button{flex-shrink:0;height:38px;margin-left:8px} -
sharable-password-protected-posts/tags/2.0.0/build/index.js
r3145331 r3342923 1 (()=>{"use strict";const e=window.wp.plugins,t=window. React,s=window.wp.components,o=window.wp.i18n,n=window.wp.data,i=window.wp.editor,p=window.wp.element,r=window.wp.url,a=window.wp.compose,l={META_ENABLED:"_sppp_enabled",META_KEY:"_sppp_key",QUERY_PARAM:"_sppp_key"},{META_KEY:d,QUERY_PARAM:c}=l,w=({text:e,onCopy:o,children:n,...i})=>{const p=(0,a.useCopyToClipboard)(e,o);return(0,t.createElement)(s.Button,{variant:"secondary",ref:p,...i},n)};class u extends p.Component{constructor(){super(...arguments),this.state={showCopyConfirmation:!1},this.onCopy=this.onCopy.bind(this),this.onSelectInput=this.onSelectInput.bind(this)}componentWillUnmount(){clearTimeout(this.dismissCopyConfirmation)}onCopy(){this.setState({showCopyConfirmation:!0}),clearTimeout(this.dismissCopyConfirmation),this.dismissCopyConfirmation=setTimeout((()=>{this.setState({showCopyConfirmation:!1})}),4e3)}onSelectInput(e){e.target.select()}render(){const e=(0,r.addQueryArgs)(this.props.postLink,{[c]:this.props.secretKey});return(0,t.createElement)("div",null,(0,t.createElement)("label",{htmlFor:"sppp-link-field",className:"screen-reader-text"},(0,o.__)("Share this URL","sharable-password-protected-posts")),(0,t.createElement)(s.Flex,{className:"sppp__link-copy"},(0,t.createElement)(s.TextControl,{id:"sppp-link-field",className:"sppp__link-field",readOnly:!0,label:(0,o.__)("Secret URL:","sharable-password-protected-posts"),value:(0,r.safeDecodeURIComponent)(e),onFocus:this.onSelectInput}),(0,t.createElement)(w,{text:e,onCopy:this.onCopy,className:"sppp__copy-button"},this.state.showCopyConfirmation?(0,o.__)("Copied!","sharable-password-protected-posts"):(0,o.__)("Copy","sharable-password-protected-posts"))))}}const m=(0,n.withSelect)((e=>{const{getEditedPostAttribute:t,getPermalink:s}=e(i.store);return{postLink:s(),secretKey:t("meta")[d]}}))(u),h=window.wp.coreData,y=({children:e})=>{const{isPostTypeVisible:t,postType:s,isPostPrivate:o}=(0,n.useSelect)((e=>{let t=!1;const s=e(i.store).getCurrentPostType(),o=e(h.store).getPostType(s),n=e(i.store).getEditedPostAttribute("link"),p=e(i.store).getEditedPostVisibility();return o?.viewable&&(t=!0),n&&(t=!0),e(i.store).getPermalinkParts()&&(t=!0),{isPostTypeVisible:t,postType:s,isPostPrivate:"private"===p||"password"===p}}),[]),p=window.sppp&&window.sppp.settings.postTypes.includes(s);return window.sppp&&window.sppp.settings.hasPermissions&&t&&p&&o?e:null};var _,E;const C=null!==(_=wp.editor?.PluginPostStatusInfo)&&void 0!==_?_:null!==(E=wp.editPost?.PluginPostStatusInfo)&&void 0!==E?E:wp.editSite?.PluginPostStatusInfo,{META_ENABLED:P,META_KEY:b}=l;(0,e.registerPlugin)("sharable-password-protected-posts",{render:()=>{const{sharingEnabled:e,existingKey:p}=(0,n.useSelect)((e=>{const{getEditedPostAttribute:t}=e(i.store),s=t("meta");return{sharingEnabled:s?.[P]||null,existingKey:s?.[b]||null}})),{editPost:r}=(0,n.useDispatch)(i.store);return(0,t.createElement)(C,{className:"sppp"},(0,t.createElement)(y,null,(0,t.createElement)("div",{className:"sppp__checkbox"},(0,t.createElement)(s.CheckboxControl,{label:(0,o.__)("Share post via secret URL","sharable-password-protected-posts"),checked:!!e,onChange:e=>{r(e?{meta:{[P]:!0,[b]:p||window.sppp.newKey||""}}:{meta:{[P]:!1,[b]:""}})}})),e&&(0,t.createElement)("div",{className:"sppp__link"},(0,t.createElement)(m,null))))}})})();1 (()=>{"use strict";const e=window.wp.plugins,t=window.wp.components,s=window.wp.data,o=window.wp.editor,i=window.wp.i18n,n=window.wp.coreData,r=({children:e})=>{const{isPostTypeVisible:t,postType:i,isPostPrivate:r}=(0,s.useSelect)((e=>{let t=!1;const s=e(o.store).getCurrentPostType(),i=e(n.store).getPostType(s),r=e(o.store).getEditedPostAttribute("link"),a=e(o.store).getEditedPostVisibility();return i?.viewable&&(t=!0),r&&(t=!0),e(o.store).getPermalinkParts()&&(t=!0),{isPostTypeVisible:t,postType:s,isPostPrivate:"private"===a||"password"===a}}),[]),a=window.privatePostShare&&window.privatePostShare.settings.postTypes.includes(i);return window.privatePostShare&&window.privatePostShare.settings.hasPermissions&&t&&a&&r?e:null},a={META_ENABLED:"_sppp_enabled",META_KEY:"_sppp_key",QUERY_PARAM:"_sppp_key"},p=window.wp.compose,l=window.wp.element,d=window.wp.url,c=window.ReactJSXRuntime,{META_KEY:h,QUERY_PARAM:w}=a,u=({text:e,onCopy:s,children:o,...i})=>{const n=(0,p.useCopyToClipboard)(e,s);return(0,c.jsx)(t.Button,{variant:"secondary",ref:n,...i,children:o})};class m extends l.Component{constructor(){super(...arguments),this.state={showCopyConfirmation:!1},this.onCopy=this.onCopy.bind(this),this.onSelectInput=this.onSelectInput.bind(this)}componentWillUnmount(){clearTimeout(this.dismissCopyConfirmation)}onCopy(){this.setState({showCopyConfirmation:!0}),clearTimeout(this.dismissCopyConfirmation),this.dismissCopyConfirmation=setTimeout((()=>{this.setState({showCopyConfirmation:!1})}),4e3)}onSelectInput(e){e.target.select()}render(){const e=(0,d.addQueryArgs)(this.props.postLink,{[w]:this.props.secretKey});return(0,c.jsxs)("div",{children:[(0,c.jsx)("label",{htmlFor:"private-post-share-link-field",className:"screen-reader-text",children:(0,i.__)("Share this URL","sharable-password-protected-posts")}),(0,c.jsxs)(t.Flex,{className:"private-post-share__link-copy",children:[(0,c.jsx)(t.TextControl,{id:"private-post-share-link-field",className:"private-post-share__link-field",readOnly:!0,label:(0,i.__)("Secret URL:","sharable-password-protected-posts"),value:(0,d.safeDecodeURIComponent)(e),onFocus:this.onSelectInput}),(0,c.jsx)(u,{text:e,onCopy:this.onCopy,className:"private-post-share__copy-button",children:this.state.showCopyConfirmation?(0,i.__)("Copied!","sharable-password-protected-posts"):(0,i.__)("Copy","sharable-password-protected-posts")})]})]})}}const y=(0,s.withSelect)((e=>{const{getEditedPostAttribute:t,getPermalink:s}=e(o.store);return{postLink:s(),secretKey:t("meta")[h]}}))(m);var _,P;const C=null!==(_=null!==(P=wp.editor?.PluginPostStatusInfo)&&void 0!==P?P:wp.editPost?.PluginPostStatusInfo)&&void 0!==_?_:wp.editSite?.PluginPostStatusInfo,{META_ENABLED:v,META_KEY:b}=a;(0,e.registerPlugin)("private-post-share",{render:()=>{const{sharingEnabled:e,existingKey:n}=(0,s.useSelect)((e=>{const{getEditedPostAttribute:t}=e(o.store),s=t("meta");return{sharingEnabled:s?.[v]||null,existingKey:s?.[b]||null}})),{editPost:a}=(0,s.useDispatch)(o.store);return(0,c.jsx)(C,{className:"private-post-share",children:(0,c.jsxs)(r,{children:[(0,c.jsx)("div",{className:"private-post-share__checkbox",children:(0,c.jsx)(t.CheckboxControl,{label:(0,i.__)("Share post via secret URL","sharable-password-protected-posts"),checked:!!e,onChange:e=>{a(e?{meta:{[v]:!0,[b]:n||window.privatePostShare.newKey||""}}:{meta:{[v]:!1,[b]:""}})}})}),e&&(0,c.jsx)("div",{className:"private-post-share__link",children:(0,c.jsx)(y,{})})]})})}})})(); -
sharable-password-protected-posts/tags/2.0.0/languages/sharable-password-protected-posts-de_DE.l10n.php
r3145331 r3342923 1 1 <?php 2 return ['domain'=>'sharable-password-protected-posts','plural-forms'=>'nplurals=2; plural=(n != 1);','language'=>'de_DE','project-id-version'=>'Sharable Password Protected Posts 0.1.0','pot-creation-date'=>'202 2-10-29T08:32:09+00:00','po-revision-date'=>'2022-10-29 10:35+0200','x-generator'=>'Poedit 3.2','messages'=>['Sharable Password Protected Posts'=>'Passwortgeschützte Posts teilen','Share password protected posts via secret URLs'=>'Teile passwortgeschützte Beiträge mit geheimen URLs','Share this URL'=>'Teile diese URL','Secret URL:'=>'Geheime URL:','Copied!'=>'Kopiert!','Copy'=>'Kopieren','Share post via secret URL'=>'Beitrag mit geheimer URL teilen']];2 return ['domain'=>'sharable-password-protected-posts','plural-forms'=>'nplurals=2; plural=(n != 1);','language'=>'de_DE','project-id-version'=>'Sharable Password Protected Posts 0.1.0','pot-creation-date'=>'2025-08-11T15:46:21+02:00','po-revision-date'=>'2025-08-11 15:47+0200','x-generator'=>'Poedit 3.6','messages'=>['Share password protected posts via secret URLs'=>'Teile passwortgeschützte Beiträge mit geheimen URLs','Share this URL'=>'Teile diese URL','Secret URL:'=>'Geheime URL:','Copied!'=>'Kopiert!','Copy'=>'Kopieren','Share post via secret URL'=>'Beitrag mit geheimer URL teilen']]; -
sharable-password-protected-posts/tags/2.0.0/languages/sharable-password-protected-posts-de_DE.po
r2809716 r3342923 4 4 msgstr "" 5 5 "Project-Id-Version: Sharable Password Protected Posts 0.1.0\n" 6 "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/sharable-password-" 7 "protected-posts\n" 8 "POT-Creation-Date: 2022-10-29T08:32:09+00:00\n" 9 "PO-Revision-Date: 2022-10-29 10:35+0200\n" 6 "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/html\n" 7 "POT-Creation-Date: 2025-08-11T15:46:21+02:00\n" 8 "PO-Revision-Date: 2025-08-11 15:47+0200\n" 10 9 "Last-Translator: \n" 11 10 "Language-Team: \n" … … 15 14 "Content-Transfer-Encoding: 8bit\n" 16 15 "Plural-Forms: nplurals=2; plural=(n != 1);\n" 17 "X-Generator: Poedit 3. 2\n"16 "X-Generator: Poedit 3.6\n" 18 17 "X-Domain: sharable-password-protected-posts\n" 19 18 20 19 #. Plugin Name of the plugin 21 msgid "Sharable Password Protected Posts" 22 msgstr "Passwortgeschützte Posts teilen" 20 #: sharable-password-protected-posts.php 21 msgid "Private Post Share" 22 msgstr "" 23 23 24 24 #. Description of the plugin 25 #: sharable-password-protected-posts.php 25 26 msgid "Share password protected posts via secret URLs" 26 27 msgstr "Teile passwortgeschützte Beiträge mit geheimen URLs" 27 28 28 29 #. Author of the plugin 30 #: sharable-password-protected-posts.php 29 31 msgid "Fabian Todt" 30 32 msgstr "" 31 33 32 #: src/PostStatusSettings/CopyUrl.js:63 34 #. Author URI of the plugin 35 #: sharable-password-protected-posts.php 36 msgid "https://fabiantodt.at/" 37 msgstr "" 38 39 #: build/index.js:1 src/PostStatusSettings/CopyUrl.js:66 33 40 msgid "Share this URL" 34 41 msgstr "Teile diese URL" 35 42 36 #: src/PostStatusSettings/CopyUrl.js:7043 #: build/index.js:1 src/PostStatusSettings/CopyUrl.js:73 37 44 msgid "Secret URL:" 38 45 msgstr "Geheime URL:" 39 46 40 #: src/PostStatusSettings/CopyUrl.js:7647 #: build/index.js:1 src/PostStatusSettings/CopyUrl.js:85 41 48 msgid "Copied!" 42 49 msgstr "Kopiert!" 43 50 44 #: src/PostStatusSettings/CopyUrl.js:7751 #: build/index.js:1 src/PostStatusSettings/CopyUrl.js:86 45 52 msgid "Copy" 46 53 msgstr "Kopieren" 47 54 48 #: src/PostStatusSettings/index.js:4155 #: build/index.js:1 src/PostStatusSettings/index.js:50 49 56 msgid "Share post via secret URL" 50 57 msgstr "Beitrag mit geheimer URL teilen" 58 59 #~ msgid "Sharable Password Protected Posts" 60 #~ msgstr "Passwortgeschützte Posts teilen" -
sharable-password-protected-posts/tags/2.0.0/languages/sharable-password-protected-posts.pot
r2809749 r3342923 1 # Copyright (C) 202 2Fabian Todt1 # Copyright (C) 2025 Fabian Todt 2 2 # This file is distributed under the GPL-2.0-or-later. 3 3 msgid "" 4 4 msgstr "" 5 "Project-Id-Version: Sharable Password Protected Posts 1.0.2\n"6 "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/ sharable-password-protected-posts\n"5 "Project-Id-Version: Private Post Share 2.0.0\n" 6 "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/html\n" 7 7 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" 8 8 "Language-Team: LANGUAGE <[email protected]>\n" … … 10 10 "Content-Type: text/plain; charset=UTF-8\n" 11 11 "Content-Transfer-Encoding: 8bit\n" 12 "POT-Creation-Date: 202 2-11-02T10:02:27+00:00\n"12 "POT-Creation-Date: 2025-08-11T15:47:59+02:00\n" 13 13 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" 14 "X-Generator: WP-CLI 2. 7.1\n"14 "X-Generator: WP-CLI 2.12.0\n" 15 15 "X-Domain: sharable-password-protected-posts\n" 16 16 17 17 #. Plugin Name of the plugin 18 msgid "Sharable Password Protected Posts" 18 #: sharable-password-protected-posts.php 19 msgid "Private Post Share" 19 20 msgstr "" 20 21 21 22 #. Description of the plugin 23 #: sharable-password-protected-posts.php 22 24 msgid "Share password protected posts via secret URLs" 23 25 msgstr "" 24 26 25 27 #. Author of the plugin 28 #: sharable-password-protected-posts.php 26 29 msgid "Fabian Todt" 27 30 msgstr "" 28 31 29 32 #. Author URI of the plugin 30 msgid "https://fabiantodt.at/en/" 33 #: sharable-password-protected-posts.php 34 msgid "https://fabiantodt.at/" 31 35 msgstr "" 32 36 33 #: src/PostStatusSettings/CopyUrl.js:63 37 #: build/index.js:1 38 #: src/PostStatusSettings/CopyUrl.js:66 34 39 msgid "Share this URL" 35 40 msgstr "" 36 41 37 #: src/PostStatusSettings/CopyUrl.js:70 42 #: build/index.js:1 43 #: src/PostStatusSettings/CopyUrl.js:73 38 44 msgid "Secret URL:" 39 45 msgstr "" 40 46 41 #: src/PostStatusSettings/CopyUrl.js:76 47 #: build/index.js:1 48 #: src/PostStatusSettings/CopyUrl.js:85 42 49 msgid "Copied!" 43 50 msgstr "" 44 51 45 #: src/PostStatusSettings/CopyUrl.js:77 52 #: build/index.js:1 53 #: src/PostStatusSettings/CopyUrl.js:86 46 54 msgid "Copy" 47 55 msgstr "" 48 56 49 #: src/PostStatusSettings/index.js:41 57 #: build/index.js:1 58 #: src/PostStatusSettings/index.js:50 50 59 msgid "Share post via secret URL" 51 60 msgstr "" -
sharable-password-protected-posts/tags/2.0.0/sharable-password-protected-posts.php
r3310392 r3342923 1 1 <?php 2 3 2 /** 4 * Plugin Name: Sharable Password Protected Posts3 * Plugin Name: Private Post Share 5 4 * Description: Share password protected posts via secret URLs 6 * Requires at least: 6. 07 * Requires PHP: 7.48 * Version: 1.1.15 * Requires at least: 6.7 6 * Requires PHP: 8.1 7 * Version: 2.0.0 9 8 * Author: Fabian Todt 10 * Author URI: https://fabiantodt.at/ en/9 * Author URI: https://fabiantodt.at/ 11 10 * License: GPL-2.0-or-later 12 11 * License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 14 13 * Domain Path: /languages 15 14 * 16 * @package SPPP15 * @package Private_Post_Share 17 16 */ 18 17 19 namespace SPPP;18 namespace Private_Post_Share; 20 19 21 /** 22 * Adds JS & CSS to editor 23 * 24 * @return void 25 */ 26 function addEditorAssets() 27 { 28 $assetFile = plugin_dir_path(__FILE__) . 'build/index.asset.php'; 29 if (!file_exists($assetFile)) { 30 throw new \Exception('You have to build the scripts before loading them'); 31 } 32 $assetsConfig = require($assetFile); 20 defined( 'ABSPATH' ) || exit; 33 21 34 $jsData = [ 35 'settings' => [ 36 'postTypes' => getEnabledPostTypes(), 37 'hasPermissions' => current_user_can('publish_posts'), 38 ], 39 'newKey' => generateKey(), 40 ]; 22 define( 'PRIVATE_POST_SHARE_PLUGIN_FILE', __FILE__ ); 23 define( 'PRIVATE_POST_SHARE_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); 41 24 42 $scriptDependencies = $assetsConfig['dependencies']; 43 // For WordPress < 6.6 the editor script depends on wp-edit-post (because of PluginPostStatusInfo) 44 // but the script is built against 6.6, therefore only requiring the wp-editor script. 45 require ABSPATH . WPINC . '/version.php'; 46 if(version_compare($wp_version, '6.6', '<')) { 47 $scriptDependencies[] = 'wp-edit-post'; 48 } 25 require_once PRIVATE_POST_SHARE_PLUGIN_DIR . 'vendor/vendor-prefixed/autoload.php'; 26 require_once PRIVATE_POST_SHARE_PLUGIN_DIR . 'vendor/autoload.php'; 49 27 50 wp_enqueue_script( 51 'sppp', 52 plugin_dir_url(__FILE__) . 'build/index.js', 53 $scriptDependencies, 54 $assetsConfig['version'] 55 ); 56 57 wp_enqueue_style( 58 'sppp', 59 plugin_dir_url(__FILE__) . 'build/index.css', 60 [], 61 $assetsConfig['version'] 62 ); 63 64 wp_add_inline_script('sppp', 'window.sppp = ' . json_encode($jsData) . ';', 'before'); 65 } 66 add_action('enqueue_block_editor_assets', __NAMESPACE__ . '\addEditorAssets'); 67 68 function loadLanguages() 69 { 70 load_plugin_textdomain( 71 'sharable-password-protected-posts', 72 false, 73 dirname(plugin_dir_path(__FILE__)) . 'languages' 74 ); 75 } 76 add_action('init', __NAMESPACE__ . '\loadLanguages'); 77 78 /** 79 * Registers the two meta fields 80 * 81 * @return void 82 */ 83 function registerMeta() 84 { 85 $enabledMetaField = [ 86 'show_in_rest' => [ 87 'schema' => [ 88 'context' => ['edit'] // Only show when editing. 89 ], 90 // Additionally, hide value when user is not allowed to edit the post. 91 'prepare_callback' => function ($value, $request, $args) { 92 global $post; 93 // WP_REST_Posts_Controller set global post instance. 94 $postId = $post ? $post->ID : $request['id']; 95 96 $allowed = $postId ? current_user_can('edit_post', $postId) : current_user_can('edit_posts'); 97 return $allowed ? $value : null; 98 } 99 ], 100 'single' => true, 101 'type' => 'boolean', 102 'default' => false, 103 'auth_callback' => function ($allowed, $meta_key, $objectId, $userId) { 104 if ($userId) { 105 return user_can($userId, 'publish_posts', $objectId); 106 } 107 return current_user_can('publish_posts', $objectId); 108 }, 109 'sanitize_callback' => function ($value) { 110 if ($value === true || $value === 1 || $value === '1' || $value === 'true') { 111 $value = true; 112 } else { 113 $value = false; 114 } 115 return $value; 116 }, 117 ]; 118 119 $keyMetaField = [ 120 'show_in_rest' => [ 121 'schema' => [ 122 'context' => ['edit'] // Only show when editing. 123 ], 124 // Additionally, hide value when user is not allowed to edit the post. 125 'prepare_callback' => function ($value, $request, $args) { 126 global $post; 127 // WP_REST_Posts_Controller set global post instance. 128 $postId = $post ? $post->ID : $request['id']; 129 130 $allowed = $postId ? current_user_can('edit_post', $postId) : current_user_can('edit_posts'); 131 return $allowed ? $value : null; 132 } 133 ], 134 'single' => true, 135 'type' => 'string', 136 'default' => '', 137 'auth_callback' => function ($allowed, $meta_key, $objectId, $userId) { 138 if ($userId) { 139 return user_can($userId, 'publish_posts', $objectId); 140 } 141 return current_user_can('publish_posts', $objectId); 142 }, 143 'sanitize_callback' => function ($value) { 144 $value = sanitize_text_field(trim($value)); 145 if (empty($value)) { 146 return generateKey(); 147 } 148 return $value; 149 } 150 ]; 151 152 $postTypes = getEnabledPostTypes(); 153 154 foreach ($postTypes as $postType) { 155 register_post_meta($postType, '_sppp_enabled', $enabledMetaField); 156 register_post_meta($postType, '_sppp_key', $keyMetaField); 157 } 158 } 159 add_action('init', __NAMESPACE__ . '\registerMeta'); 160 161 /** 162 * Filters the main queries posts_results - for PRIVATE posts 163 * Sets the post elements status to 'publish' if it can be viewed with the key 164 * this will let the rest of WP_Query thandle the post as normal 165 * 166 * This only filters the main query's WP_Post instance, not all other objects 167 * that may be get via get_post; but using get_queried_object will work 168 * 169 * @param \WP_Post[] $posts 170 * @param \WP_Query $query 171 * @return void 172 */ 173 function filterPostsQuery($posts, $query) 174 { 175 // only handle the main query 176 if (!$query->is_main_query()) { 177 return $posts; 178 } 179 180 // only handle single views, don't handle not-found posts 181 if (count($posts) !== 1) { 182 return $posts; 183 } 184 185 $mainPost = $posts[0]; 186 $enabledPostTypes = getEnabledPostTypes(); 187 188 // if the main (single) post has a not-enabled post type, bail early 189 if (!in_array($mainPost->post_type, $enabledPostTypes)) { 190 return $posts; 191 } 192 193 // if a post type was specifically queried, check if only allowed/enabled post types where queried 194 $postTypes = $query->get('post_type'); 195 if (!empty($postTypes) && (is_array($postTypes) || is_string($postTypes))) { 196 // if a post type is queried (maybe one of multiple), that is not enabled bail early 197 if ( 198 !empty($postTypes) && 199 !empty(array_diff((array)$postTypes, $enabledPostTypes)) 200 ) { 201 return $posts; 202 } 203 } 204 205 // should only be 1 on singulars normally 206 foreach ($posts as &$post) { 207 if (canPostBeViewedWithKey($post)) { 208 $post->post_status = 'publish'; 209 } 210 } 211 return $posts; 212 } 213 add_filter('posts_results', __NAMESPACE__ . '\filterPostsQuery', 10, 2); 214 215 /** 216 * Filters whether a post password form is required - for PASSWORD protected posts 217 * 218 * @param bool $required 219 * @param \WP_Post $post 220 * @return bool 221 */ 222 function filterPostPasswordRequired($required, $post) 223 { 224 $enabledPostTypes = getEnabledPostTypes(); 225 226 // if the post has a not-enabled post type, bail early 227 if (!in_array($post->post_type, $enabledPostTypes)) { 228 return $required; 229 } 230 231 if (canPostBeViewedWithKey($post)) { 232 return false; 233 } 234 return $required; 235 } 236 add_filter('post_password_required', __NAMESPACE__ . '\filterPostPasswordRequired', 10, 2); 237 238 /** 239 * Removes the "Protected" from password protected/private posts 240 * if they can be viewd with the current url key 241 * 242 * @param string $prefix 243 * @param WP_Post|int $post 244 * @return string 245 */ 246 function filterPostTitlePrefix($prefix, $post) 247 { 248 if (canPostBeViewedWithKey($post)) { 249 return '%s'; 250 } 251 return $prefix; 252 } 253 add_filter('protected_title_format', __NAMESPACE__ . '\filterPostTitlePrefix', 10, 2); 254 add_filter('private_title_format', __NAMESPACE__ . '\filterPostTitlePrefix', 10, 2); 255 256 /** 257 * Whether a given post can be viewed with a given key 258 * 259 * @param \WP_Post $post The post to check for 260 * @param string $key A key to check against, defaults to the $_GET parameters 261 * @return bool False if the post is not private/protected or if SPPP is not enabled; 262 * True if key can be used to view the private post 263 */ 264 function canPostBeViewedWithKey($post, $key = null) 265 { 266 if (!$key) { 267 if (empty($_GET['_sppp_key'])) { 268 return false; 269 } 270 $key = sanitize_text_field($_GET['_sppp_key']); 271 } 272 273 if (empty($key)) { 274 return false; 275 } 276 277 if (empty($post->post_password) && $post->post_status !== 'private') { 278 return false; 279 } 280 281 $isKeyValid = isKeyValid($key, $post); 282 283 if ($isKeyValid) { 284 return true; 285 } 286 return false; 287 } 288 289 /** 290 * Checks the given key by the user against the stored key 291 * 292 * @param string $userKey 293 * @param WP_Post|int $post 294 * @return bool False if key is not valid or SPPP is not enabled for this post 295 */ 296 function isKeyValid($userKey, $post) 297 { 298 if (empty($userKey)) { 299 return false; 300 } 301 302 $postId = is_a($post, 'WP_Post') ? $post->ID : $post; 303 304 $isEnabled = get_post_meta($postId, '_sppp_enabled', true); 305 if (!$isEnabled) { 306 return false; 307 } 308 $savedKey = get_post_meta($postId, '_sppp_key', true); 309 310 if (empty($savedKey)) { 311 return false; 312 } 313 314 return $savedKey === $userKey; 315 } 316 317 /** 318 * Get enabled post types for SPPP 319 * 320 * @return string[] name of post types 321 */ 322 function getEnabledPostTypes() 323 { 324 /** 325 * Allows filtering the post types for which SPPP is enabled 326 * By default it's enabled for all public post types 327 * 328 * @param string[] $postTypes array of post type names (slugs) 329 */ 330 return apply_filters('sppp/postTypes', array_keys(get_post_types([ 331 'public' => true, 332 ], 'names'))); 333 } 334 335 /** 336 * Generate a new secret key 337 * 338 * @return string 339 */ 340 function generateKey() 341 { 342 return wp_generate_password(15, false); 343 } 28 require_once PRIVATE_POST_SHARE_PLUGIN_DIR . 'includes/functions.php'; 29 require_once PRIVATE_POST_SHARE_PLUGIN_DIR . 'includes/editor.php'; 30 require_once PRIVATE_POST_SHARE_PLUGIN_DIR . 'includes/meta.php'; 31 require_once PRIVATE_POST_SHARE_PLUGIN_DIR . 'includes/posts.php'; -
sharable-password-protected-posts/tags/2.0.0/src/PostStatusSettings/Check.js
r2809716 r3342923 1 import { store as coreStore } from "@wordpress/core-data"; 1 2 import { useSelect } from "@wordpress/data"; 2 import { store as coreStore } from "@wordpress/core-data";3 3 import { store as editorStore } from "@wordpress/editor"; 4 4 … … 10 10 */ 11 11 const Check = ({ children }) => { 12 const { isPostTypeVisible, postType, isPostPrivate } = useSelect((select) => { 13 let isPostTypeVisible = false; 14 const postTypeSlug = select(editorStore).getCurrentPostType(); 15 const postType = select(coreStore).getPostType(postTypeSlug); 16 const link = select(editorStore).getEditedPostAttribute("link"); 17 const editedPostVisibility = select(editorStore).getEditedPostVisibility(); 12 const { isPostTypeVisible, postType, isPostPrivate } = useSelect( 13 (select) => { 14 let isPostTypeVisible = false; 15 const postTypeSlug = select(editorStore).getCurrentPostType(); 16 const postType = select(coreStore).getPostType(postTypeSlug); 17 const link = select(editorStore).getEditedPostAttribute("link"); 18 const editedPostVisibility = 19 select(editorStore).getEditedPostVisibility(); 18 20 19 if (postType?.viewable) {20 isPostTypeVisible = true;21 }21 if (postType?.viewable) { 22 isPostTypeVisible = true; 23 } 22 24 23 if (link) {24 isPostTypeVisible = true;25 }25 if (link) { 26 isPostTypeVisible = true; 27 } 26 28 27 const permalinkParts = select(editorStore).getPermalinkParts();28 if (permalinkParts) {29 isPostTypeVisible = true;30 }29 const permalinkParts = select(editorStore).getPermalinkParts(); 30 if (permalinkParts) { 31 isPostTypeVisible = true; 32 } 31 33 32 return { 33 isPostTypeVisible, 34 postType: postTypeSlug, 35 isPostPrivate: editedPostVisibility === "private" || editedPostVisibility === "password", 36 }; 37 }, []); 34 return { 35 isPostTypeVisible, 36 postType: postTypeSlug, 37 isPostPrivate: 38 editedPostVisibility === "private" || 39 editedPostVisibility === "password", 40 }; 41 }, 42 [] 43 ); 38 44 39 const isEnabledForPostType = window.sppp && window.sppp.settings.postTypes.includes(postType); 40 const hasPermissions = window.sppp && window.sppp.settings.hasPermissions; 45 const isEnabledForPostType = 46 window.privatePostShare && 47 window.privatePostShare.settings.postTypes.includes(postType); 48 const hasPermissions = 49 window.privatePostShare && 50 window.privatePostShare.settings.hasPermissions; 41 51 42 if (!hasPermissions || !isPostTypeVisible || !isEnabledForPostType || !isPostPrivate) { 52 if ( 53 !hasPermissions || 54 !isPostTypeVisible || 55 !isEnabledForPostType || 56 !isPostPrivate 57 ) { 43 58 return null; 44 59 } -
sharable-password-protected-posts/tags/2.0.0/src/PostStatusSettings/CopyUrl.js
r2809716 r3342923 1 import { Button, Flex, TextControl } from "@wordpress/components"; 2 import { useCopyToClipboard } from "@wordpress/compose"; 3 import { withSelect } from "@wordpress/data"; 4 import { store as editorStore } from "@wordpress/editor"; 1 5 import { Component } from "@wordpress/element"; 2 import { safeDecodeURIComponent, addQueryArgs } from "@wordpress/url";3 import { TextControl, Button, Flex } from "@wordpress/components";4 import { withSelect } from "@wordpress/data";5 import { useCopyToClipboard } from "@wordpress/compose";6 import { store as editorStore } from "@wordpress/editor";7 6 import { __ } from "@wordpress/i18n"; 7 import { addQueryArgs, safeDecodeURIComponent } from "@wordpress/url"; 8 8 9 9 import CONSTANTS from "./constants"; 10 10 11 const { META_KEY, QUERY_PARAM } = CONSTANTS; 11 12 … … 60 61 return ( 61 62 <div> 62 <label htmlFor="sppp-link-field" className="screen-reader-text"> 63 <label 64 htmlFor="private-post-share-link-field" 65 className="screen-reader-text"> 63 66 {__("Share this URL", "sharable-password-protected-posts")} 64 67 </label> 65 <Flex className=" sppp__link-copy">68 <Flex className="private-post-share__link-copy"> 66 69 <TextControl 67 id=" sppp-link-field"68 className=" sppp__link-field"70 id="private-post-share-link-field" 71 className="private-post-share__link-field" 69 72 readOnly 70 label={__("Secret URL:", "sharable-password-protected-posts")} 73 label={__( 74 "Secret URL:", 75 "sharable-password-protected-posts" 76 )} 71 77 value={safeDecodeURIComponent(url)} 72 78 onFocus={this.onSelectInput} 73 79 /> 74 <CopyButton text={url} onCopy={this.onCopy} className="sppp__copy-button"> 80 <CopyButton 81 text={url} 82 onCopy={this.onCopy} 83 className="private-post-share__copy-button"> 75 84 {this.state.showCopyConfirmation 76 85 ? __("Copied!", "sharable-password-protected-posts") -
sharable-password-protected-posts/tags/2.0.0/src/PostStatusSettings/index.js
r3145331 r3342923 1 1 import { CheckboxControl } from "@wordpress/components"; 2 import { useDispatch, useSelect } from "@wordpress/data"; 3 import { store as editorStore } from "@wordpress/editor"; 2 4 import { __ } from "@wordpress/i18n"; 3 import { useSelect, useDispatch } from "@wordpress/data";4 import { store as editorStore } from "@wordpress/editor";5 import Check from "./Check"; 6 import CONSTANTS from "./constants"; 5 7 import CopyUrl from "./CopyUrl"; 6 import Check from "./Check";8 import "./styles.scss"; 7 9 8 10 // Support < WP 6.6 and > WP 6.6 9 11 // See https://make.wordpress.org/core/2024/06/18/editor-unified-extensibility-apis-in-6-6/ 10 const PluginPostStatusInfo = wp.editor?.PluginPostStatusInfo ?? ( wp.editPost?.PluginPostStatusInfo ?? wp.editSite?.PluginPostStatusInfo ); 12 const PluginPostStatusInfo = 13 wp.editor?.PluginPostStatusInfo ?? 14 wp.editPost?.PluginPostStatusInfo ?? 15 wp.editSite?.PluginPostStatusInfo; 11 16 12 import CONSTANTS from "./constants";13 17 const { META_ENABLED, META_KEY } = CONSTANTS; 14 15 import "./styles.scss";16 18 17 19 const PostStatusSettings = () => { … … 28 30 if (value) { 29 31 editPost({ 30 meta: { [META_ENABLED]: true, [META_KEY]: existingKey || window.sppp.newKey || "" }, 32 meta: { 33 [META_ENABLED]: true, 34 [META_KEY]: 35 existingKey || window.privatePostShare.newKey || "", 36 }, 31 37 }); 32 38 } else { … … 38 44 39 45 return ( 40 <PluginPostStatusInfo className=" sppp">46 <PluginPostStatusInfo className="private-post-share"> 41 47 <Check> 42 <div className=" sppp__checkbox">48 <div className="private-post-share__checkbox"> 43 49 <CheckboxControl 44 label={__("Share post via secret URL", "sharable-password-protected-posts")} 50 label={__( 51 "Share post via secret URL", 52 "sharable-password-protected-posts" 53 )} 45 54 checked={!!sharingEnabled} // Cast to bool, so null value after changing and reloading state does not trigger uncontrolled input warning. 46 55 onChange={onChangeEnabled} … … 49 58 50 59 {sharingEnabled && ( 51 <div className=" sppp__link">60 <div className="private-post-share__link"> 52 61 <CopyUrl /> 53 62 </div> -
sharable-password-protected-posts/tags/2.0.0/src/PostStatusSettings/styles.scss
r2809716 r3342923 1 .components-panel__row. sppp{1 .components-panel__row.private-post-share { 2 2 flex-direction: column; 3 3 align-items: flex-start; 4 4 5 . sppp__link-copy {5 .private-post-share__link-copy { 6 6 display: flex; 7 7 align-items: flex-end; … … 11 11 } 12 12 13 . sppp__link-field {13 .private-post-share__link-field { 14 14 flex: 1; 15 15 } … … 22 22 } 23 23 24 . sppp__copy-button {24 .private-post-share__copy-button { 25 25 flex-shrink: 0; 26 26 margin-left: 8px; // margin left for copy button -
sharable-password-protected-posts/tags/2.0.0/src/index.js
r2809716 r3342923 2 2 import PostStatusSettings from "./PostStatusSettings"; 3 3 4 registerPlugin(" sharable-password-protected-posts", {5 render: PostStatusSettings,4 registerPlugin("private-post-share", { 5 render: PostStatusSettings, 6 6 }); -
sharable-password-protected-posts/trunk/build/index.asset.php
r3145331 r3342923 1 <?php return array('dependencies' => array('react ', 'wp-components', 'wp-compose', 'wp-core-data', 'wp-data', 'wp-editor', 'wp-element', 'wp-i18n', 'wp-plugins', 'wp-url'), 'version' => 'eb9f3e35316836719bd7');1 <?php return array('dependencies' => array('react-jsx-runtime', 'wp-components', 'wp-compose', 'wp-core-data', 'wp-data', 'wp-editor', 'wp-element', 'wp-i18n', 'wp-plugins', 'wp-url'), 'version' => 'a0338c091bc90438ef14'); -
sharable-password-protected-posts/trunk/build/index.css
r2809716 r3342923 1 .components-panel__row. sppp{align-items:flex-start;flex-direction:column}.components-panel__row.sppp .sppp__link-copy{align-items:flex-end;display:flex;margin-bottom:16px 0}.components-panel__row.sppp .sppp__link-copy .components-base-control__field{margin-bottom:0}.components-panel__row.sppp .sppp__link-copy .sppp__link-field{flex:1}.components-panel__row.sppp .sppp__link-copy input[readonly]{background:#ddd;overflow:hidden;padding:10px;text-overflow:ellipsis}.components-panel__row.sppp .sppp__link-copy .sppp__copy-button{flex-shrink:0;height:38px;margin-left:8px}1 .components-panel__row.private-post-share{align-items:flex-start;flex-direction:column}.components-panel__row.private-post-share .private-post-share__link-copy{align-items:flex-end;display:flex;margin-bottom:16px 0}.components-panel__row.private-post-share .private-post-share__link-copy .components-base-control__field{margin-bottom:0}.components-panel__row.private-post-share .private-post-share__link-copy .private-post-share__link-field{flex:1}.components-panel__row.private-post-share .private-post-share__link-copy input[readonly]{background:#ddd;overflow:hidden;padding:10px;text-overflow:ellipsis}.components-panel__row.private-post-share .private-post-share__link-copy .private-post-share__copy-button{flex-shrink:0;height:38px;margin-left:8px} -
sharable-password-protected-posts/trunk/build/index.js
r3145331 r3342923 1 (()=>{"use strict";const e=window.wp.plugins,t=window. React,s=window.wp.components,o=window.wp.i18n,n=window.wp.data,i=window.wp.editor,p=window.wp.element,r=window.wp.url,a=window.wp.compose,l={META_ENABLED:"_sppp_enabled",META_KEY:"_sppp_key",QUERY_PARAM:"_sppp_key"},{META_KEY:d,QUERY_PARAM:c}=l,w=({text:e,onCopy:o,children:n,...i})=>{const p=(0,a.useCopyToClipboard)(e,o);return(0,t.createElement)(s.Button,{variant:"secondary",ref:p,...i},n)};class u extends p.Component{constructor(){super(...arguments),this.state={showCopyConfirmation:!1},this.onCopy=this.onCopy.bind(this),this.onSelectInput=this.onSelectInput.bind(this)}componentWillUnmount(){clearTimeout(this.dismissCopyConfirmation)}onCopy(){this.setState({showCopyConfirmation:!0}),clearTimeout(this.dismissCopyConfirmation),this.dismissCopyConfirmation=setTimeout((()=>{this.setState({showCopyConfirmation:!1})}),4e3)}onSelectInput(e){e.target.select()}render(){const e=(0,r.addQueryArgs)(this.props.postLink,{[c]:this.props.secretKey});return(0,t.createElement)("div",null,(0,t.createElement)("label",{htmlFor:"sppp-link-field",className:"screen-reader-text"},(0,o.__)("Share this URL","sharable-password-protected-posts")),(0,t.createElement)(s.Flex,{className:"sppp__link-copy"},(0,t.createElement)(s.TextControl,{id:"sppp-link-field",className:"sppp__link-field",readOnly:!0,label:(0,o.__)("Secret URL:","sharable-password-protected-posts"),value:(0,r.safeDecodeURIComponent)(e),onFocus:this.onSelectInput}),(0,t.createElement)(w,{text:e,onCopy:this.onCopy,className:"sppp__copy-button"},this.state.showCopyConfirmation?(0,o.__)("Copied!","sharable-password-protected-posts"):(0,o.__)("Copy","sharable-password-protected-posts"))))}}const m=(0,n.withSelect)((e=>{const{getEditedPostAttribute:t,getPermalink:s}=e(i.store);return{postLink:s(),secretKey:t("meta")[d]}}))(u),h=window.wp.coreData,y=({children:e})=>{const{isPostTypeVisible:t,postType:s,isPostPrivate:o}=(0,n.useSelect)((e=>{let t=!1;const s=e(i.store).getCurrentPostType(),o=e(h.store).getPostType(s),n=e(i.store).getEditedPostAttribute("link"),p=e(i.store).getEditedPostVisibility();return o?.viewable&&(t=!0),n&&(t=!0),e(i.store).getPermalinkParts()&&(t=!0),{isPostTypeVisible:t,postType:s,isPostPrivate:"private"===p||"password"===p}}),[]),p=window.sppp&&window.sppp.settings.postTypes.includes(s);return window.sppp&&window.sppp.settings.hasPermissions&&t&&p&&o?e:null};var _,E;const C=null!==(_=wp.editor?.PluginPostStatusInfo)&&void 0!==_?_:null!==(E=wp.editPost?.PluginPostStatusInfo)&&void 0!==E?E:wp.editSite?.PluginPostStatusInfo,{META_ENABLED:P,META_KEY:b}=l;(0,e.registerPlugin)("sharable-password-protected-posts",{render:()=>{const{sharingEnabled:e,existingKey:p}=(0,n.useSelect)((e=>{const{getEditedPostAttribute:t}=e(i.store),s=t("meta");return{sharingEnabled:s?.[P]||null,existingKey:s?.[b]||null}})),{editPost:r}=(0,n.useDispatch)(i.store);return(0,t.createElement)(C,{className:"sppp"},(0,t.createElement)(y,null,(0,t.createElement)("div",{className:"sppp__checkbox"},(0,t.createElement)(s.CheckboxControl,{label:(0,o.__)("Share post via secret URL","sharable-password-protected-posts"),checked:!!e,onChange:e=>{r(e?{meta:{[P]:!0,[b]:p||window.sppp.newKey||""}}:{meta:{[P]:!1,[b]:""}})}})),e&&(0,t.createElement)("div",{className:"sppp__link"},(0,t.createElement)(m,null))))}})})();1 (()=>{"use strict";const e=window.wp.plugins,t=window.wp.components,s=window.wp.data,o=window.wp.editor,i=window.wp.i18n,n=window.wp.coreData,r=({children:e})=>{const{isPostTypeVisible:t,postType:i,isPostPrivate:r}=(0,s.useSelect)((e=>{let t=!1;const s=e(o.store).getCurrentPostType(),i=e(n.store).getPostType(s),r=e(o.store).getEditedPostAttribute("link"),a=e(o.store).getEditedPostVisibility();return i?.viewable&&(t=!0),r&&(t=!0),e(o.store).getPermalinkParts()&&(t=!0),{isPostTypeVisible:t,postType:s,isPostPrivate:"private"===a||"password"===a}}),[]),a=window.privatePostShare&&window.privatePostShare.settings.postTypes.includes(i);return window.privatePostShare&&window.privatePostShare.settings.hasPermissions&&t&&a&&r?e:null},a={META_ENABLED:"_sppp_enabled",META_KEY:"_sppp_key",QUERY_PARAM:"_sppp_key"},p=window.wp.compose,l=window.wp.element,d=window.wp.url,c=window.ReactJSXRuntime,{META_KEY:h,QUERY_PARAM:w}=a,u=({text:e,onCopy:s,children:o,...i})=>{const n=(0,p.useCopyToClipboard)(e,s);return(0,c.jsx)(t.Button,{variant:"secondary",ref:n,...i,children:o})};class m extends l.Component{constructor(){super(...arguments),this.state={showCopyConfirmation:!1},this.onCopy=this.onCopy.bind(this),this.onSelectInput=this.onSelectInput.bind(this)}componentWillUnmount(){clearTimeout(this.dismissCopyConfirmation)}onCopy(){this.setState({showCopyConfirmation:!0}),clearTimeout(this.dismissCopyConfirmation),this.dismissCopyConfirmation=setTimeout((()=>{this.setState({showCopyConfirmation:!1})}),4e3)}onSelectInput(e){e.target.select()}render(){const e=(0,d.addQueryArgs)(this.props.postLink,{[w]:this.props.secretKey});return(0,c.jsxs)("div",{children:[(0,c.jsx)("label",{htmlFor:"private-post-share-link-field",className:"screen-reader-text",children:(0,i.__)("Share this URL","sharable-password-protected-posts")}),(0,c.jsxs)(t.Flex,{className:"private-post-share__link-copy",children:[(0,c.jsx)(t.TextControl,{id:"private-post-share-link-field",className:"private-post-share__link-field",readOnly:!0,label:(0,i.__)("Secret URL:","sharable-password-protected-posts"),value:(0,d.safeDecodeURIComponent)(e),onFocus:this.onSelectInput}),(0,c.jsx)(u,{text:e,onCopy:this.onCopy,className:"private-post-share__copy-button",children:this.state.showCopyConfirmation?(0,i.__)("Copied!","sharable-password-protected-posts"):(0,i.__)("Copy","sharable-password-protected-posts")})]})]})}}const y=(0,s.withSelect)((e=>{const{getEditedPostAttribute:t,getPermalink:s}=e(o.store);return{postLink:s(),secretKey:t("meta")[h]}}))(m);var _,P;const C=null!==(_=null!==(P=wp.editor?.PluginPostStatusInfo)&&void 0!==P?P:wp.editPost?.PluginPostStatusInfo)&&void 0!==_?_:wp.editSite?.PluginPostStatusInfo,{META_ENABLED:v,META_KEY:b}=a;(0,e.registerPlugin)("private-post-share",{render:()=>{const{sharingEnabled:e,existingKey:n}=(0,s.useSelect)((e=>{const{getEditedPostAttribute:t}=e(o.store),s=t("meta");return{sharingEnabled:s?.[v]||null,existingKey:s?.[b]||null}})),{editPost:a}=(0,s.useDispatch)(o.store);return(0,c.jsx)(C,{className:"private-post-share",children:(0,c.jsxs)(r,{children:[(0,c.jsx)("div",{className:"private-post-share__checkbox",children:(0,c.jsx)(t.CheckboxControl,{label:(0,i.__)("Share post via secret URL","sharable-password-protected-posts"),checked:!!e,onChange:e=>{a(e?{meta:{[v]:!0,[b]:n||window.privatePostShare.newKey||""}}:{meta:{[v]:!1,[b]:""}})}})}),e&&(0,c.jsx)("div",{className:"private-post-share__link",children:(0,c.jsx)(y,{})})]})})}})})(); -
sharable-password-protected-posts/trunk/languages/sharable-password-protected-posts-de_DE.l10n.php
r3145331 r3342923 1 1 <?php 2 return ['domain'=>'sharable-password-protected-posts','plural-forms'=>'nplurals=2; plural=(n != 1);','language'=>'de_DE','project-id-version'=>'Sharable Password Protected Posts 0.1.0','pot-creation-date'=>'202 2-10-29T08:32:09+00:00','po-revision-date'=>'2022-10-29 10:35+0200','x-generator'=>'Poedit 3.2','messages'=>['Sharable Password Protected Posts'=>'Passwortgeschützte Posts teilen','Share password protected posts via secret URLs'=>'Teile passwortgeschützte Beiträge mit geheimen URLs','Share this URL'=>'Teile diese URL','Secret URL:'=>'Geheime URL:','Copied!'=>'Kopiert!','Copy'=>'Kopieren','Share post via secret URL'=>'Beitrag mit geheimer URL teilen']];2 return ['domain'=>'sharable-password-protected-posts','plural-forms'=>'nplurals=2; plural=(n != 1);','language'=>'de_DE','project-id-version'=>'Sharable Password Protected Posts 0.1.0','pot-creation-date'=>'2025-08-11T15:46:21+02:00','po-revision-date'=>'2025-08-11 15:47+0200','x-generator'=>'Poedit 3.6','messages'=>['Share password protected posts via secret URLs'=>'Teile passwortgeschützte Beiträge mit geheimen URLs','Share this URL'=>'Teile diese URL','Secret URL:'=>'Geheime URL:','Copied!'=>'Kopiert!','Copy'=>'Kopieren','Share post via secret URL'=>'Beitrag mit geheimer URL teilen']]; -
sharable-password-protected-posts/trunk/languages/sharable-password-protected-posts-de_DE.po
r2809716 r3342923 4 4 msgstr "" 5 5 "Project-Id-Version: Sharable Password Protected Posts 0.1.0\n" 6 "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/sharable-password-" 7 "protected-posts\n" 8 "POT-Creation-Date: 2022-10-29T08:32:09+00:00\n" 9 "PO-Revision-Date: 2022-10-29 10:35+0200\n" 6 "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/html\n" 7 "POT-Creation-Date: 2025-08-11T15:46:21+02:00\n" 8 "PO-Revision-Date: 2025-08-11 15:47+0200\n" 10 9 "Last-Translator: \n" 11 10 "Language-Team: \n" … … 15 14 "Content-Transfer-Encoding: 8bit\n" 16 15 "Plural-Forms: nplurals=2; plural=(n != 1);\n" 17 "X-Generator: Poedit 3. 2\n"16 "X-Generator: Poedit 3.6\n" 18 17 "X-Domain: sharable-password-protected-posts\n" 19 18 20 19 #. Plugin Name of the plugin 21 msgid "Sharable Password Protected Posts" 22 msgstr "Passwortgeschützte Posts teilen" 20 #: sharable-password-protected-posts.php 21 msgid "Private Post Share" 22 msgstr "" 23 23 24 24 #. Description of the plugin 25 #: sharable-password-protected-posts.php 25 26 msgid "Share password protected posts via secret URLs" 26 27 msgstr "Teile passwortgeschützte Beiträge mit geheimen URLs" 27 28 28 29 #. Author of the plugin 30 #: sharable-password-protected-posts.php 29 31 msgid "Fabian Todt" 30 32 msgstr "" 31 33 32 #: src/PostStatusSettings/CopyUrl.js:63 34 #. Author URI of the plugin 35 #: sharable-password-protected-posts.php 36 msgid "https://fabiantodt.at/" 37 msgstr "" 38 39 #: build/index.js:1 src/PostStatusSettings/CopyUrl.js:66 33 40 msgid "Share this URL" 34 41 msgstr "Teile diese URL" 35 42 36 #: src/PostStatusSettings/CopyUrl.js:7043 #: build/index.js:1 src/PostStatusSettings/CopyUrl.js:73 37 44 msgid "Secret URL:" 38 45 msgstr "Geheime URL:" 39 46 40 #: src/PostStatusSettings/CopyUrl.js:7647 #: build/index.js:1 src/PostStatusSettings/CopyUrl.js:85 41 48 msgid "Copied!" 42 49 msgstr "Kopiert!" 43 50 44 #: src/PostStatusSettings/CopyUrl.js:7751 #: build/index.js:1 src/PostStatusSettings/CopyUrl.js:86 45 52 msgid "Copy" 46 53 msgstr "Kopieren" 47 54 48 #: src/PostStatusSettings/index.js:4155 #: build/index.js:1 src/PostStatusSettings/index.js:50 49 56 msgid "Share post via secret URL" 50 57 msgstr "Beitrag mit geheimer URL teilen" 58 59 #~ msgid "Sharable Password Protected Posts" 60 #~ msgstr "Passwortgeschützte Posts teilen" -
sharable-password-protected-posts/trunk/languages/sharable-password-protected-posts.pot
r2809749 r3342923 1 # Copyright (C) 202 2Fabian Todt1 # Copyright (C) 2025 Fabian Todt 2 2 # This file is distributed under the GPL-2.0-or-later. 3 3 msgid "" 4 4 msgstr "" 5 "Project-Id-Version: Sharable Password Protected Posts 1.0.2\n"6 "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/ sharable-password-protected-posts\n"5 "Project-Id-Version: Private Post Share 2.0.0\n" 6 "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/html\n" 7 7 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" 8 8 "Language-Team: LANGUAGE <[email protected]>\n" … … 10 10 "Content-Type: text/plain; charset=UTF-8\n" 11 11 "Content-Transfer-Encoding: 8bit\n" 12 "POT-Creation-Date: 202 2-11-02T10:02:27+00:00\n"12 "POT-Creation-Date: 2025-08-11T15:47:59+02:00\n" 13 13 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" 14 "X-Generator: WP-CLI 2. 7.1\n"14 "X-Generator: WP-CLI 2.12.0\n" 15 15 "X-Domain: sharable-password-protected-posts\n" 16 16 17 17 #. Plugin Name of the plugin 18 msgid "Sharable Password Protected Posts" 18 #: sharable-password-protected-posts.php 19 msgid "Private Post Share" 19 20 msgstr "" 20 21 21 22 #. Description of the plugin 23 #: sharable-password-protected-posts.php 22 24 msgid "Share password protected posts via secret URLs" 23 25 msgstr "" 24 26 25 27 #. Author of the plugin 28 #: sharable-password-protected-posts.php 26 29 msgid "Fabian Todt" 27 30 msgstr "" 28 31 29 32 #. Author URI of the plugin 30 msgid "https://fabiantodt.at/en/" 33 #: sharable-password-protected-posts.php 34 msgid "https://fabiantodt.at/" 31 35 msgstr "" 32 36 33 #: src/PostStatusSettings/CopyUrl.js:63 37 #: build/index.js:1 38 #: src/PostStatusSettings/CopyUrl.js:66 34 39 msgid "Share this URL" 35 40 msgstr "" 36 41 37 #: src/PostStatusSettings/CopyUrl.js:70 42 #: build/index.js:1 43 #: src/PostStatusSettings/CopyUrl.js:73 38 44 msgid "Secret URL:" 39 45 msgstr "" 40 46 41 #: src/PostStatusSettings/CopyUrl.js:76 47 #: build/index.js:1 48 #: src/PostStatusSettings/CopyUrl.js:85 42 49 msgid "Copied!" 43 50 msgstr "" 44 51 45 #: src/PostStatusSettings/CopyUrl.js:77 52 #: build/index.js:1 53 #: src/PostStatusSettings/CopyUrl.js:86 46 54 msgid "Copy" 47 55 msgstr "" 48 56 49 #: src/PostStatusSettings/index.js:41 57 #: build/index.js:1 58 #: src/PostStatusSettings/index.js:50 50 59 msgid "Share post via secret URL" 51 60 msgstr "" -
sharable-password-protected-posts/trunk/sharable-password-protected-posts.php
r3310392 r3342923 1 1 <?php 2 3 2 /** 4 * Plugin Name: Sharable Password Protected Posts3 * Plugin Name: Private Post Share 5 4 * Description: Share password protected posts via secret URLs 6 * Requires at least: 6. 07 * Requires PHP: 7.48 * Version: 1.1.15 * Requires at least: 6.7 6 * Requires PHP: 8.1 7 * Version: 2.0.0 9 8 * Author: Fabian Todt 10 * Author URI: https://fabiantodt.at/ en/9 * Author URI: https://fabiantodt.at/ 11 10 * License: GPL-2.0-or-later 12 11 * License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 14 13 * Domain Path: /languages 15 14 * 16 * @package SPPP15 * @package Private_Post_Share 17 16 */ 18 17 19 namespace SPPP;18 namespace Private_Post_Share; 20 19 21 /** 22 * Adds JS & CSS to editor 23 * 24 * @return void 25 */ 26 function addEditorAssets() 27 { 28 $assetFile = plugin_dir_path(__FILE__) . 'build/index.asset.php'; 29 if (!file_exists($assetFile)) { 30 throw new \Exception('You have to build the scripts before loading them'); 31 } 32 $assetsConfig = require($assetFile); 20 defined( 'ABSPATH' ) || exit; 33 21 34 $jsData = [ 35 'settings' => [ 36 'postTypes' => getEnabledPostTypes(), 37 'hasPermissions' => current_user_can('publish_posts'), 38 ], 39 'newKey' => generateKey(), 40 ]; 22 define( 'PRIVATE_POST_SHARE_PLUGIN_FILE', __FILE__ ); 23 define( 'PRIVATE_POST_SHARE_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); 41 24 42 $scriptDependencies = $assetsConfig['dependencies']; 43 // For WordPress < 6.6 the editor script depends on wp-edit-post (because of PluginPostStatusInfo) 44 // but the script is built against 6.6, therefore only requiring the wp-editor script. 45 require ABSPATH . WPINC . '/version.php'; 46 if(version_compare($wp_version, '6.6', '<')) { 47 $scriptDependencies[] = 'wp-edit-post'; 48 } 25 require_once PRIVATE_POST_SHARE_PLUGIN_DIR . 'vendor/vendor-prefixed/autoload.php'; 26 require_once PRIVATE_POST_SHARE_PLUGIN_DIR . 'vendor/autoload.php'; 49 27 50 wp_enqueue_script( 51 'sppp', 52 plugin_dir_url(__FILE__) . 'build/index.js', 53 $scriptDependencies, 54 $assetsConfig['version'] 55 ); 56 57 wp_enqueue_style( 58 'sppp', 59 plugin_dir_url(__FILE__) . 'build/index.css', 60 [], 61 $assetsConfig['version'] 62 ); 63 64 wp_add_inline_script('sppp', 'window.sppp = ' . json_encode($jsData) . ';', 'before'); 65 } 66 add_action('enqueue_block_editor_assets', __NAMESPACE__ . '\addEditorAssets'); 67 68 function loadLanguages() 69 { 70 load_plugin_textdomain( 71 'sharable-password-protected-posts', 72 false, 73 dirname(plugin_dir_path(__FILE__)) . 'languages' 74 ); 75 } 76 add_action('init', __NAMESPACE__ . '\loadLanguages'); 77 78 /** 79 * Registers the two meta fields 80 * 81 * @return void 82 */ 83 function registerMeta() 84 { 85 $enabledMetaField = [ 86 'show_in_rest' => [ 87 'schema' => [ 88 'context' => ['edit'] // Only show when editing. 89 ], 90 // Additionally, hide value when user is not allowed to edit the post. 91 'prepare_callback' => function ($value, $request, $args) { 92 global $post; 93 // WP_REST_Posts_Controller set global post instance. 94 $postId = $post ? $post->ID : $request['id']; 95 96 $allowed = $postId ? current_user_can('edit_post', $postId) : current_user_can('edit_posts'); 97 return $allowed ? $value : null; 98 } 99 ], 100 'single' => true, 101 'type' => 'boolean', 102 'default' => false, 103 'auth_callback' => function ($allowed, $meta_key, $objectId, $userId) { 104 if ($userId) { 105 return user_can($userId, 'publish_posts', $objectId); 106 } 107 return current_user_can('publish_posts', $objectId); 108 }, 109 'sanitize_callback' => function ($value) { 110 if ($value === true || $value === 1 || $value === '1' || $value === 'true') { 111 $value = true; 112 } else { 113 $value = false; 114 } 115 return $value; 116 }, 117 ]; 118 119 $keyMetaField = [ 120 'show_in_rest' => [ 121 'schema' => [ 122 'context' => ['edit'] // Only show when editing. 123 ], 124 // Additionally, hide value when user is not allowed to edit the post. 125 'prepare_callback' => function ($value, $request, $args) { 126 global $post; 127 // WP_REST_Posts_Controller set global post instance. 128 $postId = $post ? $post->ID : $request['id']; 129 130 $allowed = $postId ? current_user_can('edit_post', $postId) : current_user_can('edit_posts'); 131 return $allowed ? $value : null; 132 } 133 ], 134 'single' => true, 135 'type' => 'string', 136 'default' => '', 137 'auth_callback' => function ($allowed, $meta_key, $objectId, $userId) { 138 if ($userId) { 139 return user_can($userId, 'publish_posts', $objectId); 140 } 141 return current_user_can('publish_posts', $objectId); 142 }, 143 'sanitize_callback' => function ($value) { 144 $value = sanitize_text_field(trim($value)); 145 if (empty($value)) { 146 return generateKey(); 147 } 148 return $value; 149 } 150 ]; 151 152 $postTypes = getEnabledPostTypes(); 153 154 foreach ($postTypes as $postType) { 155 register_post_meta($postType, '_sppp_enabled', $enabledMetaField); 156 register_post_meta($postType, '_sppp_key', $keyMetaField); 157 } 158 } 159 add_action('init', __NAMESPACE__ . '\registerMeta'); 160 161 /** 162 * Filters the main queries posts_results - for PRIVATE posts 163 * Sets the post elements status to 'publish' if it can be viewed with the key 164 * this will let the rest of WP_Query thandle the post as normal 165 * 166 * This only filters the main query's WP_Post instance, not all other objects 167 * that may be get via get_post; but using get_queried_object will work 168 * 169 * @param \WP_Post[] $posts 170 * @param \WP_Query $query 171 * @return void 172 */ 173 function filterPostsQuery($posts, $query) 174 { 175 // only handle the main query 176 if (!$query->is_main_query()) { 177 return $posts; 178 } 179 180 // only handle single views, don't handle not-found posts 181 if (count($posts) !== 1) { 182 return $posts; 183 } 184 185 $mainPost = $posts[0]; 186 $enabledPostTypes = getEnabledPostTypes(); 187 188 // if the main (single) post has a not-enabled post type, bail early 189 if (!in_array($mainPost->post_type, $enabledPostTypes)) { 190 return $posts; 191 } 192 193 // if a post type was specifically queried, check if only allowed/enabled post types where queried 194 $postTypes = $query->get('post_type'); 195 if (!empty($postTypes) && (is_array($postTypes) || is_string($postTypes))) { 196 // if a post type is queried (maybe one of multiple), that is not enabled bail early 197 if ( 198 !empty($postTypes) && 199 !empty(array_diff((array)$postTypes, $enabledPostTypes)) 200 ) { 201 return $posts; 202 } 203 } 204 205 // should only be 1 on singulars normally 206 foreach ($posts as &$post) { 207 if (canPostBeViewedWithKey($post)) { 208 $post->post_status = 'publish'; 209 } 210 } 211 return $posts; 212 } 213 add_filter('posts_results', __NAMESPACE__ . '\filterPostsQuery', 10, 2); 214 215 /** 216 * Filters whether a post password form is required - for PASSWORD protected posts 217 * 218 * @param bool $required 219 * @param \WP_Post $post 220 * @return bool 221 */ 222 function filterPostPasswordRequired($required, $post) 223 { 224 $enabledPostTypes = getEnabledPostTypes(); 225 226 // if the post has a not-enabled post type, bail early 227 if (!in_array($post->post_type, $enabledPostTypes)) { 228 return $required; 229 } 230 231 if (canPostBeViewedWithKey($post)) { 232 return false; 233 } 234 return $required; 235 } 236 add_filter('post_password_required', __NAMESPACE__ . '\filterPostPasswordRequired', 10, 2); 237 238 /** 239 * Removes the "Protected" from password protected/private posts 240 * if they can be viewd with the current url key 241 * 242 * @param string $prefix 243 * @param WP_Post|int $post 244 * @return string 245 */ 246 function filterPostTitlePrefix($prefix, $post) 247 { 248 if (canPostBeViewedWithKey($post)) { 249 return '%s'; 250 } 251 return $prefix; 252 } 253 add_filter('protected_title_format', __NAMESPACE__ . '\filterPostTitlePrefix', 10, 2); 254 add_filter('private_title_format', __NAMESPACE__ . '\filterPostTitlePrefix', 10, 2); 255 256 /** 257 * Whether a given post can be viewed with a given key 258 * 259 * @param \WP_Post $post The post to check for 260 * @param string $key A key to check against, defaults to the $_GET parameters 261 * @return bool False if the post is not private/protected or if SPPP is not enabled; 262 * True if key can be used to view the private post 263 */ 264 function canPostBeViewedWithKey($post, $key = null) 265 { 266 if (!$key) { 267 if (empty($_GET['_sppp_key'])) { 268 return false; 269 } 270 $key = sanitize_text_field($_GET['_sppp_key']); 271 } 272 273 if (empty($key)) { 274 return false; 275 } 276 277 if (empty($post->post_password) && $post->post_status !== 'private') { 278 return false; 279 } 280 281 $isKeyValid = isKeyValid($key, $post); 282 283 if ($isKeyValid) { 284 return true; 285 } 286 return false; 287 } 288 289 /** 290 * Checks the given key by the user against the stored key 291 * 292 * @param string $userKey 293 * @param WP_Post|int $post 294 * @return bool False if key is not valid or SPPP is not enabled for this post 295 */ 296 function isKeyValid($userKey, $post) 297 { 298 if (empty($userKey)) { 299 return false; 300 } 301 302 $postId = is_a($post, 'WP_Post') ? $post->ID : $post; 303 304 $isEnabled = get_post_meta($postId, '_sppp_enabled', true); 305 if (!$isEnabled) { 306 return false; 307 } 308 $savedKey = get_post_meta($postId, '_sppp_key', true); 309 310 if (empty($savedKey)) { 311 return false; 312 } 313 314 return $savedKey === $userKey; 315 } 316 317 /** 318 * Get enabled post types for SPPP 319 * 320 * @return string[] name of post types 321 */ 322 function getEnabledPostTypes() 323 { 324 /** 325 * Allows filtering the post types for which SPPP is enabled 326 * By default it's enabled for all public post types 327 * 328 * @param string[] $postTypes array of post type names (slugs) 329 */ 330 return apply_filters('sppp/postTypes', array_keys(get_post_types([ 331 'public' => true, 332 ], 'names'))); 333 } 334 335 /** 336 * Generate a new secret key 337 * 338 * @return string 339 */ 340 function generateKey() 341 { 342 return wp_generate_password(15, false); 343 } 28 require_once PRIVATE_POST_SHARE_PLUGIN_DIR . 'includes/functions.php'; 29 require_once PRIVATE_POST_SHARE_PLUGIN_DIR . 'includes/editor.php'; 30 require_once PRIVATE_POST_SHARE_PLUGIN_DIR . 'includes/meta.php'; 31 require_once PRIVATE_POST_SHARE_PLUGIN_DIR . 'includes/posts.php'; -
sharable-password-protected-posts/trunk/src/PostStatusSettings/Check.js
r2809716 r3342923 1 import { store as coreStore } from "@wordpress/core-data"; 1 2 import { useSelect } from "@wordpress/data"; 2 import { store as coreStore } from "@wordpress/core-data";3 3 import { store as editorStore } from "@wordpress/editor"; 4 4 … … 10 10 */ 11 11 const Check = ({ children }) => { 12 const { isPostTypeVisible, postType, isPostPrivate } = useSelect((select) => { 13 let isPostTypeVisible = false; 14 const postTypeSlug = select(editorStore).getCurrentPostType(); 15 const postType = select(coreStore).getPostType(postTypeSlug); 16 const link = select(editorStore).getEditedPostAttribute("link"); 17 const editedPostVisibility = select(editorStore).getEditedPostVisibility(); 12 const { isPostTypeVisible, postType, isPostPrivate } = useSelect( 13 (select) => { 14 let isPostTypeVisible = false; 15 const postTypeSlug = select(editorStore).getCurrentPostType(); 16 const postType = select(coreStore).getPostType(postTypeSlug); 17 const link = select(editorStore).getEditedPostAttribute("link"); 18 const editedPostVisibility = 19 select(editorStore).getEditedPostVisibility(); 18 20 19 if (postType?.viewable) {20 isPostTypeVisible = true;21 }21 if (postType?.viewable) { 22 isPostTypeVisible = true; 23 } 22 24 23 if (link) {24 isPostTypeVisible = true;25 }25 if (link) { 26 isPostTypeVisible = true; 27 } 26 28 27 const permalinkParts = select(editorStore).getPermalinkParts();28 if (permalinkParts) {29 isPostTypeVisible = true;30 }29 const permalinkParts = select(editorStore).getPermalinkParts(); 30 if (permalinkParts) { 31 isPostTypeVisible = true; 32 } 31 33 32 return { 33 isPostTypeVisible, 34 postType: postTypeSlug, 35 isPostPrivate: editedPostVisibility === "private" || editedPostVisibility === "password", 36 }; 37 }, []); 34 return { 35 isPostTypeVisible, 36 postType: postTypeSlug, 37 isPostPrivate: 38 editedPostVisibility === "private" || 39 editedPostVisibility === "password", 40 }; 41 }, 42 [] 43 ); 38 44 39 const isEnabledForPostType = window.sppp && window.sppp.settings.postTypes.includes(postType); 40 const hasPermissions = window.sppp && window.sppp.settings.hasPermissions; 45 const isEnabledForPostType = 46 window.privatePostShare && 47 window.privatePostShare.settings.postTypes.includes(postType); 48 const hasPermissions = 49 window.privatePostShare && 50 window.privatePostShare.settings.hasPermissions; 41 51 42 if (!hasPermissions || !isPostTypeVisible || !isEnabledForPostType || !isPostPrivate) { 52 if ( 53 !hasPermissions || 54 !isPostTypeVisible || 55 !isEnabledForPostType || 56 !isPostPrivate 57 ) { 43 58 return null; 44 59 } -
sharable-password-protected-posts/trunk/src/PostStatusSettings/CopyUrl.js
r2809716 r3342923 1 import { Button, Flex, TextControl } from "@wordpress/components"; 2 import { useCopyToClipboard } from "@wordpress/compose"; 3 import { withSelect } from "@wordpress/data"; 4 import { store as editorStore } from "@wordpress/editor"; 1 5 import { Component } from "@wordpress/element"; 2 import { safeDecodeURIComponent, addQueryArgs } from "@wordpress/url";3 import { TextControl, Button, Flex } from "@wordpress/components";4 import { withSelect } from "@wordpress/data";5 import { useCopyToClipboard } from "@wordpress/compose";6 import { store as editorStore } from "@wordpress/editor";7 6 import { __ } from "@wordpress/i18n"; 7 import { addQueryArgs, safeDecodeURIComponent } from "@wordpress/url"; 8 8 9 9 import CONSTANTS from "./constants"; 10 10 11 const { META_KEY, QUERY_PARAM } = CONSTANTS; 11 12 … … 60 61 return ( 61 62 <div> 62 <label htmlFor="sppp-link-field" className="screen-reader-text"> 63 <label 64 htmlFor="private-post-share-link-field" 65 className="screen-reader-text"> 63 66 {__("Share this URL", "sharable-password-protected-posts")} 64 67 </label> 65 <Flex className=" sppp__link-copy">68 <Flex className="private-post-share__link-copy"> 66 69 <TextControl 67 id=" sppp-link-field"68 className=" sppp__link-field"70 id="private-post-share-link-field" 71 className="private-post-share__link-field" 69 72 readOnly 70 label={__("Secret URL:", "sharable-password-protected-posts")} 73 label={__( 74 "Secret URL:", 75 "sharable-password-protected-posts" 76 )} 71 77 value={safeDecodeURIComponent(url)} 72 78 onFocus={this.onSelectInput} 73 79 /> 74 <CopyButton text={url} onCopy={this.onCopy} className="sppp__copy-button"> 80 <CopyButton 81 text={url} 82 onCopy={this.onCopy} 83 className="private-post-share__copy-button"> 75 84 {this.state.showCopyConfirmation 76 85 ? __("Copied!", "sharable-password-protected-posts") -
sharable-password-protected-posts/trunk/src/PostStatusSettings/index.js
r3145331 r3342923 1 1 import { CheckboxControl } from "@wordpress/components"; 2 import { useDispatch, useSelect } from "@wordpress/data"; 3 import { store as editorStore } from "@wordpress/editor"; 2 4 import { __ } from "@wordpress/i18n"; 3 import { useSelect, useDispatch } from "@wordpress/data";4 import { store as editorStore } from "@wordpress/editor";5 import Check from "./Check"; 6 import CONSTANTS from "./constants"; 5 7 import CopyUrl from "./CopyUrl"; 6 import Check from "./Check";8 import "./styles.scss"; 7 9 8 10 // Support < WP 6.6 and > WP 6.6 9 11 // See https://make.wordpress.org/core/2024/06/18/editor-unified-extensibility-apis-in-6-6/ 10 const PluginPostStatusInfo = wp.editor?.PluginPostStatusInfo ?? ( wp.editPost?.PluginPostStatusInfo ?? wp.editSite?.PluginPostStatusInfo ); 12 const PluginPostStatusInfo = 13 wp.editor?.PluginPostStatusInfo ?? 14 wp.editPost?.PluginPostStatusInfo ?? 15 wp.editSite?.PluginPostStatusInfo; 11 16 12 import CONSTANTS from "./constants";13 17 const { META_ENABLED, META_KEY } = CONSTANTS; 14 15 import "./styles.scss";16 18 17 19 const PostStatusSettings = () => { … … 28 30 if (value) { 29 31 editPost({ 30 meta: { [META_ENABLED]: true, [META_KEY]: existingKey || window.sppp.newKey || "" }, 32 meta: { 33 [META_ENABLED]: true, 34 [META_KEY]: 35 existingKey || window.privatePostShare.newKey || "", 36 }, 31 37 }); 32 38 } else { … … 38 44 39 45 return ( 40 <PluginPostStatusInfo className=" sppp">46 <PluginPostStatusInfo className="private-post-share"> 41 47 <Check> 42 <div className=" sppp__checkbox">48 <div className="private-post-share__checkbox"> 43 49 <CheckboxControl 44 label={__("Share post via secret URL", "sharable-password-protected-posts")} 50 label={__( 51 "Share post via secret URL", 52 "sharable-password-protected-posts" 53 )} 45 54 checked={!!sharingEnabled} // Cast to bool, so null value after changing and reloading state does not trigger uncontrolled input warning. 46 55 onChange={onChangeEnabled} … … 49 58 50 59 {sharingEnabled && ( 51 <div className=" sppp__link">60 <div className="private-post-share__link"> 52 61 <CopyUrl /> 53 62 </div> -
sharable-password-protected-posts/trunk/src/PostStatusSettings/styles.scss
r2809716 r3342923 1 .components-panel__row. sppp{1 .components-panel__row.private-post-share { 2 2 flex-direction: column; 3 3 align-items: flex-start; 4 4 5 . sppp__link-copy {5 .private-post-share__link-copy { 6 6 display: flex; 7 7 align-items: flex-end; … … 11 11 } 12 12 13 . sppp__link-field {13 .private-post-share__link-field { 14 14 flex: 1; 15 15 } … … 22 22 } 23 23 24 . sppp__copy-button {24 .private-post-share__copy-button { 25 25 flex-shrink: 0; 26 26 margin-left: 8px; // margin left for copy button -
sharable-password-protected-posts/trunk/src/index.js
r2809716 r3342923 2 2 import PostStatusSettings from "./PostStatusSettings"; 3 3 4 registerPlugin(" sharable-password-protected-posts", {5 render: PostStatusSettings,4 registerPlugin("private-post-share", { 5 render: PostStatusSettings, 6 6 });
Note: See TracChangeset
for help on using the changeset viewer.