Files
OTSSigns-Website/wp-content/plugins/ots-signs-setup/ots-signs-setup.php
Matt Batchelder 9fddd43a2c Add custom page templates for Home, Contact, and Services
- Created a new Contact Page template with a contact form and information section.
- Developed a Home Page template featuring a hero section, core capabilities, and pricing details.
- Introduced a Services Page template outlining core services and industry solutions.
- Added a default page template for standard pages without a custom template.
- Implemented a single post template for displaying individual blog posts.
- Created a style.css file for theme metadata and styling.
2026-02-19 09:10:01 -05:00

140 lines
5.6 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
/**
* Plugin Name: OTS Signs One-Click Site Setup
* Description: Run once after importing pages and activating the OTS Signs theme. Sets the front page, creates the navigation menu, and configures site options. Delete this plugin when done.
* Version: 1.0.0
* Author: OTS Signs
*/
if ( ! defined( 'ABSPATH' ) ) exit;
// ─── Run setup on plugin activation ───────────────────────────────────────────
register_activation_hook( __FILE__, 'ots_setup_run' );
function ots_setup_run() {
// 1. Site identity
update_option( 'blogname', 'OTS Signs' );
update_option( 'blogdescription', 'The Complete Digital Signage Solution' );
// 2. Set reading settings — show a static front page
update_option( 'show_on_front', 'page' );
// 3. Find the pages by slug and set front/posts page
$home_page = get_page_by_path( 'home' );
if ( $home_page ) {
update_option( 'page_on_front', $home_page->ID );
}
// 4. Permalinks — set to post name
update_option( 'permalink_structure', '/%postname%/' );
flush_rewrite_rules();
// 5. Build the Primary navigation menu
ots_build_primary_menu();
// 6. Disable comments site-wide (marketing site)
update_option( 'default_comment_status', 'closed' );
update_option( 'default_ping_status', 'closed' );
// 7. Set timezone
update_option( 'timezone_string', 'America/New_York' );
// 8. Mark setup as done
update_option( 'ots_setup_done', '1' );
}
function ots_build_primary_menu() {
// Delete existing menu with same name if any
$existing = get_term_by( 'name', 'Primary Menu', 'nav_menu' );
if ( $existing ) {
wp_delete_nav_menu( $existing->term_id );
}
$menu_id = wp_create_nav_menu( 'Primary Menu' );
if ( is_wp_error( $menu_id ) ) return;
$menu_pages = [
[ 'slug' => 'home', 'label' => 'Home' ],
[ 'slug' => 'services', 'label' => 'Services' ],
[ 'slug' => 'about', 'label' => 'About' ],
[ 'slug' => 'contact', 'label' => 'Contact' ],
];
foreach ( $menu_pages as $item ) {
$page = get_page_by_path( $item['slug'] );
if ( ! $page ) continue;
wp_update_nav_menu_item( $menu_id, 0, [
'menu-item-title' => $item['label'],
'menu-item-object-id' => $page->ID,
'menu-item-object' => 'page',
'menu-item-type' => 'post_type',
'menu-item-status' => 'publish',
] );
}
// Assign menu to the 'primary' theme location
$locations = get_theme_mod( 'nav_menu_locations', [] );
$locations['primary'] = $menu_id;
set_theme_mod( 'nav_menu_locations', $locations );
}
// ─── Admin notice ─────────────────────────────────────────────────────────────
add_action( 'admin_notices', 'ots_setup_admin_notice' );
function ots_setup_admin_notice() {
if ( ! current_user_can( 'manage_options' ) ) return;
$done = get_option( 'ots_setup_done' );
?>
<div class="notice notice-<?php echo $done ? 'success' : 'warning'; ?> is-dismissible" style="padding:16px 20px;">
<?php if ( $done ) : ?>
<h3 style="margin:0 0 8px;">&#10003; OTS Signs Setup Complete!</h3>
<p style="margin:0 0 12px;">
Your site has been configured:<br>
&bull; Front page set to <strong>Home</strong><br>
&bull; Primary navigation menu created (Home, Services, About, Contact)<br>
&bull; Permalink structure set to <code>/%postname%/</code><br>
&bull; Comments disabled site-wide
</p>
<p style="margin:0;">
<a href="<?php echo esc_url( admin_url( 'plugins.php' ) ); ?>" class="button button-primary">Go to Plugins to delete this setup plugin</a>
&nbsp;<a href="<?php echo esc_url( home_url( '/' ) ); ?>" class="button" target="_blank">View Site</a>
</p>
<?php else : ?>
<h3 style="margin:0 0 8px;">OTS Signs Site Setup Required</h3>
<p style="margin:0 0 12px;">
The OTS Signs setup plugin is installed but hasn't run yet.
Make sure you have <strong>imported <code>ots-signs-import.xml</code></strong> via
<em>Tools → Import → WordPress</em> first, then deactivate and reactivate this plugin.
</p>
<p style="margin:0;">
<a href="<?php echo esc_url( admin_url( 'import.php' ) ); ?>" class="button button-primary">Go to Import</a>
</p>
<?php endif; ?>
</div>
<?php
}
// ─── Re-run button from plugin list ──────────────────────────────────────────
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'ots_setup_plugin_links' );
function ots_setup_plugin_links( $links ) {
$run_link = '<a href="' . esc_url( wp_nonce_url( admin_url( '?ots_rerun_setup=1' ), 'ots_rerun' ) ) . '" style="color:#2271b1;font-weight:600;">Re-run Setup</a>';
array_unshift( $links, $run_link );
return $links;
}
add_action( 'admin_init', 'ots_maybe_rerun_setup' );
function ots_maybe_rerun_setup() {
if ( ! isset( $_GET['ots_rerun_setup'] ) ) return;
if ( ! current_user_can( 'manage_options' ) ) return;
if ( ! wp_verify_nonce( $_GET['_wpnonce'], 'ots_rerun' ) ) return;
ots_setup_run();
wp_redirect( admin_url( 'plugins.php?ots_setup_reran=1' ) );
exit;
}