Plugin Directory

Changeset 3342923


Ignore:
Timestamp:
08/11/2025 01:55:23 PM (4 months ago)
Author:
gaambo
Message:

Update to version 2.0.0 from GitHub

Location:
sharable-password-protected-posts
Files:
50 added
4 deleted
26 edited
1 copied

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  
    11<?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'=>'2022-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']];
     2return ['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  
    44msgstr ""
    55"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"
    109"Last-Translator: \n"
    1110"Language-Team: \n"
     
    1514"Content-Transfer-Encoding: 8bit\n"
    1615"Plural-Forms: nplurals=2; plural=(n != 1);\n"
    17 "X-Generator: Poedit 3.2\n"
     16"X-Generator: Poedit 3.6\n"
    1817"X-Domain: sharable-password-protected-posts\n"
    1918
    2019#. Plugin Name of the plugin
    21 msgid "Sharable Password Protected Posts"
    22 msgstr "Passwortgeschützte Posts teilen"
     20#: sharable-password-protected-posts.php
     21msgid "Private Post Share"
     22msgstr ""
    2323
    2424#. Description of the plugin
     25#: sharable-password-protected-posts.php
    2526msgid "Share password protected posts via secret URLs"
    2627msgstr "Teile passwortgeschützte Beiträge mit geheimen URLs"
    2728
    2829#. Author of the plugin
     30#: sharable-password-protected-posts.php
    2931msgid "Fabian Todt"
    3032msgstr ""
    3133
    32 #: src/PostStatusSettings/CopyUrl.js:63
     34#. Author URI of the plugin
     35#: sharable-password-protected-posts.php
     36msgid "https://fabiantodt.at/"
     37msgstr ""
     38
     39#: build/index.js:1 src/PostStatusSettings/CopyUrl.js:66
    3340msgid "Share this URL"
    3441msgstr "Teile diese URL"
    3542
    36 #: src/PostStatusSettings/CopyUrl.js:70
     43#: build/index.js:1 src/PostStatusSettings/CopyUrl.js:73
    3744msgid "Secret URL:"
    3845msgstr "Geheime URL:"
    3946
    40 #: src/PostStatusSettings/CopyUrl.js:76
     47#: build/index.js:1 src/PostStatusSettings/CopyUrl.js:85
    4148msgid "Copied!"
    4249msgstr "Kopiert!"
    4350
    44 #: src/PostStatusSettings/CopyUrl.js:77
     51#: build/index.js:1 src/PostStatusSettings/CopyUrl.js:86
    4552msgid "Copy"
    4653msgstr "Kopieren"
    4754
    48 #: src/PostStatusSettings/index.js:41
     55#: build/index.js:1 src/PostStatusSettings/index.js:50
    4956msgid "Share post via secret URL"
    5057msgstr "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) 2022 Fabian Todt
     1# Copyright (C) 2025 Fabian Todt
    22# This file is distributed under the GPL-2.0-or-later.
    33msgid ""
    44msgstr ""
    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"
    77"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
    88"Language-Team: LANGUAGE <[email protected]>\n"
     
    1010"Content-Type: text/plain; charset=UTF-8\n"
    1111"Content-Transfer-Encoding: 8bit\n"
    12 "POT-Creation-Date: 2022-11-02T10:02:27+00:00\n"
     12"POT-Creation-Date: 2025-08-11T15:47:59+02:00\n"
    1313"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"
    1515"X-Domain: sharable-password-protected-posts\n"
    1616
    1717#. Plugin Name of the plugin
    18 msgid "Sharable Password Protected Posts"
     18#: sharable-password-protected-posts.php
     19msgid "Private Post Share"
    1920msgstr ""
    2021
    2122#. Description of the plugin
     23#: sharable-password-protected-posts.php
    2224msgid "Share password protected posts via secret URLs"
    2325msgstr ""
    2426
    2527#. Author of the plugin
     28#: sharable-password-protected-posts.php
    2629msgid "Fabian Todt"
    2730msgstr ""
    2831
    2932#. Author URI of the plugin
    30 msgid "https://fabiantodt.at/en/"
     33#: sharable-password-protected-posts.php
     34msgid "https://fabiantodt.at/"
    3135msgstr ""
    3236
    33 #: src/PostStatusSettings/CopyUrl.js:63
     37#: build/index.js:1
     38#: src/PostStatusSettings/CopyUrl.js:66
    3439msgid "Share this URL"
    3540msgstr ""
    3641
    37 #: src/PostStatusSettings/CopyUrl.js:70
     42#: build/index.js:1
     43#: src/PostStatusSettings/CopyUrl.js:73
    3844msgid "Secret URL:"
    3945msgstr ""
    4046
    41 #: src/PostStatusSettings/CopyUrl.js:76
     47#: build/index.js:1
     48#: src/PostStatusSettings/CopyUrl.js:85
    4249msgid "Copied!"
    4350msgstr ""
    4451
    45 #: src/PostStatusSettings/CopyUrl.js:77
     52#: build/index.js:1
     53#: src/PostStatusSettings/CopyUrl.js:86
    4654msgid "Copy"
    4755msgstr ""
    4856
    49 #: src/PostStatusSettings/index.js:41
     57#: build/index.js:1
     58#: src/PostStatusSettings/index.js:50
    5059msgid "Share post via secret URL"
    5160msgstr ""
  • sharable-password-protected-posts/tags/2.0.0/sharable-password-protected-posts.php

    r3310392 r3342923  
    11<?php
    2 
    32/**
    4  * Plugin Name:       Sharable Password Protected Posts
     3 * Plugin Name:       Private Post Share
    54 * Description:       Share password protected posts via secret URLs
    6  * Requires at least: 6.0
    7  * Requires PHP:      7.4
    8  * Version:           1.1.1
     5 * Requires at least: 6.7
     6 * Requires PHP:      8.1
     7 * Version:           2.0.0
    98 * Author:            Fabian Todt
    10  * Author URI:        https://fabiantodt.at/en/
     9 * Author URI:        https://fabiantodt.at/
    1110 * License:           GPL-2.0-or-later
    1211 * License URI:       https://www.gnu.org/licenses/gpl-2.0.html
     
    1413 * Domain Path:       /languages
    1514 *
    16  * @package           SPPP
     15 * @package           Private_Post_Share
    1716 */
    1817
    19 namespace SPPP;
     18namespace Private_Post_Share;
    2019
    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);
     20defined( 'ABSPATH' ) || exit;
    3321
    34     $jsData = [
    35         'settings' => [
    36             'postTypes' => getEnabledPostTypes(),
    37             'hasPermissions' => current_user_can('publish_posts'),
    38         ],
    39         'newKey' => generateKey(),
    40     ];
     22define( 'PRIVATE_POST_SHARE_PLUGIN_FILE', __FILE__ );
     23define( 'PRIVATE_POST_SHARE_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
    4124
    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     }
     25require_once PRIVATE_POST_SHARE_PLUGIN_DIR . 'vendor/vendor-prefixed/autoload.php';
     26require_once PRIVATE_POST_SHARE_PLUGIN_DIR . 'vendor/autoload.php';
    4927
    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 }
     28require_once PRIVATE_POST_SHARE_PLUGIN_DIR . 'includes/functions.php';
     29require_once PRIVATE_POST_SHARE_PLUGIN_DIR . 'includes/editor.php';
     30require_once PRIVATE_POST_SHARE_PLUGIN_DIR . 'includes/meta.php';
     31require_once PRIVATE_POST_SHARE_PLUGIN_DIR . 'includes/posts.php';
  • sharable-password-protected-posts/tags/2.0.0/src/PostStatusSettings/Check.js

    r2809716 r3342923  
     1import { store as coreStore } from "@wordpress/core-data";
    12import { useSelect } from "@wordpress/data";
    2 import { store as coreStore } from "@wordpress/core-data";
    33import { store as editorStore } from "@wordpress/editor";
    44
     
    1010 */
    1111const 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();
    1820
    19         if (postType?.viewable) {
    20             isPostTypeVisible = true;
    21         }
     21            if (postType?.viewable) {
     22                isPostTypeVisible = true;
     23            }
    2224
    23         if (link) {
    24             isPostTypeVisible = true;
    25         }
     25            if (link) {
     26                isPostTypeVisible = true;
     27            }
    2628
    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            }
    3133
    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    );
    3844
    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;
    4151
    42     if (!hasPermissions || !isPostTypeVisible || !isEnabledForPostType || !isPostPrivate) {
     52    if (
     53        !hasPermissions ||
     54        !isPostTypeVisible ||
     55        !isEnabledForPostType ||
     56        !isPostPrivate
     57    ) {
    4358        return null;
    4459    }
  • sharable-password-protected-posts/tags/2.0.0/src/PostStatusSettings/CopyUrl.js

    r2809716 r3342923  
     1import { Button, Flex, TextControl } from "@wordpress/components";
     2import { useCopyToClipboard } from "@wordpress/compose";
     3import { withSelect } from "@wordpress/data";
     4import { store as editorStore } from "@wordpress/editor";
    15import { 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";
    76import { __ } from "@wordpress/i18n";
     7import { addQueryArgs, safeDecodeURIComponent } from "@wordpress/url";
    88
    99import CONSTANTS from "./constants";
     10
    1011const { META_KEY, QUERY_PARAM } = CONSTANTS;
    1112
     
    6061        return (
    6162            <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">
    6366                    {__("Share this URL", "sharable-password-protected-posts")}
    6467                </label>
    65                 <Flex className="sppp__link-copy">
     68                <Flex className="private-post-share__link-copy">
    6669                    <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"
    6972                        readOnly
    70                         label={__("Secret URL:", "sharable-password-protected-posts")}
     73                        label={__(
     74                            "Secret URL:",
     75                            "sharable-password-protected-posts"
     76                        )}
    7177                        value={safeDecodeURIComponent(url)}
    7278                        onFocus={this.onSelectInput}
    7379                    />
    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">
    7584                        {this.state.showCopyConfirmation
    7685                            ? __("Copied!", "sharable-password-protected-posts")
  • sharable-password-protected-posts/tags/2.0.0/src/PostStatusSettings/index.js

    r3145331 r3342923  
    11import { CheckboxControl } from "@wordpress/components";
     2import { useDispatch, useSelect } from "@wordpress/data";
     3import { store as editorStore } from "@wordpress/editor";
    24import { __ } from "@wordpress/i18n";
    3 import { useSelect, useDispatch } from "@wordpress/data";
    4 import { store as editorStore } from "@wordpress/editor";
     5import Check from "./Check";
     6import CONSTANTS from "./constants";
    57import CopyUrl from "./CopyUrl";
    6 import Check from "./Check";
     8import "./styles.scss";
    79
    810// Support < WP 6.6 and > WP 6.6
    911// 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 );
     12const PluginPostStatusInfo =
     13    wp.editor?.PluginPostStatusInfo ??
     14    wp.editPost?.PluginPostStatusInfo ??
     15    wp.editSite?.PluginPostStatusInfo;
    1116
    12 import CONSTANTS from "./constants";
    1317const { META_ENABLED, META_KEY } = CONSTANTS;
    14 
    15 import "./styles.scss";
    1618
    1719const PostStatusSettings = () => {
     
    2830        if (value) {
    2931            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                },
    3137            });
    3238        } else {
     
    3844
    3945    return (
    40         <PluginPostStatusInfo className="sppp">
     46        <PluginPostStatusInfo className="private-post-share">
    4147            <Check>
    42                 <div className="sppp__checkbox">
     48                <div className="private-post-share__checkbox">
    4349                    <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                        )}
    4554                        checked={!!sharingEnabled} // Cast to bool, so null value after changing and reloading state does not trigger uncontrolled input warning.
    4655                        onChange={onChangeEnabled}
     
    4958
    5059                {sharingEnabled && (
    51                     <div className="sppp__link">
     60                    <div className="private-post-share__link">
    5261                        <CopyUrl />
    5362                    </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 {
    22    flex-direction: column;
    33    align-items: flex-start;
    44
    5     .sppp__link-copy {
     5    .private-post-share__link-copy {
    66        display: flex;
    77        align-items: flex-end;
     
    1111        }
    1212
    13         .sppp__link-field {
     13        .private-post-share__link-field {
    1414            flex: 1;
    1515        }
     
    2222        }
    2323
    24         .sppp__copy-button {
     24        .private-post-share__copy-button {
    2525            flex-shrink: 0;
    2626            margin-left: 8px; // margin left for copy button
  • sharable-password-protected-posts/tags/2.0.0/src/index.js

    r2809716 r3342923  
    22import PostStatusSettings from "./PostStatusSettings";
    33
    4 registerPlugin("sharable-password-protected-posts", {
    5     render: PostStatusSettings,
     4registerPlugin("private-post-share", {
     5    render: PostStatusSettings,
    66});
  • 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  
    11<?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'=>'2022-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']];
     2return ['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  
    44msgstr ""
    55"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"
    109"Last-Translator: \n"
    1110"Language-Team: \n"
     
    1514"Content-Transfer-Encoding: 8bit\n"
    1615"Plural-Forms: nplurals=2; plural=(n != 1);\n"
    17 "X-Generator: Poedit 3.2\n"
     16"X-Generator: Poedit 3.6\n"
    1817"X-Domain: sharable-password-protected-posts\n"
    1918
    2019#. Plugin Name of the plugin
    21 msgid "Sharable Password Protected Posts"
    22 msgstr "Passwortgeschützte Posts teilen"
     20#: sharable-password-protected-posts.php
     21msgid "Private Post Share"
     22msgstr ""
    2323
    2424#. Description of the plugin
     25#: sharable-password-protected-posts.php
    2526msgid "Share password protected posts via secret URLs"
    2627msgstr "Teile passwortgeschützte Beiträge mit geheimen URLs"
    2728
    2829#. Author of the plugin
     30#: sharable-password-protected-posts.php
    2931msgid "Fabian Todt"
    3032msgstr ""
    3133
    32 #: src/PostStatusSettings/CopyUrl.js:63
     34#. Author URI of the plugin
     35#: sharable-password-protected-posts.php
     36msgid "https://fabiantodt.at/"
     37msgstr ""
     38
     39#: build/index.js:1 src/PostStatusSettings/CopyUrl.js:66
    3340msgid "Share this URL"
    3441msgstr "Teile diese URL"
    3542
    36 #: src/PostStatusSettings/CopyUrl.js:70
     43#: build/index.js:1 src/PostStatusSettings/CopyUrl.js:73
    3744msgid "Secret URL:"
    3845msgstr "Geheime URL:"
    3946
    40 #: src/PostStatusSettings/CopyUrl.js:76
     47#: build/index.js:1 src/PostStatusSettings/CopyUrl.js:85
    4148msgid "Copied!"
    4249msgstr "Kopiert!"
    4350
    44 #: src/PostStatusSettings/CopyUrl.js:77
     51#: build/index.js:1 src/PostStatusSettings/CopyUrl.js:86
    4552msgid "Copy"
    4653msgstr "Kopieren"
    4754
    48 #: src/PostStatusSettings/index.js:41
     55#: build/index.js:1 src/PostStatusSettings/index.js:50
    4956msgid "Share post via secret URL"
    5057msgstr "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) 2022 Fabian Todt
     1# Copyright (C) 2025 Fabian Todt
    22# This file is distributed under the GPL-2.0-or-later.
    33msgid ""
    44msgstr ""
    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"
    77"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
    88"Language-Team: LANGUAGE <[email protected]>\n"
     
    1010"Content-Type: text/plain; charset=UTF-8\n"
    1111"Content-Transfer-Encoding: 8bit\n"
    12 "POT-Creation-Date: 2022-11-02T10:02:27+00:00\n"
     12"POT-Creation-Date: 2025-08-11T15:47:59+02:00\n"
    1313"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"
    1515"X-Domain: sharable-password-protected-posts\n"
    1616
    1717#. Plugin Name of the plugin
    18 msgid "Sharable Password Protected Posts"
     18#: sharable-password-protected-posts.php
     19msgid "Private Post Share"
    1920msgstr ""
    2021
    2122#. Description of the plugin
     23#: sharable-password-protected-posts.php
    2224msgid "Share password protected posts via secret URLs"
    2325msgstr ""
    2426
    2527#. Author of the plugin
     28#: sharable-password-protected-posts.php
    2629msgid "Fabian Todt"
    2730msgstr ""
    2831
    2932#. Author URI of the plugin
    30 msgid "https://fabiantodt.at/en/"
     33#: sharable-password-protected-posts.php
     34msgid "https://fabiantodt.at/"
    3135msgstr ""
    3236
    33 #: src/PostStatusSettings/CopyUrl.js:63
     37#: build/index.js:1
     38#: src/PostStatusSettings/CopyUrl.js:66
    3439msgid "Share this URL"
    3540msgstr ""
    3641
    37 #: src/PostStatusSettings/CopyUrl.js:70
     42#: build/index.js:1
     43#: src/PostStatusSettings/CopyUrl.js:73
    3844msgid "Secret URL:"
    3945msgstr ""
    4046
    41 #: src/PostStatusSettings/CopyUrl.js:76
     47#: build/index.js:1
     48#: src/PostStatusSettings/CopyUrl.js:85
    4249msgid "Copied!"
    4350msgstr ""
    4451
    45 #: src/PostStatusSettings/CopyUrl.js:77
     52#: build/index.js:1
     53#: src/PostStatusSettings/CopyUrl.js:86
    4654msgid "Copy"
    4755msgstr ""
    4856
    49 #: src/PostStatusSettings/index.js:41
     57#: build/index.js:1
     58#: src/PostStatusSettings/index.js:50
    5059msgid "Share post via secret URL"
    5160msgstr ""
  • sharable-password-protected-posts/trunk/sharable-password-protected-posts.php

    r3310392 r3342923  
    11<?php
    2 
    32/**
    4  * Plugin Name:       Sharable Password Protected Posts
     3 * Plugin Name:       Private Post Share
    54 * Description:       Share password protected posts via secret URLs
    6  * Requires at least: 6.0
    7  * Requires PHP:      7.4
    8  * Version:           1.1.1
     5 * Requires at least: 6.7
     6 * Requires PHP:      8.1
     7 * Version:           2.0.0
    98 * Author:            Fabian Todt
    10  * Author URI:        https://fabiantodt.at/en/
     9 * Author URI:        https://fabiantodt.at/
    1110 * License:           GPL-2.0-or-later
    1211 * License URI:       https://www.gnu.org/licenses/gpl-2.0.html
     
    1413 * Domain Path:       /languages
    1514 *
    16  * @package           SPPP
     15 * @package           Private_Post_Share
    1716 */
    1817
    19 namespace SPPP;
     18namespace Private_Post_Share;
    2019
    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);
     20defined( 'ABSPATH' ) || exit;
    3321
    34     $jsData = [
    35         'settings' => [
    36             'postTypes' => getEnabledPostTypes(),
    37             'hasPermissions' => current_user_can('publish_posts'),
    38         ],
    39         'newKey' => generateKey(),
    40     ];
     22define( 'PRIVATE_POST_SHARE_PLUGIN_FILE', __FILE__ );
     23define( 'PRIVATE_POST_SHARE_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
    4124
    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     }
     25require_once PRIVATE_POST_SHARE_PLUGIN_DIR . 'vendor/vendor-prefixed/autoload.php';
     26require_once PRIVATE_POST_SHARE_PLUGIN_DIR . 'vendor/autoload.php';
    4927
    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 }
     28require_once PRIVATE_POST_SHARE_PLUGIN_DIR . 'includes/functions.php';
     29require_once PRIVATE_POST_SHARE_PLUGIN_DIR . 'includes/editor.php';
     30require_once PRIVATE_POST_SHARE_PLUGIN_DIR . 'includes/meta.php';
     31require_once PRIVATE_POST_SHARE_PLUGIN_DIR . 'includes/posts.php';
  • sharable-password-protected-posts/trunk/src/PostStatusSettings/Check.js

    r2809716 r3342923  
     1import { store as coreStore } from "@wordpress/core-data";
    12import { useSelect } from "@wordpress/data";
    2 import { store as coreStore } from "@wordpress/core-data";
    33import { store as editorStore } from "@wordpress/editor";
    44
     
    1010 */
    1111const 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();
    1820
    19         if (postType?.viewable) {
    20             isPostTypeVisible = true;
    21         }
     21            if (postType?.viewable) {
     22                isPostTypeVisible = true;
     23            }
    2224
    23         if (link) {
    24             isPostTypeVisible = true;
    25         }
     25            if (link) {
     26                isPostTypeVisible = true;
     27            }
    2628
    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            }
    3133
    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    );
    3844
    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;
    4151
    42     if (!hasPermissions || !isPostTypeVisible || !isEnabledForPostType || !isPostPrivate) {
     52    if (
     53        !hasPermissions ||
     54        !isPostTypeVisible ||
     55        !isEnabledForPostType ||
     56        !isPostPrivate
     57    ) {
    4358        return null;
    4459    }
  • sharable-password-protected-posts/trunk/src/PostStatusSettings/CopyUrl.js

    r2809716 r3342923  
     1import { Button, Flex, TextControl } from "@wordpress/components";
     2import { useCopyToClipboard } from "@wordpress/compose";
     3import { withSelect } from "@wordpress/data";
     4import { store as editorStore } from "@wordpress/editor";
    15import { 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";
    76import { __ } from "@wordpress/i18n";
     7import { addQueryArgs, safeDecodeURIComponent } from "@wordpress/url";
    88
    99import CONSTANTS from "./constants";
     10
    1011const { META_KEY, QUERY_PARAM } = CONSTANTS;
    1112
     
    6061        return (
    6162            <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">
    6366                    {__("Share this URL", "sharable-password-protected-posts")}
    6467                </label>
    65                 <Flex className="sppp__link-copy">
     68                <Flex className="private-post-share__link-copy">
    6669                    <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"
    6972                        readOnly
    70                         label={__("Secret URL:", "sharable-password-protected-posts")}
     73                        label={__(
     74                            "Secret URL:",
     75                            "sharable-password-protected-posts"
     76                        )}
    7177                        value={safeDecodeURIComponent(url)}
    7278                        onFocus={this.onSelectInput}
    7379                    />
    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">
    7584                        {this.state.showCopyConfirmation
    7685                            ? __("Copied!", "sharable-password-protected-posts")
  • sharable-password-protected-posts/trunk/src/PostStatusSettings/index.js

    r3145331 r3342923  
    11import { CheckboxControl } from "@wordpress/components";
     2import { useDispatch, useSelect } from "@wordpress/data";
     3import { store as editorStore } from "@wordpress/editor";
    24import { __ } from "@wordpress/i18n";
    3 import { useSelect, useDispatch } from "@wordpress/data";
    4 import { store as editorStore } from "@wordpress/editor";
     5import Check from "./Check";
     6import CONSTANTS from "./constants";
    57import CopyUrl from "./CopyUrl";
    6 import Check from "./Check";
     8import "./styles.scss";
    79
    810// Support < WP 6.6 and > WP 6.6
    911// 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 );
     12const PluginPostStatusInfo =
     13    wp.editor?.PluginPostStatusInfo ??
     14    wp.editPost?.PluginPostStatusInfo ??
     15    wp.editSite?.PluginPostStatusInfo;
    1116
    12 import CONSTANTS from "./constants";
    1317const { META_ENABLED, META_KEY } = CONSTANTS;
    14 
    15 import "./styles.scss";
    1618
    1719const PostStatusSettings = () => {
     
    2830        if (value) {
    2931            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                },
    3137            });
    3238        } else {
     
    3844
    3945    return (
    40         <PluginPostStatusInfo className="sppp">
     46        <PluginPostStatusInfo className="private-post-share">
    4147            <Check>
    42                 <div className="sppp__checkbox">
     48                <div className="private-post-share__checkbox">
    4349                    <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                        )}
    4554                        checked={!!sharingEnabled} // Cast to bool, so null value after changing and reloading state does not trigger uncontrolled input warning.
    4655                        onChange={onChangeEnabled}
     
    4958
    5059                {sharingEnabled && (
    51                     <div className="sppp__link">
     60                    <div className="private-post-share__link">
    5261                        <CopyUrl />
    5362                    </div>
  • sharable-password-protected-posts/trunk/src/PostStatusSettings/styles.scss

    r2809716 r3342923  
    1 .components-panel__row.sppp {
     1.components-panel__row.private-post-share {
    22    flex-direction: column;
    33    align-items: flex-start;
    44
    5     .sppp__link-copy {
     5    .private-post-share__link-copy {
    66        display: flex;
    77        align-items: flex-end;
     
    1111        }
    1212
    13         .sppp__link-field {
     13        .private-post-share__link-field {
    1414            flex: 1;
    1515        }
     
    2222        }
    2323
    24         .sppp__copy-button {
     24        .private-post-share__copy-button {
    2525            flex-shrink: 0;
    2626            margin-left: 8px; // margin left for copy button
  • sharable-password-protected-posts/trunk/src/index.js

    r2809716 r3342923  
    22import PostStatusSettings from "./PostStatusSettings";
    33
    4 registerPlugin("sharable-password-protected-posts", {
    5     render: PostStatusSettings,
     4registerPlugin("private-post-share", {
     5    render: PostStatusSettings,
    66});
Note: See TracChangeset for help on using the changeset viewer.