| Server IP : 3.147.158.171 / Your IP : 216.73.216.216 Web Server : Apache/2.4.67 (Amazon Linux) OpenSSL/3.5.5 System : Linux ip-172-31-2-178.us-east-2.compute.internal 6.1.172-216.329.amzn2023.x86_64 #1 SMP PREEMPT_DYNAMIC Wed May 20 06:31:34 UTC 2026 x86_64 User : ec2-user ( 1000) PHP Version : 8.4.21 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /tsai/repo/sites/example2/wp-content/plugins/tsai-plugin/ |
Upload File : |
<?php
/*
Plugin Name: tsai
Description: A plugin to add custom functionality.
Version: 1.1
Author: John Turman
*/
require_once 'Site.php';
/* [banner] */
function tsai_banner($atts) {
// error_log("tsai_banner");
$environment = defined('WP_ENV') ? WP_ENV : getenv('WP_ENV');
// $base = '/wp-content/uploads/tsai';
$secure = $environment === 'production';
$sites = [];
$host = ($secure) ? 'turmansolutions.ai' : 'turmansolutions.local';
$site = new Site(
'tsai',
$host,
'Turman Solutions',
$secure,
$host,
'tsai.png'
);
$sites[] = $site;
$host = ($secure) ? 'dev.turmansolutions.ai' : 'dev.turmansolutions.local';
$site = new Site(
'dev',
$host,
'Dev Central',
$secure,
$host,
'dev.png'
);
$sites[] = $site;
$host = ($secure) ? 'demo.turmansolutions.ai' : 'demo.turmansolutions.local';
$site = new Site(
'demo',
$host,
'Demo Site',
$secure,
$host,
'demo.png',
);
$sites[] = $site;
$host = ($secure) ? 'johnturman.net' : 'johnturman.local';
$site = new Site(
'jpt',
$host,
'John\'s Blog',
$secure,
$host,
'jpt.png',
);
$sites[] = $site;
$host = ($secure) ? 'sandbox.turmansolutions.ai' : 'sandbox.turmansolutions.local';
$site = new Site(
'sandbox',
$host,
'Sandbox',
$secure,
$host,
'sandbox.png'
);
$sites[] = $site;
$host = ($secure) ? 'news.turmansolutions.ai' : 'news.turmansolutions.local';
$site = new Site(
'news',
$host,
'News',
$secure,
$host,
'news.png'
);
$sites[] = $site;
$host = ($secure) ? 'autosave.turmansolutions.ai' : 'autosave.turmansolutions.local';
$site = new Site(
'autosave',
$host,
'Autosave',
$secure,
$host,
'autosave.png'
);
$sites[] = $site;
$out = '<span class="site"><div class="site-container"><h4>Affiliates</h4></div></span>';
foreach ($sites as $site) {
$out .= $site->display();
}
$div = '<div class="affiliates">'.$out .'</div>';
return $div;
}
add_shortcode('banner', 'tsai_banner');
/* [banner2] - Angular banner app in iframe with auto-resize */
function tsai_banner2($atts) {
$atts = shortcode_atts(array(
'width' => '100%',
'mode' => 'dark', // 'dark' or 'light'
), $atts);
$banner_url = content_url('uploads/tsai/banner/browser/index.html');
$banner_url .= '?mode=' . urlencode($atts['mode']);
// Add user login state and role
if (is_user_logged_in()) {
$user = wp_get_current_user();
$roles = $user->roles;
$primary_role = !empty($roles) ? $roles[0] : '';
$banner_url .= '&logged_in=1';
$banner_url .= '&role=' . urlencode($primary_role);
} else {
$banner_url .= '&logged_in=0';
}
$iframe_id = 'banner-iframe-' . uniqid();
$iframe = sprintf(
'<iframe id="%s" src="%s" style="width:%s; border:none; overflow:hidden; display:block;" frameborder="0" scrolling="no"></iframe>',
esc_attr($iframe_id),
esc_url($banner_url),
esc_attr($atts['width'])
);
$script = sprintf('<script>(function(){var iframe=document.getElementById("%s");if(!iframe)return;iframe.addEventListener("load",function(){var resize=function(){try{var doc=iframe.contentDocument||iframe.contentWindow.document;iframe.style.height="0";iframe.style.height=doc.documentElement.scrollHeight+"px";}catch(e){console.warn("Cannot access iframe content:",e);}};resize();try{var doc=iframe.contentDocument||iframe.contentWindow.document;var observer=new ResizeObserver(resize);observer.observe(doc.documentElement);}catch(e){console.warn("Cannot observe iframe content:",e);}});})();</script>', esc_js($iframe_id));
return $iframe . $script;
}
add_shortcode('banner2', 'tsai_banner2');
function tsai_styles() {
error_log("tsai_styles");
wp_enqueue_style(
'my-plugin-custom-styles', // handle
plugin_dir_url(__FILE__) . 'styles.css'
);
}
add_action('wp_enqueue_scripts', 'tsai_styles');