How to solve UnderConstructionPage without a plugin?

How to solve UnderConstructionPage without a plugin?

If I create a template, how to set functions.php and a button UnderConstructionPage without a purchased plugin?

Hi, the best way to do this without a plugin is to put the site into a simple maintenance mode via functions.php.

add_action('template_redirect', function () {
    if (current_user_can('manage_options') || is_user_logged_in()) {
        return; // this allows admins/editors through
    }

    if (!is_admin() && !in_array($GLOBALS['pagenow'], ['wp-login.php'])) {
        status_header(503);
        nocache_headers();
        include get_template_directory() . '/under-construction.php';
        exit;
    }
});

Then create under-construction.php in your theme with whatever HTML you want.
This will be site-wide. Let me know if you want a per-page solution instead.

What does it mean a per-page solution?

How to activate your PHP script or add a button within admin page under settings to push Under Construction page?

Instead of blocking the entire site, you block only individual pages.

Add the following to functions.php:

function uc_settings_page() { ?>
  <div class="wrap">
    <h1>Under Construction</h1>
    <form method="post" action="options.php">
      <?php settings_fields('uc_settings'); ?>
      <label>
        <input type="checkbox" name="uc_enabled" value="1" <?php checked(1, (int) get_option('uc_enabled')); ?>>
        Enable under construction mode
      </label>
      <?php submit_button('Save'); ?>
    </form>
  </div>
<?php }

add_action('admin_menu', function () {
  add_options_page(
    'Under Construction',
    'Under Construction',
    'manage_options',
    'under-construction',
    'uc_settings_page'
  );
});

add_action('admin_init', function () {
  register_setting('uc_settings', 'uc_enabled', [
    'type' => 'boolean',
    'sanitize_callback' => function ($v) { return (int) !!$v; },
    'default' => 0,
  ]);
});

add_action('template_redirect', function () {
  if (!(int) get_option('uc_enabled')) return;

  // Let admins + logged-in users see the real site
  if (current_user_can('manage_options') || is_user_logged_in()) return;

  status_header(503);
  nocache_headers();

  $file = get_stylesheet_directory() . '/under-construction.php';
  if (file_exists($file)) {
    include $file;
    exit;
  }

  wp_die('Under construction is enabled, but under-construction.php was not found in the active theme.');
});

Now under Settings > Under Construction you can toggle the mode on and off.

Don’t forget to add an under-construction.php to your theme directory:

<?php echo 'UNDER CONSTRUCTION'; ?>

Thank you for the message!