Forum Replies Created

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter nightillusions

    (@wdjac)

    Hi Cristian,

    we can close this issue.
    After enabling the option “Disable dynamic translation” under “Advanced” settings, everything works fine.

    Thank you!

    Thread Starter nightillusions

    (@wdjac)

    Thank you for your advice!

    I think you may want to add $page && before checking if the status == draft to avoid logging warnings when $page is assigned null.

    Fully right 😉 Thanks!

    Thread Starter nightillusions

    (@wdjac)

    Okay I think this is a possible solution, but it feels kind of ugly:

    /**
         * Redirect if is a single page and newsletter tag is set
         */
        public function newsletter_lock_redirect(){
    	    global $wp_query;
    
    	    if($wp_query->is_404()) {
    
    		    $page = get_page_by_path( $wp_query->query_vars['name'], OBJECT, 'post' );
    		    if ( $page->post_status == 'draft' ) {
    			    $wp_query->is_404 = false;
    			    header("HTTP/1.1 200 OK");
    
    			    $cid = $this->nse_get_campaign_id();
    
    			    global $wpdb;
    
    			    $post_tags = get_the_tags( $page->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 = ' . $page->ID . ' AND lock_status = 1';
    			    $locked = $wpdb->get_row( $query, OBJECT );
    
    			    if ( empty( $locked ) ) {
    				    return;
    			    }
    
    			    if ( $locked->lock_status == "0" ) {
    				    return;
    			    }
    
    			    $permalink = $this->location . "?cid=" . $cid . "&origin=nl_locked";
    			    wp_safe_redirect( $permalink, $this->status );
    			    exit;
    		    }
    	    }
        }
    add_action('wp', array($this->public, 'newsletter_lock_redirect'));

    Now guests being redirected and admins not. But for me this is okay.
    What do you think?

    Thread Starter nightillusions

    (@wdjac)

    The draft status is required, because of other plugin logic.

    When I looked inside template-loader.php, where the hook is fired, I saw that this hook is before the 404 question elseif ( is_404() && $template = get_404_template() ) :.

    I also tried to use the “wp” hook:

    This hook is one effective place to perform any high-level filtering or validation, following queries, but before WordPress does any routing, processing, or handling.

    But for my plugin logic, it is highly needed to get the post ID at this moment. Do you have any solution for this?

    Thanks for your advice!

Viewing 4 replies - 1 through 4 (of 4 total)