Skip to content

Commit

Permalink
Removed Env dependency, added redirect URL directly into theme custom…
Browse files Browse the repository at this point in the history
…izer, markup fixes, added favicon
  • Loading branch information
biohzrdmx committed Aug 5, 2024
1 parent aa52db0 commit e6b524a
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 25 deletions.
7 changes: 3 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "vecode/headless-theme",
"description": "Headless theme, for headless WordPress instances.",
"version": "1.0",
"version": "1.1",
"type": "wordpress-theme",
"license": "MIT",
"authors": [
Expand All @@ -14,8 +14,7 @@
"require": {
"php": ">=8.1",
"ext-mbstring": "*",
"composer/installers": "^2.2",
"oscarotero/env": "^2.1"
"composer/installers": "^2.2"
},
"minimum-stability": "stable"
}
}
10 changes: 10 additions & 0 deletions favicon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 11 additions & 1 deletion functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,14 @@
false => __('Enabled'),
],
]);
});
$wp_customize->add_setting( 'headless_redirect_url' , [
'default' => null,
'transport' => 'refresh',
]);
$wp_customize->add_control('headless_redirect_url', [
'label' => __('Redirect URL'),
'section' => 'headless_options',
'settings' => 'headless_redirect_url',
'type' => 'url'
]);
});
58 changes: 40 additions & 18 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,49 @@
global $wp_customize;

$in_customizer = isset( $wp_customize );
$redirect = Env\env('REDIRECT_URL') ?? null;
$redirect = get_theme_mod('headless_redirect_url', null);
if (!$redirect) {
wp_die('Redirect not defined, please add a REDIRECT_URL entry in your ENV file.');
wp_die('Redirect not defined, please set the redirect URL in the theme customizer.');
}
if (! $in_customizer ):
if ( $in_customizer || is_user_logged_in() ):
?>
<meta content="0; URL='<?php echo $redirect ?>'" http-equiv="refresh">
<script type="text/javascript">
window.location = '<?php echo $redirect ?>';
</script>
<?php else: ?>
<html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Headless</title>
<link rel="icon" href="<?php echo get_template_directory_uri() ?>/favicon.svg">
<style>
body { background: #FFF; height: 100%; display: flex; flex-direction: column; margin: 0; }
section { flex: 1 0 0; text-align: center; display: flex; font-display: column; justify-content: center; align-items: center; }
img { max-width: 100%; height: auto; }
html { height: 100vh; }
body { background: #FFF; height: 100%; display: flex; flex-direction: column; margin: 0; font-family: system-ui, sans-serif; font-weight: normal; }
section { flex: 1 0 0; text-align: center; display: flex; justify-content: center; align-items: center; }
img { max-width: 100%; height: auto; }
a { text-decoration: none; color: #222; transition: all 350ms; }
a span { position: relative; transition: all 350ms ease-out; display: inline-block; }
a:hover { text-decoration: none; color: #1976D2; }
a:hover span { transform: translateX(0.25rem); }
</style>
<body>
<section>
</head>
<body>
<section>
<div>
<img src="<?php echo get_template_directory_uri() ?>/logo.svg" width="640" alt="">
</section>
</body>
</html>
<?php endif ?>
<?php if (! $in_customizer ): ?>
<p><a href="<?php echo admin_url() ?>"> <?php _e('Go to the dashboard') ?> <span>&rarr;</span></a></p>
<?php endif ?>
</div>
</section>
</body>
</html>
<?php else: ?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta content="0; URL='<?php echo $redirect ?>'" http-equiv="refresh">
<script type="text/javascript">
window.location = '<?php echo $redirect ?>';
</script>
</head>
</html>
<?php endif; ?>
4 changes: 2 additions & 2 deletions style.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
* Theme Name: Headless
* Description: Headless theme, for headless WordPress instances.
* Author: Vecode
* Version: 1.0
*/
* Version: 1.1
*/

0 comments on commit e6b524a

Please sign in to comment.