Comments (4)
Would it be sufficient with a method like user_has_access():boolean
?
Can you tell me more about the use case, e.g. why would you not use the built-in redirect/tease functionality on restricted content?
from restrict-user-access.
@intoxstudio - thanks for getting back.
Sometimes we need to know something about a page (and it's access level) before outputting its link or content. This needs to be separate from a user's access level.
global $post;
if ( empty( get_post_meta( $post->ID, "access_level", true ) ) {
// ...
}
In our particular case, we want to filter all links so that the direct link to protected content is never exposed. By this same logic, we can change the URL, say, to the login url with the redirect url query string.
For us, this also makes for a smoother user experience; i.e. click->login popup->redirected vs click->get redirected to login->login->redirected
from restrict-user-access.
Thanks for the clarification! Due to the way the restrictions/conditions are stored, it is currently not always feasable to get that info about a particular post/page. It is something I am working on, and this functionality would also allow automatically hiding/filtering restricted content from archives, lists, widgets etc.
If you restrict posts/pages individually (not by category, author, etc.) then you might be able to leverage something like this for now:
global $wpdb, $post;
//get levels current user doesnt have
$other_levels = array_diff(
array_keys(RUA_App::instance()->get_levels()),
rua_get_user_levels()
);
//get posts/page IDS that current user does not have access to
$post_ids = array_flip($wpdb->get_col("SELECT m.meta_value FROM $wpdb->postmeta m INNER JOIN $wpdb->posts p ON m.post_id = p.ID WHERE m.meta_key = '_ca_post_type' AND p.post_parent IN ('".implode("','", $other_levels)."')"));
if ( !isset($post_ids[$post->ID])) {
//display link
}
from restrict-user-access.
I have a similar problem: Is there a workaround to prevent protected terms from appearing to a user without access when looping through get_terms or get_categories?
from restrict-user-access.
Related Issues (20)
- show_admin_bar on / off always for all roles HOT 2
- Redirect to Login Landing Page HOT 1
- Fatal when using rua_get_level_caps() HOT 10
- Does your plugin limit REST API v2? HOT 1
- DepShield encountered errors while building your project HOT 1
- 404 after first page redirect
- Hide from category page HOT 1
- Shortcode for anonymous user
- Problems with redirecting HOT 1
- Can't bulk remove members from access level HOT 3
- Multiple Access to restricted section HOT 2
- 2.3.1 Update wp_get_current_user error HOT 1
- Restrict visibility of BuddyPress pages to a user's BuddyPress friends? HOT 1
- Redirects happen even when user can edit post
- Feature request: Manage object restriction on the edit page
- filtering in a loop HOT 1
- WPCAObjectManager not found HOT 1
- Buddypress Groups HOT 1
- Use RUA SVG icon in WP backend HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from restrict-user-access.