Siteβ―Builder
Editing:
BDO-Page-Maker.txt
writable 0666
<?php /* Plugin Name: BDO PageΒ Maker Description: Miniβsite builder for the Bestialone Multisite network. Each site (whose subβdirectory path is the 10βdigit phone number set by the βPhone Number Slug for Multisiteβ plugin) can create a handful of pages that are rendered to static HTML inside /{phone}/slug.html. Version: 0.2.0 Author: BestDealOnΒ DevΒ Team Network: true */ if ( ! defined( 'ABSPATH' ) ) { exit; // safety first } // βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ // 1. CONSTANTS // βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ // Absolute filesystem base where static miniβsites live. *No* trailing slash. // Adjust to your server root. if ( ! defined( 'BDO_PM_STATIC_BASE' ) ) { define( 'BDO_PM_STATIC_BASE', '/home/bestialone/public_html' ); } // βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ // 2. HELPERS // βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ /** * Fetch the 10βdigit phone number that identifies this site. * Priority: blogmeta βpns_phoneβ (added by Phone Number Slug plugin) β parse from path β fallback placeholder. */ function bdo_pm_get_phone_digits() : string { $blog_id = get_current_blog_id(); // Preferred: blogmeta (WPΒ β₯5.3) if ( function_exists( 'get_blog_meta' ) ) { $digits = get_blog_meta( $blog_id, 'pns_phone', true ); if ( $digits ) { return $digits; } } // Fallback: try to glean from the subβdirectory URL itself. $path = trim( parse_url( home_url( '/' ), PHP_URL_PATH ), '/' ); if ( preg_match( '/^(\\d{10})$/', $path, $m ) ) { return $m[1]; } return '0000000000'; // emergency placeholder so we never write outside BASE } /** * Absolute directory for this siteβs static pages (β¦/public_html/1234567890). */ function bdo_pm_static_dir() : string { return trailingslashit( BDO_PM_STATIC_BASE ) . bdo_pm_get_phone_digits(); } /** * Write static HTML file. Creates the directory if needed. */ function bdo_pm_write_static( string $slug, string $html ) : bool { $dir = bdo_pm_static_dir(); if ( ! wp_mkdir_p( $dir ) ) { error_log( '[BDO_PM] mkdir failed β ' . $dir ); return false; } $file = trailingslashit( $dir ) . $slug . '.html'; if ( file_put_contents( $file, $html ) === false ) { error_log( '[BDO_PM] write failed β ' . $file ); return false; } return true; } // βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ // 3. CUSTOM POST TYPE β one βbdo_pageβ = one static page // βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ function bdo_pm_register_cpt() { register_post_type( 'bdo_page', [ 'label' => 'MiniβSite Pages', 'public' => true, 'show_in_menu' => true, 'menu_icon' => 'dashicons-media-default', 'supports' => [ 'title', 'editor', 'thumbnail', 'excerpt', 'revisions' ], 'rewrite' => false, 'capability_type' => 'post', 'map_meta_cap' => true, ] ); } add_action( 'init', 'bdo_pm_register_cpt' ); // βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ // 4. STATIC RENDER on save/publish // βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ function bdo_pm_render_static( int $post_id, WP_Post $post ) { if ( wp_is_post_revision( $post_id ) || $post->post_type !== 'bdo_page' || $post->post_status !== 'publish' ) { return; } $slug = $post->post_name; $title = $post->post_title; // Render Gutenberg blocks, shortcodes, etc. $body = apply_filters( 'the_content', $post->post_content ); $body = bdo_pm_expand_placeholders( $body ); // VERY minimal template β replace with your branded header/footer. $html = '<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><title>' . esc_html( $title ) . '</title>' . '<style>body{font-family:system-ui,Arial,sans-serif;max-width:800px;margin:2rem auto;line-height:1.6;color:#333;padding:0 1rem;}img{max-width:100%;height:auto;}</style>' . '</head><body>' . $body . '</body></html>'; if ( bdo_pm_write_static( $slug, $html ) ) { update_post_meta( $post_id, '_bdo_pm_last_build', current_time( 'mysql' ) ); } } add_action( 'save_post_bdo_page', 'bdo_pm_render_static', 10, 2 ); /** * Replace simple placeholders such as {{PHONE}} in page content. */ function bdo_pm_expand_placeholders( string $html ) : string { $digits = bdo_pm_get_phone_digits(); $pretty = '('.substr($digits,0,3).') '.substr($digits,3,3).'-'.substr($digits,6); return str_replace( '{{PHONE}}', esc_html( $pretty ), $html ); } // βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ // 5. ADMIN βMiniβSite Builderβ screen β shows required pages // βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ function bdo_pm_admin_menu() { add_submenu_page( 'edit.php?post_type=bdo_page', 'MiniβSite Builder', 'MiniβSite Builder', 'edit_posts', 'bdo_pm_builder', 'bdo_pm_render_builder' ); } add_action( 'admin_menu', 'bdo_pm_admin_menu' ); function bdo_pm_render_builder() { $required = [ 'home', 'about', 'services', 'contact' ]; // tweak as needed $existing = get_posts( [ 'post_type' => 'bdo_page', 'numberposts' => -1, 'post_status' => [ 'publish', 'draft' ] ] ); $map = []; foreach ( $existing as $p ) $map[ $p->post_name ] = $p; echo '<div class="wrap"><h1>MiniβSite Builder</h1><table class="widefat"><thead><tr><th>Page</th><th>Status</th><th>Action</th></tr></thead><tbody>'; foreach ( $required as $slug ) { $page = $map[ $slug ] ?? null; echo '<tr>'; echo '<td>' . esc_html( ucfirst( $slug ) ) . '</td>'; if ( $page ) { $built = get_post_meta( $page->ID, '_bdo_pm_last_build', true ); echo '<td>Exists (' . esc_html( $page->post_status ) . ') | Last build: ' . esc_html( $built ?: 'β' ) . '</td>'; echo '<td><a class="button" href="' . esc_url( get_edit_post_link( $page->ID ) ) . '">Edit</a></td>'; } else { $url = admin_url( 'post-new.php?post_type=bdo_page&post_title=' . urlencode( ucfirst( $slug ) ) . '&post_name=' . $slug ); echo '<td><span style="color:#dc3232">Missing</span></td>'; echo '<td><a class="button button-primary" href="' . esc_url( $url ) . '">Create</a></td>'; } echo '</tr>'; } echo '</tbody></table></div>'; } // βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ // 6. CLEANβUP β remove static HTML if the page is deleted // βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ function bdo_pm_delete_static( int $post_id ) { $post = get_post( $post_id ); if ( $post->post_type !== 'bdo_page' ) return; $file = trailingslashit( bdo_pm_static_dir() ) . $post->post_name . '.html'; if ( file_exists( $file ) ) unlink( $file ); } add_action( 'before_delete_post', 'bdo_pm_delete_static' ); // End plugin ?>
Save changes
Create folder
writable 0777
Create
Cancel