173 lines
15 KiB
PHP
173 lines
15 KiB
PHP
<?php
|
|
/**
|
|
* @snippet WooCommerce Add Provision Info Tab
|
|
* @author Ross Trottier
|
|
*/
|
|
|
|
// 1. Register new endpoint (URL) for My Account page
|
|
// Note: Re-save Permalinks or it will give 404 error
|
|
add_action('init', 'register_federated_my_account_styles');
|
|
function register_federated_my_account_styles() {
|
|
wp_register_style( 'my-account', '/wp-content/plugins/fed-comp-customizations/css/federated-my-account.css' );
|
|
wp_register_style( 'my-account-sidebar', '/wp-content/plugins/fed-comp-customizations/css/federated-my-account-sidebar.css' );
|
|
}
|
|
add_action( 'wp_enqueue_scripts', 'conditionally_enqueue_federated_my_account_styles_scripts' );
|
|
function conditionally_enqueue_federated_my_account_styles_scripts() {
|
|
if ( is_page('my-account') ) {
|
|
wp_enqueue_style( 'my-account' );
|
|
wp_enqueue_style( 'my-account-sidebar' );
|
|
}
|
|
}
|
|
|
|
function federated_provision_info_endpoint() {
|
|
add_rewrite_endpoint( 'provision-info', EP_ROOT | EP_PAGES );
|
|
}
|
|
|
|
add_action( 'init', 'federated_provision_info_endpoint' );
|
|
|
|
// 2. Add new query var
|
|
|
|
function federated_provision_info_query_vars( $vars ) {
|
|
$vars[] = 'provision-info';
|
|
return $vars;
|
|
}
|
|
|
|
add_filter( 'query_vars', 'federated_provision_info_query_vars', 0 );
|
|
|
|
// 3. Insert the new endpoint into the My Account menu
|
|
|
|
function federated_add_provision_info_link_my_account( $items ) {
|
|
unset($items['downloads']);
|
|
unset($items['edit-address']);
|
|
return $items;
|
|
}
|
|
|
|
add_filter( 'woocommerce_account_menu_items', 'federated_add_provision_info_link_my_account' );
|
|
|
|
// 4. Add content to the new tab
|
|
add_action( 'woocommerce_account_content', 'federated_provision_info_content', 1 );
|
|
function federated_provision_info_content() {
|
|
global $wp;
|
|
$home_url = home_url();
|
|
$this_page_url = add_query_arg( $wp->query_vars, $home_url );
|
|
if($this_page_url != $home_url . '?page&pagename=my-account'){
|
|
return;
|
|
}
|
|
|
|
$user = wp_get_current_user();
|
|
|
|
// Loop through user subscriptions
|
|
foreach ( wcs_get_users_subscriptions($user->ID) as $subscription ) {
|
|
if($subscription->has_status( 'active' )){
|
|
echo_subscription_info($subscription);
|
|
}
|
|
}
|
|
}
|
|
|
|
function echo_subscription_info($subscription){
|
|
$subscription_id = $subscription->ID;
|
|
$domain = get_field('domain', $subscription_id);
|
|
$domain_status = get_field('domain_status', $subscription_id);
|
|
$provision_status = get_field('provision_status', $subscription_id);
|
|
$initial_admin_password = get_field('initial_admin_password', $subscription_id);
|
|
|
|
$tier = get_subscription_tier($subscription);
|
|
|
|
if(!empty($domain) && $provision_status === 'provisioned'){
|
|
echo '<div class="bg-white px-6 py-24 sm:py-32 lg:px-8">';
|
|
echo '<div class="mx-auto max-w-2xl text-center">';
|
|
echo '<h2 class="text-4xl font-bold tracking-tight text-gray-900 sm:text-6xl">Apps for ' . $domain . '</h2>';
|
|
echo '<p class="mt-6 text-lg leading-8 text-gray-600">Click the links below to access your apps. Also, check out our helpful articles here for tips and tutorials on how to use these amazing open source tools.</p>';
|
|
if($domain_status === 'default'){
|
|
echo '<p class="mt-6 text-lg leading-8 text-gray-600">This is a default domain, please do not change your admin password until you have switched to your custom domain.</p>';
|
|
}
|
|
echo '<p class="mt-6 text-lg leading-8 text-gray-600"><b>Admin Username:</b> admin@' . $domain . ' \\ <b>Initial Admin Password:</b> ' . $initial_admin_password . '</p>';
|
|
echo '</div>';
|
|
echo '</div>';
|
|
echo_links($tier, $domain);
|
|
} else if($provision_status === 'needs_provision' || $provision_status === 'provisioning') {
|
|
echo '<div class="bg-white px-6 py-24 sm:py-32 lg:px-8">';
|
|
echo '<div class="mx-auto max-w-2xl text-center">';
|
|
echo '<h2 class="text-4xl font-bold tracking-tight text-gray-900 sm:text-6xl">Welcome To Federated, Your Core is being provisioned as we speak.</h2>';
|
|
echo '<p class="mt-6 text-lg leading-8 text-gray-600">Your Federated Core is your very own, we provision each one made-to-order. Your apps, on your server, without having to share with anyone else. This only takes about 5 - 10 minutes, please check back shortly.</p>';
|
|
echo '</div>';
|
|
echo '</div>';
|
|
}
|
|
}
|
|
|
|
function echo_links($tier, $domain){
|
|
//echo container
|
|
echo '<div class="divide-y divide-gray-200 overflow-hidden rounded-lg bg-gray-200 shadow sm:grid sm:grid-cols-2 sm:gap-px sm:divide-y-0">';
|
|
if($tier === 'starter' || $tier === 'creator' || $tier === 'team' || $tier === 'enterprise'){
|
|
echo_base_app_links($domain);
|
|
}
|
|
if($tier === 'creator' || $tier === 'team' || $tier === 'enterprise'){
|
|
echo_creator_app_links($domain);
|
|
}
|
|
if($tier === 'team' || $tier === 'enterprise'){
|
|
echo_team_app_links($domain);
|
|
}
|
|
if($tier === 'enterprise'){
|
|
echo_enterprise_app_links($domain);
|
|
}
|
|
echo '</div>';
|
|
}
|
|
|
|
function echo_base_app_links($domain){
|
|
echo_link_for_core_app($domain, 'panel', 'User Management', 'teal', '<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6"><path stroke-linecap="round" stroke-linejoin="round" d="M16.5 12a4.5 4.5 0 1 1-9 0 4.5 4.5 0 0 1 9 0Zm0 0c0 1.657 1.007 3 2.25 3S21 13.657 21 12a9 9 0 1 0-2.636 6.364M16.5 12V8.25" /></svg>', 'Use panel to create users for your core. The first default user is your admin user.');
|
|
echo_link_for_core_app($domain, 'nextcloud', 'Email, File Storage, and Documents', 'purple', '<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6"><path stroke-linecap="round" stroke-linejoin="round" d="M9 3.75H6.912a2.25 2.25 0 0 0-2.15 1.588L2.35 13.177a2.25 2.25 0 0 0-.1.661V18a2.25 2.25 0 0 0 2.25 2.25h15A2.25 2.25 0 0 0 21.75 18v-4.162c0-.224-.034-.447-.1-.661L19.24 5.338a2.25 2.25 0 0 0-2.15-1.588H15M2.25 13.5h3.86a2.25 2.25 0 0 1 2.012 1.244l.256.512a2.25 2.25 0 0 0 2.013 1.244h3.218a2.25 2.25 0 0 0 2.013-1.244l.256-.512a2.25 2.25 0 0 1 2.013-1.244h3.859M12 3v8.25m0 0-3-3m3 3 3-3" /></svg>', 'Use Nextcloud for Email, File Storage, Project Management, Documents, and more.');
|
|
echo_link_for_core_app($domain, 'vaultwarden', 'Password Management', 'sky', '<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6"><path stroke-linecap="round" stroke-linejoin="round" d="M16.5 10.5V6.75a4.5 4.5 0 1 0-9 0v3.75m-.75 11.25h10.5a2.25 2.25 0 0 0 2.25-2.25v-6.75a2.25 2.25 0 0 0-2.25-2.25H6.75a2.25 2.25 0 0 0-2.25 2.25v6.75a2.25 2.25 0 0 0 2.25 2.25Z" /></svg>', 'Manage Passwords with Vaultwarden');
|
|
}
|
|
|
|
function echo_creator_app_links($domain){
|
|
echo_link_for_core_app($domain, 'element', 'Team Chat', 'yellow', '<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6"><path stroke-linecap="round" stroke-linejoin="round" d="M20.25 8.511c.884.284 1.5 1.128 1.5 2.097v4.286c0 1.136-.847 2.1-1.98 2.193-.34.027-.68.052-1.02.072v3.091l-3-3c-1.354 0-2.694-.055-4.02-.163a2.115 2.115 0 0 1-.825-.242m9.345-8.334a2.126 2.126 0 0 0-.476-.095 48.64 48.64 0 0 0-8.048 0c-1.131.094-1.976 1.057-1.976 2.192v4.286c0 .837.46 1.58 1.155 1.951m9.345-8.334V6.637c0-1.621-1.152-3.026-2.76-3.235A48.455 48.455 0 0 0 11.25 3c-2.115 0-4.198.137-6.24.402-1.608.209-2.76 1.614-2.76 3.235v6.226c0 1.621 1.152 3.026 2.76 3.235.577.075 1.157.14 1.74.194V21l4.155-4.155" /></svg>', 'Chat with your team using Element and Matrix.');
|
|
echo_link_for_core_app($domain, '', 'Website', 'rose', '<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6"><path stroke-linecap="round" stroke-linejoin="round" d="M12 21a9.004 9.004 0 0 0 8.716-6.747M12 21a9.004 9.004 0 0 1-8.716-6.747M12 21c2.485 0 4.5-4.03 4.5-9S14.485 3 12 3m0 18c-2.485 0-4.5-4.03-4.5-9S9.515 3 12 3m0 0a8.997 8.997 0 0 1 7.843 4.582M12 3a8.997 8.997 0 0 0-7.843 4.582m15.686 0A11.953 11.953 0 0 1 12 10.5c-2.998 0-5.74-1.1-7.843-2.918m15.686 0A8.959 8.959 0 0 1 21 12c0 .778-.099 1.533-.284 2.253m0 0A17.919 17.919 0 0 1 12 16.5c-3.162 0-6.133-.815-8.716-2.247m0 0A9.015 9.015 0 0 1 3 12c0-1.605.42-3.113 1.157-4.418" /></svg>', 'Create the website of your dreams with WordPress.');
|
|
}
|
|
|
|
function echo_team_app_links($domain){
|
|
echo_link_for_core_app($domain, 'espocrm', 'CRM', 'indigo', '<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6"><path stroke-linecap="round" stroke-linejoin="round" d="M18 18.72a9.094 9.094 0 0 0 3.741-.479 3 3 0 0 0-4.682-2.72m.94 3.198.001.031c0 .225-.012.447-.037.666A11.944 11.944 0 0 1 12 21c-2.17 0-4.207-.576-5.963-1.584A6.062 6.062 0 0 1 6 18.719m12 0a5.971 5.971 0 0 0-.941-3.197m0 0A5.995 5.995 0 0 0 12 12.75a5.995 5.995 0 0 0-5.058 2.772m0 0a3 3 0 0 0-4.681 2.72 8.986 8.986 0 0 0 3.74.477m.94-3.197a5.971 5.971 0 0 0-.94 3.197M15 6.75a3 3 0 1 1-6 0 3 3 0 0 1 6 0Zm6 3a2.25 2.25 0 1 1-4.5 0 2.25 2.25 0 0 1 4.5 0Zm-13.5 0a2.25 2.25 0 1 1-4.5 0 2.25 2.25 0 0 1 4.5 0Z" /></svg>', 'Perfect your sales pipeline with EspoCRM.');
|
|
echo_link_for_core_app($domain, 'freescout', 'Helpdesk', 'sky', '<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6"><path stroke-linecap="round" stroke-linejoin="round" d="M18 18.72a9.094 9.094 0 0 0 3.741-.479 3 3 0 0 0-4.682-2.72m.94 3.198.001.031c0 .225-.012.447-.037.666A11.944 11.944 0 0 1 12 21c-2.17 0-4.207-.576-5.963-1.584A6.062 6.062 0 0 1 6 18.719m12 0a5.971 5.971 0 0 0-.941-3.197m0 0A5.995 5.995 0 0 0 12 12.75a5.995 5.995 0 0 0-5.058 2.772m0 0a3 3 0 0 0-4.681 2.72 8.986 8.986 0 0 0 3.74.477m.94-3.197a5.971 5.971 0 0 0-.94 3.197M15 6.75a3 3 0 1 1-6 0 3 3 0 0 1 6 0Zm6 3a2.25 2.25 0 1 1-4.5 0 2.25 2.25 0 0 1 4.5 0Zm-13.5 0a2.25 2.25 0 1 1-4.5 0 2.25 2.25 0 0 1 4.5 0Z" /></svg>', 'Provide amazing customer support with FreeScout.');
|
|
}
|
|
|
|
function echo_enterprise_app_links($domain){
|
|
echo_link_for_core_app($domain, 'jitsi', 'Video Chat', 'zinc', '<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6"><path stroke-linecap="round" stroke-linejoin="round" d="m15.75 10.5 4.72-4.72a.75.75 0 0 1 1.28.53v11.38a.75.75 0 0 1-1.28.53l-4.72-4.72M4.5 18.75h9a2.25 2.25 0 0 0 2.25-2.25v-9a2.25 2.25 0 0 0-2.25-2.25h-9A2.25 2.25 0 0 0 2.25 7.5v9a2.25 2.25 0 0 0 2.25 2.25Z" /></svg>', 'Host secure video calls with your clients and team.');
|
|
echo_link_for_core_app($domain, 'listmonk', 'Email Marketing', 'pink', '<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6"><path stroke-linecap="round" stroke-linejoin="round" d="M21.75 9v.906a2.25 2.25 0 0 1-1.183 1.981l-6.478 3.488M2.25 9v.906a2.25 2.25 0 0 0 1.183 1.981l6.478 3.488m8.839 2.51-4.66-2.51m0 0-1.023-.55a2.25 2.25 0 0 0-2.134 0l-1.022.55m0 0-4.661 2.51m16.5 1.615a2.25 2.25 0 0 1-2.25 2.25h-15a2.25 2.25 0 0 1-2.25-2.25V8.844a2.25 2.25 0 0 1 1.183-1.981l7.5-4.039a2.25 2.25 0 0 1 2.134 0l7.5 4.039a2.25 2.25 0 0 1 1.183 1.98V19.5Z" /></svg>', 'Boost sales and engagement with ListMonk.');
|
|
echo_link_for_core_app($domain, 'baserow', 'Visual Databases', 'yellow', '<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6"><path stroke-linecap="round" stroke-linejoin="round" d="M20.25 6.375c0 2.278-3.694 4.125-8.25 4.125S3.75 8.653 3.75 6.375m16.5 0c0-2.278-3.694-4.125-8.25-4.125S3.75 4.097 3.75 6.375m16.5 0v11.25c0 2.278-3.694 4.125-8.25 4.125s-8.25-1.847-8.25-4.125V6.375m16.5 0v3.75m-16.5-3.75v3.75m16.5 0v3.75C20.25 16.153 16.556 18 12 18s-8.25-1.847-8.25-4.125v-3.75m16.5 0c0 2.278-3.694 4.125-8.25 4.125s-8.25-1.847-8.25-4.125" /></svg>', 'Maintain your data, or build a back end for your next web app with Baserow.');
|
|
echo_link_for_core_app($domain, 'bookstack', 'Wiki Documentation', 'amber', '<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6"><path stroke-linecap="round" stroke-linejoin="round" d="M12 6.042A8.967 8.967 0 0 0 6 3.75c-1.052 0-2.062.18-3 .512v14.25A8.987 8.987 0 0 1 6 18c2.305 0 4.408.867 6 2.292m0-14.25a8.966 8.966 0 0 1 6-2.292c1.052 0 2.062.18 3 .512v14.25A8.987 8.987 0 0 0 18 18a8.967 8.967 0 0 0-6 2.292m0-14.25v14.25" /></svg>', 'Create and maintain beautiful documentation for your personal knowledge, company processes, and more.');
|
|
echo_link_for_core_app($domain, 'gitea', 'GIT Source Control', 'emerald', '<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6"><path stroke-linecap="round" stroke-linejoin="round" d="M17.25 6.75 22.5 12l-5.25 5.25m-10.5 0L1.5 12l5.25-5.25m7.5-3-4.5 16.5" /></svg>', 'Manage your repos and CI/CD with confidence using GiTea source control.');
|
|
echo_link_for_core_app($domain, 'castopod', 'Podcast Broadcasting', 'yellow', '<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6"><path stroke-linecap="round" stroke-linejoin="round" d="M12 18.75a6 6 0 0 0 6-6v-1.5m-6 7.5a6 6 0 0 1-6-6v-1.5m6 7.5v3.75m-3.75 0h7.5M12 15.75a3 3 0 0 1-3-3V4.5a3 3 0 1 1 6 0v8.25a3 3 0 0 1-3 3Z" /></svg>', 'Keep your audience engaged and aggregate your podcast easily with Castopod.');
|
|
}
|
|
|
|
function echo_link_for_core_app($domain, $subdomain = '', $app_title = '', $color = 'emerald', $svg = '', $app_description = ''){
|
|
$url = '';
|
|
if (isset($subdomain) && $subdomain !== '') {
|
|
$url = $subdomain . '.' . $domain;
|
|
} else {
|
|
$url = $domain;
|
|
}
|
|
echo '<div class="divide-y divide-gray-200 overflow-hidden rounded-lg bg-gray-200 shadow sm:grid sm:grid-cols-2 sm:gap-px sm:divide-y-0">';
|
|
echo '<div class="rounded-tl-lg rounded-tr-lg sm:rounded-tr-none group relative bg-white p-6 focus-within:ring-2 focus-within:ring-inset focus-within:ring-indigo-500">';
|
|
echo '<div>';
|
|
echo '<span class="inline-flex rounded-lg p-3 bg-' . $color . '-50 text-' . $color . '-700 ring-4 ring-white">';
|
|
echo $svg;
|
|
echo '</span>';
|
|
echo '</div>';
|
|
echo '<div class="mt-8">';
|
|
echo '<h3 class="text-base font-semibold leading-6 text-gray-900">';
|
|
echo '<a href="https://' . $url . '" class="focus:outline-none" target="_blank">';
|
|
echo '<span class="absolute inset-0" aria-hidden="true"></span>';
|
|
echo $app_title;
|
|
echo '</a>';
|
|
echo '</h3>';
|
|
echo '<p class="mt-2 text-sm text-gray-500">' . $app_description . '</p>';
|
|
echo '</div>';
|
|
echo '<span class="pointer-events-none absolute right-6 top-6 text-gray-300 group-hover:text-gray-400" aria-hidden="true">';
|
|
echo '<svg class="h-6 w-6" fill="currentColor" viewBox="0 0 24 24">';
|
|
echo '<path d="M20 4h1a1 1 0 00-1-1v1zm-1 12a1 1 0 102 0h-2zM8 3a1 1 0 000 2V3zM3.293 19.293a1 1 0 101.414 1.414l-1.414-1.414zM19 4v12h2V4h-2zm1-1H8v2h12V3zm-.707.293l-16 16 1.414 1.414 16-16-1.414-1.414z" />';
|
|
echo '</svg>';
|
|
echo '</span>';
|
|
echo '</div>';
|
|
}
|
|
|
|
add_action( 'woocommerce_account_provision-info_endpoint', 'federated_provision_info_content' );
|
|
// Note: add_action must follow 'woocommerce_account_{your-endpoint-slug}_endpoint' format
|