Call a function I created?
-
Hi, I am not a php or js coder, but with a little help I’ve created the following php function using your plugin. I’m just not sure how to tell if it’s being called or do I need to place a call to this php function somewhere.
I need this run every time someone who is not logged in attempts to access content via a search engine referral. So if they clink on a link to content from Google, I need this function to run before displaying the content. Do I need to put a call to this function somewhere? If so where? I’ve created the function, but it doesn’t seem to be working (ie I can still access the restricted content without being forced to the members login page).
function redirect_from_search_engines() { $url = parse_url( $_SERVER['HTTP_REFERER'] ); $sites = array( 'google', 'yahoo', 'bing' ); foreach( $sites as $site ) { if ( ! stristr( $url['host'], $site ) ) continue; $terms = get_the_terms( get_the_ID(), 'role' ); if ( (! is_user_logged_in()) and ( ! is_array( $terms ) || ! in_array( 'general-public', $terms ) ) ) continue; wp-redirect('https://www.mders.org/my-membership-options'); } } add_action( 'wp', 'redirect_from_search_engines' );
Thank you!
- The topic ‘Call a function I created?’ is closed to new replies.