Skip to content
This repository has been archived by the owner on Sep 27, 2022. It is now read-only.

Enhancement - Shortcode Display Member Error Instead of Blank/Nothing #3

Closed
jconroy opened this issue Feb 17, 2013 · 10 comments
Closed

Comments

@jconroy
Copy link

jconroy commented Feb 17, 2013

Hi Justin,

Question / Enhancement - Do you think it would be worth displaying non members an error or message when viewing content hidden by one of the members shortcodes?

So for example if I use [is_user_logged_in] to wrap (and hide) some member only content - instead of just displaying nothing it might be nice to show one of the member error messages. Like so -> findingsimple@ef8b295

Perhaps for a nicer implementation the output could just be wrapped with a filter so that it can be hooked into within a theme or another plugin?

@justintadlock
Copy link
Owner

It shouldn't use members_get_post_error_message() since those are two unrelated things. The best bet is to provide a shortcode parameter that will display an error message.

@jconroy
Copy link
Author

jconroy commented May 16, 2013

I don't think they are that unrelated, slightly different but not unrelated - as its displaying an error message to users who can't view that post content instead of just nothing.

Even your comments for the 'members_get_post_error_message' function say "Gets the error message to display for users who do not have access to view the given post."

You've also got the handy 'members_post_error_message' filter there as well.

Perhaps a separate function would be useful to distinguish but it probably could be quite similar and/or take a shortcode parameter as well as you say.

@justintadlock
Copy link
Owner

Actually, they are very much unrelated. Technically, members_post_error_message() won't even work the same without the Content Permissions component activated. While I have separated the function out a bit in the 0.2 branch to make it more flexible, it's still tied to Content Permissions.

Nevertheless, members_post_error_message() is for an entire post error message. And, the shortcodes are for blocking out individual pieces of data, which may or may not be related to any particular post.

Just as an example of using one of the shortcodes in a theme header.php template (note that it's not tied to a post or post content at all):

<?php echo do_shortcode( '[is_user_logged_in]Do something.[/is_user_logged_in]' ); ?>

I hope that helps explain it a bit.

@jconroy
Copy link
Author

jconroy commented May 17, 2013

Gotcha - I see where you are going with it - especially in that particular use case - but If I'm someone that is able to edit the template (and understand the intricacies of how to do that) why would I use that shortcode (tied to the plugin) to hide the content? I could just use something like:

http://codex.wordpress.org/Function_Reference/is_user_logged_in

I would have assumed the shortcode would be most useful in a post/page situation?

Anyhoo, not a big issue just thought I'd post a question as it's something I found of use on a few sites as people typically want to show that they are hiding something.

Thanks for the discussion!

@justintadlock
Copy link
Owner

I'm not saying the user would edit a template. The above is showing how shortcodes are used outside the post content. A theme could have a shortcode-ready area, for example, and allow the user to add data to it via a theme option. With my own themes, this is a common thing.

Anyway, the feature you're asking about is definitely on the radar. I'm still thinking about using a shortcode parameter. But, I'm not sure about formatting the data passed through that parameter.

@drreen
Copy link

drreen commented Oct 15, 2015

Gonna dig this one out. Any chance you will add custom error messages which can be triiggered by shortcode parameter near future?

@justintadlock
Copy link
Owner

Here's some problems that must be overcome and tested.

Inline vs. block-level

The following is two example posts. As you can see, one usage is inline and the other is block-level.

Post #1:

Hello world! [members_access capability="read"]How are you doing?[/members_access]

Post #2:

Hello world!

[members_access capability="read"]How are you doing?[/members_access]

Content vs. parameter

You can add pretty much anything as the content of the shortcode, even HTML. However, you can't add anything to a parameter.

Allowed:

[members_access capability="read" error="What's up doc?"]<p>Oh, no! This is a paragraph.</p>[/members_access]

Not Allowed:

[members_access capability="read" error="<p>What's up doc?</p>"]<p>Oh, no! This is a paragraph.</p>[/members_access]

@justintadlock
Copy link
Owner

One idea might be to introduce an additional parameter, such as [members_access output="block"] where output could be block or inline. Or, something like that. It's pretty much a nasty way to do it, but I'm not sure what else to do to allow an error message while handling the block vs. inline content issue.

The other option might simply be to let users go for two separate shortcodes (one for each of the two groups of users). That seems easier to do.

@justintadlock
Copy link
Owner

Since Gutenberg is going to be the future editor, we should probably roll this into a custom access block. See: #198

@justintadlock
Copy link
Owner

Given the issues I outlined above with the shortcode system and that this feature will be available in the Block Permissions add-on (see early screenshot below), I'm closing this ticket.

Ultimately, the block editor is the way forward and provides the necessary flexiblity for properly handling this.

members-bp-003

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants