Redirect before 404
-
Hello,
I have a big problem with a plugin I´m writing:
The visitor should be forwarded to a newsletter registration page, if he visits a post within a blocklist. Unfortunately the forwarding does not work for guests, but when I am logged in, everything works as it should be. The guests only see the 404 page.
The posts, on which this redirect should be fired, are in „draft“ status!public function newsletter_lock_redirect(){ if (is_single()) { $cid = $this->nse_get_campaign_id(); if(isset($_GET['origin'])) $origin = filter_var($_GET['origin'], FILTER_SANITIZE_STRING); global $post; global $wpdb; $post_tags = get_the_tags($post->ID); if (!$post_tags) return; $post_tags_array = json_decode(json_encode($post_tags), true); if (!$this->in_array_r($this->tag_name, $post_tags_array)) return; $query = 'SELECT * FROM '.$wpdb->newsletter_lock.' WHERE lock_postid = '.$post->ID.' AND lock_status = 1'; $locked = $wpdb->get_row($query, OBJECT); if(empty($locked)) return; if($locked->lock_status == "0") return; $permalink = get_post_permalink($this->location) . "&cid=" . $cid . "&origin=nl_locked"; wp_safe_redirect( $permalink, $this->status ); exit; } } add_action('template_redirect', array($this->public, 'newsletter_lock_redirect'), 10, 2);
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
The topic ‘Redirect before 404’ is closed to new replies.