Skip to content
This repository has been archived by the owner on Apr 16, 2023. It is now read-only.

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
aldolat committed Dec 9, 2018
2 parents 9de8c29 + 868b9d1 commit 1ac8732
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 14 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

## [5.0] - 2018-12-08
### Added
* Added `reverse` option to change the logic of the `recipient` option.

## [4.4] - 2018-10-20
### Changed
* Checked code against PHPCS.
Expand Down Expand Up @@ -83,6 +87,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
* First release of the plugin.

[Unreleased]: https://github.com/aldolat/private-content/commits/develop
[5.0]: https://github.com/aldolat/private-content/compare/4.4...5.0
[4.3]: https://github.com/aldolat/private-content/compare/4.3...4.4
[4.3]: https://github.com/aldolat/private-content/compare/4.2...4.3
[4.2]: https://github.com/aldolat/private-content/compare/4.1...4.2
Expand Down
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
**Tags:** content, private
**Requires at least:** 3.0
**Tested up to:** 5.0
**Stable tag:** 4.4
**Stable tag:** 5.0
**License:** GPLv3 or later
**License URI:** http://www.gnu.org/licenses/gpl-3.0.html

Expand Down Expand Up @@ -78,7 +78,7 @@ Display this text to Visitors only:

`[private role="visitor-only"]Text for Visitors only[/private]`

### Text only for a specific user ###
### Text only for a specific user or multiple users ###

In the case you want to show a text only to a specific user, assign `none` to `role` and a login name to `recipient`:

Expand All @@ -92,6 +92,13 @@ You can use a comma separated list of usernames to target certain users:

Change `login-name1`, `login-name2`, and `login-name3` with the correct login names of the target users.

### Text NOT for some users

If you want to show a text to all users but not to some, activate the option `reverse`, so that users added in the `recipient` option will not read the note.
For example.

`[private role="none" recipient="alice,bob,charlie" reverse=1]We all read this message while Alice, Bob, and Charlie can't read it![/private]`

### Alternate text for non-targeted users ###

If you want to show an alternate text in case the reader can't read, you can use:
Expand Down Expand Up @@ -235,7 +242,7 @@ Many thanks to:
[CHANGELOG]: ./CHANGELOG.md
[LICENSE]: ./gpl-3.0.txt
[README]: ./README.md
[version-badge]: https://img.shields.io/badge/Version-4.4-blue.svg
[version-badge]: https://img.shields.io/badge/Version-5.0-blue.svg
[requires-badge]: https://img.shields.io/badge/Requires_WordPress-3.0.0-green.svg
[tested-badge]: https://img.shields.io/badge/Tested_up_to_WordPress-5.0.0-green.svg
[license-badge]: https://img.shields.io/badge/License-GPLv3-ff69b4.svg
4 changes: 4 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
== Changelog ==

= 5.0 =

* Added `reverse` option to change the logic of the `recipient` option.

= 4.4 =

