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);
?>