function tool_private_get_node($post_type, $posts, $is_hierarchical = false) { $go_private = get_option(TOOL_PRIVATE_OPTIONS_GO_PRIVATE, "0"); global $post; ?> <ul class="tool-private-box post-type-<?php echo $post_type; ?> "> <?php foreach ($posts as $post) { setup_postdata($post); ?> <li> <input class="tool-private-item" type="checkbox" id="tool-private-item-<?php the_ID(); ?> " name="tool-private-item-<?php the_ID(); ?> " <?php if (tool_private_is_private_post(get_the_ID()) && !empty($go_private) && $go_private == "2") { ?> checked="checked"<?php } ?> /> <label for="tool-private-item-<?php the_ID(); ?> "><?php the_title(); ?> </label> </li> <?php if ($is_hierarchical) { $sub_posts = get_pages(array("post_type" => $post_type, 'numberposts' => -1, "orderby" => "name", "order" => "ASC", "parent" => get_the_ID(), "suppress_filters" => false)); if (!empty($sub_posts)) { tool_private_get_node($post_type, $sub_posts, $is_hierarchical); } } wp_reset_postdata(); } ?> </ul> <?php }
/** * template_include filter (allow to override template hierarchy) * @return template path */ function private_template_include($template) { $post_id = get_the_id(); if (is_home()) { $post_id = get_option('page_for_posts'); } if (tool_private_is_private_post($post_id) && !is_user_logged_in()) { $private_template = locate_ressource(CUSTOM_PLUGIN_TOOLS_FOLDER . PRIVATE_TOOL_NAME . '/templates/tool-private-template.php'); if (!empty($private_template)) { $template = $private_template; } else { wp_redirect(wp_login_url(get_current_url(true))); } } return $template; }