* Checked code against PHPCS.
Expand Down
4 changes: 2 additions & 2 deletions languages/private-content.pot
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# This file is distributed under the same license as the Private content package.
msgid ""
msgstr ""
"Project-Id-Version: Private content 4.3\n"
"Project-Id-Version: Private content 4.4\n"
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/private-content\n"
"POT-Creation-Date: 2018-10-20 05:41:25+00:00\n"
"POT-Creation-Date: 2018-12-08 07:21:05+00:00\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
Expand Down
30 changes: 23 additions & 7 deletions private-content.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Plugin URI: http://dev.aldolat.it/projects/private-content/
* Author: Aldo Latino
* Author URI: http://www.aldolat.it/
* Version: 4.4
* Version: 5.0
* License: GPLv3 or later
* Text Domain: private-content
* Domain Path: /languages/
Expand Down Expand Up @@ -159,7 +159,8 @@ function ubn_private_check_capability_exists() {
* "none". When using "none", you must specify a recipients list in $recipient.
* @type string $recipient The target role to view the note.
* It is used when $role = "none".
*
* @type bool $reverse Reverse the logic of recipient.
* If activated, users added in $recipient will not read the private note.
* @type string $align The alignment of text.
* It can be:
* "left"
Expand All @@ -180,6 +181,7 @@ function ubn_private_content( $atts, $content = null ) {
$defaults = array(
'role' => 'administrator', // The default role if none has been provided.
'recipient' => '',
'reverse' => false,
'align' => '',
'alt' => '',
'container' => 'p',
Expand All @@ -189,6 +191,7 @@ function ubn_private_content( $atts, $content = null ) {

$role = $atts['role'];
$recipient = $atts['recipient'];
$reverse = $atts['reverse'];
$align = $atts['align'];
$alt = $atts['alt'];
$container = $atts['container'];
Expand Down Expand Up @@ -393,12 +396,25 @@ function ubn_private_content( $atts, $content = null ) {
case 'none':
$all_recipients = array_map( 'trim', explode( ',', $recipient ) );
$current_user = wp_get_current_user();
if ( in_array( $current_user->user_login, $all_recipients, true ) ) {
$text = $container_open . ' class="private user-content user-only ' . esc_attr( $current_user->user_login ) . '-only"' . $align_style . '>' . $content . $container_close;
if ( $reverse ) {
// Reverse the logic of the function. Users added in recipient WILL NOT see the private note.
if ( in_array( $current_user->user_login, $all_recipients, true ) ) {
$text = '';
if ( $alt ) {
$text = $container_open . ' class="private alt-text"' . $align_style . '>' . $alt . $container_close;
}
} else {
$text = $container_open . ' class="private user-content user-only-reverse"' . $align_style . '>' . $content . $container_close;
}
} else {
$text = '';
if ( $alt ) {
$text = $container_open . ' class="private alt-text"' . $align_style . '>' . $alt . $container_close;
// The standard logic of the function. Users added in recipient WILL see the private note.
if ( in_array( $current_user->user_login, $all_recipients, true ) ) {
$text = $container_open . ' class="private user-content user-only ' . esc_attr( $current_user->user_login ) . '-only"' . $align_style . '>' . $content . $container_close;
} else {
$text = '';
if ( $alt ) {
$text = $container_open . ' class="private alt-text"' . $align_style . '>' . $alt . $container_close;
}
}
}
break;
Expand Down
13 changes: 11 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Donate link: https://dev.aldolat.it/projects/private-content/
Tags: content, private
Requires at least: 3.0
Tested up to: 5.0
Stable tag: 4.4
Stable tag: 5.0
License: GPLv3 or later
License URI: http://www.gnu.org/licenses/gpl-3.0.html

Expand All @@ -24,6 +24,8 @@ As of version 4.0 you can mark a text as visible to multiple users, using their

As of version 4.3 you can use either the usual `private` shortcode or the extra `ubn_private`, in case the first is already in use.

As of version 5.0 you can use the new option `reverse` to change the logic of the `recipient` option. If `reverse` is activated, it will not allow users in recipient read the private note.

= Usage =

Display this text to Administrators:
Expand Down Expand Up @@ -73,7 +75,7 @@ Display this text to Visitors only:

`[private role="visitor-only"]Text for Visitors only[/private]`

= Text only for a specific user =
= Text only for a specific user or multiple users =

In the case you want to show a text only to a specific user, assign `none` to `role` and a login name to `recipient`:

Expand All @@ -87,6 +89,13 @@ You can use a comma separated list of usernames to target certain users:

Change `login-name1`, `login-name2`, and `login-name3` with the correct login names of the target users.

= Text NOT for some users =

If you want to show a text to all users but not to some, activate the option `reverse`, so that users added in the `recipient` option will not read the note.
For example.

`[private role="none" recipient="alice,bob,charlie" reverse=1]We all read this message while Alice, Bob, and Charlie can't read it![/private]`

= Alternate text for non-targeted users =

If you want to show an alternate text in case the reader can't read, you can use:
Expand Down

0 comments on commit 1ac8732

Please sign in to comment.