← Back
Editing: page-min-side.php
<?php /** * Template Name: My Page (Min Side) * Description: Displays authenticated user information */ if (!defined('ABSPATH')) { exit; // Prevent direct access } // Start session if not already started if (session_status() === PHP_SESSION_NONE) { session_start(); } class MyPage { private static $is_page_builder_used; /** * Initialize class properties */ public static function init() { self::$is_page_builder_used = et_pb_is_pagebuilder_used(get_the_ID()); } /** * Check if user is authenticated * @return bool */ private static function isAuthenticated(): bool { return isset($_SESSION['access_token']) && isset($_SESSION['token_expiry']) && $_SESSION['token_expiry'] > time(); } /** * Get user info from session * @return array|null */ private static function getUserInfo(): ?array { return $_SESSION['user_info'] ?? null; } /** * Render user information section */ private static function renderUserInfo($userInfo) { $fields = [ 'Id' => ['class' => 'id', 'label' => 'User ID'], 'email' => ['class' => 'email', 'label' => 'Email'], 'sub' => ['class' => 'sub', 'label' => 'Subject'], 'given_name' => ['class' => 'first-name', 'label' => 'First Name'], 'family_name' => ['class' => 'last-name', 'label' => 'Last Name'] ]; ?> <div class="api-user-info et_pb_section" style="display: none;"> <div class="et_pb_row"> <div class="et_pb_column et_pb_column_4_4"> <?php foreach ($fields as $key => $field) { if (!empty($userInfo[$key])) { printf( '<div class="user-info-item %s"><span class="label">%s:</span><span class="value">%s</span></div>', esc_attr($field['class']), esc_html($field['label']), esc_html($userInfo[$key]) ); } } if (!empty($_SESSION['token_expiry'])) { printf( '<div class="user-info-item token-expiry"><span class="label">%s:</span><span class="value">%s</span></div>', esc_html__('Session Expires', 'Divi'), esc_html(date('Y-m-d H:i:s', $_SESSION['token_expiry'])) ); } ?> </div> </div> </div> <?php if (defined('WP_DEBUG') && WP_DEBUG): ?> <div class="debug-info et_pb_section"> <div class="et_pb_row"> <div class="et_pb_column et_pb_column_4_4"> <h2><?php esc_html_e('Debug Information', 'Divi'); ?></h2> <pre><?php print_r($_SESSION); ?></pre> </div> </div> </div> <?php endif; } /** * Display the page content */ public static function displayPage() { if (!self::isAuthenticated()) { wp_safe_redirect(home_url('/login')); exit; } $userInfo = self::getUserInfo(); if (!$userInfo) { wp_die( wp_json_encode(['error' => 'User information not found']), 'Authentication Error', ['response' => 403] ); } get_header(); ?> <div id="main-content"> <?php if (!self::$is_page_builder_used) : ?> <div class="container"> <div id="content-area" class="clearfix"> <div id="left-area"> <?php endif; ?> <?php while (have_posts()) : the_post(); ?> <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>> <?php if (!self::$is_page_builder_used) : ?> <h1 class="entry-title main_title"><?php the_title(); ?></h1> <?php $thumb = ''; $width = (int) apply_filters('et_pb_index_blog_image_width', 1080); $height = (int) apply_filters('et_pb_index_blog_image_height', 675); $thumbnail = get_thumbnail($width, $height, 'et_featured_image', get_post_meta(get_post_thumbnail_id(), '_wp_attachment_image_alt', true), get_the_title(), false, 'Blogimage'); $thumb = $thumbnail["thumb"]; if ('on' === et_get_option('divi_page_thumbnails', 'false') && $thumb) { print_thumbnail($thumb, $thumbnail["use_timthumb"], $thumbnail["alttext"], $width, $height); } ?> <?php endif; ?> <div class="entry-content"> <?php the_content(); self::renderUserInfo($userInfo); if (!self::$is_page_builder_used) { wp_link_pages([ 'before' => '<div class="page-links">' . esc_html__('Pages:', 'Divi'), 'after' => '</div>' ]); } ?> </div> <?php if (!self::$is_page_builder_used && comments_open() && 'on' === et_get_option('divi_show_pagescomments', 'false')) { comments_template('', true); } ?> </article> <?php endwhile; ?> <?php if (!self::$is_page_builder_used) : ?> </div> <?php get_sidebar(); ?> </div> </div> <?php endif; ?> </div> <?php get_footer(); } } // Initialize and display page MyPage::init(); MyPage::displayPage();
Save File
Cancel