HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux wordpress-ubuntu-s-2vcpu-4gb-fra1-01 5.4.0-169-generic #187-Ubuntu SMP Thu Nov 23 14:52:28 UTC 2023 x86_64
User: root (0)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/linde/wp-content/plugins/lindevr-site-plugin/faqs/index.php
<?php
if ( ! defined( 'ABSPATH' ) ) {
    exit; // Exit if accessed directly
}




require_once( 'yoast.php' );
require_once( 'rest/helpers.php' );
require_once( 'rest/articles.php' );
require_once( 'rest/posts.php' );

/**
 * This function controls post visibility based on the ACF "post_visibility" field.
 * It blocks access to posts on the website when "post_visibility" is set to "lva-platform".
 * The restriction only applies to the "post" post type and triggers a 404 error for non-logged-in users.
 */
function block_lva_platform_faq_posts() {
    // Only proceed if we're on a single post page and the user is not logged in
    if (is_single() && !is_user_logged_in()) {
        $post = get_post();



        
        // Check if the current post type is "post" (exclude custom post types)
        if ($post->post_type !== 'linde_faq') {
            return;
        }

        // Get the value of the ACF "post_visibility" field for the current post
        $post_visibility = get_field('post_visibility', $post->ID);

        // Check if the post_visibility is set to "lva-platform"
        // If true, this post should only be visible on the LVA platform, not the website
        if ($post_visibility && $post_visibility["value"] === 'lva-platform') {
            global $wp_query;
            
            // Set the query to return a 404 status
            $wp_query->set_404();
            status_header(404);
            
            // Load the theme's 404 template
            include get_template_directory() . '/404.php';
            exit;
        }
    }
}

add_action('template_redirect', 'block_lva_platform_faq_posts');


// Add a new column to the admin post list
function linde_add_post_visibility_column($columns) {
    $columns['post_visibility'] = 'Post Visibility';
    return $columns;
}
add_filter('manage_posts_columns', 'linde_add_post_visibility_column');


function show_post_visibility_column($column, $post_id) {
    if ($column == 'post_visibility') {
        $visibility = get_field('post_visibility', $post_id);
        // defaults to show only on website
        echo !empty($visibility) ? esc_html($visibility['label']) : 'Show only on website';
    }
}
add_action('manage_posts_custom_column', 'show_post_visibility_column', 10, 2);





?>