Java script to restrict content
-
Hi, I hope you can help me out. I’m not a java script developer, but through lots of searching and reading on my part I’ve tried to patch together some code to solve my problem.
The problem is this: When a user sees a post title link on the results from a search engine such as google, yahoo, bing, etc., and clicks on that link, I need our site to determine if that user has access to that content or not. Some of our content can be viewed by the public and some cannot. We have created a custom taxonomy called Role that is used to determine what content our users can view. If Role has the value of general-public, then the user can see the post content. If Role does not have that value, then the user must be redirected to our membership options page.
I’ve come up with the following code and created it through this plugin. I set the options to External File, Header, and In Frontend, although I’m not sure if that’s even correct. Can you help me with this?
$url = parse_url($_SERVER['HTTP_REFERER']); $sites = array('google','yahoo','bing'); foreach ($sites as $site) { if stristr($url['host'],$site) { $terms = get_the_terms( get_the_ID(), role ); if ( is_array( $terms ) && in_array( 'general-public', $terms ) ) { //do nothing } else { wp-redirect('https://www.mders.org/my-membership-options'); } } }
Thank you!
Gail
- The topic ‘Java script to restrict content’ is closed to new replies.