Code Monkey home page Code Monkey logo

Comments (4)

intoxstudio avatar intoxstudio commented on August 11, 2024 1

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.

wturnerharris avatar wturnerharris commented on August 11, 2024

@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.

intoxstudio avatar intoxstudio commented on August 11, 2024

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.

Sanabria avatar Sanabria commented on August 11, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.