Skip to content

Commit 50885fc

Browse files
committed
Use alternate address with ?toggleDev parameter
1 parent 115f646 commit 50885fc

File tree

1 file changed

+26
-16
lines changed

1 file changed

+26
-16
lines changed

template/functions/webpack_enqueue.php

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
2+
33
/**
44
* Enqueue Scripts & Development Toggle
55
*
@@ -9,38 +9,46 @@
99

1010
session_start();
1111

12-
global $dev_server;
13-
$dev_server = 'localhost';
1412

15-
if ( !isset($_SESSION['__devReload']) || !empty($_GET['toggleDev']) ) {
13+
if ( empty($_SESSION['__devReload']) ) {
1614
$_SESSION['__devReload'] = false;
17-
18-
if ( $_GET['toggleDev'] == 'true' ) {
19-
$_SESSION['__devReload'] = true;
15+
}
16+
17+
if ( !empty($_GET['toggleDev']) ) {
18+
if ( $_GET['toggleDev'] == 'false' ) {
19+
$_SESSION['__devReload'] = false;
20+
} else {
21+
$_SESSION['__devReload'] = $_GET['toggleDev'] == 'true' ? 'localhost:8080' : $_GET['toggleDev'];
2022
}
2123
}
2224

2325
function toggle_dev_button($wp_admin_bar){
2426
global $dev_server;
2527
if ( is_super_admin() ) {
26-
28+
2729
$indicator = '';
28-
29-
if ( $_SESSION['__devReload'] == true ) {
30+
31+
if ( !empty($_SESSION['__devReload']) ) {
3032
$color = '#E03E36';
31-
if ( $fp = @fsockopen($dev_server, '8080', $errCode, $errStr, 0.1) ) {
33+
34+
$matches = array();
35+
preg_match('/:(\d+)/', $_SESSION['__devReload'], $matches);
36+
$dev_port = $matches[1];
37+
38+
if ( $fp = @fsockopen($_SESSION['__devReload'], $dev_port, $errCode, $errStr, 0.1) ) {
3239
$color = '#2EAC6D';
3340
fclose($fp);
3441
}
42+
3543
$indicator = '<style>.dev-indicator:before { content: " "; position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: inherit; opacity: 0.2 }</style> <b class="dev-indicator" style="display: inline-block; vertical-align: middle; width: 1em; height: 1em; border-radius: 50%; margin-right: 0.5em; background: '.$color.'; position: relative;"></b>';
3644
}
37-
45+
3846
$wp_admin_bar->add_node(array(
3947
'id' => 'toggle-dev-button',
4048
'title' => $indicator . 'Turn Dev Refreshing ' . ( $_SESSION['__devReload'] == true ? 'Off' : 'On' ),
4149
'href' => '?toggleDev=' . ( $_SESSION['__devReload'] == true ? 'false' : 'true' )
4250
));
43-
51+
4452
}
4553
}
4654
add_action('admin_bar_menu', 'toggle_dev_button', 80);
@@ -49,9 +57,11 @@ function toggle_dev_button($wp_admin_bar){
4957
function vue_theme_scripts() {
5058
global $dev_server;
5159
$root = get_stylesheet_directory_uri();
52-
53-
if ( is_super_admin() && !empty($_SESSION) && $_SESSION['__devReload'] ) {
54-
wp_enqueue_script('main-dev', 'http://' . $dev_server . ':8080/assets/main.js', NULL, NULL, TRUE);
60+
61+
if (
62+
//is_super_admin() &&
63+
!empty($_SESSION) && $_SESSION['__devReload'] ) {
64+
wp_enqueue_script('main-dev', 'http://' . $_SESSION['__devReload'] . '/assets/main.js', NULL, NULL, TRUE);
5565
} else {
5666
wp_enqueue_style( 'main', $root . '/assets/style.css', NULL, THEME_VERSION, 'all' );
5767
wp_enqueue_script('vendor', $root . '/assets/vendor.js', NULL, THEME_VERSION, TRUE);

0 commit comments

Comments
 (0)